Class MethodSelectingRouter
java.lang.Object
org.glassfish.jersey.server.internal.routing.MethodSelectingRouter
- All Implemented Interfaces:
Router
A single router responsible for selecting a single method from all the methods
bound to the same routed request path.
The method selection algorithm selects the handling method based on the HTTP request
method name, requested media type as well as defined resource method media type
capabilities.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static class
Represents a 1-1-1 relation between input and output media type and an methodAcceptorPair.private static class
Helper class to select matching resource method to be invoked.private static final class
The same as above ConsumesProducesAcceptor, only concrete request content-type and accept header info is included in addition.Nested classes/interfaces inherited from interface org.glassfish.jersey.server.internal.routing.Router
Router.Continuation
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Comparator
<MethodSelectingRouter.ConsumesProducesAcceptor> private final Map
<String, List<MethodSelectingRouter.ConsumesProducesAcceptor>> private static final Logger
private final Router
private final MessageBodyWorkers
-
Constructor Summary
ConstructorsConstructorDescriptionMethodSelectingRouter
(MessageBodyWorkers workers, List<MethodRouting> methodRoutings) Create a newMethodSelectingRouter
for all the methods on the same path. -
Method Summary
Modifier and TypeMethodDescriptionprivate void
addAllConsumesProducesCombinations
(List<MethodSelectingRouter.ConsumesProducesAcceptor> acceptors, MethodRouting methodRouting) apply
(RequestProcessingContext requestContext) Performs a request routing task and returns the routed request together with arouting continuation
.private Router
private Router
private javax.ws.rs.core.MediaType
determineResponseMediaType
(Class<?> entityClass, Type entityType, MethodSelectingRouter.RequestSpecificConsumesProducesAcceptor selectedMethod, List<AcceptableMediaType> acceptableMediaTypes) Determine theMediaType
of theResponse
based on writers suitable for the given entity class, pre-selected method and acceptable media types.private void
fillInputTypesFromWorkers
(Set<javax.ws.rs.core.MediaType> effectiveInputTypes, Invocable invocableMethod) private boolean
fillMediaTypes
(Set<javax.ws.rs.core.MediaType> effectiveTypes, ResourceMethod resourceMethod, List<javax.ws.rs.core.MediaType> methodTypes, boolean inputTypes) private void
fillOutputTypesFromWorkers
(Set<javax.ws.rs.core.MediaType> effectiveOutputTypes, Class<?> returnEntityType) private Parameter
getEntityParam
(Invocable invocable) getMethodRouter
(RequestProcessingContext context) private boolean
private boolean
private void
reportMethodSelectionAmbiguity
(List<AcceptableMediaType> acceptableTypes, MethodSelectingRouter.RequestSpecificConsumesProducesAcceptor selected, List<MethodSelectingRouter.RequestSpecificConsumesProducesAcceptor> sameFitnessAcceptors) selectMethod
(List<AcceptableMediaType> acceptableMediaTypes, List<MethodSelectingRouter.ConsumesProducesAcceptor> satisfyingAcceptors, javax.ws.rs.core.MediaType effectiveContentType, boolean singleInvokableMethod) Select method to be invoked.private static boolean
usePreSelectedMediaType
(MethodSelectingRouter.RequestSpecificConsumesProducesAcceptor selectedMethod, List<AcceptableMediaType> acceptableMediaTypes)
-
Field Details
-
LOGGER
-
CONSUMES_PRODUCES_ACCEPTOR_COMPARATOR
private static final Comparator<MethodSelectingRouter.ConsumesProducesAcceptor> CONSUMES_PRODUCES_ACCEPTOR_COMPARATOR -
workers
-
consumesProducesAcceptors
private final Map<String,List<MethodSelectingRouter.ConsumesProducesAcceptor>> consumesProducesAcceptors -
router
-
-
Constructor Details
-
MethodSelectingRouter
MethodSelectingRouter(MessageBodyWorkers workers, List<MethodRouting> methodRoutings) Create a newMethodSelectingRouter
for all the methods on the same path. The router selects the method that best matches the request based on produce/consume information from the resource method models.- Parameters:
workers
- message body workers.methodRoutings
- [method model, method methodAcceptorPair] pairs.
-
-
Method Details
-
createInternalRouter
-
apply
Description copied from interface:Router
Performs a request routing task and returns the routed request together with arouting continuation
. -
addAllConsumesProducesCombinations
private void addAllConsumesProducesCombinations(List<MethodSelectingRouter.ConsumesProducesAcceptor> acceptors, MethodRouting methodRouting) -
fillMediaTypes
private boolean fillMediaTypes(Set<javax.ws.rs.core.MediaType> effectiveTypes, ResourceMethod resourceMethod, List<javax.ws.rs.core.MediaType> methodTypes, boolean inputTypes) -
fillOutputTypesFromWorkers
-
fillInputTypesFromWorkers
-
getEntityParam
-
getMethodRouter
-
determineResponseMediaType
private javax.ws.rs.core.MediaType determineResponseMediaType(Class<?> entityClass, Type entityType, MethodSelectingRouter.RequestSpecificConsumesProducesAcceptor selectedMethod, List<AcceptableMediaType> acceptableMediaTypes) Determine theMediaType
of theResponse
based on writers suitable for the given entity class, pre-selected method and acceptable media types.- Parameters:
entityClass
- entity class to determine the media type for.entityType
- entity type for writers.selectedMethod
- pre-selected (invoked) method.acceptableMediaTypes
- acceptable media types from request.- Returns:
- media type of the response.
-
usePreSelectedMediaType
private static boolean usePreSelectedMediaType(MethodSelectingRouter.RequestSpecificConsumesProducesAcceptor selectedMethod, List<AcceptableMediaType> acceptableMediaTypes) -
isWriteable
private boolean isWriteable(MethodSelectingRouter.RequestSpecificConsumesProducesAcceptor candidate) -
isReadable
-
selectMethod
private MethodSelectingRouter.MethodSelector selectMethod(List<AcceptableMediaType> acceptableMediaTypes, List<MethodSelectingRouter.ConsumesProducesAcceptor> satisfyingAcceptors, javax.ws.rs.core.MediaType effectiveContentType, boolean singleInvokableMethod) Select method to be invoked. Method is chosen among the given set of acceptors (if they are compatible with acceptable media types).- Parameters:
acceptableMediaTypes
- media types acceptable by the client.satisfyingAcceptors
- pre-computed acceptors.effectiveContentType
- media type of incoming entity.singleInvokableMethod
- flag determining whether only one method to be invoked has been found among satisfying acceptors.- Returns:
- method to be invoked.
-
reportMethodSelectionAmbiguity
private void reportMethodSelectionAmbiguity(List<AcceptableMediaType> acceptableTypes, MethodSelectingRouter.RequestSpecificConsumesProducesAcceptor selected, List<MethodSelectingRouter.RequestSpecificConsumesProducesAcceptor> sameFitnessAcceptors) -
createHeadEnrichedRouter
-