Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 328335

Summary: jetty.servlets.ProxyServlet.service() doesn't update ServletResponse's contentType
Product: [RT] Jetty Reporter: M.S. <bugs198011>
Component: serverAssignee: Thomas Becker <tbecker>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: gregw, jetty-inbox
Version: 7.1.5   
Target Milestone: 7.1.x   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description M.S. CLA 2010-10-21 06:28:28 EDT
In my Jetty-7 (version 7.1.6) based application, I wrote a class(MyProxyServlet) that extends org.eclipse.jetty.servlets.ProxyServlet.

MyProxyServlet's service(ServletRequest req, ServletResponse res) method calls super.service(req, res).
Afterward, I call res.getContentType() and the result is always NULL.
Comment 1 Thomas Becker CLA 2010-12-07 14:43:11 EST
The response will contain the ContentType header, but not inside your service method. 

The reason is the async behaviour of org.eclipse.jetty.servlets.ProxyServlet.

I will make up my mind to see how we can help.
Comment 2 Thomas Becker CLA 2010-12-09 06:13:04 EST
Hi M.S.,

as said your request is being processed asynchronously by ProxyServlet.service(). That's why the response object is unchanged when you call it right after your super.service(req,res) call.

The easiest way is to add a Listener to the Continuation like this:

    private class ProxyServletChild extends ProxyServlet
    {
        @Override
        public void service(final ServletRequest req, ServletResponse res) throws ServletException, IOException
        {
            ContinuationListener continuationListener = new ContinuationListener()
            {
                public void onComplete(Continuation continuation)
                {
                    System.out.println("onComplete: " + req.getContentType());
                }
                
                public void onTimeout(Continuation continuation)
                {
                }
            };
            Continuation continuation = ContinuationSupport.getContinuation(req);
            continuation.addContinuationListener(continuationListener);
            super.service(req,res);
            System.out.println("Null here, because the proxied request hasn't been processed yet. ContentType: " + res.getContentType());
        }
    }

Hope this helps you. If it does, please close the issue. If not, let me know.

Cheers,
Thomas
Comment 3 Greg Wilkins CLA 2010-12-13 05:24:28 EST
Note you could also add the listener in a filter before the proxy servlet.