You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by jy <jy...@gmail.com> on 2007/05/26 02:09:20 UTC

register DataHandler

Hello,

We are getting SOAP message with multiple attachements.  We are using
XMLBean to parse the SOAP message.  We also need to access the custom
headers in the subsequent part of this multi-part request.  It seems
like we can do that by implementing a custom DataHandler, but I don't
know how to register it so that Axis2 will return our DataHandler when
we request for attachment using
MessageContext.getAttachment(contentId).

Is this the correct approach for parsing the custom header?  If so,
how can I register my DataHandler?  If not, what's the correct
solution?

Message looks something like:

Content-Type: multipart/related;
boundary="NextPart_000_0125_01C19839.7237929064"; type=text/xml;
start=<07051419222600000000010000000000>
Content-Length: 2216
SOAPAction: ""

--NextPart_000_0125_01C19839.7237929064
Content-Type: text/xml; charset="utf-8"
Content-ID: <07051419222600000000010000000000>

<?xml version="1.0" encoding="utf-8" ?>
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
...
</env:Envelope>

--NextPart_000_0125_01C19839.7237929064
Content-Type: application/foo
Content-ID: <07051419222211111111110000000000>
Some-Custom-Header1: foo
Another-Custom-Header2: foo2

blah, blah

--NextPart_000_0125_01C19839.7237929064


Thanks,
Jennifer

---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


Re: register DataHandler

Posted by Thilina Gunarathne <cs...@gmail.com>.
ahhh. My apologies.. I forgot that... :)..

~Thilina
On 5/29/07, Davanum Srinivas <da...@gmail.com> wrote:
> Thilina,
> Am sorry, i'd have to differ :) Remember the streaming API? Jennifer
> can use that.
>
> Jennifer,
> Be prepared to do some work :) Yes, it's possible. See
> IncomingAttachmentInputTest in axiom
>
> https://svn.apache.org/repos/asf/webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/attachments/IncomingAttachmentInputTest.java
>
> Basically you start by accessing using the
> MessageConext.getAttachmentMap to get the Attachments object and then
> call the getIncomingAttachmentStreams of the attachments object. that
> will return a IncomingAttachmentInputStream and you can call
> getNextStream repeatedly till you find the one you want.
> IncomingAttachmentInputStream has a getHeaders which will let you
> access the custom headers in your mime parts.
>
> thanks,
> dims
>
> On 5/28/07, jy <jy...@gmail.com> wrote:
> > Thilina,
> >
> > Thanks for your reply.
> >
> > Do you have any suggestions as to how to address this?  Do I need to
> > abandon Axis2 framework all together and read HTTP stream directly?
> > Is there another WS framework that offers more extensibility?
> >
> > Thanks,
> > Jennifer
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
> > For additional commands, e-mail: axis-user-help@ws.apache.org
> >
> >
>
>
> --
> Davanum Srinivas :: http://davanum.wordpress.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-user-help@ws.apache.org
>
>


-- 
Thilina Gunarathne  -  http://www.wso2.com - http://thilinag.blogspot.com

---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


Re: register DataHandler

Posted by jy <jy...@gmail.com>.
Thanks.  I will give this a try.  Don't mind doing some work.  I just
didn't want to create some hackey solution or reinvent the wheel.

Thanks a lot,
Jennifer

On 5/28/07, Davanum Srinivas <da...@gmail.com> wrote:
> Thilina,
> Am sorry, i'd have to differ :) Remember the streaming API? Jennifer
> can use that.
>
> Jennifer,
> Be prepared to do some work :) Yes, it's possible. See
> IncomingAttachmentInputTest in axiom
>
> https://svn.apache.org/repos/asf/webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/attachments/IncomingAttachmentInputTest.java
>
> Basically you start by accessing using the
> MessageConext.getAttachmentMap to get the Attachments object and then
> call the getIncomingAttachmentStreams of the attachments object. that
> will return a IncomingAttachmentInputStream and you can call
> getNextStream repeatedly till you find the one you want.
> IncomingAttachmentInputStream has a getHeaders which will let you
> access the custom headers in your mime parts.
>
> thanks,
> dims
>
> On 5/28/07, jy <jy...@gmail.com> wrote:
> > Thilina,
> >
> > Thanks for your reply.
> >
> > Do you have any suggestions as to how to address this?  Do I need to
> > abandon Axis2 framework all together and read HTTP stream directly?
> > Is there another WS framework that offers more extensibility?
> >
> > Thanks,
> > Jennifer
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
> > For additional commands, e-mail: axis-user-help@ws.apache.org
> >
> >
>
>
> --
> Davanum Srinivas :: http://davanum.wordpress.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-user-help@ws.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


