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

thanks for your answer! You are right, that works!

Buy how exactly can I modify the content at this point? I tried this little example:

String receivedContent = new String(buffer);

LOG.info(">>> conent: "  + receivedContent);

// <modify string here>

super.onResponseContent(request, response, proxyResponse, buffer, offset, length);


I didn't  modified the content yet. I only printed out the content, but then the program halts at this point. Do you have any Idea how i can modify the content at this point?

kind regards



2014-05-17 20:01 GMT+02:00 Simone Bordet <sbordet@xxxxxxxxxxx>:
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.
_______________________________________________
jetty-users mailing list
jetty-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/jetty-users


Back to the top