Search in sources :

Example 1 with ServletInfo

use of org.apache.openejb.assembler.classic.ServletInfo in project tomee by apache.

the class RESTService method appPrefix.

private static String appPrefix(final WebAppInfo info, final Class<?> appClazz) {
    StringBuilder builder = null;
    // no annotation, try servlets
    for (final ServletInfo s : info.servlets) {
        if (s.mappings.isEmpty()) {
            continue;
        }
        String mapping = null;
        final String name = appClazz.getName();
        if (name.equals(s.servletClass) || name.equals(s.servletName) || "javax.ws.rs.core.Application ".equals(s.servletName)) {
            mapping = s.mappings.iterator().next();
        } else {
            for (final ParamValueInfo pvi : s.initParams) {
                if ("javax.ws.rs.Application".equals(pvi.name) || Application.class.getName().equals(pvi.name)) {
                    mapping = s.mappings.iterator().next();
                    break;
                }
            }
        }
        if (mapping != null) {
            if (mapping.endsWith("/*")) {
                mapping = mapping.substring(0, mapping.length() - 2);
            }
            if (mapping.startsWith("/")) {
                mapping = mapping.substring(1);
            }
            builder = new StringBuilder();
            builder.append(mapping);
            break;
        }
    }
    if (builder != null) {
        // https://issues.apache.org/jira/browse/CXF-5702
        return builder.toString();
    }
    // annotation
    final ApplicationPath path = appClazz.getAnnotation(ApplicationPath.class);
    if (path != null) {
        String appPath = path.value();
        if (appPath.endsWith("*")) {
            appPath = appPath.substring(0, appPath.length() - 1);
        }
        builder = new StringBuilder();
        if (appPath.startsWith("/")) {
            builder.append(appPath.substring(1));
        } else {
            builder.append(appPath);
        }
    }
    if (builder == null) {
        return null;
    }
    return builder.toString();
}
Also used : ServletInfo(org.apache.openejb.assembler.classic.ServletInfo) ParamValueInfo(org.apache.openejb.assembler.classic.ParamValueInfo) ApplicationPath(javax.ws.rs.ApplicationPath)

Example 2 with ServletInfo

use of org.apache.openejb.assembler.classic.ServletInfo in project tomee by apache.

the class WsService method undeploy.

public void undeploy(@Observes final AssemblerBeforeApplicationDestroyed event) {
    final AppInfo appInfo = event.getApp();
    if (deployedApplications.remove(appInfo) != null) {
        for (final EjbJarInfo ejbJar : appInfo.ejbJars) {
            final Map<String, PortInfo> ports = new TreeMap<String, PortInfo>();
            for (final PortInfo port : ejbJar.portInfos) {
                ports.put(port.serviceLink, port);
            }
            for (final EnterpriseBeanInfo enterpriseBean : ejbJar.enterpriseBeans) {
                if (enterpriseBean instanceof StatelessBeanInfo || enterpriseBean instanceof SingletonBeanInfo) {
                    final PortInfo portInfo = ports.get(enterpriseBean.ejbName);
                    if (portInfo == null) {
                        continue;
                    }
                    final BeanContext beanContext = containerSystem.getBeanContext(enterpriseBean.ejbDeploymentId);
                    if (beanContext == null) {
                        continue;
                    }
                    // remove wsdl addresses from global registry
                    final String address = ejbAddresses.remove(enterpriseBean.ejbDeploymentId);
                    addressesForApp(appInfo.appId).remove(new EndpointInfo(address, portInfo.wsdlPort, beanContext.getBeanClass().getName()));
                    if (address != null) {
                        portAddressRegistry.removePort(portInfo.serviceId, portInfo.wsdlService, portInfo.portId, portInfo.seiInterfaceName);
                    }
                    // remove container from web server
                    final String location = ejbLocations.get(enterpriseBean.ejbDeploymentId);
                    if (this.wsRegistry != null && location != null) {
                        this.wsRegistry.removeWsContainer(location, ejbJar.moduleId);
                    }
                    // destroy webservice container
                    destroyEjbWsContainer(enterpriseBean.ejbDeploymentId);
                    ejbLocations.remove(enterpriseBean.ejbDeploymentId);
                }
            }
        }
        for (final WebAppInfo webApp : appInfo.webApps) {
            deployedWebApps.remove(webApp);
            final Map<String, PortInfo> ports = new TreeMap<String, PortInfo>();
            for (final PortInfo port : webApp.portInfos) {
                ports.put(port.serviceLink, port);
            }
            for (final ServletInfo servlet : webApp.servlets) {
                if (servlet.servletClass == null) {
                    continue;
                }
                PortInfo portInfo = ports.remove(servlet.servletClass);
                if (portInfo == null) {
                    portInfo = ports.remove(servlet.servletName);
                    if (portInfo == null) {
                        continue;
                    }
                }
                // remove wsdl addresses from global registry
                final String address = servletAddresses.remove(webApp.moduleId + "." + servlet.servletName);
                if (address != null) {
                    portAddressRegistry.removePort(portInfo.serviceId, portInfo.wsdlService, portInfo.portId, portInfo.seiInterfaceName);
                }
                // clear servlet's reference to the webservice container
                if (this.wsRegistry != null) {
                    try {
                        this.wsRegistry.clearWsContainer(webApp.contextRoot, host(webApp), servlet, webApp.moduleId);
                    } catch (final IllegalArgumentException ignored) {
                    // no-op
                    }
                }
                // destroy webservice container
                destroyPojoWsContainer(portInfo.serviceLink);
            }
            addressesByApplication.remove(webApp.moduleId);
        }
        addressesByApplication.remove(appInfo.appId);
    }
}
Also used : StatelessBeanInfo(org.apache.openejb.assembler.classic.StatelessBeanInfo) SingletonBeanInfo(org.apache.openejb.assembler.classic.SingletonBeanInfo) TreeMap(java.util.TreeMap) WebAppInfo(org.apache.openejb.assembler.classic.WebAppInfo) AppInfo(org.apache.openejb.assembler.classic.AppInfo) PortInfo(org.apache.openejb.assembler.classic.PortInfo) EnterpriseBeanInfo(org.apache.openejb.assembler.classic.EnterpriseBeanInfo) ServletInfo(org.apache.openejb.assembler.classic.ServletInfo) BeanContext(org.apache.openejb.BeanContext) WebAppInfo(org.apache.openejb.assembler.classic.WebAppInfo) EjbJarInfo(org.apache.openejb.assembler.classic.EjbJarInfo)

