Java Code Examples for org.apache.cxf.jaxrs.model.OperationResourceInfo#getAnnotatedMethod()

The following examples show how to use org.apache.cxf.jaxrs.model.OperationResourceInfo#getAnnotatedMethod() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ValidationInterceptor.java    From carbon-device-mgt with Apache License 2.0 5 votes vote down vote up
@Override
public void handleMessage(Message message) throws Fault {
    final OperationResourceInfo operationResource = message.getExchange().get(OperationResourceInfo.class);
    if (operationResource == null) {
        log.info("OperationResourceInfo is not available, skipping validation");
        return;
    }

    final ClassResourceInfo classResource = operationResource.getClassResourceInfo();
    if (classResource == null) {
        log.info("ClassResourceInfo is not available, skipping validation");
        return;
    }

    final ResourceProvider resourceProvider = classResource.getResourceProvider();
    if (resourceProvider == null) {
        log.info("ResourceProvider is not available, skipping validation");
        return;
    }

    final List<Object> arguments = MessageContentsList.getContentsList(message);
    final Method method = operationResource.getAnnotatedMethod();
    final Object instance = resourceProvider.getInstance(message);
    if (method != null && arguments != null) {
        //validate the parameters(arguments) over the invoked method
        validate(method, arguments.toArray(), instance);

        //validate the fields of each argument
        for (Object arg : arguments) {
            if (arg != null)
                validate(arg);
        }
    }

}
 
Example 2
Source File: ValidationInterceptor.java    From carbon-device-mgt with Apache License 2.0 5 votes vote down vote up
@Override
public void handleMessage(Message message) throws Fault {
    final OperationResourceInfo operationResource = message.getExchange().get(OperationResourceInfo.class);
    if (operationResource == null) {
        log.info("OperationResourceInfo is not available, skipping validation");
        return;
    }

    final ClassResourceInfo classResource = operationResource.getClassResourceInfo();
    if (classResource == null) {
        log.info("ClassResourceInfo is not available, skipping validation");
        return;
    }

    final ResourceProvider resourceProvider = classResource.getResourceProvider();
    if (resourceProvider == null) {
        log.info("ResourceProvider is not available, skipping validation");
        return;
    }

    final List<Object> arguments = MessageContentsList.getContentsList(message);
    final Method method = operationResource.getAnnotatedMethod();
    final Object instance = resourceProvider.getInstance(message);
    if (method != null && arguments != null) {
        //validate the parameters(arguments) over the invoked method
        validate(method, arguments.toArray(), instance);

        //validate the fields of each argument
        for (Object arg : arguments) {
            if (arg != null)
                validate(arg);
        }
    }

}
 
Example 3
Source File: ValidationInInterceptor.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
public void handleMessage(Message message) {

        final OperationResourceInfo operationResource = message.getExchange().get(OperationResourceInfo.class);
        if (operationResource == null) {
            log.info("OperationResourceInfo is not available, skipping validation");
            return;
        }

        final ClassResourceInfo classResource = operationResource.getClassResourceInfo();
        if (classResource == null) {
            log.info("ClassResourceInfo is not available, skipping validation");
            return;
        }

        final ResourceProvider resourceProvider = classResource.getResourceProvider();
        if (resourceProvider == null) {
            log.info("ResourceProvider is not available, skipping validation");
            return;
        }

        final List<Object> arguments = MessageContentsList.getContentsList(message);
        final Method method = operationResource.getAnnotatedMethod();
        final Object instance = resourceProvider.getInstance(message);
        if (method != null && arguments != null) {
            //validate the parameters(arguments) over the invoked method
            validate(method, arguments.toArray(), instance);

            //validate the fields of each argument
            for (Object arg : arguments) {
                if (arg != null)
                    validate(arg);
            }
        }
    }
 
Example 4
Source File: CrossOriginResourceSharingFilter.java    From cxf with Apache License 2.0 5 votes vote down vote up
private Method getResourceMethod(Message m, String httpMethod) {
    String requestUri = HttpUtils.getPathToMatch(m, true);

    List<ClassResourceInfo> resources = JAXRSUtils.getRootResources(m);
    Map<ClassResourceInfo, MultivaluedMap<String, String>> matchedResources =
        JAXRSUtils.selectResourceClass(resources, requestUri, m);
    if (matchedResources == null) {
        return null;
    }
    MultivaluedMap<String, String> values = new MetadataMap<>();
    OperationResourceInfo ori = findPreflightMethod(matchedResources, requestUri, httpMethod, values, m);
    return ori == null ? null : ori.getAnnotatedMethod();
}
 
