| | |
Include Base64 encoded data into XML
Thread Solved |
•
•
Join Date: Sep 2008
Posts: 2
Reputation:
Solved Threads: 0
Hello,
I have to base64 encode a large quantity of data and include it in the XML response of the webservice.The WSDL define the XML element in the following way:
I have implemented it but I have some doubts. I'm not sure it's the better way for doing it.
What about performance if I have an attachment of 1MB? I'm specially worried about the "new String()" operation.
Any suggestion will be appreciated. Thanks,
Alessandro
I have to base64 encode a large quantity of data and include it in the XML response of the webservice.The WSDL define the XML element in the following way:
Java Syntax (Toggle Plain Text)
<xs:complexType name="MessagePart"> <xs:simpleContent> <xs:extension base="xs:base64Binary"> <xs:attribute name="contentType" type="xs:string" default="text/plain" use="optional"/> <xs:attribute name="length" type="xs:int" default="0" use="optional"/> <xs:attribute name="offset" type="xs:int" default="0" use="optional"/> </xs:extension> </xs:simpleContent> </xs:complexType>
I have implemented it but I have some doubts. I'm not sure it's the better way for doing it.
Java Syntax (Toggle Plain Text)
import org.apache.commons.codec.binary.Base64; ... OMElement part = factory.createOMElement("part", emptyNs); part.addAttribute("length", this.attachment.getLength(), null); byte[] value = Base64.encodeBase64(this.attachment.getValue()); part.setText( new String(value) );
What about performance if I have an attachment of 1MB? I'm specially worried about the "new String()" operation.
Any suggestion will be appreciated. Thanks,
Alessandro
•
•
Join Date: Sep 2008
Posts: 2
Reputation:
Solved Threads: 0
In fact I'm encoding binary data. Actually, I have changed it in the following way.
Alessandro
Java Syntax (Toggle Plain Text)
import com.sun.xml.rpc.encoding.simpletype.XSDBase64BinaryEncoder; ... OMElement part = factory.createOMElement("part", emptyNs); part.addAttribute("length", "" + this.attachment.getLength() + "",null); part.setText(XSDBase64BinaryEncoder.getInstance().objectToString( this.attachment.get_value() , null ));
Alessandro
![]() |
Other Threads in the Java Forum
- Previous Thread: Need Help on calling classes
- Next Thread: Guys I Need help about explaining the code of this PEMDAS calculator.
| Thread Tools | Search this Thread |
911 addball addressbook android api append applet application apps array arrays automation binary bluetooth businessintelligence button card character class client code collision component crashcourse css csv database eclipse ee error fractal free game gis givemetehcodez graphics gui html ide image integer integration j2me japplet java javaarraylist javadoc javafx javaprojects jni jpanel julia jvm linux list loan machine map method methods migrate mobile netbeans newbie objects oriented output panel phone physics problem program programming project projects radio recursion replaydirector reporting researchinmotion scanner se server service set sms software sort sql string swing test textfield threads transfer tree trolltech ubuntu utility windows






