943,662 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Marked Solved
  • Views: 2592
  • Java RSS
Sep 11th, 2008
0

Include Base64 encoded data into XML

Expand Post »
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:

Java Syntax (Toggle Plain Text)
  1. <xs:complexType name="MessagePart">
  2. <xs:simpleContent>
  3. <xs:extension base="xs:base64Binary">
  4. <xs:attribute name="contentType" type="xs:string" default="text/plain" use="optional"/>
  5. <xs:attribute name="length" type="xs:int" default="0" use="optional"/>
  6. <xs:attribute name="offset" type="xs:int" default="0" use="optional"/>
  7. </xs:extension>
  8. </xs:simpleContent>
  9. </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)
  1. import org.apache.commons.codec.binary.Base64;
  2. ...
  3.  
  4. OMElement part = factory.createOMElement("part", emptyNs);
  5. part.addAttribute("length", this.attachment.getLength(), null);
  6. byte[] value = Base64.encodeBase64(this.attachment.getValue());
  7. 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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
afolli is offline Offline
2 posts
since Sep 2008
Sep 12th, 2008
0

Re: Include Base64 encoded data into XML

Why are you encoding textual data? Base64 is primarily meant to encode binary data.
Super Moderator
Featured Poster
Reputation Points: 3233
Solved Threads: 719
Failure as a human
~s.o.s~ is offline Offline
8,871 posts
since Jun 2006
Sep 16th, 2008
0

Re: Include Base64 encoded data into XML

In fact I'm encoding binary data. Actually, I have changed it in the following way.

Java Syntax (Toggle Plain Text)
  1. import com.sun.xml.rpc.encoding.simpletype.XSDBase64BinaryEncoder;
  2. ...
  3. OMElement part = factory.createOMElement("part", emptyNs);
  4. part.addAttribute("length", "" + this.attachment.getLength() + "",null);
  5. part.setText(XSDBase64BinaryEncoder.getInstance().objectToString( this.attachment.get_value() , null ));

Alessandro
Reputation Points: 10
Solved Threads: 0
Newbie Poster
afolli is offline Offline
2 posts
since Sep 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Need Help on calling classes
Next Thread in Java Forum Timeline: Guys I Need help about explaining the code of this PEMDAS calculator.





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC