Hi,

I try to create a filter which is reading the request and response data out.
The Response is fine I can read the whole envelope.
For the Request I can read all the Parameters, Attributes, Cookies.

But if I try to read the body then it hangs.

With the following message:

2004-04-22 08:25:21 StandardWrapperValve[AxisServlet]: Servlet.service() for servlet AxisServlet threw exception
java.lang.IllegalStateException: getReader() has already been called for this request

I have tried this also with the getInputstream the same effect also tried it after the chain.doFilter invokation also the same ....

I have no Idea at the moment .........

here is the code for my filter and the request wrapper:

public void doFilter(final ServletRequest request, final ServletResponse response, FilterChain chain) throws IOException, ServletException
        {
                BasicRequestWrapper           requestWrapper  = new BasicRequestWrapper((HttpServletRequest)request);
                String requestString = requestWrapper.toString();        
                log(requestString);

                OutputStream                          out                          = response.getOutputStream();
               
                ByteArrayResponseWrapper responseWrapper = new ByteArrayResponseWrapper((HttpServletResponse) response);
       
                chain.doFilter(requestWrapper, responseWrapper);
               
                out.write(responseWrapper.getData());
                out.close();
               
                return;
        }

public class BasicRequestWrapper extends HttpServletRequestWrapper {
        public BasicRequestWrapper(HttpServletRequest request){
                super(request);
        }

        private String getBodyAsString(){
                StringBuffer buff = new StringBuffer();
                buff.append(" BODY_DATA START [ ");
               
                char[] charArr = new char[getContentLength()];
               
                try{
                        BufferedReader reader = new BufferedReader(getReader());
                        reader.read(charArr, 0, charArr.length);
                        reader.close();
                }catch (IOException e) {                        
                        e.printStackTrace();
                }
               
                buff.append(charArr);
                buff.append(" ] BODY_DATA END ");
               
                return buff.toString();
        }

        public String toString(){
                return getBodyAsString();
        }
}

Many thanks in advance ......

Levent

Reply via email to