Search in sources :

Example 1 with WebServiceHandler

use of com.sun.enterprise.deployment.WebServiceHandler in project Payara by payara.

the class HandlerChainClassCheck method check.

public Result check(WebServiceEndpoint descriptor) {
    Result result = getInitializedResult();
    ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
    // Handler chains are applicable only in the context of JAX-WS 2.0. So
    // version check for this test is not required.
    List handlerChain = descriptor.getHandlerChain();
    for (Iterator it = handlerChain.iterator(); it.hasNext(); ) {
        List handlers = ((WebServiceHandlerChain) it.next()).getHandlers();
        for (Iterator itr = handlers.iterator(); itr.hasNext(); ) {
            String hClass = ((WebServiceHandler) itr.next()).getHandlerClass();
            try {
                Class cl = Class.forName(hClass, false, getVerifierContext().getClassLoader());
                if (!((javax.xml.ws.handler.Handler.class).isAssignableFrom(cl))) {
                    addErrorDetails(result, compName);
                    result.failed(smh.getLocalString(getClass().getName() + ".failed", "Handler Class [{0}] does not implement " + "javax.xml.ws.handler.Handler Interface", new Object[] { hClass }));
                }
            } catch (ClassNotFoundException e) {
                // result.fail, handler class not found
                addErrorDetails(result, compName);
                result.failed(smh.getLocalString("com.sun.enterprise.tools.verifier.tests.webservices.clfailed", "The [{0}] Class [{1}] could not be Loaded", new Object[] { "Handler Class", hClass }));
            }
        }
    }
    if (result.getStatus() != Result.FAILED) {
        addGoodDetails(result, compName);
        result.passed(smh.getLocalString(getClass().getName() + ".passed1", "Handler chains, if any, are defined properly"));
    }
    return result;
}
Also used : WebServiceHandler(com.sun.enterprise.deployment.WebServiceHandler) Result(com.sun.enterprise.tools.verifier.Result) Iterator(java.util.Iterator) List(java.util.List) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor) WebServiceHandlerChain(com.sun.enterprise.deployment.WebServiceHandlerChain) WebServiceHandler(com.sun.enterprise.deployment.WebServiceHandler)

Example 2 with WebServiceHandler

use of com.sun.enterprise.deployment.WebServiceHandler in project Payara by payara.

the class WsCompile method setupServiceHandlerChain.

