public static void start() throws Exception {
WebApp webApp = new WebApp();
webApp.setContextRoot("/my-web-app");
webApp.setId("web");
webApp.setVersion("2.5");
WebModule webModule = new WebModule(webApp, webApp.getContextRoot(),
Thread.currentThread().getContextClassLoader(), "myapp", webApp.getId());
webModule.setFinder(new AnnotationFinder(new ClassesArchive(
MyFirstRestClass.class, MySecondRestClass.class, MyNonListedRestClass.class,
MyRESTApplication.class, MyExpertRestClass.class, HookedRest.class, RestWithInjections.class)).link());
Assembler assembler = new Assembler();
SystemInstance.get().setComponent(Assembler.class, assembler);
AnnotationDeployer annotationDeployer = new AnnotationDeployer();
ConfigurationFactory config = new ConfigurationFactory();
assembler.createProxyFactory(config.configureService(ProxyFactoryInfo.class));
assembler.createTransactionManager(config.configureService(TransactionServiceInfo.class));
assembler.createSecurityService(config.configureService(SecurityServiceInfo.class));
webModule = annotationDeployer.deploy(webModule);
EjbJar ejbJar = new EjbJar("ejb");
ejbJar.addEnterpriseBean(new StatelessBean(SimpleEJB.class));
ConfigurationFactory factory = new ConfigurationFactory(false);
AppModule appModule = new AppModule(Thread.currentThread().getContextClassLoader(), "foo");
appModule.setModuleId("rest");
appModule.getWebModules().add(webModule);
appModule.getEjbModules().add(new EjbModule(ejbJar));
appModule.getEjbModules().iterator().next().setModuleId(webModule.getModuleId());
appModule.setStandloneWebModule();
annotationDeployer.deploy(appModule);
AppInfo appInfo = factory.configureApplication(appModule);
final AppContext application = assembler.createApplication(appInfo);
Context ctx = (Context) Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), new Class<?>[]{Context.class}, new InvocationHandler() {
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
if (args.length == 1 && args[0].equals("SimpleEJBLocalBean")) {
return new SimpleEJB();
}
return method.invoke(new InitialContext(), args);
}
});
CoreContainerSystem containerSystem = new CoreContainerSystem(new IvmJndiFactory());
WebContext webContext = new WebContext(application);
webContext.setId(webApp.getId());
webContext.setClassLoader(webModule.getClassLoader());
webContext.getInjections().add(new Injection("SimpleEJBLocalBean", "simple", RestWithInjections.class));
webContext.setJndiEnc(ctx);
containerSystem.addWebContext(webContext);
SystemInstance.get().setComponent(ContainerSystem.class, containerSystem);