Irfan and Kartheek,

Thank you both for your suggestions. Kartheek, I tried using
RequestDispatcher but that didn't help and the problem remained. I then
started digging into the source code as Irfan suggested.

I was able to pin-point the exact problem. As I had suspected, it has to
do with reading data from the InputStream multiple times. The SOAP
toolkit creates TransportMessage which in turn tries to extract the data
from the InputStream of the request object. I was doing something very
similar to what the constructor of TransportMessage is doing but just to
be sure, I removed my own code and did something like:

org.apache.soap.server.ServerUtils.readEnvelopeFromInputStream (xdb,
req.getInputStream(), req.getContentLength(), req.getContentType(),
editor, reqCtx);

And lo behold! I got the same error again! I debugged some of the
classes and finally discovered, that the problem has to do with reading
from the InputStream of the request object multiple times. To isolate
the problem further, I wrote a simple Java program that reads from a
file by creating a FileInputStream. However, when you try to read from
the same stream twice, the second call fails (the following code is also
there in TransportMessage.java):

FileInputStream fis = FileInputStream ("Tester.java");

void foo () {
        int contentLength = 2048;  // hardcoded for test purpose
        byte [] bytes = new byte[contentLength];
        int offset = 0;
        int bytesRead = 0;

        while ((offset < contentLength) && (bytesRead >= 0)) {
            bytesRead = fis.read(bytes, offset, contentLength - offset);
            offset += bytesRead;
}

Once the stream has been read the first time by calling foo(), trying to
re-read by callin foo() again fails since the call fis.read()
returns -1. What is needed is some way of resetting the stream. There is
a pair of methods called mark/reset available in all Java streams but
unfortunately they are not supported for any of the streams that I
experimented with (including ServletInputStream).

So this may seem more like a basic Java question -- how can an
InputStream be reset so that its contents can be read again?

Thanks,

- Prashant

> You should look into the code of the RPCRouterServlet and see the
chain of
> calls being made to introspect the call envelope.  I think the code to
> introspect the header is in the RPCRouter class.  Look into that and
you
> should be able to figure out how to extract the necessary values.  The
> RPCJavaProvider (if ure using the default provider) should also give
you
> pointers.



> Irfan
>
> -----Original Message-----
> From: Prashant Jain [mailto:[EMAIL PROTECTED]]
> Sent: Friday, July 27, 2001 2:22 AM
> To: [EMAIL PROTECTED]
> Subject: Re: using soap with tomcat 4.0b6 filter support
>
>
> Hi Kartheek,
>
> I already tried that. Unfortunately, the getHeader method on
> HttpServletRequest returns an HTTP header which is different from the
> SOAP headers that are inserted on the client side. The problem is that
a
> ServletRequest object has no notion of the structure of the data that
is
> contained in the request. Therefore it has no way of distinguishing
> between a SOAP message or a regular XML message.
>
> - Prashant
>
> ----- Original Message -----
> From: "Kartheek Hirode" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Friday, July 27, 2001 2:42 PM
> Subject: RE: using soap with tomcat 4.0b6 filter support
>
>
> > You could try casting the ServletRequest to a HTTPServletRequest and
> > invoking getHeader(keyName) on it.
> > --KH
> >
> > -----Original Message-----
> > From: Prashant Jain [mailto:[EMAIL PROTECTED]]
> > Sent: Thursday, July 26, 2001 8:41 PM
> > To: [EMAIL PROTECTED]
> > Subject: Re: using soap with tomcat 4.0b6 filter support
> >
> >
> > KH,
> >
> > > If you're using the RPCRouterServlet, then the Call object that is
> > extracted
> > > from the Envelope has the Headers.
> > > Vector v = call.getHeader.getHeaderEntries();
> >
> > You are right that the header can be extracted from the Envelope I
get
> > when I use Message-based service. However, I want to "look" at the
> > header even before it reaches the RPCRouterServlet. I want to use
> Filter
> > support provided by Tomcat 4.0 to intercept the requests. The Filter
> can
> > be installed to intercept any request _before_ it is delivered to
the
> > servlet.
> >
> > I am able to install the Filter succesfully and also intercept the
> > request. But I don't know how to read the Header. Here is the method
> on
> > the Filter that gets called:
> >
> > public void doFilter(ServletRequest req, ServletResponse res,
> > FilterChain filterChain)
> >
> > So my basic problem is how to extract the Header information given
> just
> > the ServletRequest object.
> >
> > I tried using "getInputStream()" method on the ServletRequest object
> and
> > am able to read the contents. However, since the inputstream has
been
> > "read/touched", I get the following error when the request
eventually
> > reaches the Servlet.
> >
> > Ouch, the call failed:
> >   Fault Code   = SOAP-ENV:Protocol
> >   Fault String = Premature end of stream. Data is truncated. Read -1
> > bytes successfully, expected 1719
> >
> > Is there another way that I could look at the contents of a
> > ServletRequest without getting this error?
> >
> > Any ideas/suggestions on what I could do?
> >
> > Thanks,
> >
> > - Prashant
> >
> > > The Header value is stored as the first child of the Element whose
> > name is
> > > the name you have assigned in the client.
> > > See http://marc.theaimsgroup.com/?l=soap-user&m=99064627103560&w=2
> for
> > a
> > > similar problem.
> > >
> > > G'luck,
> > > --KH
> > >
> > > -----Original Message-----
> > > From: Prashant Jain [mailto:[EMAIL PROTECTED]]
> > > Sent: Thursday, July 26, 2001 5:30 AM
> > > To: [EMAIL PROTECTED]
> > > Subject: using soap with tomcat 4.0b6 filter support
> > >
> > >
> > > Hi,
> > >
> > > Has anyone tried using SOAP with the Filter functionality of
Tomcat
> > 4.0
> > > (beta 6)? On my client side, I am creating a SOAP header and
> inserting
> > > some data in it. What I would like to be able to do is to extract
> this
> > > data using a Filter which I install in the servlet container
> (tomcat).
> > >
> > > I am able to intercept the request in my filter but am not sure
how
> to
> > > extract a SOAP header given just an HttpServletRequest.
> > >
> > > Any help would be appreciated.
> > >
> > > Thanks,
> > >
> > > - Prashant
> > >
> >
>

Reply via email to