Search in sources :

Example 1 with NoLogging

use of net.morimekta.providence.client.internal.NoLogging in project providence by morimekta.

the class HttpClientHandlerTest method setUp.

@Before
public void setUp() throws Exception {
    Awaitility.setDefaultPollDelay(50, TimeUnit.MILLISECONDS);
    Log.setLog(new NoLogging());
    impl = mock(net.morimekta.test.thrift.client.TestService.Iface.class);
    TProcessor processor = new net.morimekta.test.thrift.client.TestService.Processor<>(impl);
    instrumentation = mock(ServiceCallInstrumentation.class);
    provider = new DefaultSerializerProvider();
    server = new Server(0);
    ServletContextHandler handler = new ServletContextHandler();
    handler.addServlet(new ServletHolder(new TServlet(processor, new TBinaryProtocol.Factory())), "/" + ENDPOINT);
    handler.addServlet(new ServletHolder(new HttpServlet() {

        @Override
        protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
            resp.sendError(HttpServletResponse.SC_NOT_FOUND);
        }
    }), "/" + NOT_FOUND);
    handler.addServlet(new ServletHolder(new HttpServlet() {

        @Override
        protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
            resp.setStatus(HttpServletResponse.SC_OK);
            resp.setContentType("text/html");
            resp.getWriter().print("<html></html>");
        }
    }), "/" + HTML);
    handler.addServlet(new ServletHolder(new HttpServlet() {

        @Override
        protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
            resp.setStatus(HttpServletResponse.SC_OK);
            Serializer serializer = provider.getDefault();
            resp.setContentType(serializer.mediaType());
            serializer.serialize(resp.getOutputStream(), reply.get());
        }
    }), "/" + RESPONSE);
    contentTypes = new ArrayList<>();
    reply = new AtomicReference<>();
    server.setHandler(handler);
    server.setRequestLog((request, response) -> contentTypes.addAll(Collections.list(request.getHeaders("Content-Type")).stream().map(Object::toString).collect(Collectors.toList())));
    server.start();
    port = getExposedPort(server);
}
Also used : TProcessor(org.apache.thrift.TProcessor) Server(org.eclipse.jetty.server.Server) NoLogging(net.morimekta.providence.client.internal.NoLogging) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) HttpServlet(javax.servlet.http.HttpServlet) DefaultSerializerProvider(net.morimekta.providence.serializer.DefaultSerializerProvider) HttpServletResponse(javax.servlet.http.HttpServletResponse) TServlet(org.apache.thrift.server.TServlet) HttpServletRequest(javax.servlet.http.HttpServletRequest) TProcessor(org.apache.thrift.TProcessor) TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) ServiceCallInstrumentation(net.morimekta.providence.util.ServiceCallInstrumentation) Serializer(net.morimekta.providence.serializer.Serializer) Before(org.junit.Before)

Aggregations

HttpServlet (javax.servlet.http.HttpServlet)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 NoLogging (net.morimekta.providence.client.internal.NoLogging)1 DefaultSerializerProvider (net.morimekta.providence.serializer.DefaultSerializerProvider)1 Serializer (net.morimekta.providence.serializer.Serializer)1 ServiceCallInstrumentation (net.morimekta.providence.util.ServiceCallInstrumentation)1 TProcessor (org.apache.thrift.TProcessor)1 TBinaryProtocol (org.apache.thrift.protocol.TBinaryProtocol)1 TServlet (org.apache.thrift.server.TServlet)1 Server (org.eclipse.jetty.server.Server)1 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)1 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)1 Before (org.junit.Before)1