> -----Original Message----- > From: Romain Manni-Bucau [mailto:[email protected]] > Sent: Saturday, November 9, 2013 5:03 PM > To: [email protected]; Mark Struberg > Cc: Niki Dokovski > Subject: Re: OWB on Tomcat 7 > > we could hack a ServletContainerInitializer but not sure the gain compared to > using tomee which will always be far more integrated "by design"
Yes OWB in TomEE works just fine. Outside TomEE a SCI is kind of "the standard" of extending a web container although there are some unclarified areas as the order of execution. For instance Mark Thomas used this approach with websocket implementation in tomcat. Still it is tempting to try this. > Romain Manni-Bucau > Twitter: @rmannibucau > Blog: http://rmannibucau.wordpress.com/ > LinkedIn: http://fr.linkedin.com/in/rmannibucau > Github: https://github.com/rmannibucau > > > > 2013/11/9 Mark Struberg <[email protected]>: > > Hi Niki! > > > > Karl and I did already work on improving our documentation at least ;) > > > > http://openwebbeans.apache.org/owbsetup_ee.html > > > > Please ping us if you find a failure! > > > > LieGrue, > > strub > > > > > > ________________________________ > > From: Niki Dokovski <[email protected]> > > To: [email protected]; 'Mark Struberg' > <[email protected]> > > Sent: Saturday, 9 November 2013, 15:01 > > Subject: RE: OWB on Tomcat 7 > > > > Hi Mark, > > > > From: Mark Struberg [mailto:[email protected]] > > Sent: Saturday, November 9, 2013 3:25 PM > > To: [email protected] > > Subject: Re: OWB on Tomcat 7 > > > > Hi folks! > > > > There are 2 different ways to work with OpenWebBeans and tomcat. > > > > > > > > A, your app is using CDI but you do not need the container to > > understand CDI. > > In that case just add owb-core jar + spi + xbean-asm4-shaded + owb-web > > into your WEB-INF/lib and add WebBeansConfigurationListener to your > > web.xml as <listener> > > > > This works perfect, but be aware that there is no CDI injection in > > Servlets themself. You can of course use DeltaSpike BeanProvider to > > pick up > > > > B.) you need it fully integrated with all other EE technologies. In > > that case I suggest you use TomEE. This is basically tomcat7 + latest > > OWB + latest MyFaces + + +. And all that in a perfectly integrated > > and ready to use configuration. > > > > IMHO, there might be cases where you dont need my faces or you just > > want to test the latest web container with the latest CDI. Current owb > > documentation is a bit confusing indeed and you need to look into the > > source code to understand what you need to configure and where. Which > > might be good exercise anyway. I like the plugins architecture of > > OWB but the integration with tomcat can be improved. The CDI RI did a > > bit better with the integration with Tomcat for now. (Yes you still > > need the servlet listener to bootstrap the CDI container) > > > > Do you folks have plans to reconsider current integrations points with > > tomcat? Are there any particular ideas for what can be improved on > > tomcat side to make the integration better? > > > > Cheers > > Niki > > > > > > LieGrue, > > strub > > > > > > > > ________________________________ > > From: aljesco <[email protected]> > > To: [email protected] > > Sent: Saturday, 9 November 2013, 14:04 > > Subject: Re: OWB on Tomcat 7 > > > > Now web.xml contain only > > <web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" > > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > > xsi:schemaLocation="http://java.sun.com/xml/ns/javaee > > http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"> > > <display-name>Archetype Created Web Application</display-name> > > </web-app> > > > > Ans that exception is still thrown. > > > > Here is lines from WebContainerLifecycle.java: > > 124:ELAdaptor elAdaptor = > > getWebBeansContext().getService(ELAdaptor.class); > > 125:ELResolver resolver = elAdaptor.getOwbELResolver(); NPE is > > being thrown on elAdaptor.getOwbELResolver(); , but why? > > ELAdaptor.class is in openwebbeans-spi-1.2.0.jar which is placed under > > lib in tomcat. I don't know what to do with all of this. > > > > 2013/11/9 Romain Manni-Bucau <[email protected]> > > > > Hmm > > Here im not sure but maybe remove it from your web.xml Le 9 nov. 2013 > > 13:52, "aljesco" <[email protected]> a écrit : > > > > > > Nov 09, 2013 2:49:31 PM org.apache.catalina.core.StandardContext > > listenerStart > > SEVERE: Exception sending context initialized event to listener > > instance of class > > org.apache.webbeans.servlet.WebBeansConfigurationListener > > java.lang.NullPointerException > > at > > org.apache.webbeans.web.lifecycle.WebContainerLifecycle.afterStartAppl > > ication(WebContainerLifecycle.java:125) > > at > > org.apache.webbeans.lifecycle.AbstractLifeCycle.startApplication(Abstr > > actLifeCycle.java:132) > > at > > org.apache.webbeans.web.lifecycle.WebContainerLifecycle.startApplicati > > on(WebContainerLifecycle.java:89) > > at > > org.apache.webbeans.servlet.WebBeansConfigurationListener.contextIniti > > alized(WebBeansConfigurationListener.java:85) > > at > > org.apache.catalina.core.StandardContext.listenerStart(StandardContext > > .java:4939) > > at > > org.apache.catalina.core.StandardContext.startInternal(StandardContext > > .java:5434) at > > org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) > > at > > org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase. > > java:901) at > > org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877 > > ) at > > org.apache.catalina.core.StandardHost.addChild(StandardHost.java:633) > > at > > org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java > > :1120) > > at > > org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig. > > java:1678) at > > java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471 > > ) at java.util.concurrent.FutureTask.run(FutureTask.java:262) > > at > > java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.j > > ava:1145) > > at > > java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor. > > java:615) at java.lang.Thread.run(Thread.java:744) > > > > > > 2013/11/9 Romain Manni-Bucau <[email protected]> > > > > So remove openwebbeans jar from the webapp to put them in tomcat libs > > Le 9 nov. 2013 13:43, "aljesco" <[email protected]> a écrit : > > > > > > Yes > > > > 2013/11/9 Romain Manni-Bucau <[email protected]> > > > > You kept owb in web-inf/lib? > > Le 9 nov. 2013 13:22, "aljesco" <[email protected]> a écrit : > > > > > > I added > > <Listener > > className="org.apache.webbeans.web.tomcat.ContextLifecycleListener" > /> > > into server.xml files. > > After that Tomcat throwed several ClassNotFoundExceptions because it > > couldn't find OWB libs. I put openwebbeans-impl-1.2.0.jar, > > openwebbeans-spi-1.2.0.jar, openwebbeans-tomcat7-1.2.0.jar and > > openwebbeans-web-1.2.0.jar into lib folder. Now Tomcat fails to start > > with exception ==== Caused by: java.lang.RuntimeException: > > java.lang.ClassCastException: Cannot cast > > org.apache.webbeans.service.DefaultLoaderService to > > org.apache.webbeans.spi.LoaderService > > at > > > org.apache.webbeans.web.tomcat.ContextLifecycleListener.containerEvent > > (ContextLifecycleListener.java:200) > > at > > org.apache.catalina.core.ContainerBase.fireContainerEvent(ContainerBas > > e.java:1398) > > at > > org.apache.catalina.core.StandardContext.listenerStart(StandardContext > > .java:4944) > > at > > org.apache.catalina.core.StandardContext.startInternal(StandardContext > > .java:5434) at > > org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) > > ... 10 more > > Caused by: java.lang.ClassCastException: Cannot cast > > org.apache.webbeans.service.DefaultLoaderService to > > org.apache.webbeans.spi.LoaderService > > at java.lang.Class.cast(Class.java:3094) > > at > > > org.apache.webbeans.config.WebBeansContext.<init>(WebBeansContext.ja > va > > :121) > > at > > > org.apache.webbeans.config.WebBeansContext.<init>(WebBeansContext.ja > va > > :98) > > at > > org.apache.webbeans.corespi.DefaultSingletonService.get(DefaultSinglet > > onService.java:54) > > at > > org.apache.webbeans.corespi.DefaultSingletonService.get(DefaultSinglet > > onService.java:28) > > at > > > org.apache.webbeans.config.WebBeansFinder.getSingletonInstance(WebBe > an > > sFinder.java:51) > > at > > > org.apache.webbeans.config.WebBeansContext.getInstance(WebBeansCon > text > > .java:164) > > at > > > org.apache.webbeans.config.WebBeansContext.currentInstance(WebBeans > Con > > text.java:182) at > > org.apache.webbeans.web.tomcat.TomcatUtil.inject(TomcatUtil.java:38) > > at > > > org.apache.webbeans.web.tomcat.ContextLifecycleListener.containerEvent > > (ContextLifecycleListener.java:182) > > ... 14 more > > ==== > > What I'm doing wrong? > > > > 2013/11/9 Romain Manni-Bucau <[email protected]> > > > > this one as tomcat listener > > https://github.com/apache/openwebbeans/blob/trunk/webbeans- > tomcat7/src > > > /main/java/org/apache/webbeans/web/tomcat/ContextLifecycleListener.ja > v > > a Le 9 nov. 2013 12:36, "aljesco" <[email protected]> a écrit : > > > > > > No, I didn't set it. What class should I set up as a listener? > > > > Do I need this lines in web.xml? > > > > <listener> > > > > <listener- > class>org.apache.webbeans.servlet.WebBeansConfigurationListener</listen > er-class> > > </listener> > > <resource-env-ref> > > <resource-env-ref-name>BeanManager</resource-env-ref-name> > > <resource-env-ref-type>javax.enterprise.inject.spi.BeanManager</resour > > ce-env-ref-type> > > </resource-env-ref> > > > > 2013/11/9 Romain Manni-Bucau <[email protected]> > > > > Hi > > Api jars are geronimo*spec ones (jcdi and atinject IIRC) In tomcat you > > need tomcat owb listener to get servlet injection, did you set it? > > Le 9 nov. 2013 12:13, "aljesco" <[email protected]> a écrit : > > > > > > Hello everyone, > > > > I've tried to get OWB working for about several hours on Tomcat 7 and > > afterall I got really confused. > > I'd be very thankful if someone can clarify some points with OWB. > > > > So, I'm developing a test project with just one servlet > > > > ==== > > @WebServlet(urlPatterns="/test") > > public class extends HttpServlet { > > > > private @Inject MyService s; > > @Override > > protected void doGet(HttpServletRequest req, HttpServletResponse resp) > > throws ServletException, IOException { > > > > WebBeansContext currentInstance = WebBeansContext.currentInstance(); > > MyService s2 = currentInstance.get(MyService.class); > > resp.getWriter().println(s); > > resp.getWriter().println("s2: " + s2.getHash()); } } ==== > > > > it tries get injected MyService instance which is POJO: > > > > ==== > > public class MyService { > > public MyService() { > > } > > public String getHash() { > > return new Random().nextInt() + ""; > > } > > } > > ==== > > > > here is WEB-INF/web.xml: > > > > ==== > > <web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" > > xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > > xsi:schemaLocation="http://java.sun.com/xml/ns/javaee > > http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"> > > <display-name>Archetype Created Web Application</display-name> > > <listener> > > > > <listener- > class>org.apache.webbeans.servlet.WebBeansConfigurationListener</listen > er-class> > > </listener> > > <resource-env-ref> > > <resource-env-ref-name>BeanManager</resource-env-ref-name> > > <resource-env-ref-type>javax.enterprise.inject.spi.BeanManager</resour > > ce-env-ref-type> > > </resource-env-ref> > > </web-app> > > ==== > > > > libs in WEB-INF/libs: > > > > openwebbeans-ee-common-1.2.0.jar > > openwebbeans-el22-1.2.0.jar > > openwebbeans-impl-1.2.0.jar > > openwebbeans-resource-1.2.0.jar > > openwebbeans-spi-1.2.0.jar > > openwebbeans-tomcat7-1.2.0.jar > > openwebbeans-web-1.2.0.jar > > xbean-asm-shaded-3.13.jar > > xbean-finder-shaded-3.13.jar > > > > The first question is about CDI implementation library. > > If I try to deploy webapp as it is, the Tomcat will fail with next > > exception: java.lang.NoClassDefFoundError: > > javax/enterprise/context/spi/Contextual > > I couldn't find OWB library which provides such class. I only grabbed > > javaee-api-6.0-5-tomcat.jar from TomEE and placed in under Tomcat 7 > > lib/ folder. > > What is a proper way to solve this problem? Where should I get > > javax.enterprise.context.* library? > > > > The second question is about CDI itself. > > After successful deploying (with javaee-api-6.0-5-tomcat.jar in lib/) > > I accessed my servlet by http://localhost:8080/testproject/test and > > got this > > responce: > > ==== > > > > null > > > > s2: 1064451662 > > > > ==== > > > > Why WebBeansContext.currentInstance().get(MyService.class) returns a > > proper instance of MyService class and fails to inject it into private > > @Inject MyService s? > > > > > > > > > > > > > > > > > > > > > > > > > > > > > >
