Class MethodSelectingRouter
- java.lang.Object
-
- org.glassfish.jersey.server.internal.routing.MethodSelectingRouter
-
- All Implemented Interfaces:
Router
final class MethodSelectingRouter extends java.lang.Object implements 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 Classes Modifier and Type Class Description private static class
MethodSelectingRouter.ConsumesProducesAcceptor
Represents a 1-1-1 relation between input and output media type and an methodAcceptorPair.private static class
MethodSelectingRouter.MethodSelector
Helper class to select matching resource method to be invoked.private static class
MethodSelectingRouter.RequestSpecificConsumesProducesAcceptor
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
Fields Modifier and Type Field Description private static java.util.Comparator<MethodSelectingRouter.ConsumesProducesAcceptor>
CONSUMES_PRODUCES_ACCEPTOR_COMPARATOR
private java.util.Map<java.lang.String,java.util.List<MethodSelectingRouter.ConsumesProducesAcceptor>>
consumesProducesAcceptors
private static java.util.logging.Logger
LOGGER
private Router
router
private MessageBodyWorkers
workers
-
Constructor Summary
Constructors Constructor Description MethodSelectingRouter(MessageBodyWorkers workers, java.util.List<MethodRouting> methodRoutings)
Create a newMethodSelectingRouter
for all the methods on the same path.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
addAllConsumesProducesCombinations(java.util.List<MethodSelectingRouter.ConsumesProducesAcceptor> acceptors, MethodRouting methodRouting)
Router.Continuation
apply(RequestProcessingContext requestContext)
Performs a request routing task and returns the routed request together with arouting continuation
.private Router
createHeadEnrichedRouter()
private Router
createInternalRouter()
private javax.ws.rs.core.MediaType
determineResponseMediaType(java.lang.Class<?> entityClass, java.lang.reflect.Type entityType, MethodSelectingRouter.RequestSpecificConsumesProducesAcceptor selectedMethod, java.util.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(java.util.Set<javax.ws.rs.core.MediaType> effectiveInputTypes, Invocable invocableMethod)
private boolean
fillMediaTypes(java.util.Set<javax.ws.rs.core.MediaType> effectiveTypes, ResourceMethod resourceMethod, java.util.List<javax.ws.rs.core.MediaType> methodTypes, boolean inputTypes)
private void
fillOutputTypesFromWorkers(java.util.Set<javax.ws.rs.core.MediaType> effectiveOutputTypes, java.lang.Class<?> returnEntityType)
private Parameter
getEntityParam(Invocable invocable)
private java.util.List<Router>
getMethodRouter(RequestProcessingContext context)
private boolean
isReadable(MethodSelectingRouter.RequestSpecificConsumesProducesAcceptor candidate)
private boolean
isWriteable(MethodSelectingRouter.RequestSpecificConsumesProducesAcceptor candidate)
private void
reportMethodSelectionAmbiguity(java.util.List<AcceptableMediaType> acceptableTypes, MethodSelectingRouter.RequestSpecificConsumesProducesAcceptor selected, java.util.List<MethodSelectingRouter.RequestSpecificConsumesProducesAcceptor> sameFitnessAcceptors)
private MethodSelectingRouter.MethodSelector
selectMethod(java.util.List<AcceptableMediaType> acceptableMediaTypes, java.util.List<MethodSelectingRouter.ConsumesProducesAcceptor> satisfyingAcceptors, javax.ws.rs.core.MediaType effectiveContentType, boolean singleInvokableMethod)
Select method to be invoked.private static boolean
usePreSelectedMediaType(MethodSelectingRouter.RequestSpecificConsumesProducesAcceptor selectedMethod, java.util.List<AcceptableMediaType> acceptableMediaTypes)
-
-
-
Field Detail
-
LOGGER
private static final java.util.logging.Logger LOGGER
-
CONSUMES_PRODUCES_ACCEPTOR_COMPARATOR
private static final java.util.Comparator<MethodSelectingRouter.ConsumesProducesAcceptor> CONSUMES_PRODUCES_ACCEPTOR_COMPARATOR
-
workers
private final MessageBodyWorkers workers
-
consumesProducesAcceptors
private final java.util.Map<java.lang.String,java.util.List<MethodSelectingRouter.ConsumesProducesAcceptor>> consumesProducesAcceptors
-
router
private final Router router
-
-
Constructor Detail
-
MethodSelectingRouter
MethodSelectingRouter(MessageBodyWorkers workers, java.util.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 Detail
-
createInternalRouter
private Router createInternalRouter()
-
apply
public Router.Continuation apply(RequestProcessingContext requestContext)
Description copied from interface:Router
Performs a request routing task and returns the routed request together with arouting continuation
.
-
addAllConsumesProducesCombinations
private void addAllConsumesProducesCombinations(java.util.List<MethodSelectingRouter.ConsumesProducesAcceptor> acceptors, MethodRouting methodRouting)
-
fillMediaTypes
private boolean fillMediaTypes(java.util.Set<javax.ws.rs.core.MediaType> effectiveTypes, ResourceMethod resourceMethod, java.util.List<javax.ws.rs.core.MediaType> methodTypes, boolean inputTypes)
-
fillOutputTypesFromWorkers
private void fillOutputTypesFromWorkers(java.util.Set<javax.ws.rs.core.MediaType> effectiveOutputTypes, java.lang.Class<?> returnEntityType)
-
fillInputTypesFromWorkers
private void fillInputTypesFromWorkers(java.util.Set<javax.ws.rs.core.MediaType> effectiveInputTypes, Invocable invocableMethod)
-
getMethodRouter
private java.util.List<Router> getMethodRouter(RequestProcessingContext context)
-
determineResponseMediaType
private javax.ws.rs.core.MediaType determineResponseMediaType(java.lang.Class<?> entityClass, java.lang.reflect.Type entityType, MethodSelectingRouter.RequestSpecificConsumesProducesAcceptor selectedMethod, java.util.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, java.util.List<AcceptableMediaType> acceptableMediaTypes)
-
isWriteable
private boolean isWriteable(MethodSelectingRouter.RequestSpecificConsumesProducesAcceptor candidate)
-
isReadable
private boolean isReadable(MethodSelectingRouter.RequestSpecificConsumesProducesAcceptor candidate)
-
selectMethod
private MethodSelectingRouter.MethodSelector selectMethod(java.util.List<AcceptableMediaType> acceptableMediaTypes, java.util.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(java.util.List<AcceptableMediaType> acceptableTypes, MethodSelectingRouter.RequestSpecificConsumesProducesAcceptor selected, java.util.List<MethodSelectingRouter.RequestSpecificConsumesProducesAcceptor> sameFitnessAcceptors)
-
createHeadEnrichedRouter
private Router createHeadEnrichedRouter()
-
-