Package net.morimekta.providence.server
Class ProvidenceHttpServletWrapper
- java.lang.Object
-
- javax.servlet.GenericServlet
-
- javax.servlet.http.HttpServlet
-
- net.morimekta.providence.server.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
-
-
Constructor Summary
Constructors Constructor Description ProvidenceHttpServletWrapper(net.morimekta.providence.descriptor.PService service, ProcessorProvider processorProvider, ExceptionHandler exceptionHandler, net.morimekta.providence.serializer.SerializerProvider serializerProvider, net.morimekta.providence.PServiceCallInstrumentation instrumentation)
ProvidenceHttpServletWrapper(ProcessorProvider processorProvider, java.util.Map<java.lang.String,net.morimekta.providence.descriptor.PServiceMethod> mapping, ExceptionHandler exceptionHandler, net.morimekta.providence.serializer.SerializerProvider serializerProvider, net.morimekta.providence.PServiceCallInstrumentation instrumentation)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
doPost(javax.servlet.http.HttpServletRequest httpRequest, javax.servlet.http.HttpServletResponse httpResponse)
-
Methods inherited from class javax.servlet.http.HttpServlet
doDelete, doGet, doHead, doOptions, doPut, doTrace, getLastModified, service, service
-
-
-
-
Constructor Detail
-
ProvidenceHttpServletWrapper
public ProvidenceHttpServletWrapper(@Nonnull net.morimekta.providence.descriptor.PService service, @Nonnull ProcessorProvider processorProvider, ExceptionHandler exceptionHandler, net.morimekta.providence.serializer.SerializerProvider serializerProvider, net.morimekta.providence.PServiceCallInstrumentation instrumentation)
-
ProvidenceHttpServletWrapper
public ProvidenceHttpServletWrapper(@Nonnull ProcessorProvider processorProvider, @Nonnull java.util.Map<java.lang.String,net.morimekta.providence.descriptor.PServiceMethod> mapping, ExceptionHandler exceptionHandler, net.morimekta.providence.serializer.SerializerProvider serializerProvider, net.morimekta.providence.PServiceCallInstrumentation instrumentation)
-
-