Search in sources :

Example 1 with ResponseStatus

use of org.apache.cxf.jaxrs.ext.ResponseStatus in project cxf by apache.

the class WadlGenerator method handleOperation.

// CHECKSTYLE:OFF
protected boolean handleOperation(StringBuilder sb, Set<Class<?>> jaxbTypes, ElementQNameResolver qnameResolver, Map<Class<?>, QName> clsMap, OperationResourceInfo ori, Map<Parameter, Object> classParams, OperationResourceInfo nextOp, boolean resourceTagOpened, boolean isJson, int index) {
    Annotation[] anns = getMethod(ori).getAnnotations();
    // CHECKSTYLE:ON
    boolean samePathOperationFollows = singleResourceMultipleMethods && compareOperations(ori, nextOp);
    String path = ori.getURITemplate().getValue();
    if (!resourceTagOpened && openResource(path)) {
        resourceTagOpened = true;
        URITemplate template = ori.getClassResourceInfo().getURITemplate();
        if (template != null) {
            String parentPath = template.getValue();
            if (parentPath.endsWith("/") && path.startsWith("/") && path.length() > 1) {
                path = path.substring(1);
            }
        }
        startResourceTag(sb, ori, getPath(path));
        handleDocs(anns, sb, DocTarget.RESOURCE, false, isJson);
        handlePathAndMatrixClassParams(ori, sb, classParams, isJson);
        handlePathAndMatrixParams(sb, ori, isJson);
    } else if (index == 0) {
        handlePathAndMatrixClassParams(ori, sb, classParams, isJson);
        handlePathAndMatrixParams(sb, ori, isJson);
    }
    startMethodTag(sb, ori);
    if (!handleDocs(anns, sb, DocTarget.METHOD, true, isJson)) {
        handleOperJavaDocs(ori, sb);
    }
    int numOfParams = getMethod(ori).getParameterTypes().length;
    if ((numOfParams > 1 || numOfParams == 1 && !ori.isAsync()) || !classParams.isEmpty()) {
        startMethodRequestTag(sb, ori);
        handleDocs(anns, sb, DocTarget.REQUEST, false, isJson);
        boolean isForm = isFormRequest(ori);
        doHandleClassParams(ori, sb, classParams, isJson, ParameterType.QUERY, ParameterType.HEADER);
        doHandleJaxrsBeanParamClassParams(ori, sb, classParams, isJson, ParameterType.QUERY, ParameterType.HEADER);
        for (Parameter p : ori.getParameters()) {
            if (isForm && p.getType() == ParameterType.REQUEST_BODY) {
                continue;
            }
            handleParameter(sb, jaxbTypes, qnameResolver, clsMap, ori, p, isJson);
        }
        if (isForm) {
            handleFormRepresentation(sb, jaxbTypes, qnameResolver, clsMap, ori, getFormClass(ori), isJson);
        }
        endMethodRequestTag(sb, ori);
    }
    startMethodResponseTag(sb, ori);
    Class<?> returnType = getMethod(ori).getReturnType();
    boolean isVoid = void.class == returnType && !ori.isAsync();
    ResponseStatus responseStatus = getMethod(ori).getAnnotation(ResponseStatus.class);
    if (responseStatus != null) {
        setResponseStatus(sb, responseStatus.value());
    } else if (isVoid) {
        boolean oneway = getMethod(ori).getAnnotation(Oneway.class) != null;
        setResponseStatus(sb, oneway ? Response.Status.ACCEPTED : Response.Status.NO_CONTENT);
    }
    sb.append(">");
    handleDocs(anns, sb, DocTarget.RESPONSE, false, isJson);
    if (!isVoid) {
        handleRepresentation(sb, jaxbTypes, qnameResolver, clsMap, ori, returnType, isJson, false);
    }
    endMethodResponseTag(sb, ori);
    endMethodTag(sb, ori);
    if (resourceTagOpened && !samePathOperationFollows) {
        endResourceTag(sb, ori);
        resourceTagOpened = false;
    }
    return resourceTagOpened;
}
Also used : ResponseStatus(org.apache.cxf.jaxrs.ext.ResponseStatus) URITemplate(org.apache.cxf.jaxrs.model.URITemplate) Parameter(org.apache.cxf.jaxrs.model.Parameter) Annotation(java.lang.annotation.Annotation) Endpoint(org.apache.cxf.endpoint.Endpoint)

Aggregations

Annotation (java.lang.annotation.Annotation)1 Endpoint (org.apache.cxf.endpoint.Endpoint)1 ResponseStatus (org.apache.cxf.jaxrs.ext.ResponseStatus)1 Parameter (org.apache.cxf.jaxrs.model.Parameter)1 URITemplate (org.apache.cxf.jaxrs.model.URITemplate)1