You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ws.apache.org by Anirban Majumdar <an...@altair.com> on 2010/10/26 14:29:42 UTC

Building SOAP Message from Chunked Response

Hi,

 

I am using an abstraction over HTTPClient i.e. Camel-Http component to
communicate with a remote Webservice.

The remote Webservice handles attachments without using MTOM.

I called a method on the Webservice which returns an inline base64
encoded attachment with it.

As the remote Webservice is unaware of the length of the attachment, it
sends it in chunked form

 

The response with chunked data looks like this in TCPMon.

 

2000

<?xml version="1.0" ?><S:Envelope
xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><ns2:GetFile
Response
xmlns:ns2="http://www.example.org/Danger/"><xmlPayload>LlJNRgAAABIAAQAAA
AAAAAAGUFJPUAAAADIAAAAAUMAAA

AAAAAAAAAAQbG9naWNhbC1maWxlaW5mbwAAAj8AAAI/AAAAAAAAAAsAAAAaAAAJSW5kZXhhY
mxlAAAAAAAEAAAAAQA

:

:

:

2000

UKLJli8cAss/98U+OllJQfyuNI7/qg6b2gzlQ4GKDNv0iBMnUFGD/nVAqQWklZ0W956TkEUT
bQKYf/aCS9J6VDPppbVDrRmKz4P3pima

:

:

:

AAAAAAAAABAAAAAA==</xmlPayload></ns2:GetFileResponse></S:Body></S:Envelo
pe>

0

 

 

At the client side, I am using axiom's StAXSOAPModelBuilder to build a
SOAP structure.

The StaxSOAPModelBuilder only returns the first chunk when I retrieved
the attachment using following code.

 

DataHandler dataHandler = null;

OMText omText = null;

 

omText = (OMText) omElement.getFirstOMChild();

omText.setBinary(true);

dataHandler = (DataHandler) omText.getDataHandler();

 

As per my understanding the white space after the chunk de-limiters
could be a reason for getting the first chunk only.

 

Please suggest how to get the whole attachment when the response is sent
as chunked by the remote Webservice.

 

Thanks,

--------

anirban

 


RE: Building SOAP Message from Chunked Response

Posted by Martin Gainty <mg...@hotmail.com>.
/* implementing StAXOMBuilder you can call the next method to determine the node-type e.g. */

    public int next() throws OMException {
        try {
            // We need a loop here because we may decide to skip an event
            while (true) {
                if (done) {
                    throw new OMException();
                }
                int token = parserNext();
                if (!cache) {
                    return token;
                }
               
                // The current token should be the same as the 
                // one just obtained.  This bit of code is used to 
                // detect invalid parser state.
                if (doTrace) {
                    int currentParserToken = parser.getEventType();
                    if (currentParserToken != token) {
    
    
                        log.debug("WARNING: The current state of the parser is not equal to the " +
                                  "state just received from the parser. The current state in the paser is " +
                                  XMLEventUtils.getEventTypeString(currentParserToken) + " the state just received is " +
                                  XMLEventUtils.getEventTypeString(token));
    
                        /*
                          throw new OMException("The current token " + token + 
                                         " does not match the current event " +
                                         "reported by the parser token.  The parser did not update its state correctly.  " +
                                         "The parser is " + parser);
                         */
                    }
                }
                
                // Now log the current state of the parser
                if (doTrace) {
                    logParserState();
                }
               
                switch (token) {
                    case XMLStreamConstants.START_ELEMENT:  //7
                        elementLevel++;
                        lastNode = createNextOMElement();
                        break;
                    case XMLStreamConstants.CHARACTERS:   //4
                        lastNode = createOMText(XMLStreamConstants.CHARACTERS);
                        break;
                    case XMLStreamConstants.CDATA:   //12
                        lastNode = createOMText(XMLStreamConstants.CDATA);
                        break;
                    case XMLStreamConstants.END_ELEMENT:      // 2
                        endElement();
                        elementLevel--;
                        break;
                    case XMLStreamConstants.END_DOCUMENT:    // 8
                        done = true;
                        ((OMContainerEx) this.document).setComplete(true);
                        break;
                    case XMLStreamConstants.SPACE:                // 6
                        try {
                            lastNode = createOMText(XMLStreamConstants.SPACE);
                        } catch (OMHierarchyException ex) {
                            // The OM implementation doesn't allow text nodes at the current
                            // position in the tree. Since it is only whitespace, we can safely
                            // skip this event.
                            continue;
                        }
                        break;
                    case XMLStreamConstants.COMMENT:      // 5
                        lastNode = createComment();
                        break;
                    case XMLStreamConstants.DTD:               // 11
                        createDTD();
                        break;
                    case XMLStreamConstants.PROCESSING_INSTRUCTION:      // 3
                        lastNode = createPI();
                        break;
                    case XMLStreamConstants.ENTITY_REFERENCE:      // 9
                        lastNode = createOMText(XMLStreamConstants.ENTITY_REFERENCE);
                        break;
                    default :
                        throw new OMException();
                }
                return token;
            }
        } catch (XMLStreamException e) {
            throw new OMException(e);
        }
    }

    /**
     * Pushes the virtual parser ahead one token.
     * If a look ahead token was calculated it is returned.
     * @return next token
     * @throws XMLStreamException
     */
    private int parserNext() throws XMLStreamException {
        if (lookAheadToken >= 0) {
            int token = lookAheadToken;
            lookAheadToken = -1; // Reset
            return token;
        } else {
            if (parserException != null) {
                log.warn("Attempt to access a parser that has thrown a parse exception before; " +
                        "rethrowing the original exception.");
                if (parserException instanceof XMLStreamException) {
                    throw (XMLStreamException)parserException;
                } else {
                    throw (RuntimeException)parserException;
                }
            }
            try {
                return parser.next();
            } catch (XMLStreamException ex) {
                parserException = ex;
                throw ex;
            }
        }
    }

