Search in sources :

Example 1 with HandlerChains$JAXB.readHandlerChains

use of org.apache.openejb.jee.HandlerChains$JAXB.readHandlerChains in project tomee by apache.

the class HandlerResolverImplTest method readHandlerChains.

private HandlerChains readHandlerChains(final String filePath) throws Exception {
    final URL url = getClass().getResource(filePath);
    assertNotNull("Could not find handler chains file " + filePath, url);
    final HandlerChains handlerChains = ReadDescriptors.readHandlerChains(url);
    return handlerChains;
}
Also used : HandlerChains(org.apache.openejb.jee.HandlerChains) URL(java.net.URL)

Example 2 with HandlerChains$JAXB.readHandlerChains

use of org.apache.openejb.jee.HandlerChains$JAXB.readHandlerChains in project tomee by apache.

the class HandlerResolverImplTest method testBasic.

public void testBasic() throws Exception {
    final HandlerChains handlerChains = readHandlerChains("/handlers.xml");
    assertEquals(3, handlerChains.getHandlerChain().size());
    final List<HandlerChainInfo> handlerChainInfos = ConfigurationFactory.toHandlerChainInfo(handlerChains);
    final List<HandlerChainData> handlerChainDatas = WsBuilder.toHandlerChainData(handlerChainInfos, getClass().getClassLoader());
    final HandlerResolverImpl resolver = new HandlerResolverImpl(handlerChainDatas, null, new InitialContext());
    List<Handler> handlers = null;
    handlers = resolver.getHandlerChain(new TestPortInfo(null, null, null));
    assertEquals(3, handlers.size());
}
Also used : HandlerChainInfo(org.apache.openejb.assembler.classic.HandlerChainInfo) Handler(javax.xml.ws.handler.Handler) HandlerChains(org.apache.openejb.jee.HandlerChains) InitialContext(javax.naming.InitialContext)

Example 3 with HandlerChains$JAXB.readHandlerChains

use of org.apache.openejb.jee.HandlerChains$JAXB.readHandlerChains in project tomee by apache.

the class HandlerResolverImplTest method testServiceMatching.

public void testServiceMatching() throws Exception {
    final HandlerChains handlerChains = readHandlerChains("/handlers_service.xml");
    assertEquals(3, handlerChains.getHandlerChain().size());
    final List<HandlerChainInfo> handlerChainInfos = ConfigurationFactory.toHandlerChainInfo(handlerChains);
    final List<HandlerChainData> handlerChainDatas = WsBuilder.toHandlerChainData(handlerChainInfos, getClass().getClassLoader());
    final HandlerResolverImpl resolver = new HandlerResolverImpl(handlerChainDatas, null, new InitialContext());
    List<Handler> handlers = null;
    handlers = resolver.getHandlerChain(new TestPortInfo(null, null, null));
    assertEquals(0, handlers.size());
    final QName serviceName1 = new QName("http://java.sun.com/xml/ns/javaee", "Bar");
    handlers = resolver.getHandlerChain(new TestPortInfo(null, null, serviceName1));
    assertEquals(1, handlers.size());
    final QName serviceName2 = new QName("http://java.sun.com/xml/ns/javaee", "Foo");
    handlers = resolver.getHandlerChain(new TestPortInfo(null, null, serviceName2));
    assertEquals(2, handlers.size());
    final QName serviceName3 = new QName("http://java.sun.com/xml/ns/javaee", "FooBar");
    handlers = resolver.getHandlerChain(new TestPortInfo(null, null, serviceName3));
    assertEquals(1, handlers.size());
    final QName serviceName4 = new QName("http://java.sun.com/xml/ns/javaee", "BarFoo");
    handlers = resolver.getHandlerChain(new TestPortInfo(null, null, serviceName4));
    assertEquals(0, handlers.size());
}
Also used : HandlerChainInfo(org.apache.openejb.assembler.classic.HandlerChainInfo) QName(javax.xml.namespace.QName) Handler(javax.xml.ws.handler.Handler) HandlerChains(org.apache.openejb.jee.HandlerChains) InitialContext(javax.naming.InitialContext)

