Search in sources :

Example 1 with StringTemplate

use of org.apache.openejb.util.StringTemplate 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 StringTemplate

use of org.apache.openejb.util.StringTemplate in project tomee by apache.

the class InitEjbDeployments method deploy.

private EjbModule deploy(final EjbModule ejbModule, final Map<String, String> contextData, final Set<String> abstractSchemaNames) throws OpenEJBException {
    contextData.put("moduleId", ejbModule.getModuleId());
    contextData.put("moduleUri", ejbModule.getModuleUri().toString());
    final OpenejbJar openejbJar;
    if (ejbModule.getOpenejbJar() != null) {
        openejbJar = ejbModule.getOpenejbJar();
    } else {
        openejbJar = new OpenejbJar();
        ejbModule.setOpenejbJar(openejbJar);
    }
    StringTemplate deploymentIdTemplate = this.deploymentIdTemplate;
    if (openejbJar.getProperties().containsKey(DEPLOYMENT_ID_FORMAT)) {
        final String format = openejbJar.getProperties().getProperty(DEPLOYMENT_ID_FORMAT);
        logger.info("Using " + DEPLOYMENT_ID_FORMAT + " '" + format + "'");
        deploymentIdTemplate = new StringTemplate(format);
    }
    for (final EnterpriseBean bean : ejbModule.getEjbJar().getEnterpriseBeans()) {
        StringTemplate template = deploymentIdTemplate;
        final org.apache.openejb.api.EjbDeployment annotation = getEjbDeploymentAnnotation(ejbModule, bean);
        EjbDeployment ejbDeployment = openejbJar.getDeploymentsByEjbName().get(bean.getEjbName());
        if (ejbDeployment == null) {
            ejbDeployment = new EjbDeployment();
            ejbDeployment.setEjbName(bean.getEjbName());
            if (annotation != null && isDefined(annotation.id())) {
                template = new StringTemplate(annotation.id());
                ejbDeployment.setDeploymentId(formatDeploymentId(bean, contextData, template));
            } else {
                ejbDeployment.setDeploymentId(formatDeploymentId(bean, contextData, template));
                if (!(bean instanceof ManagedBean) || !((ManagedBean) bean).isHidden()) {
                    logger.info("Auto-deploying ejb " + bean.getEjbName() + ": EjbDeployment(deployment-id=" + ejbDeployment.getDeploymentId() + ")");
                }
            }
            openejbJar.getEjbDeployment().add(ejbDeployment);
        } else if (ejbDeployment.getDeploymentId() == null) {
            if (annotation != null && isDefined(annotation.id())) {
                template = new StringTemplate(annotation.id());
                ejbDeployment.setDeploymentId(formatDeploymentId(bean, contextData, template));
            } else {
                ejbDeployment.setDeploymentId(formatDeploymentId(bean, contextData, template));
                logger.info("Auto-assigning deployment-id for ejb " + bean.getEjbName() + ": EjbDeployment(deployment-id=" + ejbDeployment.getDeploymentId() + ")");
            }
        }
        if (ejbDeployment.getContainerId() == null && annotation != null && isDefined(annotation.container())) {
            ejbDeployment.setContainerId(annotation.container());
        }
        if (isCmpEntity(bean)) {
            final EntityBean entity = (EntityBean) bean;
            if (entity.getAbstractSchemaName() == null) {
                String abstractSchemaName = bean.getEjbName().trim().replaceAll("[ \\t\\n\\r-]+", "_");
                // The AbstractSchemaName must be unique, we should check that it is
                if (abstractSchemaNames.contains(abstractSchemaName)) {
                    int i = 2;
                    while (abstractSchemaNames.contains(abstractSchemaName + i)) {
                        i++;
                    }
                    abstractSchemaName = abstractSchemaName + i;
                }
                abstractSchemaNames.add(abstractSchemaName);
                entity.setAbstractSchemaName(abstractSchemaName);
            }
        }
    }
    return ejbModule;
}
Also used : OpenejbJar(org.apache.openejb.jee.oejb3.OpenejbJar) EnterpriseBean(org.apache.openejb.jee.EnterpriseBean) StringTemplate(org.apache.openejb.util.StringTemplate) EntityBean(org.apache.openejb.jee.EntityBean) EjbDeployment(org.apache.openejb.jee.oejb3.EjbDeployment) ManagedBean(org.apache.openejb.jee.ManagedBean)

Example 3 with StringTemplate

use of org.apache.openejb.util.StringTemplate in project tomee by apache.

the class WsService method init.

@Override
public void init(final Properties props) throws Exception {
    if (props == null)
        return;
    final String format = props.getProperty(WS_ADDRESS_FORMAT);
    if (format != null) {
        this.wsAddressTemplate = new StringTemplate(format);
    }
    realmName = props.getProperty("realmName");
    transportGuarantee = props.getProperty("transportGuarantee");
    authMethod = props.getProperty("authMethod");
    virtualHost = props.getProperty("virtualHost", "localhost");
}
Also used : StringTemplate(org.apache.openejb.util.StringTemplate)

Example 4 with StringTemplate

use of org.apache.openejb.util.StringTemplate in project tomee by apache.

the class ServiceDaemon method init.

@Override
public void init(final Properties props) throws Exception {
    this.props = props;
    final String formatString = props.getProperty("discovery");
    if (formatString != null) {
        this.discoveryUriFormat = new StringTemplate(formatString);
    }
    this.ip = PropertyPlaceHolderHelper.simpleValue(props.getProperty("bind"));
    this.inetAddress = getAddress(this.ip);
    final Options options = new Options(props);
    this.port = Integer.parseInt(PropertyPlaceHolderHelper.simpleValue(options.get("port", "0")));
    final int threads = options.get("threads", 100);
    this.backlog = options.get("backlog", threads);
    this.secure = options.get("secure", false);
    this.timeout = options.get("timeout", this.timeout);
    this.enabledCipherSuites = options.get("enabledCipherSuites", "SSL_DH_anon_WITH_RC4_128_MD5").split(",");
    this.next.init(props);
}
Also used : Options(org.apache.openejb.loader.Options) StringTemplate(org.apache.openejb.util.StringTemplate)

Aggregations

StringTemplate (org.apache.openejb.util.StringTemplate)4 File (java.io.File)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 HashMap (java.util.HashMap)1 TreeMap (java.util.TreeMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 BeanContext (org.apache.openejb.BeanContext)1 EjbJarInfo (org.apache.openejb.assembler.classic.EjbJarInfo)1 EnterpriseBeanInfo (org.apache.openejb.assembler.classic.EnterpriseBeanInfo)1 PortInfo (org.apache.openejb.assembler.classic.PortInfo)1 SingletonBeanInfo (org.apache.openejb.assembler.classic.SingletonBeanInfo)1 StatelessBeanInfo (org.apache.openejb.assembler.classic.StatelessBeanInfo)1 WebAppInfo (org.apache.openejb.assembler.classic.WebAppInfo)1 ServiceConfiguration (org.apache.openejb.assembler.classic.util.ServiceConfiguration)1 PortData (org.apache.openejb.core.webservices.PortData)1 EnterpriseBean (org.apache.openejb.jee.EnterpriseBean)1 EntityBean (org.apache.openejb.jee.EntityBean)1 ManagedBean (org.apache.openejb.jee.ManagedBean)1 EjbDeployment (org.apache.openejb.jee.oejb3.EjbDeployment)1