Re: register DataHandler

Posted by jy <jy...@gmail.com>.
Dims,

I am sending mult-part request using HttpClient.  When I try reading
from the IncomingAttachmentStream, I get read-time-out error on the
last attachment.  It seems the location where read-time-out occurs
depends on the content of stream input.  Repeated attempts of a same
request always timesout at the same location.  Adding another
attachment to the same request runs into readtime out on the last
attachment.  This seems like the read buffer is blocked.  When I
intercept the incoming request using TCPMon, the entire request is
there.  Hence, I don't think it's a flush problem from the sender
side.

Any idea?  Am I missing something?

Here is the code snippet:

    private void getAttachments(MessageContext msgCtx) throws IOException {
    	Attachments attchts = msgCtx.getAttachmentMap();
    	IncomingAttachmentStreams instreams =
attchts.getIncomingAttachmentStreams();
    	
    	int attchtIndex = 1;
    	while (instreams.isReadyToGetNextStream()) {
    		IncomingAttachmentInputStream instream = null;
    		try {
    			instream = instreams.getNextStream();
    			if (instream == null)
    				break;
    			System.out.println("\n\n-------------------- content= " +
instream.getContentId() + " ---------------------");
    			Map headers = instream.getHeaders();
    			for (Iterator iter = headers.keySet().iterator(); iter.hasNext(); ) {
    				String header = (String) iter.next();
    				System.out.println("header: " + header + " = " + headers.get(header));
    			}
    			System.out.println("-------------------------------------------------------\n\n");
    			
    			readContent(attchtIndex++, instream);
    		}
    		finally {
    			if (instream != null) {
    				instream.close();
    			}
    		}
    	}
    }


    private void readContent(int attachmentIndex,
IncomingAttachmentInputStream instream) throws IOException {
    	byte buffer[] = new byte[1024];
    	File file = new File(baseOutputDir + File.separator +
attachmentIndex + ".out");
    	FileOutputStream fout = null;
    	try {
    		int len;
    		fout = new FileOutputStream(file);
    		while ((len = instream.read(buffer)) > 0 ) {
    			fout.write(buffer, 0, len);
    		}
    		fout.flush();
    	}
    	finally {
    		if (fout != null) {
    			fout.close();
    		}
    	}
    	
    }


Exception statck:
java.net.SocketTimeoutException: Read timed out
        at java.net.SocketInputStream.socketRead0(Native Method)
        at java.net.SocketInputStream.read(SocketInputStream.java:129)
        at org.apache.coyote.http11.InternalInputBuffer.fill(InternalInputBuffer.java:747)
        at org.apache.coyote.http11.InternalInputBuffer$InputStreamInputBuffer.doRead(InternalInputBuffer.java:777)
        at org.apache.coyote.http11.filters.IdentityInputFilter.doRead(IdentityInputFilter.java:115)
        at org.apache.coyote.http11.InternalInputBuffer.doRead(InternalInputBuffer.java:712)
        at org.apache.coyote.Request.doRead(Request.java:429)
        at org.apache.coyote.tomcat5.InputBuffer.realReadBytes(InputBuffer.java:290)
        at org.apache.tomcat.util.buf.ByteChunk.substract(ByteChunk.java:374)
        at org.apache.coyote.tomcat5.InputBuffer.read(InputBuffer.java:305)
        at org.apache.coyote.tomcat5.CoyoteInputStream.read(CoyoteInputStream.java:179)
        at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
        at java.io.BufferedInputStream.read1(BufferedInputStream.java:256)
        at java.io.BufferedInputStream.read(BufferedInputStream.java:313)
        at java.io.FilterInputStream.read(FilterInputStream.java:111)
        at java.io.PushbackInputStream.read(PushbackInputStream.java:161)
        at org.apache.axiom.attachments.BoundaryDelimitedStream.readFromStream(BoundaryDelimitedStream.java:215)
        at org.apache.axiom.attachments.BoundaryDelimitedStream.read(BoundaryDelimitedStream.java:302)
        at org.apache.axiom.attachments.BoundaryDelimitedStream.read(BoundaryDelimitedStream.java:359)
        at org.apache.axiom.attachments.IncomingAttachmentInputStream.read(IncomingAttachmentInputStream.java:127)
