private String getKey(final AbstractResourceMethod resourceMethod) { final String key = keys.get(resourceMethod); if (key == null) { final String name = resourceMethod.getMethod().getDeclaringClass().getSimpleName() + "#" + resourceMethod.getMethod().getName(); keys.put(resourceMethod, name); return name; } return key; } }
@Override public RequestDispatcher create(AbstractResourceMethod abstractResourceMethod, JavaMethodInvoker invoker) { // TODO: add return type to ARM if (abstractResourceMethod.getMethod().getReturnType() != void.class) return null; // TODO: use ARM getParams instead Class<?>[] parameters = abstractResourceMethod.getMethod().getParameterTypes(); if (!Arrays.deepEquals(parameters, EXPECTED_METHOD_PARAMS)) return null; return new HttpReqResDispatcher(abstractResourceMethod, invoker); } }
@Override public String toString() { Method m = arm.getMethod(); return ImplMessages.RESOURCE_METHOD(m.getDeclaringClass(), m.getName()); } }
private List<Response> generateResponses(AbstractResource r, final AbstractResourceMethod m) { if (m.getMethod().getReturnType() == void.class) { return null; } return _wadlGenerator.createResponses(r, m); }
public ResourceJavaMethodDispatcher(AbstractResourceMethod abstractResourceMethod, JavaMethodInvoker invoker) { this.method = abstractResourceMethod.getMethod(); this.annotations = abstractResourceMethod.getAnnotations(); this.invoker = invoker; }
private boolean hasEmptyProducibleMediaTypeSet(final AbstractResourceMethod method) { final Produces produces = method.getMethod().getAnnotation(Produces.class); return produces != null && getProducibleMediaTypes(method).isEmpty(); }
private List<String> getProducibleMediaTypes(final AbstractResourceMethod method) { List<String> mediaTypes = Collections.emptyList(); final Produces produces = method.getMethod().getAnnotation(Produces.class); if (produces != null && produces.value() != null) { mediaTypes = Arrays.asList(produces.value()); } return mediaTypes; }
public ContainerRequest filter(ContainerRequest request) { LOGGER.log(Level.INFO, "Resource Method matched." + "\n HttpMethod: " + arm.getHttpMethod() + "\n Resource: " + arm.getDeclaringResource().getResourceClass().getName() + "\n Method: " + arm.getMethod().toGenericString()); return request; } }
@Override public com.sun.research.ws.wadl.Method createMethod( AbstractResource r, final AbstractResourceMethod m ) { com.sun.research.ws.wadl.Method wadlMethod = new com.sun.research.ws.wadl.Method(); wadlMethod.setName(m.getHttpMethod()); wadlMethod.setId( m.getMethod().getName() ); return wadlMethod; }
@Override public RequestDispatcher create(AbstractResourceMethod abstractResourceMethod) { // Mark the errors so it is possible to reset Errors.mark(); for (ResourceMethodDispatchProvider rmdp : dispatchers) { try { RequestDispatcher d = rmdp.create(abstractResourceMethod); if (d != null) { // Reset any errors, if any, produced from previous dispatch // providers Errors.reset(); return d; } } catch (Exception e) { LOGGER.log(Level.SEVERE, ImplMessages.ERROR_PROCESSING_METHOD( abstractResourceMethod.getMethod(), rmdp.getClass().getName()), e); } } Errors.unmark(); return null; } }
public RequestDispatcher getDispatcher(AbstractResourceMethod abstractResourceMethod, JavaMethodInvoker invoker) { if (invoker == null) { return null; } // Mark the errors so it is possible to reset Errors.mark(); for (ResourceMethodCustomInvokerDispatchProvider rmdp : customInvokerDispatchProviders) { try { RequestDispatcher d = rmdp.create(abstractResourceMethod, invoker); if (d != null) { // Reset any errors, if any, produced from previous dispatch // providers Errors.reset(); return d; } } catch (Exception e) { LOGGER.log(Level.SEVERE, ImplMessages.ERROR_PROCESSING_METHOD( abstractResourceMethod.getMethod(), rmdp.getClass().getName()), e); } } Errors.unmark(); return null; } }
protected List<Injectable> getInjectables(AbstractResourceMethod method) { List<Injectable> is = new ArrayList<Injectable>(method.getParameters().size()); for (int i = 0; i < method.getParameters().size(); i++) { Parameter p = method.getParameters().get(i); if (Parameter.Source.ENTITY == p.getSource()) { if (MultivaluedMap.class.isAssignableFrom(p.getParameterClass())) { is.add(new FormEntityInjectable(p.getParameterClass(), p.getParameterType(), p.getAnnotations())); } else is.add(null); } else { Injectable injectable = getInjectableProviderContext(). getInjectable(method.getMethod(), p, ComponentScope.PerRequest); is.add(injectable); } } return is; } }
private boolean isValidResourceMethod( final ResourceMethod rm, final ResourceMethodMap rmm) { final List<ResourceMethod> rml = rmm.get(rm.getHttpMethod()); if (rml != null) { boolean conflict = false; ResourceMethod erm = null; for (int i = 0; i < rml.size() && !conflict; i++) { erm = rml.get(i); conflict = MediaTypes.intersects(rm.getConsumes(), erm.getConsumes()) && MediaTypes.intersects(rm.getProduces(), erm.getProduces()); } if (conflict) { if (rm.getAbstractResourceMethod().hasEntity()) { Errors.error(String.format("Consuming media type conflict. " + "The resource methods %s and %s can consume the same media type", rm.getAbstractResourceMethod().getMethod(), erm.getAbstractResourceMethod().getMethod())); } else { Errors.error(String.format("Producing media type conflict. " + "The resource methods %s and %s can produce the same media type", rm.getAbstractResourceMethod().getMethod(), erm.getAbstractResourceMethod().getMethod())); } } if (conflict) return false; } return true; }
Errors.missingDependency(abstractResourceMethod.getMethod(), i);
/** * @param r * @param m * @return the enhanced {@link Method} * @see com.sun.jersey.server.wadl.WadlGenerator#createMethod(com.sun.jersey.api.model.AbstractResource, com.sun.jersey.api.model.AbstractResourceMethod) */ public Method createMethod( AbstractResource r, AbstractResourceMethod m ) { final Method result = _delegate.createMethod( r, m ); final MethodDocType methodDoc = resourceDoc.getMethodDoc( r.getResourceClass(), m.getMethod() ); if ( methodDoc != null && !isEmpty( methodDoc.getCommentText() ) ) { final Doc doc = new Doc(); doc.getContent().add( methodDoc.getCommentText() ); // doc.getOtherAttributes().put( new QName( "xmlns" ), "http://www.w3.org/1999/xhtml" ); result.getDoc().add( doc ); } return result; }
private static void workOutResourceMethodsList( AbstractResource resource, MethodList methodList, boolean isEncoded, Consumes classScopeConsumesAnnotation, Produces classScopeProducesAnnotation) { for (AnnotatedMethod m : methodList.hasMetaAnnotation(HttpMethod.class). hasNotAnnotation(Path.class)) { final ReflectionHelper.ClassTypePair ct = getGenericReturnType(resource.getResourceClass(), m.getMethod()); final AbstractResourceMethod resourceMethod = new AbstractResourceMethod( resource, m.getMethod(), ct.c, ct.t, m.getMetaMethodAnnotations(HttpMethod.class).get(0).value(), m.getAnnotations()); addConsumes(m, resourceMethod, classScopeConsumesAnnotation); addProduces(m, resourceMethod, classScopeProducesAnnotation); processParameters( resourceMethod.getResource().getResourceClass(), resourceMethod.getMethod().getDeclaringClass(), resourceMethod, m, isEncoded); resource.getResourceMethods().add(resourceMethod); } }
public ResourceHttpMethod( ResourceMethodDispatchProvider dp, FilterFactory ff, List<ResourceFilter> resourceFilters, UriTemplate template, AbstractResourceMethod arm) { super(arm.getHttpMethod(), template, arm.getSupportedInputTypes(), arm.getSupportedOutputTypes(), arm.areOutputTypesDeclared(), dp.create(arm), FilterFactory.getRequestFilters(resourceFilters), FilterFactory.getResponseFilters(resourceFilters)); this.arm = arm; if (getDispatcher() == null) { Method m = arm.getMethod(); String msg = ImplMessages.NOT_VALID_HTTPMETHOD(m, arm.getHttpMethod(), m.getDeclaringClass()); Errors.error(msg); } }
/** * @param r * @param m * @param mediaType * @return the enhanced {@link Representation} * @see com.sun.jersey.server.wadl.WadlGenerator#createRequestRepresentation(com.sun.jersey.api.model.AbstractResource, com.sun.jersey.api.model.AbstractResourceMethod, javax.ws.rs.core.MediaType) */ public Representation createRequestRepresentation( AbstractResource r, AbstractResourceMethod m, MediaType mediaType ) { final Representation result = _delegate.createRequestRepresentation( r, m, mediaType ); final RepresentationDocType requestRepresentation = resourceDoc.getRequestRepresentation( r.getResourceClass(), m.getMethod(), result.getMediaType() ); if ( requestRepresentation != null ) { result.setElement( requestRepresentation.getElement() ); addDocForExample( result.getDoc(), requestRepresentation.getExample() ); } return result; }