Search in sources :

Example 1 with PortData

use of org.apache.openejb.core.webservices.PortData in project tomee by apache.

the class WsService method deployApp.

private void deployApp(final AppInfo appInfo, final Collection<BeanContext> ejbs) {
    final Collection<BeanContext> alreadyDeployed = deployedApplications.get(appInfo);
    final Map<String, WebAppInfo> webContextByEjb = new HashMap<>();
    for (final WebAppInfo webApp : appInfo.webApps) {
        for (final String ejb : webApp.ejbWebServices) {
            webContextByEjb.put(ejb, webApp);
        }
    }
    final Map<String, String> contextData = new HashMap<>();
    contextData.put("appId", appInfo.path);
    for (final EjbJarInfo ejbJar : appInfo.ejbJars) {
        final Map<String, PortInfo> ports = new TreeMap<>();
        for (final PortInfo port : ejbJar.portInfos) {
            ports.put(port.serviceLink, port);
        }
        URL moduleBaseUrl = null;
        if (ejbJar.path != null) {
            try {
                moduleBaseUrl = new File(ejbJar.path).toURI().toURL();
            } catch (final MalformedURLException e) {
                logger.error("Invalid ejb jar location " + ejbJar.path, e);
            }
        }
        StringTemplate deploymentIdTemplate = this.wsAddressTemplate;
        if (ejbJar.properties.containsKey(WS_ADDRESS_FORMAT)) {
            final String format = ejbJar.properties.getProperty(WS_ADDRESS_FORMAT);
            logger.info("Using " + WS_ADDRESS_FORMAT + " '" + format + "'");
            deploymentIdTemplate = new StringTemplate(format);
        }
        contextData.put("ejbJarId", ejbJar.moduleName);
        final String host = host(ejbJar, appInfo);
        for (final EnterpriseBeanInfo bean : ejbJar.enterpriseBeans) {
            if (bean instanceof StatelessBeanInfo || bean instanceof SingletonBeanInfo) {
                final BeanContext beanContext = containerSystem.getBeanContext(bean.ejbDeploymentId);
                if (beanContext == null || (ejbs != null && !ejbs.contains(beanContext))) {
                    continue;
                }
                final PortInfo portInfo = ports.get(bean.ejbName);
                if (portInfo == null || alreadyDeployed.contains(beanContext))
                    continue;
                final ClassLoader old = Thread.currentThread().getContextClassLoader();
                Thread.currentThread().setContextClassLoader(beanContext.getClassLoader());
                try {
                    final PortData port = WsBuilder.toPortData(portInfo, beanContext.getInjections(), moduleBaseUrl, beanContext.getClassLoader());
                    final HttpListener container = createEjbWsContainer(moduleBaseUrl, port, beanContext, new ServiceConfiguration(beanContext.getProperties(), appInfo.services));
                    // generate a location if one was not assigned
                    String location = port.getLocation();
                    if (location == null) {
                        location = autoAssignWsLocation(bean, port, contextData, deploymentIdTemplate);
                    }
                    if (!location.startsWith("/"))
                        location = "/" + location;
                    ejbLocations.put(bean.ejbDeploymentId, location);
                    final ClassLoader classLoader = beanContext.getClassLoader();
                    if (wsRegistry != null) {
                        String auth = authMethod;
                        String realm = realmName;
                        String transport = transportGuarantee;
                        if ("BASIC".equals(portInfo.authMethod) || "DIGEST".equals(portInfo.authMethod) || "CLIENT-CERT".equals(portInfo.authMethod)) {
                            auth = portInfo.authMethod;
                            realm = portInfo.realmName;
                            transport = portInfo.transportGuarantee;
                        }
                        final WebAppInfo webAppInfo = webContextByEjb.get(bean.ejbClass);
                        String context = webAppInfo != null ? webAppInfo.contextRoot : null;
                        String moduleId = webAppInfo != null ? webAppInfo.moduleId : null;
                        if (context == null && !OLD_WEBSERVICE_DEPLOYMENT) {
                            context = ejbJar.moduleName;
                        }
                        final List<String> addresses = wsRegistry.addWsContainer(container, classLoader, context, host, location, realm, transport, auth, moduleId);
                        alreadyDeployed.add(beanContext);
                        // one of the registered addresses to be the canonical address
                        final String address = HttpUtil.selectSingleAddress(addresses);
                        if (address != null) {
                            // register wsdl location
                            portAddressRegistry.addPort(portInfo.serviceId, portInfo.wsdlService, portInfo.portId, portInfo.wsdlPort, portInfo.seiInterfaceName, address);
                            setWsdl(container, address);
                            logger.info("Webservice(wsdl=" + address + ", qname=" + port.getWsdlService() + ") --> Ejb(id=" + portInfo.portId + ")");
                            ejbAddresses.put(bean.ejbDeploymentId, address);
                            addressesForApp(appInfo.appId).add(new EndpointInfo(address, port.getWsdlService(), beanContext.getBeanClass().getName()));
                        }
                    }
                } catch (final Throwable e) {
                    logger.error("Error deploying JAX-WS Web Service for EJB " + beanContext.getDeploymentID(), e);
                } finally {
                    Thread.currentThread().setContextClassLoader(old);
                }
            }
        }
    }
    if (ejbs == null || appInfo.webAppAlone) {
        for (final WebAppInfo webApp : appInfo.webApps) {
            afterApplicationCreated(appInfo, webApp);
        }
    }
// else called because of ear case where new ejbs are deployed in webapps
}
Also used : MalformedURLException(java.net.MalformedURLException) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) SingletonBeanInfo(org.apache.openejb.assembler.classic.SingletonBeanInfo) URL(java.net.URL) PortInfo(org.apache.openejb.assembler.classic.PortInfo) EnterpriseBeanInfo(org.apache.openejb.assembler.classic.EnterpriseBeanInfo) WebAppInfo(org.apache.openejb.assembler.classic.WebAppInfo) ServiceConfiguration(org.apache.openejb.assembler.classic.util.ServiceConfiguration) PortData(org.apache.openejb.core.webservices.PortData) StringTemplate(org.apache.openejb.util.StringTemplate) HttpListener(org.apache.openejb.server.httpd.HttpListener) StatelessBeanInfo(org.apache.openejb.assembler.classic.StatelessBeanInfo) TreeMap(java.util.TreeMap) BeanContext(org.apache.openejb.BeanContext) EjbJarInfo(org.apache.openejb.assembler.classic.EjbJarInfo) File(java.io.File)

