View Single Post
Join Date: Sep 2008
Posts: 2
Reputation: afolli is an unknown quantity at this point 
Solved Threads: 0
afolli afolli is offline Offline
Newbie Poster

Include Base64 encoded data into XML

 
0
  #1
Sep 11th, 2008
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:

  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.


  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
Reply With Quote