Method method = methodMetadata.getReflectionMethod(); if (Void.TYPE.equals(method.getReturnType())) { if (produces.size() > 0 && methodMetadata.getProduces().equals(produces)) { methodMetadata.addProduces(MediaType.WILDCARD_TYPE); logger .trace("Method has a @Produces value but also a void return type so adding a */* to allow any response: {} ", if (consumes.size() > 0 && methodMetadata.getConsumes().equals(consumes)) { List<Injectable> params = methodMetadata.getFormalParameters(); boolean isEntityParamFound = false; for (Injectable p : params) { methodMetadata.addConsumes(MediaType.WILDCARD_TYPE); logger .trace("Method has a @Consumes value but no entity parameter so adding a */* to allow any request: {} ",
private boolean providesOpenSearch(MethodMetadata method) { if (method.getHttpMethod().equals(HttpMethod.GET) && method.getProduces() .equals(MediaTypeUtils.OPENSEARCH_TYPE)) { return true; } return false; } }
public SubResourceRecord(MethodMetadata metadata) { super(UriTemplateProcessor.newNormalizedInstance(metadata.getPath())); this.metadata = metadata; }
private static Set<MediaType> getCollectionConsumes(ClassMetadata metadata) { Set<MediaType> consumes = new HashSet<MediaType>(); for (MethodMetadata method : metadata.getResourceMethods()) { if (method.getHttpMethod().equals(HttpMethod.POST)) { consumes.addAll(method.getConsumes()); } } for (MethodMetadata method : metadata.getSubResourceMethods()) { if (method.getHttpMethod().equals(HttpMethod.POST)) { consumes.addAll(method.getConsumes()); } } return consumes; }
private void mergeFormalParameterMetadata(MethodMetadata metadata, Method method) { logger.trace("mergeFormalParameterMetadata({})", new Object[] {metadata, method}); Type[] parameterTypes = method.getGenericParameterTypes(); List<Injectable> currentParameters = new ArrayList<Injectable>(metadata.getFormalParameters()); metadata.getFormalParameters().clear(); int i = 0; for (Injectable injectable : currentParameters) { Injectable fp = InjectableFactory.getInstance().create(parameterTypes[i], injectable.getAnnotations(), method, getMetadata().isEncoded() || metadata .isEncoded(), metadata.getDefaultValue()); metadata.getFormalParameters().add(fp); ++i; } logger.trace("mergeFormalParameterMetadata exit"); }
MethodMetadata metadata = new MethodMetadata(getMetadata()); metadata.setReflectionMethod(method); if (httpMethod != null) { hasAnnotation = true; metadata.setHttpMethod(httpMethod.value()); if (path != null) { hasAnnotation = true; metadata.addPath(path.value()); for (String mediaType : consumes) { hasAnnotation = true; metadata.addConsumes(MediaType.valueOf(mediaType)); for (String mediaType : produces) { hasAnnotation = true; metadata.addProduces(MediaType.valueOf(mediaType)); metadata.setDefaultValue(defaultValue); hasAnnotation = true; metadata.setEncoded(true); hasAnnotation = true; if (metadata.getHttpMethod() == null && metadata.getPath() == null) { if (metadata.isEncoded() || defaultValue != null) {
String path = methodMetadata.getPath(); String httpMethod = methodMetadata.getHttpMethod(); if (path != null) { for (Injectable id : methodMetadata.getFormalParameters()) { if (id.getParamType() == Injectable.ParamType.ENTITY) { if (logger.isWarnEnabled()) { if (!methodMetadata.getConsumes().isEmpty() || !methodMetadata .getProduces().isEmpty()) { if (logger.isWarnEnabled()) { logger.warn(Messages
try { String path = resourcePath; String httpMethod = methodMetadata.getHttpMethod(); String consumes = constructMediaTypeString(methodMetadata.getConsumes()); String produces = constructMediaTypeString(methodMetadata.getProduces()); constructMethodString(methodMetadata.getReflectionMethod()); path.append("/"); path.append(method.getPath()); String httpMethod = method.getHttpMethod(); if (httpMethod == null) { httpMethod = "(Sub-Locator)"; String consumes = constructMediaTypeString(method.getConsumes()); String produces = constructMediaTypeString(method.getProduces()); String methodName = constructMethodString(method.getReflectionMethod());
List<Injectable> params = methodMeta.getFormalParameters(); if (params != null && params.size() > 0) { for (Injectable p : params) { Method m = buildMethod(metadata, methodMeta); subRes.getMethodOrResource().add(m); subRes.setPath(methodMeta.getPath()); methodOrSubresource.add(subRes); List<Param> subResParams = subRes.getParam(); List<Injectable> params = methodMeta.getFormalParameters(); if (params != null && params.size() > 0) { for (Injectable p : params) { for (MethodMetadata methodMeta : methodMetadata) { Resource subRes = new Resource(); subRes.setPath(methodMeta.getPath()); java.lang.reflect.Method reflMethod = methodMeta.getReflectionMethod(); if (reflMethod != null) { WADLDoc d = reflMethod.getAnnotation(WADLDoc.class); List<Injectable> params = methodMeta.getFormalParameters(); List<Param> subResParams = subRes.getParam(); if (params != null && params.size() > 0) {
private static Set<MediaType> getCollectionProduces(ClassMetadata metadata) { Set<MediaType> produces = new HashSet<MediaType>(); for (MethodMetadata method : metadata.getResourceMethods()) { produces.addAll(method.getProduces()); } for (MethodMetadata method : metadata.getSubResourceMethods()) { produces.addAll(method.getProduces()); } return produces; }
/* package */Method buildMethod(ClassMetadata classMetadata, MethodMetadata metadata) { Method m = new Method(); m.setName(metadata.getHttpMethod()); java.lang.reflect.Method reflMethod = metadata.getReflectionMethod(); if (reflMethod != null) { WADLDoc d = reflMethod.getAnnotation(WADLDoc.class); if (d != null) { m.getDoc().add(getDocument(d)); } } Request r = buildRequest(classMetadata, metadata); if (r != null) { m.setRequest(r); } List<Response> resp = buildResponse(metadata); if (resp != null) { m.getResponse().addAll(resp); } return m; }
Set<MediaType> consumesMT = methodMetadata.getConsumes(); Set<Representation> reps = null; if (consumesMT != null && !consumesMT.isEmpty()) { if (mt.isCompatible(MediaType.APPLICATION_FORM_URLENCODED_TYPE) || mt .isCompatible(MediaType.MULTIPART_FORM_DATA_TYPE)) { List<Injectable> injectables = methodMetadata.getFormalParameters(); if (injectables != null) { for (Injectable i : injectables) {
/** * Compares two methods the in terms of the number of parameters * * @param record1 the first method * @param record2 the second method * @return positive integer if record1 has more parameters, negative integer * if record2 has more parameters, 0 if they are equal in number of * parameters */ private int compareMethodsParameters(MethodRecord record1, MethodRecord record2) { List<Injectable> params1 = record1.getMetadata().getFormalParameters(); List<Injectable> params2 = record2.getMetadata().getFormalParameters(); return params1.size() - params2.size(); }
SubResource subResource = resourcesObjectFactory.createSubResource(); UriTemplateProcessor uriTemplate = record.getTemplateProcessor(); subResource.setUri(SLASH + uriTemplate.getTemplate() + subResourceLocator.getPath()); if (isLocator) { subResource.setType("Locator"); //$NON-NLS-1$ } else { subResource.setType("Method"); //$NON-NLS-1$ subResource.setMethod(subResourceLocator.getHttpMethod().toString());
/** * Checks if the method record matches the http method of the request * * @param record the method record to check * @param context the context of the current request * @return true if the method should be filtered, false otherwise */ private boolean filterByHttpMethod(MethodRecord record, RuntimeContext context) { String httpMethod = context.getRequest().getMethod(); String recordHttpMethod = record.getMetadata().getHttpMethod(); // non existing http method (with a path on the method), // then it's a sub-resource locator and it's ok if (recordHttpMethod == null) { return false; } // the http method is different than the request http method, // then the resource method should be filtered if (!recordHttpMethod.equals(httpMethod)) { return true; } return false; }
/* package */List<Response> buildResponse(MethodMetadata metadata) { if (metadata == null) { return null; } Response r = null; // Set<MediaType> produces = metadata.getProduces(); Set<Representation> representations = buildOutgoingRepresentation(metadata, null); if (representations != null && !representations.isEmpty()) { r = new Response(); r.getRepresentation().addAll(representations); } java.lang.reflect.Method m = metadata.getReflectionMethod(); if (Void.TYPE.equals(m.getReturnType())) { if (r == null) { r = new Response(); } r.getStatus().add(Long.valueOf(204)); } else if (!javax.ws.rs.core.Response.class.isAssignableFrom(m.getReturnType())) { if (r == null) { r = new Response(); } r.getStatus().add(Long.valueOf(200)); } return Collections.singletonList(r); }
private void buildCunsumeMimeTypes(MethodMetadata methodMetadata, org.apache.wink.common.internal.model.admin.AcceptMediaTypes xmlAcceptMediaTypes) { Set<MediaType> consumedMime = methodMetadata.getConsumes(); for (MediaType mediaType : consumedMime) { xmlAcceptMediaTypes.getAcceptMediaType().add(mediaType.getType() + SLASH + mediaType.getSubtype()); } } }
private void parseMethodParameters(Method method, MethodMetadata methodMetadata) { logger.trace("parseMethodParameters({}, {}), entry", method, methodMetadata); Annotation[][] parameterAnnotations = method.getParameterAnnotations(); Type[] paramTypes = getParamTypesFilterByXmlElementAnnotation(method); boolean entityParamExists = false; for (int pos = 0, limit = paramTypes.length; pos < limit; pos++) { Injectable fp = InjectableFactory.getInstance().create(paramTypes[pos], parameterAnnotations[pos], method, getMetadata().isEncoded() || methodMetadata .isEncoded(), methodMetadata.getDefaultValue()); if (fp.getParamType() == Injectable.ParamType.ENTITY) { if (entityParamExists) { // we are allowed to have only one entity parameter String methodName = method.getDeclaringClass().getName() + "." + method.getName(); //$NON-NLS-1$ throw new IllegalStateException(Messages .getMessage("resourceMethodMoreThanOneEntityParam", methodName)); //$NON-NLS-1$ } entityParamExists = true; } methodMetadata.getFormalParameters().add(fp); logger.trace("Adding formal parameter {}", fp); } logger.trace("parseMethodParameters(), exit"); }
private void buildProduceMimeTypes(MethodMetadata methodMetadata, org.apache.wink.common.internal.model.admin.ProducedMediaTypes xmlProducedMediaTypes) { Set<MediaType> producedMime = methodMetadata.getProduces(); for (MediaType mediaType : producedMime) { xmlProducedMediaTypes.getProducedMediaType().add(mediaType.getType() + SLASH + mediaType.getSubtype()); } }
public void handleRequest(MessageContext context, HandlersChain chain) throws Throwable { SearchResult result = context.getAttribute(SearchResult.class); // create and save the invocation parameters for the found method List<Injectable> formal = result.getMethod().getMetadata().getFormalParameters(); logger.trace("Formal Injectable parameters list is: {}", formal); //$NON-NLS-1$ Object[] parameters = InjectableFactory.getInstance().instantiate(formal, context); if(logger.isTraceEnabled()) { if(parameters == null) { logger.trace("Actual parameters list to inject is: null"); //$NON-NLS-1$ } else { logger.trace("Actual parameters list to inject is: {}", parameters); //$NON-NLS-1$ } } result.setInvocationParameters(parameters); chain.doChain(context); }