Search in sources :

Example 1 with ApplicationClient

use of org.apache.openejb.jee.ApplicationClient in project tomee by apache.

the class AppInfoBuilder method buildClientModules.

private void buildClientModules(final AppModule appModule, final AppInfo appInfo, final JndiEncInfoBuilder jndiEncInfoBuilder) throws OpenEJBException {
    for (final ClientModule clientModule : appModule.getClientModules()) {
        final ApplicationClient applicationClient = clientModule.getApplicationClient();
        final ClientInfo clientInfo = new ClientInfo();
        clientInfo.description = applicationClient.getDescription();
        clientInfo.displayName = applicationClient.getDisplayName();
        clientInfo.path = clientModule.getJarLocation();
        clientInfo.mainClass = clientModule.getMainClass();
        clientInfo.localClients.addAll(clientModule.getLocalClients());
        clientInfo.remoteClients.addAll(clientModule.getRemoteClients());
        clientInfo.callbackHandler = applicationClient.getCallbackHandler();
        clientInfo.moduleId = getClientModuleId(clientModule);
        clientInfo.watchedResources.addAll(clientModule.getWatchedResources());
        clientInfo.validationInfo = ValidatorBuilder.getInfo(clientModule.getValidationConfig());
        clientInfo.uniqueId = clientModule.getUniqueId();
        jndiEncInfoBuilder.build(applicationClient, clientModule.getJarLocation(), clientInfo.moduleId, clientModule.getModuleUri(), clientInfo.jndiEnc, clientInfo.jndiEnc);
        appInfo.clients.add(clientInfo);
    }
}
Also used : ApplicationClient(org.apache.openejb.jee.ApplicationClient) ClientInfo(org.apache.openejb.assembler.classic.ClientInfo)

Example 2 with ApplicationClient

use of org.apache.openejb.jee.ApplicationClient in project tomee by apache.

the class SunConversion method convertModule.