Example 2 with PortData

use of org.apache.openejb.core.webservices.PortData in project tomee by apache.

the class WsService method afterApplicationCreated.

public void afterApplicationCreated(final AppInfo appInfo, final WebAppInfo webApp) {
    final WebContext webContext = containerSystem.getWebContextByHost(webApp.moduleId, webApp.host != null ? webApp.host : virtualHost);
    if (webContext == null)
        return;
    // if already deployed skip this webapp
    if (!deployedWebApps.add(webApp))
        return;
    final Map<String, PortInfo> ports = new TreeMap<String, PortInfo>();
    for (final PortInfo port : webApp.portInfos) {
        ports.put(port.serviceLink, port);
    }
    URL moduleBaseUrl = null;
    try {
        moduleBaseUrl = new File(webApp.path).toURI().toURL();
    } catch (final MalformedURLException e) {
        logger.error("Invalid ejb jar location " + webApp.path, e);
    }
    // lazy init
    Collection<IdPropertiesInfo> pojoConfiguration = null;
    for (final ServletInfo servlet : webApp.servlets) {
        if (servlet.servletName == null) {
            continue;
        }
        final PortInfo portInfo = ports.get(servlet.servletName);
        if (portInfo == null) {
            continue;
        }
        final ClassLoader old = Thread.currentThread().getContextClassLoader();
        final ClassLoader classLoader = webContext.getClassLoader();
        Thread.currentThread().setContextClassLoader(classLoader);
        try {
            final Collection<Injection> injections = webContext.getInjections();
            final Context context = webContext.getJndiEnc();
            final Class target = classLoader.loadClass(servlet.servletClass);
            final Map<String, Object> bindings = webContext.getBindings();
            final PortData port = WsBuilder.toPortData(portInfo, injections, moduleBaseUrl, classLoader);
            pojoConfiguration = PojoUtil.findPojoConfig(pojoConfiguration, appInfo, webApp);
            final HttpListener container = createPojoWsContainer(classLoader, moduleBaseUrl, port, portInfo.serviceLink, target, context, webApp.contextRoot, bindings, new ServiceConfiguration(PojoUtil.findConfiguration(pojoConfiguration, target.getName()), appInfo.services));
            if (wsRegistry != null) {
                String auth = authMethod;
                String realm = realmName;
                String transport = transportGuarantee;
                if ("BASIC".equals(portInfo.authMethod) || "DIGEST".equals(portInfo.authMethod) || "CLIENT-CERT".equals(portInfo.authMethod)) {
                    auth = portInfo.authMethod;
                    realm = portInfo.realmName;
                    transport = portInfo.transportGuarantee;
                }
                // give servlet a reference to the webservice container
                final List<String> addresses = wsRegistry.setWsContainer(container, classLoader, webApp.contextRoot, host(webApp), servlet, realm, transport, auth, webApp.moduleId);
                // one of the registered addresses to be the connonical address
                final String address = HttpUtil.selectSingleAddress(addresses);
                // add address to global registry
                portAddressRegistry.addPort(portInfo.serviceId, portInfo.wsdlService, portInfo.portId, portInfo.wsdlPort, portInfo.seiInterfaceName, address);
                setWsdl(container, address);
                logger.info("Webservice(wsdl=" + address + ", qname=" + port.getWsdlService() + ") --> Pojo(id=" + portInfo.portId + ")");
                servletAddresses.put(webApp.moduleId + "." + servlet.servletName, address);
                addressesForApp(webApp.moduleId).add(new EndpointInfo(address, port.getWsdlService(), target.getName()));
            }
        } catch (final Throwable e) {
            logger.error("Error deploying CXF webservice for servlet " + portInfo.serviceLink, e);
        } finally {
            Thread.currentThread().setContextClassLoader(old);
        }
    }
}
Also used : WebContext(org.apache.openejb.core.WebContext) AppContext(org.apache.openejb.AppContext) BeanContext(org.apache.openejb.BeanContext) Context(javax.naming.Context) MalformedURLException(java.net.MalformedURLException) WebContext(org.apache.openejb.core.WebContext) Injection(org.apache.openejb.Injection) TreeMap(java.util.TreeMap) URL(java.net.URL) PortInfo(org.apache.openejb.assembler.classic.PortInfo) ServletInfo(org.apache.openejb.assembler.classic.ServletInfo) ServiceConfiguration(org.apache.openejb.assembler.classic.util.ServiceConfiguration) PortData(org.apache.openejb.core.webservices.PortData) IdPropertiesInfo(org.apache.openejb.assembler.classic.IdPropertiesInfo) HttpListener(org.apache.openejb.server.httpd.HttpListener) File(java.io.File)