Example 3 with ServletInfo

use of org.apache.openejb.assembler.classic.ServletInfo 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 4 with ServletInfo

use of org.apache.openejb.assembler.classic.ServletInfo in project tomee by apache.

the class OpenEJBContextConfig method addAddedJAXWsServices.

private void addAddedJAXWsServices() {
    final WebAppInfo webAppInfo = info.get();
    final AppInfo appInfo = info.app();
    if (webAppInfo == null || appInfo == null || "false".equalsIgnoreCase(appInfo.properties.getProperty("openejb.jaxws.add-missing-servlets", "true"))) {
        return;
    }
    try {
        // if no jaxws classes are here don't try anything
        OpenEJBContextConfig.class.getClassLoader().loadClass("org.apache.openejb.server.webservices.WsServlet");
    } catch (final ClassNotFoundException | NoClassDefFoundError e) {
        return;
    }
    for (final ServletInfo servlet : webAppInfo.servlets) {
        if (!servlet.mappings.iterator().hasNext()) {
            // no need to do anything
            continue;
        }
        for (final ParamValueInfo pv : servlet.initParams) {
            if ("openejb-internal".equals(pv.name) && "true".equals(pv.value)) {
                if (context.findChild(servlet.servletName) == null) {
                    final Wrapper wrapper = context.createWrapper();
                    wrapper.setName(servlet.servletName);
                    wrapper.setServletClass("org.apache.openejb.server.webservices.WsServlet");
                    // add servlet to context
                    context.addChild(wrapper);
                    context.addServletMappingDecoded(servlet.mappings.iterator().next(), wrapper.getName());
                }
                break;
            }
        }
    }
}
Also used : ServletInfo(org.apache.openejb.assembler.classic.ServletInfo) Wrapper(org.apache.catalina.Wrapper) StandardWrapper(org.apache.catalina.core.StandardWrapper) WebAppInfo(org.apache.openejb.assembler.classic.WebAppInfo) ParamValueInfo(org.apache.openejb.assembler.classic.ParamValueInfo) WebAppInfo(org.apache.openejb.assembler.classic.WebAppInfo) AppInfo(org.apache.openejb.assembler.classic.AppInfo)

Example 5 with ServletInfo

use of org.apache.openejb.assembler.classic.ServletInfo in project tomee by apache.

the class OpenEJBDeployableContainer method deploy.

