soap TO rest APIGEE

I have proxy which convert soap to rest. I observed that, when i get the response data with Base64 encoded then Apigee policy "XML to JSON" does not convert my response FROM SOAP to JSON. I see "XML to JSON" return XML response only. Though it convert XML to JSON if i don't have base64 data in response. 

0 7 371
7 REPLIES 7

Hi Nitesh,

Can you tell me.... what is the content-type header, in the case where you see "response data with Base64" ?

The XMLToJSON policy will not convert a message, if the content-type header is not application/xml or text/xml.  If you have something else, then you may need to manually modify that header, to forcibly set it to have an acceptable value, before the XMLtoJSON step executes.  You can do that with an AssignMessage like this: 

<AssignMessage name='AM-OverrideContentType'>
  <AssignTo>NameOfMessageHere</AssignTo>
  <Set> 
    <Headers>
      <Header name='content-type'>text/xml</Header>
    </Headers>
  </Set>
</AssignMessage>

 

@dchiesa1  Here is the Content-Type my target webservice is returning "  multipart/related; boundary=MIMEBoundaryurn_uuid_FE481460ACFA6FBD351625772148980; start-info="text/xml"; type="application/xop+xml"; start="<0.urn:uuid:FE481460ACFA6FBD351625772148981@apache.org>"
Can you please help how i can handle above response Content-Type in Apigee?

ok, this is why the XMLToJSON is not converting the message to JSON.  It's a multipart message!

 

i have a callout that can help with this. Will update here shortly. 

 

@dchiesa1 I also see in response target application is returning PDF as a attachment. not sure how to handle this in Apigee

Can you check this callout to see if it helps? https://github.com/DinoChiesa/Apigee-Java-XOP-Handler

This callout will let you extract the SOAP portion of a XOP message.  You said you wanted to transform the XML to JSON.  If you extract the SOAP portion, you can then configure the proxy to create a new message, and pass THAT to the XMLToJSON policy to transform it in the way you described. 

I am unsure what you want to do with the PDF attachment. The callout doesn't do anything with the attachment. I might be able to help with that, but you'll need to clarify your desires and requirements there. 

@dchiesa1 Thanks for details, I'll go over to callout and regarding the attachment here is my requirement.
I have created proxy which does REST to SOAP to REST. When i am making call to my target server in response server returns the success along with PDF attachment and content type is "  multipart/related; boundary=MIMEBoundaryurn_uuid_FE481460ACFA6FBD351625772148980; start-info="text/xml"; type="application/xop+xml"; start="<0.urn:uuid:FE481460ACFA6FBD351625772148981@apache.org>".. 
I need to read the response and convert to JSON and also need to return the PDF back to caller. 

OK I understand what you've written.  But I don't understand how you plan to return both the JSON and the PDF to the original caller.  What is your idea here? 

XOP refers to XML binary Optimized Processing, about which you can read here. In short, this standard was defined as part of the SOAP-related specifications, as a way to allow transmission of a SOAP document, which contains a binary image (like a PDF, PNG, ZIP etc) in an optimized manner.

XOP describes how to format a single HTTP message, which contains multiple parts. One part is an XML document, another part is the binary file.  The XML document refers to the binary attachment via an agreed-upon mechanism. That's XOP. The benefit of XOP is you no longer need to base64-encode the binary blob directly into the XML document.  You can instead insert a reference element into the XML document, which points to the binary attachment.  The IBM tech article describes this well here.

There is no analogue, that I know of, that describes how to package JSON and a binary attachment in an HTTP message.  

I understand you have said "I want to convert the XML to JSON, and send the JSON and the PDF attachment to the caller." But how?  What form do you expect the response message to take?  Do you have an idea here?

EDIT: 2021 Jul 12  1407

As a start, I've modified the callout to add a new capability: It processes the XOP Package, base64 encodes the attachment, and embeds that encoded data into the XML document. An example follows.

The input, which is a "XOP Package", looks like this: 

 

--MIME_boundary
Content-Type: application/soap+xml; charset=UTF-8
Content-ID: <rootpart@soapui.org>

<S:Envelope xmlns:S='http://schemas.xmlsoap.org/soap/envelope/'>
  <S:Body>
    <GenericRequest xmlns='http://www.oracle.com/UCM' webKey='cs'>
      <Service IdcService='CHECKIN_UNIVERSAL'>
        <Document>
          <Field name='dDocType'>Application</Field>
          <Field name='dDocTitle'>filename.zip</Field>
          <File name='primaryFile' href='5D7541BA-04FD-4FF8'>
            <Contents>
              <Include
                  xmlns='http://www.w3.org/2004/08/xop/include' href='cid:0b83cd6b-af15-45d2-bbda-23895de2a73d'/>
            </Contents>
          </File>
        </Document>
      </Service>
    </GenericRequest>
  </S:Body>
</S:Envelope>

--MIME_boundary
Content-Type: application/zip
Content-Transfer-Encoding: binary
Content-ID: <0b83cd6b-af15-45d2-bbda-23895de2a73d>

...binary zip data...

--MIME_boundary--

 

and the output looks like this: 

 

<S:Envelope xmlns:S='http://schemas.xmlsoap.org/soap/envelope/'>
  <S:Body>
    <GenericRequest xmlns='http://www.oracle.com/UCM' webKey='cs'>
      <Service IdcService='CHECKIN_UNIVERSAL'>
        <Document>
          <Field name='dDocType'>Application</Field>
          <Field name='dDocTitle'>filename.zip</Field>
          <File name='primaryFile' href='5D7541BA-04FD-4FF8'>
            <Contents>....base64 content here....</Contents>
          </File>
        </Document>
      </Service>
    </GenericRequest>
  </S:Body>
</S:Envelope>

 

You could do THAT, then follow it with an XMLToJSON policy to transform a XOP package into a readable JSON message. It would look like this:

 

{
    "Envelope": {
        "Body": {
            "GenericRequest": {
                "webKey": "cs",
                "Service": {
                    "IdcService": "CHECKIN_UNIVERSAL",
                    "Document": {
                        "Field": [
                            {
                                "name": "dDocType",
                                "": "Application"
                            },
                            {
                                "name": "dDocTitle",
                                "": "multipart-handler-master.zip"
                            }
                        ],
                        "File": {
                            "href": "af75b881-f028-4781-8c3e-35c1c2403444",
                            "name": "primaryFile",
                            "Contents": "...base64 encoded content here..."
                        }
                    }
                }
            }
        }
    }
}

 

If you use this, The caller will need to base64-decode the correct field in the JSON to get the attached file.