use of org.apache.openejb.jee.oejb3.OpenejbJar in project tomee by apache.
the class CustomEndpointConfiguratorTest method module.
@Module
public EjbModule module() {
final EjbModule module = new EjbModule(new EjbJar());
module.setOpenejbJar(new OpenejbJar());
final SingletonBean bean = new SingletonBean(MyWebservice.class);
bean.setLocalBean(new Empty());
final EjbDeployment deployment = new EjbDeployment(bean);
deployment.getProperties().setProperty("openejb.endpoint.configurator", CustomConfigurator.class.getName());
module.getOpenejbJar().addEjbDeployment(deployment);
module.getEjbJar().addEnterpriseBean(bean);
return module;
}
use of org.apache.openejb.jee.oejb3.OpenejbJar in project tomee by apache.
the class Container method addCallersAsEjbModule.
private static void addCallersAsEjbModule(final ClassLoader loader, final AppModule app, final String... additionalCallers) {
final Set<String> callers = new HashSet<>(NewLoaderLogic.callers(Filters.classes(Container.class.getName(), "org.apache.openejb.maven.plugins.TomEEEmbeddedMojo")));
// we don't care of these
callers.remove("org.apache.tomee.embedded.Container");
callers.remove("org.apache.tomee.gradle.embedded.TomEEEmbeddedTask");
final Iterator<String> callerIt = callers.iterator();
while (callerIt.hasNext()) {
// TomEEEmbeddedMojo is also used with some anonymous classes (TomEEEmbeddedMojo$x)
if (callerIt.next().startsWith("org.apache.openejb.maven.plugins.TomEEEmbeddedMojo")) {
callerIt.remove();
// no break since we remove anonymous class+the mojo itself
}
}
if (additionalCallers != null && additionalCallers.length > 0) {
callers.addAll(asList(additionalCallers));
}
if (callers.isEmpty()) {
return;
}
final EjbJar ejbJar = new EjbJar();
final OpenejbJar openejbJar = new OpenejbJar();
for (final String caller : callers) {
try {
if (!AnnotationDeployer.isInstantiable(loader.loadClass(caller))) {
continue;
}
} catch (final ClassNotFoundException e) {
continue;
}
final String name = caller.replace("$", "_");
final ManagedBean bean = ejbJar.addEnterpriseBean(new ManagedBean(caller.replace("$", "_"), caller, true));
bean.localBean();
bean.setTransactionType(TransactionType.BEAN);
final EjbDeployment ejbDeployment = openejbJar.addEjbDeployment(bean);
ejbDeployment.setDeploymentId(name);
}
final EjbModule ejbModule = new EjbModule(ejbJar, openejbJar);
ejbModule.setBeans(new Beans());
app.getEjbModules().add(ejbModule);
}
use of org.apache.openejb.jee.oejb3.OpenejbJar in project tomee by apache.
the class PropertiesPropogationTest method test.
public void test() throws Exception {
EjbServer ejbServer = new EjbServer();
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());
ServicePool pool = new ServicePool(ejbServer, 10);
ServiceDaemon serviceDaemon = new ServiceDaemon(pool, 0, "localhost");
serviceDaemon.start();
int port = serviceDaemon.getPort();
Assembler assembler = SystemInstance.get().getComponent(Assembler.class);
ConfigurationFactory config = new ConfigurationFactory();
EjbModule ejbModule = new EjbModule(new EjbJar(), new OpenejbJar());
EjbJar ejbJar = ejbModule.getEjbJar();
OpenejbJar openejbJar = ejbModule.getOpenejbJar();
StatelessBean statelessBean = ejbJar.addEnterpriseBean(new StatelessBean(WidgetBean.class));
EjbDeployment deployment = openejbJar.addEjbDeployment(statelessBean);
deployment.getProperties().put("color", "orange");
deployment.getProperties().put("openejb.client.color", "red");
EjbJarInfo ejbJarInfo = config.configureApplication(ejbModule);
EnterpriseBeanInfo beanInfo = ejbJarInfo.enterpriseBeans.get(0);
assertTrue(beanInfo.properties.containsKey("color"));
assertTrue(beanInfo.properties.containsKey("openejb.client.color"));
assertEquals("orange", beanInfo.properties.get("color"));
assertEquals("red", beanInfo.properties.get("openejb.client.color"));
assembler.createApplication(ejbJarInfo);
ContainerSystem cs = SystemInstance.get().getComponent(ContainerSystem.class);
BeanContext info = cs.getBeanContext("WidgetBean");
assertNotNull(info);
assertTrue(info.getProperties().containsKey("color"));
assertTrue(info.getProperties().containsKey("openejb.client.color"));
assertEquals("orange", info.getProperties().get("color"));
assertEquals("red", info.getProperties().get("openejb.client.color"));
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);
Context context = new InitialContext(props);
Widget remote = (Widget) context.lookup("WidgetBeanRemote");
InvocationHandler handler = ProxyManager.getInvocationHandler(remote);
EJBObjectHandler objectHandler = EJBObjectHandler.class.cast(handler);
Properties properties = objectHandler.getEjb().getProperties();
// Should only contain "openejb.client.*" properties
assertFalse(properties.containsKey("color"));
// The openejb.client.color property should have been propogated
assertTrue(properties.containsKey("openejb.client.color"));
assertEquals("red", properties.getProperty("openejb.client.color"));
serviceDaemon.stop();
OpenEJB.destroy();
}
use of org.apache.openejb.jee.oejb3.OpenejbJar 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();
}
use of org.apache.openejb.jee.oejb3.OpenejbJar in project tomee by apache.
the class FeatureTest method app.
@Module
public EjbModule app() {
final EjbJar jar = new EjbJar();
jar.addEnterpriseBean(new SingletonBean(AuthenticatorServiceBean.class).localBean());
final OpenejbJar openejbJar = new OpenejbJar();
openejbJar.addEjbDeployment(new EjbDeployment(jar.getEnterpriseBeans()[0]));
final Properties properties = openejbJar.getEjbDeployment().iterator().next().getProperties();
properties.setProperty(CxfService.OPENEJB_JAXWS_CXF_FEATURES, MyFeature.class.getName());
properties.setProperty("cxf.jaxws.features", "my-feature");
properties.setProperty("cxf.jaxws.properties", "my-props");
final EjbModule module = new EjbModule(jar);
module.setOpenejbJar(openejbJar);
final Resources resources = new Resources();
final Service service = new Service("my-feature", null, null, null);
service.setClassName(MyFeature.class.getName());
resources.add(service);
final Service myProps = new Service("my-props", null, null, null);
myProps.setClassName(Properties.class.getName());
myProps.getProperties().setProperty("faultStackTraceEnabled", "true");
resources.add(myProps);
module.initResources(resources);
return module;
}
Aggregations