Example 5
Source File: ResourceMapJavaDocProvider.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Override
public String getMethodDoc(OperationResourceInfo ori) {
    Method method = ori.getAnnotatedMethod() == null ? ori.getMethodToInvoke()
        : ori.getAnnotatedMethod();
    String methodKey = method.getDeclaringClass().getName()
        + "." + method.getName();
    return dumpedDocFile.getProperty(methodKey);
}
 
Example 6
Source File: ResourceMapJavaDocProvider.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Override
public String getMethodResponseDoc(OperationResourceInfo ori) {
    Method method = ori.getAnnotatedMethod() == null ? ori.getMethodToInvoke()
        : ori.getAnnotatedMethod();
    String methodResponseKey = method.getDeclaringClass().getName()
        + "." + method.getName() + "." + "returnCommentTag";
    return dumpedDocFile.getProperty(methodResponseKey);
}
 
Example 7
Source File: ResourceMapJavaDocProvider.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Override
public String getMethodParameterDoc(OperationResourceInfo ori, int paramIndex) {
    Method method = ori.getAnnotatedMethod() == null ? ori.getMethodToInvoke()
        : ori.getAnnotatedMethod();
    String methodParamKey = method.getDeclaringClass().getName()
        + "." + method.getName()
        + ".paramCommentTag." + paramIndex;
    return dumpedDocFile.getProperty(methodParamKey);
}
 
Example 8
Source File: ResourceUtils.java    From cxf with Apache License 2.0 4 votes vote down vote up
private static void getAllTypesForResource(ClassResourceInfo resource,
                                           ResourceTypes types,
                                           boolean jaxbOnly,
                                           MessageBodyWriter<?> jaxbWriter) {
    Class<?> jaxbElement = null;
    try {
        jaxbElement = ClassLoaderUtils.loadClass("javax.xml.bind.JAXBElement", ResourceUtils.class);
    } catch (final ClassNotFoundException e) {
        // no-op
    }

    for (OperationResourceInfo ori : resource.getMethodDispatcher().getOperationResourceInfos()) {
        Method method = ori.getAnnotatedMethod() == null ? ori.getMethodToInvoke() : ori.getAnnotatedMethod();
        Class<?> realReturnType = method.getReturnType();
        Class<?> cls = realReturnType;
        if (cls == Response.class || ori.isAsync()) {
            cls = getActualJaxbType(cls, method, false);
        }
        Type type = method.getGenericReturnType();
        if (jaxbOnly) {
            checkJaxbType(resource.getServiceClass(), cls, realReturnType == Response.class || ori.isAsync()
                ? cls : type, types, method.getAnnotations(), jaxbWriter, jaxbElement);
        } else {
            types.getAllTypes().put(cls, type);
        }

        for (Parameter pm : ori.getParameters()) {
            if (pm.getType() == ParameterType.REQUEST_BODY) {
                Class<?> inType = method.getParameterTypes()[pm.getIndex()];
                if (inType != AsyncResponse.class) {
                    Type paramType = method.getGenericParameterTypes()[pm.getIndex()];
                    if (jaxbOnly) {
                        checkJaxbType(resource.getServiceClass(), inType, paramType, types,
                                      method.getParameterAnnotations()[pm.getIndex()], jaxbWriter, jaxbElement);
                    } else {
                        types.getAllTypes().put(inType, paramType);
                    }
                }
            }
        }

    }

    for (ClassResourceInfo sub : resource.getSubResources()) {
        if (!isRecursiveSubResource(resource, sub)) {
            getAllTypesForResource(sub, types, jaxbOnly, jaxbWriter);
        }
    }
}
 
