Search in sources :

Example 31 with Handler

use of javax.xml.ws.handler.Handler in project Payara by payara.

the class WSServletContextListener method contextDestroyed.

@Override
public void contextDestroyed(ServletContextEvent sce) {
    ServletContext servletContext = sce.getServletContext();
    synchronized (this) {
        ServletAdapterList list = (ServletAdapterList) servletContext.getAttribute("ADAPTER_LIST");
        if (list != null) {
            for (ServletAdapter x : list) {
                x.getEndpoint().dispose();
                for (Handler handler : x.getEndpoint().getBinding().getHandlerChain()) {
                    try {
                        WebServiceContractImpl wscImpl = WebServiceContractImpl.getInstance();
                        InjectionManager injManager = wscImpl.getInjectionManager();
                        injManager.destroyManagedObject(handler);
                    } catch (InjectionException e) {
                        logger.log(Level.WARNING, LogUtils.DESTORY_ON_HANDLER_FAILED, new Object[] { handler.getClass(), x.getEndpoint().getServiceName(), e.getMessage() });
                        continue;
                    }
                }
            }
            servletContext.removeAttribute("ADAPTER_LIST");
        }
        JAXWSAdapterRegistry.getInstance().removeAdapter(contextRoot);
    /*
                 Fix for bug 3932/4052 since the x.getEndpoint().dispose is being
                 called above we do not need to call this explicitly
                 try {
                 (new WsUtil()).doPreDestroy(endpoint, classLoader);
                 } catch (Throwable t) {
                 logger.log(Level.WARNING, "@PreDestroy lifecycle call failed for service"
                 + endpoint.getName(), t);
                 }*/
    }
    JAXWSServletModule.destroy(contextRoot);
}
Also used : InjectionException(com.sun.enterprise.container.common.spi.util.InjectionException) ServletAdapter(com.sun.xml.ws.transport.http.servlet.ServletAdapter) ServletContext(javax.servlet.ServletContext) Handler(javax.xml.ws.handler.Handler) ServletAdapterList(com.sun.xml.ws.transport.http.servlet.ServletAdapterList) InjectionManager(com.sun.enterprise.container.common.spi.util.InjectionManager)

Example 32 with Handler

use of javax.xml.ws.handler.Handler in project Payara by payara.

the class WebServiceEjbEndpointRegistry method unregisterEndpoint.

@Override
public void unregisterEndpoint(String endpointAddressUri) {
    EjbRuntimeEndpointInfo endpoint = null;
    synchronized (webServiceEjbEndpoints) {
        String uriRaw = endpointAddressUri;
        String uri = (uriRaw.charAt(0) == '/') ? uriRaw.substring(1) : uriRaw;
        ServletAdapterList list = adapterListMap.get(uri);
        if (list != null) {
            // since we are using the uri in the adapterListMap
            for (ServletAdapter x : list) {
                x.getEndpoint().dispose();
                for (Handler handler : x.getEndpoint().getBinding().getHandlerChain()) {
                    try {
                        WebServiceContractImpl wscImpl = WebServiceContractImpl.getInstance();
                        if (wscImpl.getInvocationManager().getCurrentInvocation() != null) {
                            InjectionManager injManager = wscImpl.getInjectionManager();
                            injManager.destroyManagedObject(handler);
                        }
                    } catch (InjectionException e) {
                        logger.log(Level.WARNING, LogUtils.DESTORY_ON_HANDLER_FAILED, new Object[] { handler.getClass(), x.getEndpoint().getServiceName(), e.getMessage() });
                        continue;
                    }
                }
            }
            // Fix for issue 9523
            adapterListMap.remove(uri);
        }
        endpoint = (EjbRuntimeEndpointInfo) webServiceEjbEndpoints.remove(uri);
        regenerateEjbContextRoots();
    }
    if (endpoint == null) {
        return;
    }
    // notify the monitoring layers that an endpoint is destroyed
    WebServiceEngineImpl engine = WebServiceEngineImpl.getInstance();
    engine.removeHandler(endpoint.getEndpoint());
}
Also used : InjectionException(com.sun.enterprise.container.common.spi.util.InjectionException) ServletAdapter(com.sun.xml.ws.transport.http.servlet.ServletAdapter) Handler(javax.xml.ws.handler.Handler) ServletAdapterList(com.sun.xml.ws.transport.http.servlet.ServletAdapterList) WebServiceEngineImpl(org.glassfish.webservices.monitoring.WebServiceEngineImpl) InjectionManager(com.sun.enterprise.container.common.spi.util.InjectionManager)

