public class ProvidenceHttpServletWrapper
extends javax.servlet.http.HttpServlet
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));
}
}
| Constructor and Description |
|---|
ProvidenceHttpServletWrapper(ProcessorProvider processorProvider,
Map<String,net.morimekta.providence.descriptor.PServiceMethod> mapping,
ExceptionHandler exceptionHandler,
net.morimekta.providence.serializer.SerializerProvider serializerProvider,
net.morimekta.providence.PServiceCallInstrumentation instrumentation) |
ProvidenceHttpServletWrapper(net.morimekta.providence.descriptor.PService service,
ProcessorProvider processorProvider,
ExceptionHandler exceptionHandler,
net.morimekta.providence.serializer.SerializerProvider serializerProvider,
net.morimekta.providence.PServiceCallInstrumentation instrumentation) |
| Modifier and Type | Method and Description |
|---|---|
protected void |
doPost(javax.servlet.http.HttpServletRequest httpRequest,
javax.servlet.http.HttpServletResponse httpResponse) |
doDelete, doGet, doHead, doOptions, doPut, doTrace, getLastModified, service, servicepublic ProvidenceHttpServletWrapper(@Nonnull net.morimekta.providence.descriptor.PService service, @Nonnull ProcessorProvider processorProvider, ExceptionHandler exceptionHandler, net.morimekta.providence.serializer.SerializerProvider serializerProvider, net.morimekta.providence.PServiceCallInstrumentation instrumentation)
public ProvidenceHttpServletWrapper(@Nonnull ProcessorProvider processorProvider, @Nonnull Map<String,net.morimekta.providence.descriptor.PServiceMethod> mapping, ExceptionHandler exceptionHandler, net.morimekta.providence.serializer.SerializerProvider serializerProvider, net.morimekta.providence.PServiceCallInstrumentation instrumentation)
protected final void doPost(javax.servlet.http.HttpServletRequest httpRequest,
javax.servlet.http.HttpServletResponse httpResponse)
throws IOException
doPost in class javax.servlet.http.HttpServletIOExceptionCopyright © 2015–2020 morimekta.net. All rights reserved.