Search in sources :

Example 1 with CompletionFailureException

use of com.webcohesion.enunciate.CompletionFailureException in project enunciate by stoicflame.

the class JaxrsModule method call.

@Override
public void call(EnunciateContext context) {
    jaxrsContext = new EnunciateJaxrsContext(context, isDisableExamples());
    DataTypeDetectionStrategy detectionStrategy = getDataTypeDetectionStrategy();
    String relativeContextPath = "";
    if (detectionStrategy != DataTypeDetectionStrategy.passive) {
        Set<? extends Element> elements = detectionStrategy == DataTypeDetectionStrategy.local ? context.getLocalApiElements() : context.getApiElements();
        for (Element declaration : elements) {
            LinkedList<Element> contextStack = new LinkedList<>();
            contextStack.push(declaration);
            try {
                if (declaration instanceof TypeElement) {
                    TypeElement element = (TypeElement) declaration;
                    if ("org.glassfish.jersey.server.wadl.internal.WadlResource".equals(element.getQualifiedName().toString())) {
                        // known internal wadl resource not to be documented.
                        continue;
                    }
                    if (isIgnored(declaration)) {
                        continue;
                    }
                    javax.ws.rs.Path pathInfo = declaration.getAnnotation(javax.ws.rs.Path.class);
                    jakarta.ws.rs.Path pathInfo2 = declaration.getAnnotation(jakarta.ws.rs.Path.class);
                    if (pathInfo != null || pathInfo2 != null) {
                        // add root resource.
                        RootResource rootResource = new RootResource(element, jaxrsContext);
                        jaxrsContext.add(rootResource);
                        for (ResourceMethod resourceMethod : rootResource.getResourceMethods(true)) {
                            addReferencedDataTypeDefinitions(resourceMethod, contextStack);
                        }
                    }
                    javax.ws.rs.ext.Provider providerInfo = declaration.getAnnotation(javax.ws.rs.ext.Provider.class);
                    jakarta.ws.rs.ext.Provider providerInfo2 = declaration.getAnnotation(jakarta.ws.rs.ext.Provider.class);
                    if (providerInfo != null || providerInfo2 != null) {
                        // add jax-rs provider
                        jaxrsContext.addJAXRSProvider(element);
                    }
                    javax.ws.rs.ApplicationPath applicationPathInfo = declaration.getAnnotation(javax.ws.rs.ApplicationPath.class);
                    jakarta.ws.rs.ApplicationPath applicationPathInfo2 = declaration.getAnnotation(jakarta.ws.rs.ApplicationPath.class);
                    if (applicationPathInfo != null || applicationPathInfo2 != null) {
                        relativeContextPath = applicationPathInfo != null ? applicationPathInfo.value() : applicationPathInfo2.value();
                    }
                }
            } catch (RuntimeException e) {
                if (e.getClass().getName().endsWith("CompletionFailure")) {
                    throw new CompletionFailureException(contextStack, e);
                }
                throw e;
            } finally {
                contextStack.pop();
            }
        }
    }
    // tidy up the application path.
    relativeContextPath = this.config.getString("application[@path]", relativeContextPath);
    relativeContextPath = sanitizeContextPath(relativeContextPath);
    jaxrsContext.setRelativeContextPath(relativeContextPath);
    jaxrsContext.setGroupingStrategy(getGroupingStrategy());
    jaxrsContext.setPathSortStrategy(getPathSortStrategy());
    if (jaxrsContext.getRootResources().size() > 0) {
        this.enunciate.addArtifact(new JaxrsRootResourceClassListArtifact(this.jaxrsContext));
    }
    if (this.jaxrsContext.getProviders().size() > 0) {
        this.enunciate.addArtifact(new JaxrsProviderClassListArtifact(this.jaxrsContext));
    }
}
Also used : Element(javax.lang.model.element.Element) TypeElement(javax.lang.model.element.TypeElement) EnunciateContext(com.webcohesion.enunciate.EnunciateContext) TypeElement(javax.lang.model.element.TypeElement) CompletionFailureException(com.webcohesion.enunciate.CompletionFailureException)

Example 2 with CompletionFailureException

use of com.webcohesion.enunciate.CompletionFailureException in project enunciate by stoicflame.

the class JaxwsModule method addReferencedTypeDefinitions.