Example 4 with HandlerChains$JAXB.readHandlerChains

use of org.apache.openejb.jee.HandlerChains$JAXB.readHandlerChains in project tomee by apache.

the class WsDeployer method processPorts.

private void processPorts(final EjbModule ejbModule) throws OpenEJBException {
    // map existing webservice port declarations by servlet link
    Webservices webservices = ejbModule.getWebservices();
    final Map<String, PortComponent> portMap = new TreeMap<String, PortComponent>();
    if (webservices != null) {
        for (final WebserviceDescription webserviceDescription : webservices.getWebserviceDescription()) {
            for (final PortComponent portComponent : webserviceDescription.getPortComponent()) {
                final ServiceImplBean serviceImplBean = portComponent.getServiceImplBean();
                if (serviceImplBean != null && serviceImplBean.getEjbLink() != null) {
                    portMap.put(serviceImplBean.getEjbLink(), portComponent);
                }
            }
        }
    }
    final Map<String, EjbDeployment> deploymentsByEjbName = ejbModule.getOpenejbJar().getDeploymentsByEjbName();
    WebserviceDescription webserviceDescription;
    for (final EnterpriseBean enterpriseBean : ejbModule.getEjbJar().getEnterpriseBeans()) {
        // skip if this is not a webservices endpoint
        if (!(enterpriseBean instanceof SessionBean)) {
            continue;
        }
        final SessionBean sessionBean = (SessionBean) enterpriseBean;
        if (sessionBean.getSessionType() == SessionType.STATEFUL) {
            continue;
        }
        if (sessionBean.getSessionType() == SessionType.MANAGED) {
            continue;
        }
        if (sessionBean.getServiceEndpoint() == null) {
            continue;
        }
        final EjbDeployment deployment = deploymentsByEjbName.get(sessionBean.getEjbName());
        if (deployment == null) {
            continue;
        }
        final Class<?> ejbClass;
        try {
            ejbClass = ejbModule.getClassLoader().loadClass(sessionBean.getEjbClass());
        } catch (final ClassNotFoundException e) {
            throw new OpenEJBException("Unable to load ejb class: " + sessionBean.getEjbClass(), e);
        }
        // for now, skip all non jaxws beans
        if (!JaxWsUtils.isWebService(ejbClass)) {
            continue;
        }
        // create webservices dd if not defined
        if (webservices == null) {
            webservices = new Webservices();
            ejbModule.setWebservices(webservices);
        }
        webserviceDescription = webservices.getWebserviceDescriptionMap().get(JaxWsUtils.getServiceName(ejbClass));
        if (webserviceDescription == null) {
            webserviceDescription = new WebserviceDescription();
            if (JaxWsUtils.isWebService(ejbClass)) {
                webserviceDescription.setWebserviceDescriptionName(JaxWsUtils.getServiceName(ejbClass));
            }
            // TODO else { /* create webserviceDescription name using some sort of jaxrpc data */ }
            webservices.getWebserviceDescription().add(webserviceDescription);
        }
        // add a port component if we don't alrady have one
        PortComponent portComponent = portMap.get(sessionBean.getEjbName());
        if (portComponent == null) {
            portComponent = new PortComponent();
            if (webserviceDescription.getPortComponentMap().containsKey(JaxWsUtils.getPortQName(ejbClass).getLocalPart())) {
                // when to webservices.xml is defined and when we want to
                // publish more than one port for the same implementation by configuration
                portComponent.setPortComponentName(sessionBean.getEjbName());
            } else {
                // JAX-WS Metadata specification default
                portComponent.setPortComponentName(JaxWsUtils.getPortQName(ejbClass).getLocalPart());
            }
            webserviceDescription.getPortComponent().add(portComponent);
            final ServiceImplBean serviceImplBean = new ServiceImplBean();
            serviceImplBean.setEjbLink(sessionBean.getEjbName());
            portComponent.setServiceImplBean(serviceImplBean);
            // Checking if MTOM must be enabled
            if (portComponent.getProtocolBinding() == null) {
                portComponent.setProtocolBinding(JaxWsUtils.getBindingUriFromAnn(ejbClass));
            }
            configMtomAnnotation(ejbClass, portComponent);
            if (SOAPBinding.SOAP12HTTP_MTOM_BINDING.equals(portComponent.getProtocolBinding()) || SOAPBinding.SOAP11HTTP_MTOM_BINDING.equals(portComponent.getProtocolBinding())) {
                portComponent.setEnableMtom(true);
            }
        }
        // default portId == deploymentId
        if (portComponent.getId() == null) {
            portComponent.setId(deployment.getDeploymentId());
        }
        if (webserviceDescription.getId() == null) {
            webserviceDescription.setId(deployment.getDeploymentId());
        }
        // set service endpoint interface
        if (portComponent.getServiceEndpointInterface() == null) {
            portComponent.setServiceEndpointInterface(sessionBean.getServiceEndpoint());
        }
        // default location is /@WebService.serviceName/@WebService.name
        if (JaxWsUtils.isWebService(ejbClass)) {
            if (portComponent.getWsdlPort() == null) {
                portComponent.setWsdlPort(JaxWsUtils.getPortQName(ejbClass));
            }
            if (webserviceDescription.getWsdlFile() == null) {
                webserviceDescription.setWsdlFile(JaxWsUtils.getServiceWsdlLocation(ejbClass, ejbModule.getClassLoader()));
            }
            if (portComponent.getWsdlService() == null) {
                final Definition definition = getWsdl(ejbModule, webserviceDescription.getWsdlFile());
                if (definition != null && definition.getServices().size() == 1) {
                    final QName serviceQName = (QName) definition.getServices().keySet().iterator().next();
                    portComponent.setWsdlService(serviceQName);
                } else {
                    portComponent.setWsdlService(JaxWsUtils.getServiceQName(ejbClass));
                }
            }
            if (portComponent.getLocation() == null && webserviceDescription.getWsdlFile() != null) {
                // set location based on wsdl port
                final Definition definition = getWsdl(ejbModule, webserviceDescription.getWsdlFile());
                final String locationURI = getLocationFromWsdl(definition, portComponent);
                portComponent.setLocation(locationURI);
            }
            if (portComponent.getProtocolBinding() == null) {
                portComponent.setProtocolBinding(JaxWsUtils.getBindingUriFromAnn(ejbClass));
            }
            // handlers
            if (portComponent.getHandlerChains() == null) {
                final HandlerChains handlerChains = getHandlerChains(ejbClass, sessionBean.getServiceEndpoint(), ejbModule.getClassLoader());
                portComponent.setHandlerChains(handlerChains);
            }
        }
    // TODO else { /* location JAX-RPC services comes from wsdl file */ }
    }
}
Also used : OpenEJBException(org.apache.openejb.OpenEJBException) EnterpriseBean(org.apache.openejb.jee.EnterpriseBean) PortComponent(org.apache.openejb.jee.PortComponent) ServiceImplBean(org.apache.openejb.jee.ServiceImplBean) QName(javax.xml.namespace.QName) Definition(javax.wsdl.Definition) HandlerChains(org.apache.openejb.jee.HandlerChains) Webservices(org.apache.openejb.jee.Webservices) TreeMap(java.util.TreeMap) SessionBean(org.apache.openejb.jee.SessionBean) WebserviceDescription(org.apache.openejb.jee.WebserviceDescription) EjbDeployment(org.apache.openejb.jee.oejb3.EjbDeployment)