private void setupServiceHandlerChain() {
    Model model = wscompile.getProcessor().getModel();
    Collection endpoints = webService.getEndpoints();
    for (Iterator eIter = endpoints.iterator(); eIter.hasNext(); ) {
        WebServiceEndpoint nextEndpoint = (WebServiceEndpoint) eIter.next();
        if (!nextEndpoint.hasHandlers()) {
            continue;
        }
        Port port = wsUtil.getPortFromModel(model, nextEndpoint.getWsdlPort());
        if (port == null) {
            throw new IllegalStateException("Model port for endpoint " + nextEndpoint.getEndpointName() + " not found");
        }
        List handlerChain = nextEndpoint.getHandlers();
        HandlerChainInfo modelHandlerChain = port.getServerHCI();
        List handlerInfoList = new ArrayList();
        // Insert an container handler as the first element.
        // This is needed to perform method authorization checks.
        HandlerInfo preHandler = rpcFactory.createHandlerInfo();
        String handlerClassName = nextEndpoint.implementedByEjbComponent() ? "org.glassfish.webservices.EjbContainerPreHandler" : "org.glassfish.webservices.ServletPreHandler";
        preHandler.setHandlerClassName(handlerClassName);
        handlerInfoList.add(preHandler);
        // Collect all roles defined on each handler and set them on
        // handler chain. NOTE : There is a bit of a mismatch here between
        // 109 and JAXRPC.  JAXRPC only defines roles at the handler chain
        // level, whereas 109 descriptors put roles at the handler level.
        Collection soapRoles = new HashSet();
        for (Iterator hIter = handlerChain.iterator(); hIter.hasNext(); ) {
            WebServiceHandler nextHandler = (WebServiceHandler) hIter.next();
            HandlerInfo handlerInfo = createHandlerInfo(nextHandler);
            handlerInfoList.add(handlerInfo);
            soapRoles.addAll(nextHandler.getSoapRoles());
        }
        // Insert a container handler as the last element in the chain.
        HandlerInfo postHandler = rpcFactory.createHandlerInfo();
        handlerClassName = nextEndpoint.implementedByEjbComponent() ? "org.glassfish.webservices.EjbContainerPostHandler" : "org.glassfish.webservices.ServletPostHandler";
        postHandler.setHandlerClassName(handlerClassName);
        handlerInfoList.add(postHandler);
        // @@@ should probably use addHandler api instead once
        // == bug is fixed.
        modelHandlerChain.setHandlersList(handlerInfoList);
        for (Iterator roleIter = soapRoles.iterator(); roleIter.hasNext(); ) {
            modelHandlerChain.addRole((String) roleIter.next());
        }
    }
}
Also used : HandlerChainInfo(com.sun.xml.rpc.spi.tools.HandlerChainInfo) Port(com.sun.xml.rpc.spi.model.Port) ArrayList(java.util.ArrayList) WebServiceEndpoint(com.sun.enterprise.deployment.WebServiceEndpoint) Model(com.sun.xml.rpc.spi.model.Model) Iterator(java.util.Iterator) Collection(java.util.Collection) ArrayList(java.util.ArrayList) List(java.util.List) HandlerInfo(com.sun.xml.rpc.spi.tools.HandlerInfo) HashSet(java.util.HashSet) WebServiceHandler(com.sun.enterprise.deployment.WebServiceHandler)

Example 3 with WebServiceHandler

use of com.sun.enterprise.deployment.WebServiceHandler in project Payara by payara.

the class HandlerChainHandler method processHandlerChainAnnotation.