public void convertModule(final ClientModule clientModule) {
    if (clientModule == null) {
        return;
    }
    final ApplicationClient applicationClient = clientModule.getApplicationClient();
    if (applicationClient == null) {
        return;
    }
    final SunApplicationClient sunApplicationClient = getSunApplicationClient(clientModule);
    if (sunApplicationClient == null) {
        return;
    }
    // map ejb-refs
    final Map<String, org.apache.openejb.jee.EjbRef> refMap = applicationClient.getEjbRefMap();
    // map ejb-ref jndi name declaration to deploymentId
    for (final EjbRef ref : sunApplicationClient.getEjbRef()) {
        if (ref.getJndiName() != null) {
            String refName = ref.getEjbRefName();
            refName = normalize(refName);
            org.apache.openejb.jee.EjbRef ejbRef = refMap.get(refName);
            if (ejbRef == null) {
                ejbRef = new org.apache.openejb.jee.EjbRef();
                ejbRef.setEjbRefName(refName);
                refMap.put(refName, ejbRef);
                applicationClient.getEjbRef().add(ejbRef);
            }
            ejbRef.setMappedName(ref.getJndiName());
        }
    }
    // map resource-env-refs and message-destination-refs
    final Map<String, JndiReference> resEnvMap = new TreeMap<>();
    resEnvMap.putAll(applicationClient.getResourceEnvRefMap());
    resEnvMap.putAll(applicationClient.getMessageDestinationRefMap());
    for (final ResourceRef ref : sunApplicationClient.getResourceRef()) {
        if (ref.getJndiName() != null) {
            String refName = ref.getResRefName();
            refName = normalize(refName);
            final JndiReference resEnvRef = resEnvMap.get(refName);
            if (resEnvRef != null) {
                resEnvRef.setMappedName(ref.getJndiName());
            }
        }
    }
    for (final ResourceEnvRef ref : sunApplicationClient.getResourceEnvRef()) {
        if (ref.getJndiName() != null) {
            String refName = ref.getResourceEnvRefName();
            refName = normalize(refName);
            final JndiReference resEnvRef = resEnvMap.get(refName);
            if (resEnvRef != null) {
                resEnvRef.setMappedName(ref.getJndiName());
            }
        }
    }
    for (final MessageDestinationRef ref : sunApplicationClient.getMessageDestinationRef()) {
        if (ref.getJndiName() != null) {
            String refName = ref.getMessageDestinationRefName();
            refName = normalize(refName);
            final JndiReference resEnvRef = resEnvMap.get(refName);
            if (resEnvRef != null) {
                resEnvRef.setMappedName(ref.getJndiName());
            }
        }
    }
    final Map<String, ServiceRef> serviceRefMap = applicationClient.getServiceRefMap();
    for (final org.apache.openejb.jee.sun.ServiceRef ref : sunApplicationClient.getServiceRef()) {
        String refName = ref.getServiceRefName();
        refName = normalize(refName);
        final ServiceRef serviceRef = serviceRefMap.get(refName);
        if (serviceRef != null) {
            final Map<String, PortComponentRef> ports = new TreeMap<>();
            for (final PortComponentRef portComponentRef : serviceRef.getPortComponentRef()) {
                ports.put(portComponentRef.getServiceEndpointInterface(), portComponentRef);
            }
            for (final PortInfo portInfo : ref.getPortInfo()) {
                final PortComponentRef portComponentRef = ports.get(portInfo.getServiceEndpointInterface());
                if (portComponentRef != null) {
                    final WsdlPort wsdlPort = portInfo.getWsdlPort();
                    if (wsdlPort != null) {
                        final QName qname = new QName(wsdlPort.getNamespaceURI(), wsdlPort.getLocalpart());
                        portComponentRef.setQName(qname);
                    }
                    for (final StubProperty stubProperty : portInfo.getStubProperty()) {
                        final String name = stubProperty.getName();
                        final String value = stubProperty.getValue();
                        portComponentRef.getProperties().setProperty(name, value);
                    }
                }
            }
            final String wsdlOverride = ref.getWsdlOverride();
            if (wsdlOverride != null && wsdlOverride.length() > 0) {
                final String serviceId = extractServiceId(wsdlOverride);
                serviceRef.setMappedName(serviceId);
            }
        }
    }
}
Also used : WsdlPort(org.apache.openejb.jee.sun.WsdlPort) PortInfo(org.apache.openejb.jee.sun.PortInfo) MessageDestinationRef(org.apache.openejb.jee.sun.MessageDestinationRef) JndiReference(org.apache.openejb.jee.JndiReference) EjbRef(org.apache.openejb.jee.sun.EjbRef) ResourceEnvRef(org.apache.openejb.jee.sun.ResourceEnvRef) ApplicationClient(org.apache.openejb.jee.ApplicationClient) SunApplicationClient(org.apache.openejb.jee.sun.SunApplicationClient) QName(javax.xml.namespace.QName) StubProperty(org.apache.openejb.jee.sun.StubProperty) TreeMap(java.util.TreeMap) SunApplicationClient(org.apache.openejb.jee.sun.SunApplicationClient) PortComponentRef(org.apache.openejb.jee.PortComponentRef) ResourceRef(org.apache.openejb.jee.sun.ResourceRef) ServiceRef(org.apache.openejb.jee.ServiceRef)

Example 3 with ApplicationClient

use of org.apache.openejb.jee.ApplicationClient in project tomee by apache.

the class SunConversion method deploy.