Example 3 with PortData

use of org.apache.openejb.core.webservices.PortData in project tomee by apache.

the class WsBuilder method toPortData.

public static PortData toPortData(final PortInfo port, final Collection<Injection> injections, final URL baseUrl, final ClassLoader classLoader) throws OpenEJBException {
    final PortData portData = new PortData();
    portData.setPortId(port.portId);
    if (port.serviceName != null && port.serviceName.length() != 0) {
        portData.setServiceName(QName.valueOf(port.serviceName));
    }
    if (port.portName != null && port.portName.length() != 0) {
        portData.setPortName(QName.valueOf(port.portName));
    }
    portData.setWsdlUrl(getWsdlURL(port.wsdlFile, baseUrl, classLoader));
    portData.getHandlerChains().addAll(toHandlerChainData(port.handlerChains, classLoader));
    portData.getInjections().addAll(injections);
    portData.setMtomEnabled(port.mtomEnabled);
    portData.setBindingID(port.binding);
    portData.setWsdlPort(port.wsdlPort);
    portData.setWsdlService(port.wsdlService);
    portData.setLocation(port.location);
    portData.setSecure("WS-SECURITY".equals(port.authMethod));
    portData.setProperties(port.properties);
    return portData;
}
Also used : PortData(org.apache.openejb.core.webservices.PortData)

Aggregations

PortData (org.apache.openejb.core.webservices.PortData)3 File (java.io.File)2 MalformedURLException (java.net.MalformedURLException)2 URL (java.net.URL)2 TreeMap (java.util.TreeMap)2 BeanContext (org.apache.openejb.BeanContext)2 PortInfo (org.apache.openejb.assembler.classic.PortInfo)2 ServiceConfiguration (org.apache.openejb.assembler.classic.util.ServiceConfiguration)2 HttpListener (org.apache.openejb.server.httpd.HttpListener)2 HashMap (java.util.HashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Context (javax.naming.Context)1 AppContext (org.apache.openejb.AppContext)1 Injection (org.apache.openejb.Injection)1 EjbJarInfo (org.apache.openejb.assembler.classic.EjbJarInfo)1 EnterpriseBeanInfo (org.apache.openejb.assembler.classic.EnterpriseBeanInfo)1 IdPropertiesInfo (org.apache.openejb.assembler.classic.IdPropertiesInfo)1 ServletInfo (org.apache.openejb.assembler.classic.ServletInfo)1 SingletonBeanInfo (org.apache.openejb.assembler.classic.SingletonBeanInfo)1 StatelessBeanInfo (org.apache.openejb.assembler.classic.StatelessBeanInfo)1