public HandlerProcessingResult processHandlerChainAnnotation(AnnotationInfo annInfo, AnnotatedElementHandler annCtx, AnnotatedElement annElem, Class declaringClass, boolean serviceSideChain) throws AnnotationProcessorException {
    HandlerChain hChain = null;
    boolean clientSideHandlerChain = false;
    if (serviceSideChain) {
        // Ignore @WebService annotation on an interface; process only those in an actual service impl class
        if (declaringClass.isInterface()) {
            return HandlerProcessingResultImpl.getDefaultResult(getAnnotationType(), ResultType.PROCESSED);
        }
        // The @HandlerChain can be in the impl class (typically in the java-wsdl case) or
        // can be in the SEI also. Check if there is handler chain in the impl class.
        // If so, the @HandlerChain in impl class gets precedence
        hChain = annElem.getAnnotation(HandlerChain.class);
        if (hChain == null) {
            WebService webService = (WebService) declaringClass.getAnnotation(WebService.class);
            if (webService != null) {
                if (webService.endpointInterface() != null && webService.endpointInterface().length() > 0) {
                    Class endpointIntf;
                    try {
                        endpointIntf = declaringClass.getClassLoader().loadClass(webService.endpointInterface());
                    } catch (java.lang.ClassNotFoundException cfne) {
                        throw new AnnotationProcessorException(localStrings.getLocalString("enterprise.deployment.annotation.handlers.classnotfound", "class {0} referenced from annotation symbol cannot be loaded", new Object[] { webService.endpointInterface() }), annInfo);
                    }
                    if (endpointIntf.getAnnotation(HandlerChain.class) != null) {
                        hChain = (HandlerChain) endpointIntf.getAnnotation(HandlerChain.class);
                    }
                }
            }
        }
    } else {
        // this is a client side handler chain
        hChain = annElem.getAnnotation(HandlerChain.class);
        clientSideHandlerChain = true;
    }
    // At this point the hChain should be the annotation to use.
    if (hChain == null) {
        return HandlerProcessingResultImpl.getDefaultResult(getAnnotationType(), ResultType.PROCESSED);
    }
    // At this point the hChain should be the annotation to use.
    String handlerFile = hChain.file();
    HandlerChainContainer[] containers = null;
    if (annCtx instanceof HandlerContext) {
        containers = ((HandlerContext) annCtx).getHandlerChainContainers(serviceSideChain, declaringClass);
    }
    if (!clientSideHandlerChain && (containers == null || containers.length == 0)) {
        for (Annotation ann : annElem.getAnnotations()) {
            if (ann.annotationType().getPackage().getName().startsWith("javax.ejb")) {
                // let EJB handlers handle this processing
                return HandlerProcessingResultImpl.getDefaultResult(getAnnotationType(), ResultType.UNPROCESSED);
            }
        }
        // could not find my web service...
        throw new AnnotationProcessorException(localStrings.getLocalString("enterprise.deployment.annotation.handlers.componentnotfound", "component referenced from annotation symbol cannot be found"), annInfo);
    }
    try {
        URL handlerFileURL = null;
        try {
            handlerFileURL = new URL(handlerFile);
        } catch (java.net.MalformedURLException e) {
        // swallowing purposely
        }
        InputStream handlerFileStream;
        if (handlerFileURL == null) {
            ClassLoader clo = annInfo.getProcessingContext().getProcessingInput().getClassLoader();
            handlerFileStream = clo.getResourceAsStream(handlerFile);
            if (handlerFileStream == null) {
                String y = declaringClass.getPackage().getName().replaceAll("\\.", "/");
                handlerFileStream = clo.getResourceAsStream(declaringClass.getPackage().getName().replaceAll("\\.", "/") + "/" + handlerFile);
            }
            if (handlerFileStream == null) {
                // So check in the generated SEI's package
                if (annElem instanceof Class) {
                    String y = ((Class) annElem).getPackage().getName().replaceAll("\\.", "/");
                    handlerFileStream = clo.getResourceAsStream(((Class) annElem).getPackage().getName().replaceAll("\\.", "/") + "/" + handlerFile);
                }
            }
        } else {
            handlerFileStream = handlerFileURL.openConnection().getInputStream();
        }
        if (handlerFileStream == null) {
            throw new AnnotationProcessorException(localStrings.getLocalString("enterprise.deployment.annotation.handlers.handlerfilenotfound", "handler file {0} not found", new Object[] { handlerFile }), annInfo);
        }
        Document document;
        try {
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            factory.setNamespaceAware(true);
            factory.setExpandEntityReferences(false);
            factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
            DocumentBuilder builder = factory.newDocumentBuilder();
            document = builder.parse(handlerFileStream);
        } catch (SAXParseException spe) {
            throw new AnnotationProcessorException(localStrings.getLocalString("enterprise.deployment.annotation.handlers.parserexception", "{0} XML Parsing error : line  {1} ; Error = {2}", new Object[] { handlerFile, spe.getLineNumber(), spe.getMessage() }));
        } finally {
            if (handlerFileStream != null) {
                handlerFileStream.close();
            }
        }
        for (HandlerChainContainer container : containers) {
            boolean fromDD = true;
            if (!container.hasHandlerChain()) {
                fromDD = false;
                processHandlerFile(document, container);
            }
            // we now need to create the right context to push on the stack
            // and manually invoke the handlers annotation processing since
            // we know they are Jax-ws handlers.
            List<WebServiceHandlerChain> chains = container.getHandlerChain();
            ArrayList<Class> handlerClasses = new ArrayList<Class>();
            ClassLoader clo = annInfo.getProcessingContext().getProcessingInput().getClassLoader();
            for (WebServiceHandlerChain chain : chains) {
                for (WebServiceHandler handler : chain.getHandlers()) {
                    String className = handler.getHandlerClass();
                    try {
                        handlerClasses.add(clo.loadClass(className));
                    } catch (ClassNotFoundException e) {
                        if (fromDD) {
                            conLogger.log(Level.WARNING, LogUtils.DDHANDLER_NOT_FOUND, className);
                        } else {
                            conLogger.log(Level.WARNING, LogUtils.HANDLER_FILE_HANDLER_NOT_FOUND, new Object[] { className, handlerFile });
                        }
                    }
                }
            }
            // we have the list of handler classes, we can now
            // push the context and call back annotation processing.
            Descriptor jndiContainer = null;
            if (serviceSideChain) {
                WebServiceEndpoint endpoint = (WebServiceEndpoint) container;
                if (DOLUtils.warType().equals(endpoint.getBundleDescriptor().getModuleType())) {
                    jndiContainer = endpoint.getBundleDescriptor();
                } else {
                    jndiContainer = Descriptor.class.cast(endpoint.getEjbComponentImpl());
                }
            } else {
                ServiceReferenceDescriptor ref = (ServiceReferenceDescriptor) container;
                if (DOLUtils.ejbType().equals(ref.getBundleDescriptor().getModuleType())) {
                    EjbBundleDescriptor ejbBundle = (EjbBundleDescriptor) ref.getBundleDescriptor();
                    Iterator<? extends EjbDescriptor> ejbsIter = ejbBundle.getEjbs().iterator();
                    while (ejbsIter.hasNext()) {
                        EjbDescriptor ejb = ejbsIter.next();
                        try {
                            if (ejb.getServiceReferenceByName(ref.getName()) != null) {
                                // found the ejb; break out of the loop
                                jndiContainer = Descriptor.class.cast(ejb);
                                break;
                            }
                        } catch (IllegalArgumentException illex) {
                        // this ejb does not have a service-ref by this name;
                        // swallow this exception and  go to next
                        }
                    }
                } else {
                    jndiContainer = ref.getBundleDescriptor();
                }
            }
            ResourceContainerContextImpl newContext = new ResourceContainerContextImpl(jndiContainer);
            ProcessingContext ctx = annInfo.getProcessingContext();
            ctx.pushHandler(newContext);
            // process the classes
            annInfo.getProcessingContext().getProcessor().process(annInfo.getProcessingContext(), handlerClasses.toArray(new Class[handlerClasses.size()]));
            ctx.popHandler();
        }
    } catch (Throwable t) {
        throw new AnnotationProcessorException(t.getMessage(), annInfo);
    }
    return HandlerProcessingResultImpl.getDefaultResult(getAnnotationType(), ResultType.PROCESSED);
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) WebService(javax.jws.WebService) HandlerContext(com.sun.enterprise.deployment.annotation.context.HandlerContext) ArrayList(java.util.ArrayList) Document(org.w3c.dom.Document) URL(java.net.URL) HandlerChainContainer(com.sun.enterprise.deployment.types.HandlerChainContainer) WebServiceHandlerChain(com.sun.enterprise.deployment.WebServiceHandlerChain) HandlerChain(javax.jws.HandlerChain) SAXParseException(org.xml.sax.SAXParseException) ResourceContainerContextImpl(com.sun.enterprise.deployment.annotation.context.ResourceContainerContextImpl) WebServiceHandlerChain(com.sun.enterprise.deployment.WebServiceHandlerChain) InputStream(java.io.InputStream) ServiceReferenceDescriptor(com.sun.enterprise.deployment.ServiceReferenceDescriptor) Annotation(java.lang.annotation.Annotation) EjbDescriptor(com.sun.enterprise.deployment.EjbDescriptor) DocumentBuilder(javax.xml.parsers.DocumentBuilder) WebServiceEndpoint(com.sun.enterprise.deployment.WebServiceEndpoint) EjbBundleDescriptor(com.sun.enterprise.deployment.EjbBundleDescriptor) EjbDescriptor(com.sun.enterprise.deployment.EjbDescriptor) ServiceReferenceDescriptor(com.sun.enterprise.deployment.ServiceReferenceDescriptor) EjbBundleDescriptor(com.sun.enterprise.deployment.EjbBundleDescriptor) Descriptor(org.glassfish.deployment.common.Descriptor) WebServiceHandler(com.sun.enterprise.deployment.WebServiceHandler)