/* where XMLStreamReader.next is defined as
 
int
next()



          Get next parsing event - a processor may return all contiguous
 character data in a single chunk, or it may split it into several 
chunks.
*/

/* to implement single-chunk reads/writes your class will extend org.apache.axiom.util.stax.WrappedTextNodeStreamReader take a look at these examples: */

org.apache.axiom.util.stax.debug.UnclosedReaderDetector
http://ws.apache.org/commons/axiom/apidocs/org/apache/axiom/util/stax/debug/UnclosedReaderDetector.html

org.apache.axiom.util.stax.dialect.BEAStreamReaderWrapper
http://www.jarvana.com/jarvana/view/org/apache/ws/commons/axiom/axiom-api/1.2.9/axiom-api-1.2.9.jar!/org/apache/axiom/util/stax/dialect/BEADialect.class?classDetails=ok

org.apache.axiom.util.stax.dialect.DisallowDoctypeDeclStreamReaderWrapper
http://www.jarvana.com/jarvana/view/org/apache/ws/commons/axiom/axiom-api/1.2.9/axiom-api-1.2.9.jar!/org/apache/axiom/util/stax/dialect/DisallowDoctypeDeclStreamReaderWrapper.class?classDetails=ok

org.apache.axiom.util.stax.dialect.NamespaceContextCorrectingXMLStreamReaderWrapper
http://www.jarvana.com/jarvana/view/org/apache/ws/commons/axiom/axiom-api/1.2.9/axiom-api-1.2.9.jar!/org/apache/axiom/util/stax/dialect/NamespaceContextCorrectingXMLStreamReaderWrapper.class?classDetails=ok

org.apache.axiom.util.stax.dialect.SJSXPStreamReaderWrapper
http://www.jarvana.com/jarvana/view/org/apache/ws/commons/axiom/axiom-api/1.2.9/axiom-api-1.2.9-sources.jar!/org/apache/axiom/util/stax/dialect/BEAStreamReaderWrapper.java?format=ok

org.apache.axiom.util.stax.dialect.WoodstoxStreamReaderWrapper
http://www.jarvana.com/jarvana/view/org/apache/ws/commons/axiom/axiom-api/1.2.9/axiom-api-1.2.9-sources.jar!/org/apache/axiom/util/stax/dialect/WoodstoxStreamReaderWrapper.java?format=ok

org.apache.axiom.util.stax.dialect.XLXPStreamReaderWrapper
http://www.jarvana.com/jarvana/view/org/apache/ws/commons/axiom/axiom-api/1.2.9/axiom-api-1.2.9-sources.jar!/org/apache/axiom/util/stax/dialect/XLXPStreamReaderWrapper.java?format=ok

org.apache.axiom.util.stax.xop.XOPDecodingStreamReader
http://www.jarvana.com/jarvana/view/org/apache/ws/commons/axiom/axiom-api/1.2.9/axiom-api-1.2.9-javadoc.jar!/org/apache/axiom/util/stax/xop/XOPDecodingStreamReader.html

org.apache.axiom.om.xpath.AXIOMXPathTestBase
http://www.jarvana.com/jarvana/view/org/apache/ws/commons/axiom/axiom-api/1.2.9/axiom-api-1.2.9-tests.jar!/org/apache/axiom/om/xpath/AXIOMXPathTestBase.class?classDetails=ok

/* a partial analysis of your requirement */

Saludos Cordiales desde EEUU
Martin 
______________________________________________ 
Verzicht und Vertraulichkeitanmerkung
 
Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen.






