The normal approach is to wrap the request as opposed to copying it:
http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/servlet/http/HttpServletRequestWrapper.html


On Fri, 2005-04-29 at 14:16, Tuan, Frank wrote:
> Hi all,
> 
> I need some help copying a HttpServletRequest in a Filter.  I'm running 
> 5.0.28.  So far, this is what I have,
> 
>                 HttpServletRequest oldRequest = (HttpServletRequest)request;
>                 CoyoteRequest newRequest = new CoyoteRequest();
> 
>                 // handle HTTP headers
>                 log.trace ("Setting HTTP headers");
>                 Enumeration headerNames = oldRequest.getHeaderNames();
>                 while (headerNames.hasMoreElements())
>                 {
>                     String headerName = (String)headerNames.nextElement();
>                     String header = oldRequest.getHeader (headerName);
>                     log.trace ("Adding "+headerName+"="+header+" into HTTP 
> header");
>                     newRequest.addHeader (headerName, header);
>                 }
> 
>                 // handle request attributes
>                 log.trace ("Setting request attributes");
>                 Enumeration attributeNames = oldRequest.getAttributeNames();
>                 while (attributeNames.hasMoreElements())
>                 {
>                     String attributeName = 
> (String)attributeNames.nextElement();
>                     Object attribute = oldRequest.getAttribute 
> (attributeName);
>                     log.trace ("Adding "+attributeName+" as a request 
> attribute");
>                     newRequest.setAttribute (attributeName, attribute);
>                 }
>                 
>                 log.trace ("Setting request fields");
>                 newRequest.setContextPath (oldRequest.getContextPath());
>                 newRequest.setContentLength (oldRequest.getContentLength());
>                 newRequest.setContentType (oldRequest.getContentType());
>                 newRequest.setMethod (oldRequest.getMethod());
>                 newRequest.setRequestURI (oldRequest.getRequestURI());
>                 newRequest.setServletPath (oldRequest.getServletPath());
>                 newRequest.setStream (new ByteArrayInputStream (requestBody));
>                 
>                 
>                 RequestDispatcher dispatcher = 
> oldRequest.getRequestDispatcher ("/soap/some-service");
>                 CoyoteRequestFacade facade = new CoyoteRequestFacade 
> (newRequest);
>                 dispatcher.forward (facade, response);
> 
> 
> I'm getting the following exception,
> 
> 2005-04-29 10:49:23 StandardWrapperValve[default]: Servlet.service() for 
> servlet default threw exception
> java.lang.NullPointerException
>         at 
> org.apache.coyote.tomcat5.CoyoteRequest.getAttribute(CoyoteRequest.java:943)
>         at 
> org.apache.coyote.tomcat5.CoyoteRequestFacade.getAttribute(CoyoteRequestFacade.java:261)
>         at 
> org.apache.catalina.core.ApplicationDispatcher.wrapRequest(ApplicationDispatcher.java:979)
>         at 
> org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:383)
>         at 
> org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:312)
>         at 
> com.amazon.fiji.soap.RequestDumpFilter.doFilter(RequestDumpFilter.java:112)
>         at 
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:186)
>         at 
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
>         at 
> org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
>         at 
> org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
>         at 
> org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
>         at 
> org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
>         at 
> org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
>         at 
> org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
>         at 
> org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
>         at 
> org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
>         at 
> org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
>         at 
> org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
>         at 
> org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
>         at 
> org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:535)
>         at 
> org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
>         at 
> org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
>         at 
> org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
>         at 
> org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
>         at 
> org.apache.catalina.valves.RequestDumperValve.invoke(RequestDumperValve.java:169)
>         at 
> org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
>         at 
> org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
>         at 
> org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
>         at 
> org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
>         at 
> org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
>         at 
> org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
>         at 
> org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
>         at 
> org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
>         at java.lang.Thread.run(Thread.java:534)
> 
> What am I missing?
> 
> Thanks in advance,
> Frank


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to