public AppModule deploy(final AppModule appModule) {
    final SunApplication sunApplication = getSunApplication(appModule);
    if (sunApplication != null) {
        for (final Web web : sunApplication.getWeb()) {
            final String webUri = web.getWebUri();
            for (final WebModule webModule : appModule.getWebModules()) {
                if (webUri.equals(webModule.getModuleId())) {
                    webModule.setContextRoot(web.getContextRoot());
                    break;
                }
            }
        }
        for (final ClientModule clientModule : appModule.getClientModules()) {
            final ApplicationClient applicationClient = clientModule.getApplicationClient();
            if (applicationClient == null) {
                continue;
            }
            // map ejb-refs
            final Map<String, org.apache.openejb.jee.EjbRef> refMap = applicationClient.getEjbRefMap();
            // map ejb-ref jndi name declaration to deploymentId
            for (final EjbRef ref : sunApplication.getEjbRef()) {
                if (ref.getJndiName() != null) {
                    String refName = ref.getEjbRefName();
                    refName = normalize(refName);
                    org.apache.openejb.jee.EjbRef ejbRef = refMap.get(refName);
                    // try to match from lookup name
                    for (final Map.Entry<String, org.apache.openejb.jee.EjbRef> aRef : refMap.entrySet()) {
                        if (refName.equals(aRef.getValue().getLookupName())) {
                            ejbRef = aRef.getValue();
                            break;
                        }
                    }
                    if (ejbRef == null) {
                        ejbRef = new org.apache.openejb.jee.EjbRef();
                        ejbRef.setEjbRefName(refName);
                        refMap.put(refName, ejbRef);
                        applicationClient.getEjbRef().add(ejbRef);
                    }
                    ejbRef.setMappedName(ref.getJndiName());
                }
            }
            // map resource-env-refs and message-destination-refs
            final Map<String, JndiReference> resEnvMap = new TreeMap<>();
            resEnvMap.putAll(applicationClient.getResourceEnvRefMap());
            resEnvMap.putAll(applicationClient.getMessageDestinationRefMap());
            for (final ResourceRef ref : sunApplication.getResourceRef()) {
                if (ref.getJndiName() != null) {
                    String refName = ref.getResRefName();
                    refName = normalize(refName);
                    final JndiReference resEnvRef = resEnvMap.get(refName);
                    if (resEnvRef != null) {
                        resEnvRef.setMappedName(ref.getJndiName());
                    }
                }
            }
            for (final ResourceEnvRef ref : sunApplication.getResourceEnvRef()) {
                if (ref.getJndiName() != null) {
                    String refName = ref.getResourceEnvRefName();
                    refName = normalize(refName);
                    final JndiReference resEnvRef = resEnvMap.get(refName);
                    if (resEnvRef != null) {
                        resEnvRef.setMappedName(ref.getJndiName());
                    }
                }
            }
            for (final MessageDestinationRef ref : sunApplication.getMessageDestinationRef()) {
                if (ref.getJndiName() != null) {
                    String refName = ref.getMessageDestinationRefName();
                    refName = normalize(refName);
                    final JndiReference resEnvRef = resEnvMap.get(refName);
                    if (resEnvRef != null) {
                        resEnvRef.setMappedName(ref.getJndiName());
                    }
                }
            }
            for (final MessageDestination destination : sunApplication.getMessageDestination()) {
                if (destination.getJndiName() != null) {
                    String name = destination.getMessageDestinationName();
                    name = normalize(name);
                    final JndiReference ref = resEnvMap.get(name);
                    if (ref != null) {
                        ref.setMappedName(destination.getJndiName());
                    }
                }
            }
            final Map<String, ServiceRef> serviceRefMap = applicationClient.getServiceRefMap();
            for (final org.apache.openejb.jee.sun.ServiceRef ref : sunApplication.getServiceRef()) {
                String refName = ref.getServiceRefName();
                refName = normalize(refName);
                final ServiceRef serviceRef = serviceRefMap.get(refName);
                if (serviceRef != null) {
                    final Map<String, PortComponentRef> ports = new TreeMap<>();
                    for (final PortComponentRef portComponentRef : serviceRef.getPortComponentRef()) {
                        ports.put(portComponentRef.getServiceEndpointInterface(), portComponentRef);
                    }
                    for (final PortInfo portInfo : ref.getPortInfo()) {
                        final PortComponentRef portComponentRef = ports.get(portInfo.getServiceEndpointInterface());
                        if (portComponentRef != null) {
                            final WsdlPort wsdlPort = portInfo.getWsdlPort();
                            if (wsdlPort != null) {
                                final QName qname = new QName(wsdlPort.getNamespaceURI(), wsdlPort.getLocalpart());
                                portComponentRef.setQName(qname);
                            }
                            for (final StubProperty stubProperty : portInfo.getStubProperty()) {
                                final String name = stubProperty.getName();
                                final String value = stubProperty.getValue();
                                portComponentRef.getProperties().setProperty(name, value);
                            }
                        }
                    }
                    final String wsdlOverride = ref.getWsdlOverride();
                    if (wsdlOverride != null && wsdlOverride.length() > 0) {
                        final String serviceId = extractServiceId(wsdlOverride);
                        serviceRef.setMappedName(serviceId);
                    }
                }
            }
        }
    }
    for (final EjbModule ejbModule : appModule.getEjbModules()) {
        convertModule(ejbModule, appModule.getCmpMappings());
    }
    for (final ClientModule clientModule : appModule.getClientModules()) {
        convertModule(clientModule);
    }
    for (final WebModule webModule : appModule.getWebModules()) {
        convertModule(webModule);
    }
    return appModule;
}
Also used : WsdlPort(org.apache.openejb.jee.sun.WsdlPort) PortInfo(org.apache.openejb.jee.sun.PortInfo) MessageDestinationRef(org.apache.openejb.jee.sun.MessageDestinationRef) JndiReference(org.apache.openejb.jee.JndiReference) EjbRef(org.apache.openejb.jee.sun.EjbRef) ResourceEnvRef(org.apache.openejb.jee.sun.ResourceEnvRef) ApplicationClient(org.apache.openejb.jee.ApplicationClient) SunApplicationClient(org.apache.openejb.jee.sun.SunApplicationClient) MessageDestination(org.apache.openejb.jee.sun.MessageDestination) QName(javax.xml.namespace.QName) StubProperty(org.apache.openejb.jee.sun.StubProperty) SunApplication(org.apache.openejb.jee.sun.SunApplication) TreeMap(java.util.TreeMap) PortComponentRef(org.apache.openejb.jee.PortComponentRef) Web(org.apache.openejb.jee.sun.Web) ResourceRef(org.apache.openejb.jee.sun.ResourceRef) Map(java.util.Map) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) ServiceRef(org.apache.openejb.jee.ServiceRef)

