use of org.apache.openejb.jee.oejb3.OpenejbJar in project tomee by apache.
the class DynamicConnectionStrategyTest method test.
public void test() throws Exception {
ConnectionManager.registerStrategy("test", new TestConnectionStrategy());
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("openejb.client.connection.strategy", "test");
assembler.createApplication(config.configureApplication(ejbModule));
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");
assertFalse(TestConnectionStrategy.called.get());
remote.echo("foo");
assertTrue(TestConnectionStrategy.called.get());
serviceDaemon.stop();
OpenEJB.destroy();
}
use of org.apache.openejb.jee.oejb3.OpenejbJar in project tomee by apache.
the class FailoverConnectionFactoryTest method test.
public void test() throws Exception {
ConnectionManager.registerStrategy("test", new TestConnectionStrategy());
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("openejb.client.connection.strategy", "test");
assembler.createApplication(config.configureApplication(ejbModule));
Properties props = new Properties();
props.put("java.naming.factory.initial", "org.apache.openejb.client.RemoteInitialContextFactory");
props.put("java.naming.provider.url", "failover:sticky:ejbd://agwdt:9999,ejbd://127.0.0.1:" + port);
Context context = new InitialContext(props);
Widget remote = (Widget) context.lookup("WidgetBeanRemote");
assertFalse(TestConnectionStrategy.called.get());
remote.echo("foo");
assertTrue(TestConnectionStrategy.called.get());
serviceDaemon.stop();
OpenEJB.destroy();
}
use of org.apache.openejb.jee.oejb3.OpenejbJar in project tomee by apache.
the class TomEEJsonbProviderTest method service.
@Module
public static EjbModule service() {
final EjbModule module = new EjbModule(new EjbJar(), new OpenejbJar());
final EnterpriseBean bean = new SingletonBean(Endpoint.class).localBean();
module.getEjbJar().addEnterpriseBean(bean);
final Resources resources = new Resources();
final Service configuredTomEEJsonbProvider = new Service("configuredTomEEJsonbProvider", null);
configuredTomEEJsonbProvider.setClassName(TomEEJsonbProvider.class.getName());
configuredTomEEJsonbProvider.getProperties().put("dateFormat", "MMM-yyyy");
configuredTomEEJsonbProvider.getProperties().put("locale", Locale.GERMANY);
configuredTomEEJsonbProvider.getProperties().put("accessMode", new FieldAccessMode(true, true));
resources.getService().add(configuredTomEEJsonbProvider);
module.initResources(resources);
final PojoDeployment e = new PojoDeployment();
e.setClassName("jaxrs-application");
e.getProperties().setProperty("cxf.jaxrs.providers", "configuredTomEEJsonbProvider");
module.getOpenejbJar().getPojoDeployment().add(e);
return module;
}
use of org.apache.openejb.jee.oejb3.OpenejbJar in project tomee by apache.
the class TomEEConfigurableJohnzonTest method service.
@Module
public static EjbModule service() throws Exception {
final EjbModule module = new EjbModule(new EjbJar(), new OpenejbJar());
final EnterpriseBean bean = new SingletonBean(Endpoint.class).localBean();
module.getEjbJar().addEnterpriseBean(bean);
final Resources resources = new Resources();
final Service sorter = new Service("testSorter", null);
sorter.setClassName(Sorter.class.getName());
resources.getService().add(sorter);
final Service converter = new Service("customerConverter", null);
converter.setClassName(MyConverter.class.getName());
resources.getService().add(converter);
final Service johnzon = new Service("johnzon", null);
johnzon.setClassName(TomEEConfigurableJohnzon.class.getName());
johnzon.getProperties().put("datePattern", "yyyy");
// johnzon.getProperties().put("converter", "$customerConverter"); // or the collection syntax
johnzon.getProperties().put("converters", "collection:$customerConverter,$customerConverter");
johnzon.getProperties().put("attributeOrder", "$testSorter");
resources.getService().add(johnzon);
module.initResources(resources);
final PojoDeployment e = new PojoDeployment();
e.setClassName("jaxrs-application");
e.getProperties().setProperty("cxf.jaxrs.providers", "johnzon");
module.getOpenejbJar().getPojoDeployment().add(e);
return module;
}
use of org.apache.openejb.jee.oejb3.OpenejbJar in project tomee by apache.
the class LoggingJAXRSCommons method getEjbModule.
protected EjbModule getEjbModule(String pojoDeploymentClassName, String ejbModuleId) throws Exception {
final EjbModule module = new EjbModule(new EjbJar(), new OpenejbJar());
if (ejbModuleId != null) {
module.setModuleId(ejbModuleId);
}
final EnterpriseBean bean = new SingletonBean(LogginTestBean.class).localBean();
module.getEjbJar().addEnterpriseBean(bean);
final Resources resources = new Resources();
final Service feature = new Service("xml", null);
feature.setClassName(JAXBElementProvider.class.getName());
feature.getProperties().put("eventHandler", "$handler");
resources.getService().add(feature);
module.initResources(resources);
if (pojoDeploymentClassName != null) {
final PojoDeployment e = new PojoDeployment();
e.setClassName(pojoDeploymentClassName);
e.getProperties().setProperty("cxf.jaxrs.providers", "xml");
module.getOpenejbJar().getPojoDeployment().add(e);
}
return module;
}
Aggregations