Reputation: 47
I am accessing one of the web-services from our vendor which takes a pageID and returns data in xml format.
When I access the web-service on browser, the format of xml after I key in pageID is as below
<EpsBinaryEx xmlns="http://Eprise">
<ErrorString>No Error</ErrorString>
<ErrorNum>1</ErrorNum>
<Data>ajhsdjasjajadjhgasd</Data>
</EpsBinaryEx>
Am interested in retrieving the element. This is actually a Base64 string. I have a method for EpsBinaryEx which is returning data in below form
public JAXBElement<byte[]> getData() {
return data;
}
Using Java, am reading the webservice as below
PSWebService service = new PSWebService();
PSWebServiceSoap soap = service.getPSWebServiceSoap();
EpsBinaryEx base64Data = soap.getUploadedDocument(token, pageId);
System.out.println(base64Data.getData.getValue());
Instead of the base64 string, am getting output as [B@27e80064, which looks like some offset address.
Can you please let me know how to read the JABXElement element? getData.getValue() doesn't seem to work :(
Any help would be greatly appreciated.
Thanks.
Upvotes: 0
Views: 1761
Reputation: 8562
getValue()
returns byte[]
, so your println the array id not the content.
user Arrays.toString(base64Data.getData.getValue()))
or
new String(base64Data.getData.getValue()))
to print the content.
You can also think over your design. I would keep the Data mapped as string in your jaxb bean, and add the method getDataDecoded() that would transform them to the byte[] using Base64 decoding, so no need for JAXBElement
@XmlRootElement
public class EpsBinaryEx {
@XmlElement(name="ErrorString")
String errorString;
@XmlElement(name="ErrorNum")
int errorNum;
@XmlElement(name="Data")
String encoded;
@XmlTransient
byte[] decoded;
void afterUnmarshal(Unmarshaller u, Object parent) {
decoded = Base64.decode(encoded);
}
boolean beforeMarshal(Marshaller m) {
encoded = Base64.encode(decoded);
return true;
}
public byte[] getData() {
return decoded;
}
public void setData(byte[] d) {
decoded = d;
}
}
Upvotes: 1