protected void addReferencedTypeDefinitions(WebMethod webMethod, LinkedList<Element> contextStack) {
    contextStack.push(webMethod);
    try {
        WebResult result = webMethod.getWebResult();
        this.jaxbModule.getJaxbContext().addReferencedTypeDefinitions(result.isAdapted() ? result.getAdapterType() : result.getType(), contextStack);
        for (WebParam webParam : webMethod.getWebParameters()) {
            this.jaxbModule.getJaxbContext().addReferencedTypeDefinitions(webParam.isAdapted() ? webParam.getAdapterType() : webParam.getType(), contextStack);
        }
        for (WebFault webFault : webMethod.getWebFaults()) {
            addReferencedTypeDefinitions(webFault, contextStack);
        }
    } catch (RuntimeException e) {
        if (e.getClass().getName().endsWith("CompletionFailure")) {
            throw new CompletionFailureException(contextStack, e);
        }
        throw e;
    } finally {
        contextStack.pop();
    }
}
Also used : CompletionFailureException(com.webcohesion.enunciate.CompletionFailureException)

Example 3 with CompletionFailureException

use of com.webcohesion.enunciate.CompletionFailureException in project enunciate by stoicflame.

the class JaxwsModule method addReferencedDataTypeDefinitions.

protected void addReferencedDataTypeDefinitions(EndpointInterface ei) {
    LinkedList<Element> contextStack = new LinkedList<>();
    contextStack.push(ei);
    try {
        for (WebMethod webMethod : ei.getWebMethods()) {
            addReferencedTypeDefinitions(webMethod, contextStack);
        }
    } catch (RuntimeException e) {
        if (e.getClass().getName().endsWith("CompletionFailure")) {
            throw new CompletionFailureException(contextStack, e);
        }
        throw e;
    } finally {
        contextStack.pop();
    }
}
Also used : CompletionFailureException(com.webcohesion.enunciate.CompletionFailureException) Element(javax.lang.model.element.Element) TypeElement(javax.lang.model.element.TypeElement) ImplicitChildElement(com.webcohesion.enunciate.modules.jaxb.model.ImplicitChildElement)

Example 4 with CompletionFailureException

use of com.webcohesion.enunciate.CompletionFailureException in project enunciate by stoicflame.

the class JaxbModule method addPotentialJaxbElement.

public void addPotentialJaxbElement(Element declaration, LinkedList<Element> contextStack) {
    try {
        if (declaration instanceof TypeElement) {
            XmlRegistry registryMetadata = declaration.getAnnotation(XmlRegistry.class);
            if (registryMetadata != null) {
                Registry registry = new Registry((TypeElement) declaration, jaxbContext);
                this.jaxbContext.add(registry);
            } else if (!this.jaxbContext.isKnownTypeDefinition((TypeElement) declaration) && isExplicitTypeDefinition(declaration)) {
                this.jaxbContext.add(this.jaxbContext.createTypeDefinition((TypeElement) declaration), contextStack);
            }
        }
    } catch (RuntimeException e) {
        if (e.getClass().getName().endsWith("CompletionFailure")) {
            contextStack = new LinkedList<>(contextStack);
            contextStack.push(declaration);
            throw new CompletionFailureException(contextStack, e);
        }
        throw e;
    }
}
Also used : CompletionFailureException(com.webcohesion.enunciate.CompletionFailureException) ApiRegistry(com.webcohesion.enunciate.api.ApiRegistry) XmlRegistry(javax.xml.bind.annotation.XmlRegistry) Registry(com.webcohesion.enunciate.modules.jaxb.model.Registry) XmlRegistry(javax.xml.bind.annotation.XmlRegistry)

Example 5 with CompletionFailureException

use of com.webcohesion.enunciate.CompletionFailureException in project enunciate by stoicflame.

the class JaxrsModule method addReferencedDataTypeDefinitions.

/**
 * Add the referenced type definitions for the specified resource method.
 *
 * @param resourceMethod The resource method.
 */
