Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-users] ServletResponse with ProxyServlet.Transparent is empty

Hi,

On Sat, May 17, 2014 at 10:13 AM, John <johnnyenglish739@xxxxxxxxx> wrote:
> Hi,
>
> I'm using the transparent proxyseverlet with jetty 9 and try to intercept
> the response and modify it, but if I add a filter and try to read the
> response, it is empty.
>
> To show you the problem I have setup a little example:
>
> 1. I have started a hello world server which retruns "Hello world" if I
> execute a get request on localhost:8080 (Java code:
> http://pastebin.com/5rDAP4i7)
>
> 2. Now I have started a jetty server with a transparent proxyservlet on port
> 8012 which forwards all messages to 8080. I assumed that I can see the
> "hello world" string in the ServletResponse in the doFilter method, but it
> is allways "null". (Java code: http://pastebin.com/w78wY4ji wrapper class:
> http://pastebin.com/fNkAHu5b)

ProxyServlet is asynchronous. Your filter calls filterChain.doFilter()
which hits the ProxyServlet which proxies the request and returns
immediately without blocking waiting for the response.
On the next line of your filter you expect the content to be arrived,
but it's not arrived yet, because the whole processing is
asynchronous.

If you want to modify the content the proxy sends to the client,
override ProxyServlet.onResponseContent().

-- 
Simone Bordet
----
http://cometd.org
http://webtide.com
http://intalio.com
Developer advice, training, services and support
from the Jetty & CometD experts.
Intalio, the modern way to build business applications.


Back to the top