Example 33 with Handler

use of javax.xml.ws.handler.Handler in project Payara by payara.

the class WsUtil method configureJAXWSClientHandlers.

public void configureJAXWSClientHandlers(javax.xml.ws.Service svcClass, ServiceReferenceDescriptor desc) {
    // Create a resolver and get all ports for the Service
    HandlerResolverImpl resolver = new HandlerResolverImpl();
    Set<String> roles = new HashSet();
    Iterator<QName> ports = svcClass.getPorts();
    // Set handler chain for each port of this service
    while (ports.hasNext()) {
        QName nextPort = ports.next();
        LinkedList handlerChainList = desc.getHandlerChain();
        for (Iterator<WebServiceHandlerChain> i = handlerChainList.iterator(); i.hasNext(); ) {
            WebServiceHandlerChain hc = i.next();
            // that the handlers are for this service and this port
            if (!patternsMatch(hc, desc.getServiceName(), nextPort, null)) {
                continue;
            }
            // Decide for what all protocols this handler should be applied
            ArrayList<String> protocols = new ArrayList<String>();
            if (hc.getProtocolBindings() == null) {
                // No protocol bindings given in descriptor; apply this handler
                // for all protocols
                protocols.add(HTTPBinding.HTTP_BINDING);
                protocols.add(SOAPBinding.SOAP11HTTP_BINDING);
                protocols.add(SOAPBinding.SOAP12HTTP_BINDING);
                protocols.add(SOAPBinding.SOAP11HTTP_MTOM_BINDING);
                protocols.add(SOAPBinding.SOAP12HTTP_MTOM_BINDING);
            } else {
                // protocols specified; handlers are for only these protocols
                String specifiedProtocols = hc.getProtocolBindings();
                if ((specifiedProtocols.indexOf(HTTPBinding.HTTP_BINDING) != -1) || (specifiedProtocols.indexOf(WebServiceEndpoint.XML_TOKEN) != -1)) {
                    protocols.add(HTTPBinding.HTTP_BINDING);
                }
                if ((specifiedProtocols.indexOf(SOAPBinding.SOAP11HTTP_BINDING) != -1) || (specifiedProtocols.indexOf(WebServiceEndpoint.SOAP11_TOKEN) != -1)) {
                    protocols.add(SOAPBinding.SOAP11HTTP_BINDING);
                }
                if ((specifiedProtocols.indexOf(SOAPBinding.SOAP12HTTP_BINDING) != -1) || (specifiedProtocols.indexOf(WebServiceEndpoint.SOAP12_TOKEN) != -1)) {
                    protocols.add(SOAPBinding.SOAP12HTTP_BINDING);
                }
                if ((specifiedProtocols.indexOf(SOAPBinding.SOAP11HTTP_MTOM_BINDING) != -1) || (specifiedProtocols.indexOf(WebServiceEndpoint.SOAP11_MTOM_TOKEN) != -1)) {
                    protocols.add(SOAPBinding.SOAP11HTTP_MTOM_BINDING);
                }
                if ((specifiedProtocols.indexOf(SOAPBinding.SOAP12HTTP_MTOM_BINDING) != -1) || (specifiedProtocols.indexOf(WebServiceEndpoint.SOAP12_MTOM_TOKEN) != -1)) {
                    protocols.add(SOAPBinding.SOAP12HTTP_MTOM_BINDING);
                }
            }
            // Iterate through all handlers that have been configured
            List<WebServiceHandler> handlersList = hc.getHandlers();
            // than the current port
            for (WebServiceHandler thisOne : handlersList) {
                Collection portNames = thisOne.getPortNames();
                if (!portNames.isEmpty() && !portNames.contains(nextPort.getLocalPart())) {
                    handlersList.remove(thisOne);
                }
            }
            // Now you have the handlers that need to be added; process them
            List<Handler> handlerInfo = processConfiguredHandlers(handlersList, roles);
            // one set for each protocol
            for (Iterator<String> s = protocols.iterator(); s.hasNext(); ) {
                javax.xml.ws.handler.PortInfo portInfo;
                portInfo = new PortInfoImpl(BindingID.parse(s.next()), nextPort, desc.getServiceName());
                resolver.setHandlerChain(portInfo, handlerInfo);
            }
        }
    }
    // Now that processing of all handlers is over, set HandlerResolver for
    // the service
    svcClass.setHandlerResolver(resolver);
// XXX TODO : What to do with soap roles on client side ?
}
Also used : QName(javax.xml.namespace.QName) StreamingHandler(com.sun.xml.rpc.spi.runtime.StreamingHandler) Handler(javax.xml.ws.handler.Handler)

