Package com.linecorp.armeria.server
Class AbstractHttpService
java.lang.Object
com.linecorp.armeria.server.AbstractHttpService
- All Implemented Interfaces:
Unwrappable
,HttpService
,Service<HttpRequest,HttpResponse>
- Direct Known Subclasses:
AbstractUnsafeUnaryGrpcService
,FileService
,PrometheusExpositionService
,RedirectService
public abstract class AbstractHttpService extends Object implements HttpService
A skeletal
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 Summary
Constructors Constructor Description AbstractHttpService()
-
Method Summary
Modifier and Type Method Description protected HttpResponse
doDelete(ServiceRequestContext ctx, HttpRequest req)
Handles aDELETE
request.protected HttpResponse
doGet(ServiceRequestContext ctx, HttpRequest req)
Handles aGET
request.protected HttpResponse
doHead(ServiceRequestContext ctx, HttpRequest req)
Handles aHEAD
request.protected HttpResponse
doOptions(ServiceRequestContext ctx, HttpRequest req)
Handles anOPTIONS
request.protected HttpResponse
doPatch(ServiceRequestContext ctx, HttpRequest req)
Handles aPATCH
request.protected HttpResponse
doPost(ServiceRequestContext ctx, HttpRequest req)
Handles aPOST
request.protected HttpResponse
doPut(ServiceRequestContext ctx, HttpRequest req)
Handles aPUT
request.protected HttpResponse
doTrace(ServiceRequestContext ctx, HttpRequest req)
Handles aTRACE
request.HttpResponse
serve(ServiceRequestContext ctx, HttpRequest req)
Serves the specifiedHttpRequest
by delegating it to the matching'doMETHOD()'
method.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.linecorp.armeria.server.Service
as, serviceAdded, shouldCachePath
-
Constructor Details
-
AbstractHttpService
public AbstractHttpService()
-
-
Method Details
-
serve
Serves the specifiedHttpRequest
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; > } > }
- Specified by:
serve
in interfaceHttpService
- Specified by:
serve
in interfaceService<HttpRequest,HttpResponse>
- Parameters:
ctx
- the context of the receivedRequest
req
- the receivedRequest
- Returns:
- the
Response
- Throws:
Exception
-
doOptions
Handles anOPTIONS
request. This method sends a405 Method Not Allowed
response by default.- Throws:
Exception
-
doGet
Handles aGET
request. This method sends a405 Method Not Allowed
response by default.- Throws:
Exception
-
doHead
Handles aHEAD
request. This method sends a405 Method Not Allowed
response by default.- Throws:
Exception
-
doPost
Handles aPOST
request. This method sends a405 Method Not Allowed
response by default.- Throws:
Exception
-
doPut
Handles aPUT
request. This method sends a405 Method Not Allowed
response by default.- Throws:
Exception
-
doPatch
Handles aPATCH
request. This method sends a405 Method Not Allowed
response by default.- Throws:
Exception
-
doDelete
Handles aDELETE
request. This method sends a405 Method Not Allowed
response by default.- Throws:
Exception
-
doTrace
Handles aTRACE
request. This method sends a405 Method Not Allowed
response by default.- Throws:
Exception
-