* Resource Method for OPTIONS is available.
* @throws ResourceMethodNotFoundException
*/
private ResObjAndMeth identifyMethod(ResObjAndRemPath resObjAndRemPath,
MediaType givenMediaType) throws RequestHandledException {
CallContext callContext = tlContext.get();
org.restlet.data.Method httpMethod = callContext.getRequest()
.getMethod();
// 3. Identify the method that will handle the request:
// (a)
ResourceObject resObj = resObjAndRemPath.resourceObject;
RemainingPath u = resObjAndRemPath.u;
// (a) 1
ResourceClass resourceClass = resObj.getResourceClass();
Collection<ResourceMethod> resourceMethods = resourceClass
.getMethodsForPath(u);
if (resourceMethods.isEmpty())
excHandler.resourceMethodNotFound();// NICE (resourceClass, u);
// (a) 2: remove methods not support the given method
boolean alsoGet = httpMethod.equals(Method.HEAD);
removeNotSupportedHttpMethod(resourceMethods, httpMethod, alsoGet);
if (resourceMethods.isEmpty()) {
Set<Method> allowedMethods = resourceClass.getAllowedMethods(u);
if (httpMethod.equals(Method.OPTIONS)) {
callContext.getResponse().getAllowedMethods()
.addAll(allowedMethods);
throw new RequestHandledException();
}
excHandler.methodNotAllowed(allowedMethods);
}
// (a) 3
if (givenMediaType != null) {
Collection<ResourceMethod> supporting = resourceMethods;
resourceMethods = new ArrayList<ResourceMethod>();
for (ResourceMethod resourceMethod : supporting) {
if (resourceMethod.isGivenMediaTypeSupported(givenMediaType))
resourceMethods.add(resourceMethod);
}
if (resourceMethods.isEmpty())
excHandler.unsupportedMediaType(supporting);
}
// (a) 4
SortedMetadata<MediaType> accMediaTypes = callContext
.getAccMediaTypes();
Collection<ResourceMethod> supporting = resourceMethods;
resourceMethods = new ArrayList<ResourceMethod>();
for (ResourceMethod resourceMethod : supporting) {
if (resourceMethod.isAcceptedMediaTypeSupported(accMediaTypes))
resourceMethods.add(resourceMethod);
}
if (resourceMethods.isEmpty()) {
excHandler.noResourceMethodForAccMediaTypes(supporting);
}
// (b) and (c)
ResourceMethod bestResourceMethod = getBestMethod(resourceMethods,
givenMediaType, accMediaTypes, httpMethod);
MatchingResult mr = bestResourceMethod.getPathRegExp().match(u);
addPathVarsToMap(mr, callContext);
String matchedUriPart = mr.getMatched();
if (matchedUriPart.length() > 0) {
Object jaxRsResObj = resObj.getJaxRsResourceObject();
callContext.addForMatched(jaxRsResObj, matchedUriPart);
}
return new ResObjAndMeth(resObj, bestResourceMethod);
}