Interface ResourceMethodResolver
A Resource Method is a Java Method with an HTTP method annotation applied, e.g. GET, POST, ServerSentEventSource, ...
Standard threadsafe implementations can be acquired via these factory methods:
fromClasspathIntrospection()(examines an annotation-processor-generated lookup table of JavaMethoddeclarations with corresponding HTTP method annotations)withClasses(Set)(examines methods within the hardcoded set of classes)withMethods(Set)(examines the hardcoded set of methods)
It is likely that one or more of the above implementations is sufficient for your application and test suite.
However, should a custom implementation be necessary, documentation is available at https://www.soklet.com/docs/request-handling#resource-method-resolution.
- Author:
- Mark Allen
-
Method Summary
Modifier and TypeMethodDescriptionstatic ResourceMethodResolverAcquires a threadsafeResourceMethodResolverimplementation which locates Resource Methods by examining a lookup table of JavaMethoddeclarations that are annotated withGET,POST,ServerSentEventSource, etc.Vends the set of all Resource Methods registered in the system.resourceMethodForRequest(Request request, ServerType serverType) Given an HTTP request, provide a matching Resource Method to invoke.static ResourceMethodResolverwithClasses(Set<Class<?>> classes) Acquires a threadsafeResourceMethodResolverimplementation which locates Resource Methods by examining the providedclasses.static ResourceMethodResolverwithMethods(Set<Method> methods) Acquires a threadsafeResourceMethodResolverimplementation which locates Resource Methods by examining the providedmethods.
-
Method Details
-
resourceMethodForRequest
@Nonnull Optional<ResourceMethod> resourceMethodForRequest(@Nonnull Request request, @Nonnull ServerType serverType) Given an HTTP request, provide a matching Resource Method to invoke.An unmatched Resource Method generally indicates an
HTTP 404.- Parameters:
request- the HTTP requestserverType- the type of server that's handling the request- Returns:
- the matching Resource Method, or
Optional.empty()if no match was found
-
getResourceMethods
Vends the set of all Resource Methods registered in the system.- Returns:
- the set of all Resource Methods in the system
-
fromClasspathIntrospection
Acquires a threadsafeResourceMethodResolverimplementation which locates Resource Methods by examining a lookup table of JavaMethoddeclarations that are annotated withGET,POST,ServerSentEventSource, etc.This implementation requires that your application be compiled with the
SokletProcessorannotation processor, as shown below:javac -parameters -processor com.soklet.SokletProcessor ...[rest of javac command elided]
The returned instance is guaranteed to be a JVM-wide singleton.
- Returns:
- a
ResourceMethodResolverwhich performs classpath introspection against the annotation processor's lookup table
-
withClasses
Acquires a threadsafeResourceMethodResolverimplementation which locates Resource Methods by examining the providedclasses.This method is guaranteed to return a new instance.
- Parameters:
classes- the classes to inspect for Resource Methods- Returns:
- a
ResourceMethodResolverbacked by the givenclasses
-
withMethods
Acquires a threadsafeResourceMethodResolverimplementation which locates Resource Methods by examining the providedmethods.This method is guaranteed to return a new instance.
- Parameters:
methods- the methods to inspect for Resource Method annotations- Returns:
- a
ResourceMethodResolverbacked by the givenmethods
-