public abstract class AbstractHttpService extends Object implements HttpService
HttpService for easier HTTP service implementation.
This class provides the methods that handles the HTTP requests of the methods their names signify.
For example, doGet() method handles a
GET request.
doOptions(ServiceRequestContext, HttpRequest)doGet(ServiceRequestContext, HttpRequest)doHead(ServiceRequestContext, HttpRequest)doPost(ServiceRequestContext, HttpRequest)doPut(ServiceRequestContext, HttpRequest)doPatch(ServiceRequestContext, HttpRequest)doDelete(ServiceRequestContext, HttpRequest)doTrace(ServiceRequestContext, HttpRequest)405 Method Not Allowed response
by default. Override one of them to handle requests properly.| Constructor and Description |
|---|
AbstractHttpService() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitdecorate, decorateas, decorate, serviceAdded, shouldCachePathpublic HttpResponse serve(ServiceRequestContext ctx, HttpRequest req) throws Exception
HttpRequest by delegating it to the matching 'doMETHOD()' method.
Override this method to perform an action for the requests of any HTTP methods:
> public class MyHttpService extends AbstractHttpService {
> private final Map<HttpMethod, AtomicInteger> handledRequests = new ConcurrentHashMap<>();
>
> @Override
> public HttpResponse serve(ServiceRequestContext ctx, HttpRequest req) throws Exception {
> final HttpResponse res = super.serve(ctx, req);
> handledRequests.computeIfAbsent(
> req.method(), method -> new AtomicInteger()).incrementAndGet();
> return res;
> }
> }
serve in interface HttpServiceserve in interface Service<HttpRequest,HttpResponse>ctx - the context of the received Requestreq - the received RequestResponseExceptionprotected HttpResponse doOptions(ServiceRequestContext ctx, HttpRequest req) throws Exception
OPTIONS request.
This method sends a 405 Method Not Allowed response by default.Exception@Deprecated protected void doOptions(ServiceRequestContext ctx, HttpRequest req, HttpResponseWriter res) throws Exception
doOptions(ServiceRequestContext, HttpRequest).OPTIONS request.
This method sends a 405 Method Not Allowed response by default.Exceptionprotected HttpResponse doGet(ServiceRequestContext ctx, HttpRequest req) throws Exception
GET request.
This method sends a 405 Method Not Allowed response by default.Exception@Deprecated protected void doGet(ServiceRequestContext ctx, HttpRequest req, HttpResponseWriter res) throws Exception
doGet(ServiceRequestContext, HttpRequest).GET request.
This method sends a 405 Method Not Allowed response by default.Exceptionprotected HttpResponse doHead(ServiceRequestContext ctx, HttpRequest req) throws Exception
HEAD request.
This method sends a 405 Method Not Allowed response by default.Exception@Deprecated protected void doHead(ServiceRequestContext ctx, HttpRequest req, HttpResponseWriter res) throws Exception
doHead(ServiceRequestContext, HttpRequest).HEAD request.
This method sends a 405 Method Not Allowed response by default.Exceptionprotected HttpResponse doPost(ServiceRequestContext ctx, HttpRequest req) throws Exception
POST request.
This method sends a 405 Method Not Allowed response by default.Exception@Deprecated protected void doPost(ServiceRequestContext ctx, HttpRequest req, HttpResponseWriter res) throws Exception
doPost(ServiceRequestContext, HttpRequest).POST request.
This method sends a 405 Method Not Allowed response by default.Exceptionprotected HttpResponse doPut(ServiceRequestContext ctx, HttpRequest req) throws Exception
PUT request.
This method sends a 405 Method Not Allowed response by default.Exception@Deprecated protected void doPut(ServiceRequestContext ctx, HttpRequest req, HttpResponseWriter res) throws Exception
doPut(ServiceRequestContext, HttpRequest).PUT request.
This method sends a 405 Method Not Allowed response by default.Exceptionprotected HttpResponse doPatch(ServiceRequestContext ctx, HttpRequest req) throws Exception
PATCH request.
This method sends a 405 Method Not Allowed response by default.Exception@Deprecated protected void doPatch(ServiceRequestContext ctx, HttpRequest req, HttpResponseWriter res) throws Exception
doPatch(ServiceRequestContext, HttpRequest).PATCH request.
This method sends a 405 Method Not Allowed response by default.Exceptionprotected HttpResponse doDelete(ServiceRequestContext ctx, HttpRequest req) throws Exception
DELETE request.
This method sends a 405 Method Not Allowed response by default.Exception@Deprecated protected void doDelete(ServiceRequestContext ctx, HttpRequest req, HttpResponseWriter res) throws Exception
doDelete(ServiceRequestContext, HttpRequest).DELETE request.
This method sends a 405 Method Not Allowed response by default.Exceptionprotected HttpResponse doTrace(ServiceRequestContext ctx, HttpRequest req) throws Exception
TRACE request.
This method sends a 405 Method Not Allowed response by default.Exception@Deprecated protected void doTrace(ServiceRequestContext ctx, HttpRequest req, HttpResponseWriter res) throws Exception
doTrace(ServiceRequestContext, HttpRequest).TRACE request.
This method sends a 405 Method Not Allowed response by default.ExceptionCopyright © 2020 LeanCloud. All rights reserved.