> From: andreas.veithen@gmail.com
> Date: Sat, 30 Oct 2010 10:35:17 +0200
> Subject: Re: Building SOAP Message from Chunked Response
> To: dev@ws.apache.org
> 
> Can you show us a bit more of your code, in particular how it creates
> the StAXSOAPModelBuilder?
> 
> Andreas
> 
> On Tue, Oct 26, 2010 at 14:29, Anirban Majumdar
> <an...@altair.com> wrote:
> > Hi,
> >
> >
> >
> > I am using an abstraction over HTTPClient i.e. Camel-Http component to
> > communicate with a remote Webservice.
> >
> > The remote Webservice handles attachments without using MTOM.
> >
> > I called a method on the Webservice which returns an inline base64 encoded
> > attachment with it.
> >
> > As the remote Webservice is unaware of the length of the attachment, it
> > sends it in chunked form
> >
> >
> >
> > The response with chunked data looks like this in TCPMon.
> >
> >
> >
> > 2000
> >
> > <?xml version="1.0" ?><S:Envelope
> > xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><ns2:GetFileResponse
> > xmlns:ns2="http://www.example.org/Danger/"><xmlPayload>LlJNRgAAABIAAQAAAAAAAAAGUFJPUAAAADIAAAAAUMAAA
> >
> > AAAAAAAAAAQbG9naWNhbC1maWxlaW5mbwAAAj8AAAI/AAAAAAAAAAsAAAAaAAAJSW5kZXhhYmxlAAAAAAAEAAAAAQA
> >
> > :
> >
> > :
> >
> > :
> >
> > 2000
> >
> > UKLJli8cAss/98U+OllJQfyuNI7/qg6b2gzlQ4GKDNv0iBMnUFGD/nVAqQWklZ0W956TkEUTbQKYf/aCS9J6VDPppbVDrRmKz4P3pima
> >
> > :
> >
> > :
> >
> > :
> >
> > AAAAAAAAABAAAAAA==</xmlPayload></ns2:GetFileResponse></S:Body></S:Envelope>
> >
> > 0
> >
> >
> >
> >
> >
> > At the client side, I am using axiom’s StAXSOAPModelBuilder to build a SOAP
> > structure.
> >
> > The StaxSOAPModelBuilder only returns the first chunk when I retrieved the
> > attachment using following code.
> >
> >
> >
> > DataHandler dataHandler = null;
> >
> > OMText omText = null;
> >
> >
> >
> > omText = (OMText) omElement.getFirstOMChild();
> >
> > omText.setBinary(true);
> >
> > dataHandler = (DataHandler) omText.getDataHandler();
> >
> >
> >
> > As per my understanding the white space after the chunk de-limiters could be
> > a reason for getting the first chunk only.
> >
> >
> >
> > Please suggest how to get the whole attachment when the response is sent as
> > chunked by the remote Webservice.
> >
> >
> >
> > Thanks,
> >
> > --------
> >
> > anirban
> >
> >
 		 	   		  

Re: Building SOAP Message from Chunked Response

Posted by Andreas Veithen <an...@gmail.com>.
Can you show us a bit more of your code, in particular how it creates
the StAXSOAPModelBuilder?

Andreas

On Tue, Oct 26, 2010 at 14:29, Anirban Majumdar
<an...@altair.com> wrote:
> Hi,
>
>
>
> I am using an abstraction over HTTPClient i.e. Camel-Http component to
> communicate with a remote Webservice.
>
> The remote Webservice handles attachments without using MTOM.
>
> I called a method on the Webservice which returns an inline base64 encoded
> attachment with it.
>
> As the remote Webservice is unaware of the length of the attachment, it
> sends it in chunked form
>
>
>
> The response with chunked data looks like this in TCPMon.
>
>
>
> 2000
>
> <?xml version="1.0" ?><S:Envelope
> xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><ns2:GetFileResponse
> xmlns:ns2="http://www.example.org/Danger/"><xmlPayload>LlJNRgAAABIAAQAAAAAAAAAGUFJPUAAAADIAAAAAUMAAA
>
> AAAAAAAAAAQbG9naWNhbC1maWxlaW5mbwAAAj8AAAI/AAAAAAAAAAsAAAAaAAAJSW5kZXhhYmxlAAAAAAAEAAAAAQA
>
> :
>
> :
>
> :
>
> 2000
>
> UKLJli8cAss/98U+OllJQfyuNI7/qg6b2gzlQ4GKDNv0iBMnUFGD/nVAqQWklZ0W956TkEUTbQKYf/aCS9J6VDPppbVDrRmKz4P3pima
>
> :
>
> :
>
> :
>
> AAAAAAAAABAAAAAA==</xmlPayload></ns2:GetFileResponse></S:Body></S:Envelope>
>
> 0
>
>
>
>
>
> At the client side, I am using axiom’s StAXSOAPModelBuilder to build a SOAP
> structure.
>
> The StaxSOAPModelBuilder only returns the first chunk when I retrieved the
> attachment using following code.
>
>
>
> DataHandler dataHandler = null;
>
> OMText omText = null;
>
>
>
> omText = (OMText) omElement.getFirstOMChild();
>
> omText.setBinary(true);
>
> dataHandler = (DataHandler) omText.getDataHandler();
>
>
>
> As per my understanding the white space after the chunk de-limiters could be
> a reason for getting the first chunk only.
>
>
>
> Please suggest how to get the whole attachment when the response is sent as
> chunked by the remote Webservice.
>
>
>
> Thanks,
>
> --------
>
> anirban
>
>