Search in sources :

Example 1 with DefaultSerializerProvider

use of net.morimekta.providence.serializer.DefaultSerializerProvider in project providence by morimekta.

the class HttpClientHandlerNetworkTest method setUp.

@Before
public void setUp() throws Exception {
    executorService = Executors.newSingleThreadExecutor();
    provider = new DefaultSerializerProvider();
    serverSocket = new ServerSocket();
    serverSocket.bind(new InetSocketAddress("localhost", 0));
    port = serverSocket.getLocalPort();
    serverSocket.setSoTimeout(200);
    flag = new AtomicBoolean(true);
    executorService.submit(() -> {
        while (flag.get()) {
            try {
                Socket socket = serverSocket.accept();
                Thread.sleep(10L);
                // Do not read request.
                socket.getOutputStream().write(("HTTP/1.1 403 Unauthorized\r\n" + "\r\n").getBytes(StandardCharsets.UTF_8));
                socket.close();
            } catch (SocketTimeoutException e) {
            // ignore
            } catch (IOException | InterruptedException e) {
                e.printStackTrace();
            }
        }
        try {
            serverSocket.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    });
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) SocketTimeoutException(java.net.SocketTimeoutException) InetSocketAddress(java.net.InetSocketAddress) DefaultSerializerProvider(net.morimekta.providence.serializer.DefaultSerializerProvider) ServerSocket(java.net.ServerSocket) IOException(java.io.IOException) Socket(java.net.Socket) ServerSocket(java.net.ServerSocket) Before(org.junit.Before)

Example 2 with DefaultSerializerProvider

use of net.morimekta.providence.serializer.DefaultSerializerProvider 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)

Example 3 with DefaultSerializerProvider

use of net.morimekta.providence.serializer.DefaultSerializerProvider in project providence by morimekta.

the class ProvidenceServletTest method setUpServer.

@Before
public void setUpServer() throws Exception {
    Awaitility.setDefaultPollDelay(2, TimeUnit.MILLISECONDS);
    Log.setLog(new NoLogging());
    impl = mock(TestService.Iface.class);
    instrumentation = mock(ServiceCallInstrumentation.class);
    provider = new DefaultSerializerProvider();
    server = new Server(0);
    ServletContextHandler handler = new ServletContextHandler();
    handler.addServlet(new ServletHolder(new ProvidenceServlet(new TestService.Processor(impl), provider, instrumentation)), "/" + ENDPOINT);
    server.setHandler(handler);
    server.start();
    port = getExposedPort(server);
}
Also used : Server(org.eclipse.jetty.server.Server) NoLogging(net.morimekta.providence.server.internal.NoLogging) TestService(net.morimekta.test.providence.service.TestService) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) DefaultSerializerProvider(net.morimekta.providence.serializer.DefaultSerializerProvider) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) ServiceCallInstrumentation(net.morimekta.providence.util.ServiceCallInstrumentation) Before(org.junit.Before)

Example 4 with DefaultSerializerProvider

use of net.morimekta.providence.serializer.DefaultSerializerProvider in project providence by morimekta.

the class RPCProvidenceHttpTest method setUp.

@Before
public void setUp() throws Exception {
    Log.setLog(new NoLogging());
    rc = copyResourceTo("/pvdrc", temp.getRoot());
    copyResourceTo("/test.thrift", temp.getRoot());
    impl = mock(MyService.Iface.class);
    server = new Server(0);
    DefaultSerializerProvider provider = new DefaultSerializerProvider();
    ServletContextHandler handler = new ServletContextHandler();
    handler.addServlet(new ServletHolder(new ProvidenceServlet(new MyService.Processor(impl), provider)), "/" + ENDPOINT);
    server.setHandler(handler);
    server.start();
    port = getExposedPort(server);
    Thread.sleep(1);
    exitCode = 0;
    rpc = new RPC(console.tty()) {

        @Override
        protected void exit(int i) {
            exitCode = i;
        }
    };
}
Also used : Server(org.eclipse.jetty.server.Server) NoLogging(net.morimekta.providence.tools.rpc.internal.NoLogging) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) MyService(net.morimekta.test.providence.MyService) DefaultSerializerProvider(net.morimekta.providence.serializer.DefaultSerializerProvider) ProvidenceServlet(net.morimekta.providence.server.ProvidenceServlet) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) Before(org.junit.Before)

Example 5 with DefaultSerializerProvider

use of net.morimekta.providence.serializer.DefaultSerializerProvider in project providence by morimekta.

the class ProvidenceServlet_ThriftClientTest method setUpServer.

@BeforeClass
public static void setUpServer() throws Exception {
    Awaitility.setDefaultPollDelay(2, TimeUnit.MILLISECONDS);
    Log.setLog(new NoLogging());
    impl = mock(TestService.Iface.class);
    instrumentation = mock(ServiceCallInstrumentation.class);
    provider = new DefaultSerializerProvider();
    server = new Server(0);
    ServletContextHandler handler = new ServletContextHandler();
    handler.addServlet(new ServletHolder(new ProvidenceServlet(new TestService.Processor(impl), provider, instrumentation)), "/" + ENDPOINT);
    server.setHandler(handler);
    server.start();
    port = getExposedPort(server);
}
Also used : Server(org.eclipse.jetty.server.Server) NoLogging(net.morimekta.providence.server.internal.NoLogging) TestService(net.morimekta.test.providence.service.TestService) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) DefaultSerializerProvider(net.morimekta.providence.serializer.DefaultSerializerProvider) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) ServiceCallInstrumentation(net.morimekta.providence.util.ServiceCallInstrumentation) BeforeClass(org.junit.BeforeClass)

Aggregations

DefaultSerializerProvider (net.morimekta.providence.serializer.DefaultSerializerProvider)7 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)5 Server (org.eclipse.jetty.server.Server)4 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)4 Before (org.junit.Before)4 ServiceCallInstrumentation (net.morimekta.providence.util.ServiceCallInstrumentation)3 ProvidenceServlet (net.morimekta.providence.server.ProvidenceServlet)2 NoLogging (net.morimekta.providence.server.internal.NoLogging)2 Calculator (net.morimekta.test.providence.jax.rs.calculator.Calculator)2 TestService (net.morimekta.test.providence.service.TestService)2 GenericUrl (com.google.api.client.http.GenericUrl)1 IOException (java.io.IOException)1 InetSocketAddress (java.net.InetSocketAddress)1 ServerSocket (java.net.ServerSocket)1 Socket (java.net.Socket)1 SocketTimeoutException (java.net.SocketTimeoutException)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 HttpServlet (javax.servlet.http.HttpServlet)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1