Class ProvidenceHttpServletWrapper

  • All Implemented Interfaces:
    java.io.Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig

    public class ProvidenceHttpServletWrapper
    extends javax.servlet.http.HttpServlet
    A HTTP POST servlet wrapper around a service using sub-path routing to each compatible service method. Note that it will only support service methods that have a message as the response type, which will be used as the response object. The request is the method params message generated for the method.

    The servlet must be registered with a wildcard path ending, so it can capture sub-paths to be used to determine which service method to route to.

    
     class MyMain {
         void main(String... args) {
             Server server = new Server(8080);
             ServletContextHandler handler = new ServletContextHandler();
             handler.addServlet(
                     new ServletHolder(new ProvidenceHttpServletWrapper(
                             MyService.kDescriptor),
                     "/foo/*"));
             server.setHandler(handler);
             server.start();
             server.join();
         }
     }
     

    Note that this is not a full server-side handling of a thrift service, as the interface may hide and obscure exceptions, so a matching client does not exist. See HTTP helpers in providence-core-client as replacement.

    
     class OtherMain {
         void main(String... args) {
             HttpRequestFactory fac = new NetHttpTransport().createRequestFactory();
             MyResponse response = fac.buildPostRequest("http://localhost:8080/foo/method",
                     new ProvidenceHttpContent(MyService.Method$Request
                             .builder()
                             .addToArgs(args)
                             .build(), JsonSerializer.INSTANCE)
                     .setParser(new ProvidenceObjectParser(JsonSerializer.INSTANCE))
                     .execute()
                     .parseAs(MyResponse.class);
             System.out.println(PrettySerializer.toDebugString(response));
         }
     }
     
    Since:
    2.0
    See Also:
    Serialized Form