Example 4 with ApplicationClient

use of org.apache.openejb.jee.ApplicationClient in project tomee by apache.

the class DeploymentLoader method createClientModule.

protected ClientModule createClientModule(final URL clientUrl, final String absolutePath, final ClassLoader appClassLoader, final String moduleName, final boolean log) throws OpenEJBException {
    final ResourceFinder clientFinder = new ResourceFinder(clientUrl);
    URL manifestUrl = null;
    try {
        manifestUrl = clientFinder.find("META-INF/MANIFEST.MF");
    } catch (final IOException e) {
    // 
    }
    String mainClass = null;
    if (manifestUrl != null) {
        try {
            final InputStream is = IO.read(manifestUrl);
            final Manifest manifest = new Manifest(is);
            mainClass = manifest.getMainAttributes().getValue(Attributes.Name.MAIN_CLASS);
        } catch (final IOException e) {
            throw new OpenEJBException("Unable to determine Main-Class defined in META-INF/MANIFEST.MF file", e);
        }
    }
    // if (mainClass == null) throw new IllegalStateException("No Main-Class defined in META-INF/MANIFEST.MF file");
    final Map<String, URL> descriptors = getDescriptors(clientFinder, log);
    ApplicationClient applicationClient = null;
    final URL clientXmlUrl = descriptors.get("application-client.xml");
    if (clientXmlUrl != null) {
        applicationClient = ReadDescriptors.readApplicationClient(clientXmlUrl);
    }
    final ClientModule clientModule = new ClientModule(applicationClient, appClassLoader, absolutePath, mainClass, moduleName);
    clientModule.getAltDDs().putAll(descriptors);
    if (absolutePath != null) {
        clientModule.getWatchedResources().add(absolutePath);
    }
    if (clientXmlUrl != null && "file".equals(clientXmlUrl.getProtocol())) {
        clientModule.getWatchedResources().add(URLs.toFilePath(clientXmlUrl));
    }
    return clientModule;
}
Also used : ResourceFinder(org.apache.xbean.finder.ResourceFinder) OpenEJBException(org.apache.openejb.OpenEJBException) ApplicationClient(org.apache.openejb.jee.ApplicationClient) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) Manifest(java.util.jar.Manifest) URL(java.net.URL)

Example 5 with ApplicationClient

use of org.apache.openejb.jee.ApplicationClient in project tomee by apache.

the class AppClientTest method test.

