Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 328335 - jetty.servlets.ProxyServlet.service() doesn't update ServletResponse's contentType
Summary: jetty.servlets.ProxyServlet.service() doesn't update ServletResponse's conten...
Status: RESOLVED FIXED
Alias: None
Product: Jetty
Classification: RT
Component: server (show other bugs)
Version: 7.1.5   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 7.1.x   Edit
Assignee: Thomas Becker CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-10-21 06:28 EDT by M.S. CLA
Modified: 2010-12-13 05:24 EST (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.