Example 5 with HandlerChains$JAXB.readHandlerChains

use of org.apache.openejb.jee.HandlerChains$JAXB.readHandlerChains in project tomee by apache.

the class WsDeployer method processPorts.

private void processPorts(final WebModule webModule) throws OpenEJBException {
    // map existing webservice port declarations by servlet link
    Webservices webservices = webModule.getWebservices();
    final Map<String, PortComponent> portMap = new TreeMap<String, PortComponent>();
    if (webservices != null) {
        for (final WebserviceDescription webserviceDescription : webservices.getWebserviceDescription()) {
            for (final PortComponent portComponent : webserviceDescription.getPortComponent()) {
                final ServiceImplBean serviceImplBean = portComponent.getServiceImplBean();
                if (serviceImplBean != null && serviceImplBean.getServletLink() != null) {
                    portMap.put(serviceImplBean.getServletLink(), portComponent);
                }
            }
        }
    }
    // map existing servlet-mapping declarations
    final WebApp webApp = webModule.getWebApp();
    final Map<String, ServletMapping> servletMappings = new TreeMap<String, ServletMapping>();
    for (final ServletMapping servletMapping : webApp.getServletMapping()) {
        servletMappings.put(servletMapping.getServletName(), servletMapping);
    }
    // add port declarations for Pojo webservices
    WebserviceDescription webserviceDescription;
    for (final Servlet servlet : webApp.getServlet()) {
        // the implementation class will be replaced by the WsServlet in the WsRegistry
        final String className = servlet.getServletClass();
        // Skip JSPs
        if (className == null) {
            continue;
        }
        try {
            final Class<?> clazz = webModule.getClassLoader().loadClass(className);
            if (JaxWsUtils.isWebService(clazz)) {
                // add servlet mapping if not already declared
                ServletMapping servletMapping = servletMappings.get(servlet.getServletName());
                final String serviceName = JaxWsUtils.getServiceName(clazz);
                if (servletMapping == null) {
                    servletMapping = new ServletMapping();
                    servletMapping.setServletName(servlet.getServletName());
                    final String location = "/" + serviceName;
                    servletMapping.getUrlPattern().add(location);
                    webApp.getServletMapping().add(servletMapping);
                }
                // if we don't have a webservices document yet, we're gonna need one now
                if (webservices == null) {
                    webservices = new Webservices();
                    webModule.setWebservices(webservices);
                }
                // add web service description element (maps to service)
                webserviceDescription = webservices.getWebserviceDescriptionMap().get(serviceName);
                if (webserviceDescription == null) {
                    webserviceDescription = new WebserviceDescription();
                    webserviceDescription.setWebserviceDescriptionName(serviceName);
                    webservices.getWebserviceDescription().add(webserviceDescription);
                }
                // define port if not already declared
                PortComponent portComponent = portMap.get(servlet.getServletName());
                if (portComponent == null) {
                    portComponent = new PortComponent();
                    portComponent.setPortComponentName(clazz.getSimpleName());
                    final ServiceImplBean serviceImplBean = new ServiceImplBean();
                    serviceImplBean.setServletLink(servlet.getServletName());
                    portComponent.setServiceImplBean(serviceImplBean);
                    webserviceDescription.getPortComponent().add(portComponent);
                }
                // default portId == host.moduleId.servletName
                if (portComponent.getId() == null) {
                    portComponent.setId(webModule.getHost() + "." + webModule.getModuleId() + "." + servlet.getServletName());
                }
                if (webserviceDescription.getId() == null) {
                    webserviceDescription.setId(webModule.getHost() + "." + webModule.getModuleId() + "." + servlet.getServletName());
                }
                // set port values from annotations if not already set
                if (portComponent.getServiceEndpointInterface() == null) {
                    portComponent.setServiceEndpointInterface(JaxWsUtils.getServiceInterface(clazz));
                }
                if (portComponent.getWsdlPort() == null) {
                    portComponent.setWsdlPort(JaxWsUtils.getPortQName(clazz));
                }
                if (webserviceDescription.getWsdlFile() == null) {
                    webserviceDescription.setWsdlFile(JaxWsUtils.getServiceWsdlLocation(clazz, webModule.getClassLoader()));
                }
                if (portComponent.getWsdlService() == null) {
                    final Definition definition = getWsdl(webModule, webserviceDescription.getWsdlFile());
                    if (definition != null && definition.getServices().size() == 1) {
                        final QName serviceQName = (QName) definition.getServices().keySet().iterator().next();
                        portComponent.setWsdlService(serviceQName);
                    } else {
                        portComponent.setWsdlService(JaxWsUtils.getServiceQName(clazz));
                    }
                }
                if (portComponent.getProtocolBinding() == null) {
                    portComponent.setProtocolBinding(JaxWsUtils.getBindingUriFromAnn(clazz));
                }
                configMtomAnnotation(clazz, portComponent);
                if (SOAPBinding.SOAP12HTTP_MTOM_BINDING.equals(portComponent.getProtocolBinding()) || SOAPBinding.SOAP11HTTP_MTOM_BINDING.equals(portComponent.getProtocolBinding())) {
                    portComponent.setEnableMtom(true);
                }
                // handlers
                if (portComponent.getHandlerChains() == null) {
                    final HandlerChains handlerChains = getHandlerChains(clazz, portComponent.getServiceEndpointInterface(), webModule.getClassLoader());
                    portComponent.setHandlerChains(handlerChains);
                }
            }
        } catch (final Exception e) {
            throw new OpenEJBException("Unable to load servlet class: " + className, e);
        }
    }
}
Also used : ServletMapping(org.apache.openejb.jee.ServletMapping) OpenEJBException(org.apache.openejb.OpenEJBException) PortComponent(org.apache.openejb.jee.PortComponent) ServiceImplBean(org.apache.openejb.jee.ServiceImplBean) QName(javax.xml.namespace.QName) Definition(javax.wsdl.Definition) HandlerChains(org.apache.openejb.jee.HandlerChains) Webservices(org.apache.openejb.jee.Webservices) TreeMap(java.util.TreeMap) MalformedURLException(java.net.MalformedURLException) OpenEJBException(org.apache.openejb.OpenEJBException) IOException(java.io.IOException) WebserviceDescription(org.apache.openejb.jee.WebserviceDescription) Servlet(org.apache.openejb.jee.Servlet) WebApp(org.apache.openejb.jee.WebApp)