Example 34 with Handler

use of javax.xml.ws.handler.Handler in project Payara by payara.

the class WsUtil method processConfiguredHandlers.

private List<Handler> processConfiguredHandlers(List<WebServiceHandler> handlersList, Set<String> roles) {
    List<Handler> handlerChain = new ArrayList<Handler>();
    for (WebServiceHandler h : handlersList) {
        Handler handler = null;
        ClassLoader loader = Thread.currentThread().getContextClassLoader();
        // Get Handler Class instance
        Class handlerClass;
        try {
            handlerClass = Class.forName(h.getHandlerClass(), true, loader);
        } catch (Throwable t) {
            String msg = MessageFormat.format(logger.getResourceBundle().getString(LogUtils.HANDLER_UNABLE_TO_ADD), h.getHandlerClass());
            logger.log(Level.SEVERE, msg, t);
            continue;
        }
        // perform injection
        try {
            WebServiceContractImpl wscImpl = WebServiceContractImpl.getInstance();
            InjectionManager injManager = wscImpl.getInjectionManager();
            // PostConstruct is invoked by createManagedObject as well
            handler = (Handler) injManager.createManagedObject(handlerClass);
        } catch (InjectionException e) {
            logger.log(Level.SEVERE, LogUtils.HANDLER_INJECTION_FAILED, new Object[] { h.getHandlerClass(), e.getMessage() });
            continue;
        }
        // Add soap-roles
        Collection<String> rolesColl = h.getSoapRoles();
        roles.addAll(rolesColl);
        // Add this handler to the mail list
        handlerChain.add(handler);
    }
    return handlerChain;
}
Also used : StreamingHandler(com.sun.xml.rpc.spi.runtime.StreamingHandler) Handler(javax.xml.ws.handler.Handler) InjectionException(com.sun.enterprise.container.common.spi.util.InjectionException) InjectionManager(com.sun.enterprise.container.common.spi.util.InjectionManager)

Example 35 with Handler

use of javax.xml.ws.handler.Handler in project Payara by payara.

the class HandlerResolverImpl method getHandlerChain.

public List<Handler> getHandlerChain(PortInfo info) {
    Iterator<PortInfo> piSet = chainMap.keySet().iterator();
    List<Handler> chain = null;
    while (piSet.hasNext()) {
        PortInfo next = piSet.next();
        PortInfoImpl tmp = new PortInfoImpl(BindingID.parse(info.getBindingID()), info.getPortName(), info.getServiceName());
        if (tmp.equals(next)) {
            chain = chainMap.get(next);
            break;
        }
    }
    if (chain == null) {
        chain = new ArrayList<Handler>();
    }
    return chain;
}
Also used : PortInfo(javax.xml.ws.handler.PortInfo) Handler(javax.xml.ws.handler.Handler)

Aggregations

Handler (javax.xml.ws.handler.Handler)100 QName (javax.xml.namespace.QName)47 ArrayList (java.util.ArrayList)46 BindingProvider (javax.xml.ws.BindingProvider)36 URL (java.net.URL)32 Service (javax.xml.ws.Service)29 Test (org.junit.Test)29 LogicalHandler (javax.xml.ws.handler.LogicalHandler)24 Binding (javax.xml.ws.Binding)11 WebServiceException (javax.xml.ws.WebServiceException)11 MessageContext (javax.xml.ws.handler.MessageContext)9 SOAPHandler (javax.xml.ws.handler.soap.SOAPHandler)9 Exchange (org.apache.cxf.message.Exchange)9 IOException (java.io.IOException)8 SOAPMessageContext (javax.xml.ws.handler.soap.SOAPMessageContext)7 HandlerChainInvoker (org.apache.cxf.jaxws.handler.HandlerChainInvoker)7 DataHandler (javax.activation.DataHandler)6 InitialContext (javax.naming.InitialContext)6 Source (javax.xml.transform.Source)6 DOMSource (javax.xml.transform.dom.DOMSource)6