public void test() throws Exception {
    final EjbServer ejbServer = new EjbServer();
    final Properties initProps = new Properties();
    initProps.setProperty("openejb.deployments.classpath.include", "");
    initProps.setProperty("openejb.deployments.classpath.filter.descriptors", "true");
    OpenEJB.init(initProps, new ServerFederation());
    ejbServer.init(new Properties());
    final ServicePool pool = new ServicePool(ejbServer, 10);
    final ServiceDaemon serviceDaemon = new ServiceDaemon(pool, 0, "localhost");
    serviceDaemon.start();
    int port = serviceDaemon.getPort();
    final Assembler assembler = SystemInstance.get().getComponent(Assembler.class);
    final ConfigurationFactory config = new ConfigurationFactory();
    final EjbModule ejbModule = new EjbModule(new EjbJar("testejbmodule"), new OpenejbJar());
    final EjbJar ejbJar = ejbModule.getEjbJar();
    ejbJar.addEnterpriseBean(new StatelessBean(Orange.class));
    final ClassLoader loader = this.getClass().getClassLoader();
    final ClientModule clientModule = new ClientModule(new ApplicationClient(), loader, "orange-client", OrangeAppClient.class.getName(), "orange-client");
    final AppModule appModule = new AppModule(loader, "testapp");
    appModule.getClientModules().add(clientModule);
    appModule.getEjbModules().add(ejbModule);
    assembler.createApplication(config.configureApplication(appModule));
    final Properties props = new Properties();
    props.put("java.naming.factory.initial", "org.apache.openejb.client.RemoteInitialContextFactory");
    props.put("java.naming.provider.url", "ejbd://127.0.0.1:" + port);
    props.put("openejb.client.moduleId", "orange-client");
    Context context = new InitialContext(props);
    final Object home = context.lookup("comp/env/home");
    assertTrue(home instanceof OrangeHome);
    OrangeHome orangeHome = (OrangeHome) home;
    final OrangeRemote orangeRemote = orangeHome.create();
    assertEquals("bat", orangeRemote.echo("tab"));
    final Object business = context.lookup("comp/env/business");
    assertTrue(business instanceof OrangeBusinessRemote);
    OrangeBusinessRemote orangeBusinessRemote = (OrangeBusinessRemote) business;
    assertEquals("nap", orangeBusinessRemote.echo("pan"));
    final Object dataSourceObject = context.lookup("comp/env/datasource");
    assertTrue(dataSourceObject instanceof DataSource);
    // DataSource dataSource = (DataSource) dataSourceObject;
    // assertEquals("nap", orangeBusinessRemote.echo("pan"));
    props.put("openejb.client.moduleId", "openejb/global");
    context = new InitialContext(props);
    final Object global = context.lookup("global/testapp/testejbmodule/Orange!" + OrangeBusinessRemote.class.getName());
    assertTrue(global instanceof OrangeBusinessRemote);
    OrangeBusinessRemote globalOrangeBusinessRemote = (OrangeBusinessRemote) global;
    assertEquals("nap", globalOrangeBusinessRemote.echo("pan"));
    serviceDaemon.stop();
    OpenEJB.destroy();
}
Also used : AppModule(org.apache.openejb.config.AppModule) EjbModule(org.apache.openejb.config.EjbModule) Properties(java.util.Properties) OpenejbJar(org.apache.openejb.jee.oejb3.OpenejbJar) ConfigurationFactory(org.apache.openejb.config.ConfigurationFactory) EjbJar(org.apache.openejb.jee.EjbJar) Context(javax.naming.Context) InitialContext(javax.naming.InitialContext) ServerFederation(org.apache.openejb.core.ServerFederation) ApplicationClient(org.apache.openejb.jee.ApplicationClient) ServicePool(org.apache.openejb.server.ServicePool) ClientModule(org.apache.openejb.config.ClientModule) InitialContext(javax.naming.InitialContext) DataSource(javax.sql.DataSource) StatelessBean(org.apache.openejb.jee.StatelessBean) ServiceDaemon(org.apache.openejb.server.ServiceDaemon) EJBObject(javax.ejb.EJBObject) Assembler(org.apache.openejb.assembler.classic.Assembler)

Aggregations

ApplicationClient (org.apache.openejb.jee.ApplicationClient)5 TreeMap (java.util.TreeMap)2 QName (javax.xml.namespace.QName)2 JndiReference (org.apache.openejb.jee.JndiReference)2 PortComponentRef (org.apache.openejb.jee.PortComponentRef)2 ServiceRef (org.apache.openejb.jee.ServiceRef)2 EjbRef (org.apache.openejb.jee.sun.EjbRef)2 MessageDestinationRef (org.apache.openejb.jee.sun.MessageDestinationRef)2 PortInfo (org.apache.openejb.jee.sun.PortInfo)2 ResourceEnvRef (org.apache.openejb.jee.sun.ResourceEnvRef)2 ResourceRef (org.apache.openejb.jee.sun.ResourceRef)2 StubProperty (org.apache.openejb.jee.sun.StubProperty)2 SunApplicationClient (org.apache.openejb.jee.sun.SunApplicationClient)2 WsdlPort (org.apache.openejb.jee.sun.WsdlPort)2 BufferedInputStream (java.io.BufferedInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 URL (java.net.URL)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1