Example 4 with WebServiceHandler

use of com.sun.enterprise.deployment.WebServiceHandler in project Payara by payara.

the class WebServiceHandlerNode method setElementValue.

/**
 * receives notification of the value for a particular tag
 *
 * @param element the xml element
 * @param value it's associated value
 */
public void setElementValue(XMLElement element, String value) {
    String qname = element.getQName();
    WebServiceHandler handler = (WebServiceHandler) getDescriptor();
    if (WebServicesTagNames.INIT_PARAM_NAME.equals(qname)) {
        initParam = new NameValuePairDescriptor();
        initParam.setName(value);
    } else if (WebServicesTagNames.INIT_PARAM_VALUE.equals(qname)) {
        initParam.setValue(value);
        handler.addInitParam(initParam);
    } else if (TagNames.DESCRIPTION.equals(qname)) {
        if (initParam != null) {
            // description for the init-param
            initParam.setDescription(value);
            initParam = null;
        } else {
            // must be the description element of the handler itself.
            super.setElementValue(element, value);
        }
    } else if (WebServicesTagNames.SOAP_HEADER.equals(qname)) {
        String prefix = getPrefixFromQName(value);
        String localPart = getLocalPartFromQName(value);
        String namespaceUri = resolvePrefix(element, prefix);
        if (namespaceUri == null) {
            logger.log(Level.SEVERE, LogUtils.INVALID_DESC_MAPPING_FAILURE, new Object[] { prefix, handler.getHandlerName() });
        } else {
            QName soapHeader = new QName(namespaceUri, localPart);
            handler.addSoapHeader(soapHeader);
        }
    } else
        super.setElementValue(element, value);
}
Also used : NameValuePairDescriptor(com.sun.enterprise.deployment.NameValuePairDescriptor) QName(javax.xml.namespace.QName) WebServiceHandler(com.sun.enterprise.deployment.WebServiceHandler)