Example 9
Source File: JavaDocProvider.java    From cxf with Apache License 2.0 4 votes vote down vote up
private MethodDocs getOperationDocInternal(OperationResourceInfo ori) throws Exception {
    Method method = ori.getAnnotatedMethod() == null
            ? ori.getMethodToInvoke()
            : ori.getAnnotatedMethod();
    ClassDocs classDoc = getClassDocInternal(method.getDeclaringClass());
    if (classDoc == null) {
        return null;
    }
    MethodDocs mDocs = classDoc.getMethodDocs(method);
    if (mDocs == null) {
        String operLink = getOperLink();
        String operMarker = operLink + method.getName() + getOperationMarkerOpen();

        int operMarkerIndex = classDoc.getClassDoc().indexOf(operMarker);
        while (operMarkerIndex != -1) {
            int startOfOpSigIndex = operMarkerIndex + operMarker.length();
            int endOfOpSigIndex = classDoc.getClassDoc().indexOf(getOperationMarkerClose(),
                                                                 startOfOpSigIndex);
            int paramLen = method.getParameterTypes().length;
            if (endOfOpSigIndex == startOfOpSigIndex && paramLen == 0) {
                break;
            } else if (endOfOpSigIndex > startOfOpSigIndex + 1) {
                String paramSequence = classDoc.getClassDoc().substring(operMarkerIndex, endOfOpSigIndex);
                if (paramSequence.startsWith(operMarker)) {
                    paramSequence = paramSequence.substring(operMarker.length());
                    String[] opBits = paramSequence.split(getOperationParamSeparator());
                    if (opBits.length == paramLen) {
                        break;
                    }
                }
            }
            operMarkerIndex = classDoc.getClassDoc().indexOf(operMarker,
                                                             operMarkerIndex + operMarker.length());
        }

        if (operMarkerIndex == -1) {
            return null;
        }

        String operDoc = classDoc.getClassDoc().substring(operMarkerIndex + operMarker.length());
        String operInfoTag = getOperInfoTag();
        String operInfo = getJavaDocText(operDoc, operInfoTag, operLink, 0);
        String responseInfo = null;
        List<String> paramDocs = new LinkedList<>();
        if (!StringUtils.isEmpty(operInfo)) {
            int returnsIndex = operDoc.indexOf("Returns:", operLink.length());
            int nextOpIndex = operDoc.indexOf(operLink);
            if (returnsIndex != -1 && (nextOpIndex > returnsIndex || nextOpIndex == -1)) {
                responseInfo = getJavaDocText(operDoc, getResponseMarker(), operLink, returnsIndex + 8);
            }

            int paramIndex = operDoc.indexOf("Parameters:");
            if (paramIndex != -1 && (nextOpIndex == -1 || paramIndex < nextOpIndex)) {
                String paramString = returnsIndex == -1 ? operDoc.substring(paramIndex)
                    : operDoc.substring(paramIndex, returnsIndex);

                String codeTag = getCodeTag();

                int codeIndex = paramString.indexOf(codeTag);
                while (codeIndex != -1) {
                    int next = paramString.indexOf('<', codeIndex + 7);
                    if (next == -1) {
                        next = paramString.length();
                    }
                    String param = paramString.substring(codeIndex + 7, next).trim();
                    if (param.startsWith("-")) {
                        param = param.substring(1).trim();
                    }
                    paramDocs.add(param);
                    if (next == paramString.length()) {
                        break;
                    }
                    codeIndex = next + 1;
                    codeIndex = paramString.indexOf(codeTag, codeIndex);
                }

            }
        }
        mDocs = new MethodDocs(operInfo, paramDocs, responseInfo);
        classDoc.addMethodDocs(method, mDocs);
    }

    return mDocs;
}
 
Example 10
Source File: ClientProxyImpl.java    From cxf with Apache License 2.0 4 votes vote down vote up
protected static Multipart getMultipart(OperationResourceInfo ori, int index) {
    Method aMethod = ori.getAnnotatedMethod();
    return aMethod != null ? AnnotationUtils.getAnnotation(
        aMethod.getParameterAnnotations()[index], Multipart.class) : null;
}
 
Example 11
Source File: WadlGenerator.java    From cxf with Apache License 2.0 4 votes vote down vote up
private Method getMethod(OperationResourceInfo ori) {
    Method annMethod = ori.getAnnotatedMethod();
    return annMethod != null ? annMethod : ori.getMethodToInvoke();
}