protected void addReferencedDataTypeDefinitions(ResourceMethod resourceMethod, LinkedList<Element> contextStack) {
    if (AnnotationUtils.isIgnored(resourceMethod)) {
        return;
    }
    ResourceEntityParameter ep = resourceMethod.getEntityParameter();
    if (ep != null) {
        Set<com.webcohesion.enunciate.modules.jaxrs.model.util.MediaType> consumesMt = resourceMethod.getConsumesMediaTypes();
        Set<String> consumes = new TreeSet<>();
        for (MediaType mediaType : consumesMt) {
            consumes.add(mediaType.getMediaType());
        }
        contextStack.push(ep.getDelegate());
        TypeMirror type = ep.getType();
        contextStack.push(resourceMethod);
        try {
            for (MediaTypeDefinitionModule mediaTypeModule : this.mediaTypeModules) {
                mediaTypeModule.addDataTypeDefinitions(type, consumes, contextStack);
            }
        } catch (RuntimeException e) {
            if (e.getClass().getName().endsWith("CompletionFailure")) {
                throw new CompletionFailureException(contextStack, e);
            }
            throw e;
        } finally {
            contextStack.pop();
        }
    }
    ResourceRepresentationMetadata outputPayload = resourceMethod.getRepresentationMetadata();
    if (outputPayload != null) {
        TypeMirror type = outputPayload.getDelegate();
        Set<com.webcohesion.enunciate.modules.jaxrs.model.util.MediaType> producesMt = resourceMethod.getProducesMediaTypes();
        Set<String> produces = new TreeSet<>();
        for (MediaType mediaType : producesMt) {
            produces.add(mediaType.getMediaType());
        }
        contextStack.push(resourceMethod);
        try {
            for (MediaTypeDefinitionModule mediaTypeModule : this.mediaTypeModules) {
                mediaTypeModule.addDataTypeDefinitions(type, produces, contextStack);
            }
        } catch (RuntimeException e) {
            if (e.getClass().getName().endsWith("CompletionFailure")) {
                throw new CompletionFailureException(contextStack, e);
            }
            throw e;
        } finally {
            contextStack.pop();
        }
    }
    List<? extends ResponseCode> statusCodes = resourceMethod.getStatusCodes();
    if (statusCodes != null) {
        for (ResponseCode statusCode : statusCodes) {
            TypeMirror type = statusCode.getType();
            if (type != null) {
                Set<com.webcohesion.enunciate.modules.jaxrs.model.util.MediaType> producesMt = resourceMethod.getProducesMediaTypes();
                Set<String> produces = new TreeSet<>();
                for (MediaType mediaType : producesMt) {
                    produces.add(mediaType.getMediaType());
                }
                contextStack.push(resourceMethod);
                try {
                    for (MediaTypeDefinitionModule mediaTypeModule : this.mediaTypeModules) {
                        mediaTypeModule.addDataTypeDefinitions(type, produces, contextStack);
                    }
                } catch (RuntimeException e) {
                    if (e.getClass().getName().endsWith("CompletionFailure")) {
                        throw new CompletionFailureException(contextStack, e);
                    }
                    throw e;
                } finally {
                    contextStack.pop();
                }
            }
        }
    }
}
Also used : CompletionFailureException(com.webcohesion.enunciate.CompletionFailureException) TypeMirror(javax.lang.model.type.TypeMirror) MediaType(com.webcohesion.enunciate.modules.jaxrs.model.util.MediaType) com.webcohesion.enunciate.modules.jaxrs.model(com.webcohesion.enunciate.modules.jaxrs.model)

Aggregations

CompletionFailureException (com.webcohesion.enunciate.CompletionFailureException)10 Element (javax.lang.model.element.Element)4 TypeElement (javax.lang.model.element.TypeElement)4 ImplicitChildElement (com.webcohesion.enunciate.modules.jaxb.model.ImplicitChildElement)3 TypeMirror (javax.lang.model.type.TypeMirror)2 XmlRegistry (javax.xml.bind.annotation.XmlRegistry)2 EnunciateContext (com.webcohesion.enunciate.EnunciateContext)1 EnunciateException (com.webcohesion.enunciate.EnunciateException)1 ApiRegistry (com.webcohesion.enunciate.api.ApiRegistry)1 Registry (com.webcohesion.enunciate.modules.jaxb.model.Registry)1 com.webcohesion.enunciate.modules.jaxrs.model (com.webcohesion.enunciate.modules.jaxrs.model)1 MediaType (com.webcohesion.enunciate.modules.jaxrs.model.util.MediaType)1 File (java.io.File)1 DeclaredType (javax.lang.model.type.DeclaredType)1 ConfigurationException (org.apache.commons.configuration.ConfigurationException)1 HierarchicalConfiguration (org.apache.commons.configuration.HierarchicalConfiguration)1 XMLConfiguration (org.apache.commons.configuration.XMLConfiguration)1 Controller (org.springframework.stereotype.Controller)1 RestController (org.springframework.web.bind.annotation.RestController)1