...


Thanks again,
Jennifer

---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


Re: register DataHandler

Posted by Davanum Srinivas <da...@gmail.com>.
Thilina,
Am sorry, i'd have to differ :) Remember the streaming API? Jennifer
can use that.

Jennifer,
Be prepared to do some work :) Yes, it's possible. See
IncomingAttachmentInputTest in axiom

https://svn.apache.org/repos/asf/webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/attachments/IncomingAttachmentInputTest.java

Basically you start by accessing using the
MessageConext.getAttachmentMap to get the Attachments object and then
call the getIncomingAttachmentStreams of the attachments object. that
will return a IncomingAttachmentInputStream and you can call
getNextStream repeatedly till you find the one you want.
IncomingAttachmentInputStream has a getHeaders which will let you
access the custom headers in your mime parts.

thanks,
dims

On 5/28/07, jy <jy...@gmail.com> wrote:
> Thilina,
>
> Thanks for your reply.
>
> Do you have any suggestions as to how to address this?  Do I need to
> abandon Axis2 framework all together and read HTTP stream directly?
> Is there another WS framework that offers more extensibility?
>
> Thanks,
> Jennifer
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-user-help@ws.apache.org
>
>


-- 
Davanum Srinivas :: http://davanum.wordpress.com

---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


Re: register DataHandler

Posted by jy <jy...@gmail.com>.
Thilina,

Thanks for your reply.

Do you have any suggestions as to how to address this?  Do I need to
abandon Axis2 framework all together and read HTTP stream directly?
Is there another WS framework that offers more extensibility?

Thanks,
Jennifer

---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


Re: register DataHandler

Posted by Thilina Gunarathne <cs...@gmail.com>.
> We are getting SOAP message with multiple attachements.  We are using
> XMLBean to parse the SOAP message.  We also need to access the custom
> headers in the subsequent part of this multi-part request.
For this you need to have access to the underlying MIMEPart..
Currently Axis2 does not support this..  AFAIK these header
inofrmation are not captured by the DataHanlders.
>  It seems
> like we can do that by implementing a custom DataHandler, but I don't
> know how to register it so that Axis2 will return our DataHandler when
> we request for attachment using
> MessageContext.getAttachment(contentId).
AFAIK Axis2 does not provide a way to specify a custom DataHandler..

Thanks,
Thilina

>
> Is this the correct approach for parsing the custom header?  If so,
> how can I register my DataHandler?  If not, what's the correct
> solution?
>
> Message looks something like:
>
> Content-Type: multipart/related;
> boundary="NextPart_000_0125_01C19839.7237929064"; type=text/xml;
> start=<07051419222600000000010000000000>
> Content-Length: 2216
> SOAPAction: ""
>
> --NextPart_000_0125_01C19839.7237929064
> Content-Type: text/xml; charset="utf-8"
> Content-ID: <07051419222600000000010000000000>
>
> <?xml version="1.0" encoding="utf-8" ?>
> <env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
> ...
> </env:Envelope>
>
> --NextPart_000_0125_01C19839.7237929064
> Content-Type: application/foo
> Content-ID: <07051419222211111111110000000000>
> Some-Custom-Header1: foo
> Another-Custom-Header2: foo2
>
> blah, blah
>
> --NextPart_000_0125_01C19839.7237929064
>
>
> Thanks,
> Jennifer
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-user-help@ws.apache.org
>
>


-- 
Thilina Gunarathne  -  http://www.wso2.com - http://thilinag.blogspot.com

---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org