Search in sources :

Example 6 with CompletionFailureException

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

the class JaxwsModule method addReferencedTypeDefinitions.

protected void addReferencedTypeDefinitions(WebFault webFault, LinkedList<Element> contextStack) {
    contextStack.push(webFault);
    try {
        if (webFault.isImplicitSchemaElement()) {
            for (ImplicitChildElement childElement : webFault.getChildElements()) {
                WebFault.FaultBeanChildElement fbce = (WebFault.FaultBeanChildElement) childElement;
                this.jaxbModule.getJaxbContext().addReferencedTypeDefinitions(fbce.isAdapted() ? fbce.getAdapterType() : fbce.getType(), contextStack);
            }
        } else {
            DeclaredType faultBeanType = webFault.getExplicitFaultBeanType();
            if (faultBeanType != null) {
                this.jaxbModule.getJaxbContext().addReferencedTypeDefinitions(faultBeanType, 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) ImplicitChildElement(com.webcohesion.enunciate.modules.jaxb.model.ImplicitChildElement) DeclaredType(javax.lang.model.type.DeclaredType)

Example 7 with CompletionFailureException

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

the class JaxwsModule method call.

@Override
public void call(EnunciateContext context) {
    jaxwsContext = new EnunciateJaxwsContext(this.jaxbModule.getJaxbContext(), isUseSourceParameterNames());
    boolean aggressiveWebMethodExcludePolicy = isAggressiveWebMethodExcludePolicy();
    Map<String, String> eiPaths = new HashMap<>();
    File sunJaxwsXmlFile = getSunJaxwsXmlFile();
    if (sunJaxwsXmlFile != null) {
        XMLConfiguration config;
        try {
            config = new XMLConfiguration(sunJaxwsXmlFile);
        } catch (ConfigurationException e) {
            throw new EnunciateException(e);
        }
        List<HierarchicalConfiguration> endpoints = config.configurationsAt("endpoint");
        for (HierarchicalConfiguration endpoint : endpoints) {
            String impl = endpoint.getString("[@implementation]", null);
            String urlPattern = endpoint.getString("[@url-pattern]", null);
            if (impl != null && urlPattern != null) {
                eiPaths.put(impl, urlPattern);
            }
        }
    }
    DataTypeDetectionStrategy detectionStrategy = getDataTypeDetectionStrategy();
    if (detectionStrategy != DataTypeDetectionStrategy.passive) {
        Set<? extends Element> elements = detectionStrategy == DataTypeDetectionStrategy.local ? context.getLocalApiElements() : context.getApiElements();
        for (Element declaration : elements) {
            try {
                if (declaration instanceof TypeElement) {
                    TypeElement element = (TypeElement) declaration;
                    XmlRegistry registryMetadata = declaration.getAnnotation(XmlRegistry.class);
                    if (registryMetadata != null) {
                        this.jaxbModule.addPotentialJaxbElement(element, new LinkedList<>());
                    }
                    if (isEndpointInterface(element)) {
                        EndpointInterface ei = new EndpointInterface(element, elements, aggressiveWebMethodExcludePolicy, jaxwsContext);
                        for (EndpointImplementation implementation : ei.getEndpointImplementations()) {
                            String urlPattern = eiPaths.get(implementation.getQualifiedName().toString());
                            if (urlPattern != null) {
                                if (!urlPattern.startsWith("/")) {
                                    urlPattern = "/" + urlPattern;
                                }
                                if (urlPattern.endsWith("/*")) {
                                    urlPattern = urlPattern.substring(0, urlPattern.length() - 2) + ei.getServiceName();
                                }
                                implementation.setPath(urlPattern);
                            }
                        }
                        jaxwsContext.add(ei);
                        addReferencedDataTypeDefinitions(ei);
                    }
                }
            } catch (RuntimeException e) {
                if (e.getClass().getName().endsWith("CompletionFailure")) {
                    throw new CompletionFailureException(Collections.singletonList(declaration), e);
                }
                throw e;
            }
        }
    }
}
Also used : TypeElement(javax.lang.model.element.TypeElement) Element(javax.lang.model.element.Element) TypeElement(javax.lang.model.element.TypeElement) ImplicitChildElement(com.webcohesion.enunciate.modules.jaxb.model.ImplicitChildElement) HierarchicalConfiguration(org.apache.commons.configuration.HierarchicalConfiguration) XmlRegistry(javax.xml.bind.annotation.XmlRegistry) CompletionFailureException(com.webcohesion.enunciate.CompletionFailureException) XMLConfiguration(org.apache.commons.configuration.XMLConfiguration) ConfigurationException(org.apache.commons.configuration.ConfigurationException) EnunciateException(com.webcohesion.enunciate.EnunciateException) File(java.io.File)

Example 8 with CompletionFailureException

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

the class Jackson1Module method addPotentialJacksonElement.

protected void addPotentialJacksonElement(Element declaration, LinkedList<Element> contextStack) {
    try {
        if (declaration instanceof TypeElement) {
            if (!this.jacksonContext.isKnownTypeDefinition((TypeElement) declaration) && isExplicitTypeDefinition(declaration, this.jacksonContext.isHonorJaxb())) {
                OneTimeLogMessage.JACKSON_1_DEPRECATED.log(this.context);
                this.jacksonContext.add(this.jacksonContext.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)

Example 9 with CompletionFailureException

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

the class SpringWebModule method addReferencedDataTypeDefinitions.

/**
 * Add the referenced type definitions for the specified resource method.
 *
 * @param requestMapping The resource method.
 */
protected void addReferencedDataTypeDefinitions(RequestMapping requestMapping, LinkedList<Element> contextStack) {
    ResourceEntityParameter ep = requestMapping.getEntityParameter();
    if (ep != null) {
        Set<String> consumes = requestMapping.getConsumesMediaTypes();
        contextStack.push(ep.getDelegate());
        TypeMirror type = ep.getType();
        contextStack.push(requestMapping);
        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 = requestMapping.getRepresentationMetadata();
    if (outputPayload != null) {
        TypeMirror type = outputPayload.getDelegate();
        Set<String> produces = requestMapping.getProducesMediaTypes();
        contextStack.push(requestMapping);
        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 = requestMapping.getStatusCodes();
    if (statusCodes != null) {
        for (ResponseCode statusCode : statusCodes) {
            TypeMirror type = statusCode.getType();
            if (type != null) {
                Set<String> produces = requestMapping.getProducesMediaTypes();
                contextStack.push(requestMapping);
                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)

Example 10 with CompletionFailureException

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

the class SpringWebModule method call.

@Override
public void call(EnunciateContext context) {
    springContext = new EnunciateSpringWebContext(context, isDisableExamples());
    DataTypeDetectionStrategy detectionStrategy = getDataTypeDetectionStrategy();
    if (detectionStrategy != DataTypeDetectionStrategy.passive) {
        Set<? extends Element> elements = detectionStrategy == DataTypeDetectionStrategy.local ? context.getLocalApiElements() : context.getApiElements();
        for (Element declaration : elements) {
            try {
                // first loop through and gather all the controller advice.
                if (declaration instanceof TypeElement) {
                    TypeElement element = (TypeElement) declaration;
                    Controller controllerInfo = AnnotationUtils.getMetaAnnotation(Controller.class, declaration);
                    if (controllerInfo != null || AnnotationUtils.getMetaAnnotation(ControllerAdvice.class, declaration) != null) {
                        springContext.add(new SpringControllerAdvice(element, springContext));
                    }
                }
            } catch (RuntimeException e) {
                if (e.getClass().getName().endsWith("CompletionFailure")) {
                    throw new CompletionFailureException(Collections.singletonList(declaration), e);
                }
                throw e;
            }
        }
        for (Element declaration : elements) {
            LinkedList<Element> contextStack = new LinkedList<>();
            contextStack.push(declaration);
            try {
                if (declaration instanceof TypeElement) {
                    TypeElement element = (TypeElement) declaration;
                    Controller controllerInfo = AnnotationUtils.getMetaAnnotation(Controller.class, declaration);
                    if (controllerInfo != null) {
                        // add root resource.
                        SpringController springController = new SpringController(element, springContext);
                        List<RequestMapping> requestMappings = springController.getRequestMappings();
                        if (!requestMappings.isEmpty()) {
                            springContext.add(springController);
                            for (RequestMapping requestMapping : requestMappings) {
                                addReferencedDataTypeDefinitions(requestMapping, contextStack);
                            }
                        }
                    }
                }
            } catch (RuntimeException e) {
                if (e.getClass().getName().endsWith("CompletionFailure")) {
                    throw new CompletionFailureException(contextStack, e);
                }
                throw e;
            } finally {
                contextStack.pop();
            }
        }
    }
    // tidy up the application path.
    String relativeContextPath = this.config.getString("application[@path]", "");
    while (relativeContextPath.startsWith("/")) {
        relativeContextPath = relativeContextPath.substring(1);
    }
    while (relativeContextPath.endsWith("/")) {
        // trim off any leading slashes
        relativeContextPath = relativeContextPath.substring(0, relativeContextPath.length() - 1);
    }
    springContext.setRelativeContextPath(relativeContextPath);
    springContext.setGroupingStrategy(getGroupingStrategy());
    springContext.setPathSortStrategy(getPathSortStrategy());
}
Also used : TypeElement(javax.lang.model.element.TypeElement) Element(javax.lang.model.element.Element) TypeElement(javax.lang.model.element.TypeElement) Controller(org.springframework.stereotype.Controller) RestController(org.springframework.web.bind.annotation.RestController) CompletionFailureException(com.webcohesion.enunciate.CompletionFailureException)

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