Example 5 with WebServiceHandler

use of com.sun.enterprise.deployment.WebServiceHandler in project Payara by payara.

the class WebServiceHandlerNode method writeWebServiceHandlers.

public void writeWebServiceHandlers(Node parent, List handlerChain) {
    for (Iterator iter = handlerChain.iterator(); iter.hasNext(); ) {
        WebServiceHandler next = (WebServiceHandler) iter.next();
        writeDescriptor(parent, WebServicesTagNames.HANDLER, next);
    }
}
Also used : Iterator(java.util.Iterator) WebServiceHandler(com.sun.enterprise.deployment.WebServiceHandler)

Aggregations

WebServiceHandler (com.sun.enterprise.deployment.WebServiceHandler)5 Iterator (java.util.Iterator)3 WebServiceEndpoint (com.sun.enterprise.deployment.WebServiceEndpoint)2 WebServiceHandlerChain (com.sun.enterprise.deployment.WebServiceHandlerChain)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 EjbBundleDescriptor (com.sun.enterprise.deployment.EjbBundleDescriptor)1 EjbDescriptor (com.sun.enterprise.deployment.EjbDescriptor)1 NameValuePairDescriptor (com.sun.enterprise.deployment.NameValuePairDescriptor)1 ServiceReferenceDescriptor (com.sun.enterprise.deployment.ServiceReferenceDescriptor)1 HandlerContext (com.sun.enterprise.deployment.annotation.context.HandlerContext)1 ResourceContainerContextImpl (com.sun.enterprise.deployment.annotation.context.ResourceContainerContextImpl)1 HandlerChainContainer (com.sun.enterprise.deployment.types.HandlerChainContainer)1 Result (com.sun.enterprise.tools.verifier.Result)1 ComponentNameConstructor (com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor)1 Model (com.sun.xml.rpc.spi.model.Model)1 Port (com.sun.xml.rpc.spi.model.Port)1 HandlerChainInfo (com.sun.xml.rpc.spi.tools.HandlerChainInfo)1 HandlerInfo (com.sun.xml.rpc.spi.tools.HandlerInfo)1 InputStream (java.io.InputStream)1