Aggregations

QName (javax.xml.namespace.QName)9 HandlerChains (org.apache.openejb.jee.HandlerChains)9 InitialContext (javax.naming.InitialContext)5 Handler (javax.xml.ws.handler.Handler)5 HandlerChainInfo (org.apache.openejb.assembler.classic.HandlerChainInfo)5 CollapsedStringAdapter (javax.xml.bind.annotation.adapters.CollapsedStringAdapter)4 Handler$JAXB.readHandler (org.apache.openejb.jee.Handler$JAXB.readHandler)4 Handler$JAXB.writeHandler (org.apache.openejb.jee.Handler$JAXB.writeHandler)4 HandlerChains$JAXB.readHandlerChains (org.apache.openejb.jee.HandlerChains$JAXB.readHandlerChains)4 HandlerChains$JAXB.writeHandlerChains (org.apache.openejb.jee.HandlerChains$JAXB.writeHandlerChains)4 Icon$JAXB.readIcon (org.apache.openejb.jee.Icon$JAXB.readIcon)4 Icon$JAXB.writeIcon (org.apache.openejb.jee.Icon$JAXB.writeIcon)4 RuntimeContext (org.metatype.sxc.jaxb.RuntimeContext)4 OpenEJBException (org.apache.openejb.OpenEJBException)3 URL (java.net.URL)2 ArrayList (java.util.ArrayList)2 TreeMap (java.util.TreeMap)2 Definition (javax.wsdl.Definition)2 Addressing$JAXB.readAddressing (org.apache.openejb.jee.Addressing$JAXB.readAddressing)2 Addressing$JAXB.writeAddressing (org.apache.openejb.jee.Addressing$JAXB.writeAddressing)2