Web service answering multi-part

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Web service answering multi-part

Wayne Johnston
My application, and indeed it seems the whole SOAP framework, assumes that a web server will answer an XML string.  Well, I've hit a customer where the web server's response is multi-part.  That is, something like this:


HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Content-Type: multipart/related;start="<rootpart*57d54c0d>";type="application/xop+xml";boundary="uuid:7f379869f539";start-info="text/xml"
Date: Tue, 28 Mar 2017 21:36:32 GMT
Connection: close

--uuid:57d54c0d-7b7b-4020-8562-7f379869f539
Content-Id: <rootpart*57d54c0d>
Content-Type: application/xop+xml;charset=utf-8;type="text/xml"
Content-Transfer-Encoding: binary

<?xml version='1.0' encoding='UTF-8'?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body>

....lots of stuff removed...

</S:Body></S:Envelope>
--uuid:7f379869f539--


The header (first 5 lines) is no problem.  But SstWSSoapDeserializationHandler>>#invoke: creates a parser (AbtXmlMappingParser) asking it to parse everything from that first --uuid... line through the end, which it can't.  I don't see where to stick some multipart-aware code to end up with just that XML string.  Is there a good way to do this?  

--
You received this message because you are subscribed to the Google Groups "VA Smalltalk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/va-smalltalk.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Web service answering multi-part

Wayne Johnston
Note that SstHttpMultipartContentAssembler class>>#fromHeader: doesn't support such a complicated Content-Type; it assumes the boundary is after the first '='.

--
You received this message because you are subscribed to the Google Groups "VA Smalltalk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/va-smalltalk.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Web service answering multi-part

Wayne Johnston
Well, I happen to have a very convenient spot where I can put in some code to handle this.  Our application has a subclass of SstWSHttpDispatchHandler where we have our own #invoke:, and in there I can call this new method I came up with.


xmlStringFrom: anSstByteMessage
"This method exists since we need to pick out the XML string which might be buried in anSstByteMessage's contents.
See a test caller which demonstrates usefulness:
self test1 inspect  "

| boundary part bodyString ans xmlStartingIndex |

bodyString := anSstByteMessage contents asString. "entire contents string by default; in simple case it's the XML string"
(SstHttpAssembler new isMultipart: anSstByteMessage header) ifFalse: [^bodyString].
"Getting here means the header contentType is not nil; look for 'boundary=' in the contentType,
which states what the separator is between parts.
Note that SstHttpMultipartContentAssembler class>>#fromHeader: does not honor such a complicated example as ours."
boundary :=
anSstByteMessage header contentType readStream
upToAll: 'boundary="';
upTo: $".
boundary isNil ifTrue: [^bodyString].
"Standard is two dashes prior to that string"
boundary := '--' , boundary.
SstHttpMultipartContentAssembler new
boundary: boundary;
assemblePartsFrom: bodyString readStream onto: anSstByteMessage.
anSstByteMessage multipartContents isEmpty ifTrue: [^bodyString].
"assuming what we want is in the first part"
^(anSstByteMessage multipartContents at: 1) content

--
You received this message because you are subscribed to the Google Groups "VA Smalltalk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/va-smalltalk.
For more options, visit https://groups.google.com/d/optout.