0
votes

With Oracle ESB 11g, I need transform the structure of a webservice, but I have a problem with xml type, the source webservice has a type base64binary but my mockup is type string.

Source type

<xsd:element
name="MyDocument"
maxOccurs="1"
minOccurs="0"
type="xsd:base64Binary"
></xsd:element>

Destination type

<xs:element name="myBase64file" type="xs:string" minOccurs="0"/>

Why destination is String?? because my mockup in Java return a String

         InputStream stream =  this.getClass().getClassLoader().getResourceAsStream("doc3.pdf");
         byte[] bytes = IOUtils.toByteArray(stream);
         byte[] bytes64 = Base64.encodeBase64(bytes);
         myBase64file = new String(bytes64); 

But now the real service returns base64binary :(

With oepe (Eclipse more plugins for Oracle OSB) in XQuery Mapper I Tried put a hard transformation like this

 {
 for $MyDocument in $MyData/ns2:MyDocument
 return <myBase64file>{ data($MyDocument) }</myBase64file>
 }

Is this the correct way?

1

1 Answers

0
votes

I think to achieve your goal it's necessary to use the XQuery because you want to change the element name from myDocument to myBase64file, even if your destination element type was xs:base64Binary you need to execute your XQuery.

However a xs:base64Binary representation is basically a string limited to 65 alphabet characters: a-z, A-Z, 0-9, the plus sign (+), the forward slash (/) and the equal sign (=), together with the space character (#x20) (base64Binary), so you can think that xs:base64binary is an xs:string with an xs:restriction where you can only use the characters described above. Therefore if you prefer to have a xs:base64Binary instead of xs:string you can change your destination type to xs:base64Binary:

<xs:element name="myBase64file" type="xs:base64Binary" minOccurs="0"/>

and your java mockup code fits perfect this type because you are encoding your data to base64 and then returning as string.

Hope this helps,