@Override
public ProtocolMetaData deploy(final Archive<?> archive) throws DeploymentException {
    final DeploymentInfo info;
    try {
        final Closeables cl = new Closeables();
        closeablesProducer.set(cl);
        info = quickDeploy(archive, testClass.get(), cl);
        // container rules (CDI) which is not the case with this solution
        if (archive.getName().endsWith(".war")) {
            final List<BeanContext> beanContexts = info.appCtx.getBeanContexts();
            if (beanContexts.size() > 1) {
                final Iterator<BeanContext> it = beanContexts.iterator();
                while (it.hasNext()) {
                    final BeanContext next = it.next();
                    if (ModuleTestContext.class.isInstance(next.getModuleContext()) && BeanContext.Comp.class != next.getBeanClass()) {
                        for (final BeanContext b : beanContexts) {
                            if (b.getModuleContext() != next.getModuleContext()) {
                                ModuleTestContext.class.cast(next.getModuleContext()).setModuleJndiContextOverride(b.getModuleContext().getModuleJndiContext());
                                break;
                            }
                        }
                        break;
                    }
                }
            }
        }
        servletContextProducer.set(info.appServletContext);
        sessionProducer.set(info.appSession);
        appInfoProducer.set(info.appInfo);
        appContextProducer.set(info.appCtx);
        final ClassLoader loader = info.appCtx.getWebContexts().isEmpty() ? info.appCtx.getClassLoader() : info.appCtx.getWebContexts().iterator().next().getClassLoader();
        final ClassLoader classLoader = loader == null ? info.appCtx.getClassLoader() : loader;
        TestObserver.ClassLoaders classLoaders = this.classLoader.get();
        if (classLoaders == null) {
            classLoaders = new TestObserver.ClassLoaders();
            this.classLoader.set(classLoaders);
        }
        classLoaders.register(archive.getName(), classLoader);
    } catch (final Exception e) {
        throw new DeploymentException("can't deploy " + archive.getName(), e);
    }
    // if service manager is started allow @ArquillianResource URL injection
    if (PROPERTIES.containsKey(OpenEjbContainer.OPENEJB_EMBEDDED_REMOTABLE)) {
        final ProtocolMetaData metaData = ServiceManagers.protocolMetaData(appInfoProducer.get());
        HTTPContext http = null;
        for (final WebAppInfo webapp : info.appInfo.webApps) {
            for (final ServletInfo servletInfo : webapp.servlets) {
                if (http == null) {
                    http = HTTPContext.class.cast(metaData.getContexts().iterator().next());
                    http.add(new Servlet(servletInfo.servletName, webapp.contextRoot));
                }
            }
            for (final ClassListInfo classListInfo : webapp.webAnnotatedClasses) {
                for (final String path : classListInfo.list) {
                    if (!path.contains("!")) {
                        continue;
                    }
                    if (http == null) {
                        http = HTTPContext.class.cast(metaData.getContexts().iterator().next());
                    }
                    http.add(new Servlet(path.substring(path.lastIndexOf('!') + 2).replace(".class", "").replace("/", "."), webapp.contextRoot));
                }
            }
        }
        if (metaData != null) {
            return metaData;
        }
    }
    return new ProtocolMetaData();
}
Also used : HTTPContext(org.jboss.arquillian.container.spi.client.protocol.metadata.HTTPContext) TestObserver(org.apache.openejb.arquillian.common.TestObserver) NamingException(javax.naming.NamingException) LifecycleException(org.jboss.arquillian.container.spi.client.container.LifecycleException) IOException(java.io.IOException) OpenEJBRuntimeException(org.apache.openejb.OpenEJBRuntimeException) DeploymentException(org.jboss.arquillian.container.spi.client.container.DeploymentException) ClassListInfo(org.apache.openejb.assembler.classic.ClassListInfo) ServletInfo(org.apache.openejb.assembler.classic.ServletInfo) BeanContext(org.apache.openejb.BeanContext) ModuleTestContext(org.apache.openejb.ModuleTestContext) WebAppInfo(org.apache.openejb.assembler.classic.WebAppInfo) Servlet(org.jboss.arquillian.container.spi.client.protocol.metadata.Servlet) DeploymentException(org.jboss.arquillian.container.spi.client.container.DeploymentException) ProtocolMetaData(org.jboss.arquillian.container.spi.client.protocol.metadata.ProtocolMetaData)

Aggregations

ServletInfo (org.apache.openejb.assembler.classic.ServletInfo)9 WebAppInfo (org.apache.openejb.assembler.classic.WebAppInfo)7 BeanContext (org.apache.openejb.BeanContext)5 ParamValueInfo (org.apache.openejb.assembler.classic.ParamValueInfo)4 TreeMap (java.util.TreeMap)3 NamingException (javax.naming.NamingException)3 AppContext (org.apache.openejb.AppContext)3 OpenEJBRuntimeException (org.apache.openejb.OpenEJBRuntimeException)3 ClassListInfo (org.apache.openejb.assembler.classic.ClassListInfo)3 WebContext (org.apache.openejb.core.WebContext)3 IOException (java.io.IOException)2 MalformedURLException (java.net.MalformedURLException)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Context (javax.naming.Context)2 NameNotFoundException (javax.naming.NameNotFoundException)2 ServletContext (javax.servlet.ServletContext)2 AppInfo (org.apache.openejb.assembler.classic.AppInfo)2 FilterInfo (org.apache.openejb.assembler.classic.FilterInfo)2 ListenerInfo (org.apache.openejb.assembler.classic.ListenerInfo)2