Hi Everyone, 

I'm using Dropwizard v1.0.3 to provide a service that decorates JSON 
responses from another service based on some calculations. I've added 
jetty-proxy 9.3.11.v20160721 as a dependency to my project.

The intended flow is:-
1. [existing client]------request----->[new 
service]-----request--->[existing service]
2. [existing client]<----decorated response----[new 
service]<----response---[existing service]

The new service should pass requests from the existing client to the 
existing service at step 1 and update the responses at step 2.

I'm hoping to use Jetty's AsyncMiddleManServlet with a ContentTransformer 
to do this based on Jetty's own tests at the following link, see the 
testAfterContentTransformer method at line 886.
https://github.com/eclipse/jetty.project/blob/jetty-9.4.x/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/AsyncMiddleManServletTest.java

I've tried adding the proxy as follows but I get a 502 Bad Gateway error 
come back in curl when pushing requests through it. I was hoping to see 
just the data returned from the existing service via this.  I've tried the 
AsyncMiddleManServlet.Transparent servlet (without the transformer etc) and 
that works fine. 

Any advice would be most appreciated.

thx
Matt

final AsyncMiddleManServlet proxy = new  AsyncMiddleManServlet()

{

    @Override

    protected ContentTransformer 
newServerResponseContentTransformer(HttpServletRequest clientRequest, 
HttpServletResponse proxyResponse, Response serverResponse)

    {

        return new AfterContentTransformer()

        {

            @Override

            public boolean transform(Source source, Sink sink) throws 
IOException

            {

                InputStream input = source.getInputStream();

                Map<String,Object> json = mapper.readValue(new 
InputStreamReader(input, "UTF-8"), new TypeReference<Map<String,Object>>() 
{});

                // transform here...

                try (OutputStream output = sink.getOutputStream())

                {

                    output.write(json.toString().getBytes(StandardCharsets.
UTF_8));

                    return true;

                }

            }

         };

    }

};

final ServletRegistration.Dynamic proxy = environment.servlets().addServlet(
"proxy", proxy);

proxy.setInitParameter("proxyTo", configuration.getExistingService());

proxy.setInitParameter("prefix", "/");

proxy.addMapping("/*");

-- 
You received this message because you are subscribed to the Google Groups 
"dropwizard-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to