2 Replies Latest reply on Feb 3, 2014 11:37 AM by ryanrutan

    Quick Question Regarding Jetty 9.1 + Weld 2.1.x Initialization

    ryanrutan

      Just getting into Weld (a bit late to the party, as I've been working for in node.js due to work), but I am running a project that is using Maven + JEE 6 + Jetty 9.1 + Jersey 2.5.1 and I would like to try throw in Weld to get support for CDI-API... specifically the Events Observer/Inject capabilities for messaging.

       

      Here's the problem, I have been running through issue after issue getting things setup.  One issue is the HK2 injection scheme in Jersey, which I might have found a work around for (http://stackoverflow.com/questions/17224270/how-to-enable-cdi-inject-in-web-service-jaxrs-jersey-on-java-se-running-griz…) but not confirmed, but the other one is getting Jersey to get setup with the Weld BeanMapper using the Jersey Maven Plugin.

       

      I'm building a toolkit right now that is almost done, that I would like people to be able to simply spin up locally with jetty, but then deploy the WAR to Tomcat or something more Enterprise"y" when its ready for uat etc..

       

      My questions:

      • in your opinions is Weld 2.1.2.FINAL + Jersey 9.1 a good permutation of these two?   If not, what permutations are the most stable?  (I need to use Jersey 2.5.1 with it, and would prefer to keep Servlet 3.0 annotations.)
      • I'm running into an odd issue with my jetty-env.xml.

      2014-02-01 22:05:51.923:WARN:oejx.XmlConfiguration:main: Config error at <Call class="org.jboss.weld.environment.jetty.WeldDecorator" name="process"><Arg>|            <Ref id="webAppCtx"/>|        </Arg></Call> java.lang.IllegalStateException: No Method: <Call class="org.jboss.weld.environment.jetty.WeldDecorator" name="process"><Arg>

                  <Ref id="webAppCtx"/>

              </Arg></Call> on class org.jboss.weld.environment.jetty.WeldDecorator in file:/Developer/_workspace/addon/jive-sdk-java-jersey/src/main/webapp/WEB-INF/jetty-web.xml

      2014-02-01 22:05:51.923:WARN:oejw.WebAppContext:main: Failed startup of context o.e.j.m.p.JettyWebAppContext@3d2b92fd

      java.lang.IllegalStateException: No Method: <Call class="org.jboss.weld.environment.jetty.WeldDecorator" name="process"><Arg>|            <Ref id="webAppCtx"/>|        </Arg></Call> on class org.jboss.weld.environment.jetty.WeldDecorator

        at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfiguration.call(XmlConfiguration.java:738)

        at org.eclipse.jetty.xml.XmlConfiguration$JettyXmlConfigur

      • From what I can tell about this, the config file is telling Jetty to find org.jboss.weld.environment.jetty.WeldDecorator and inject webAppCtx into the static process method.  From a quick look at the Weld sources, I see that WeldDecorator.process is in fact public and static.  Note:  This class in the XML used to be a Weld...Handler of sorts, but that class looks to have been refactored.

       

      Any help someone could give me about finding the right permutation of library versions for the best possible chance at success, as well as helping me understand the issues with the "NoSuchMethod" issue above, it would be greatly appreciated.  Excited to give this extension a good kick in the tires, but having a rough time getting started =\

       

      Thanks in advance,

      RR

        • 1. Re: Quick Question Regarding Jetty 9.1 + Weld 2.1.x Initialization
          mkouba

          Hi Ryan,

          Jetty 9.1.x and Weld 2.1.2 should work fine. However we don't have any soak tests for Jetty containers and I'm not aware of any stability reports. What does your jetty-env.xml look like? I don't think anything like <Call class="org.jboss.weld.environment.jetty.WeldDecorator" name="process"> is needed for Weld 2+.

          • 2. Re: Re: Quick Question Regarding Jetty 9.1 + Weld 2.1.x Initialization
            ryanrutan

            So based on the research and looking around, these are the following files I have configured.

             

            I found either a fix/workaround, by adding this my pom.xml"

                    <dependency>
                        <groupId>org.eclipse.jetty</groupId>
                        <artifactId>jetty-server</artifactId>
                        <version>${jetty-version}</version>
                        <scope>jetty</scope>
                    </dependency>
            

             

            At least my service is running now, having some problems with getting @Inject to work for the my Jersey services, but I think that might just be me getting ramped up. Any pointers appreciated. =)

             

            For others who might be trying to do the same thing, I've attached a version of my POM file to may give you a leg up (at least to where I am at this point).

             

            WEB-INF/beans.xml

            <beans 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/beans_1_0.xsd">
            </beans>
            

             

            WEB-INF/jetty-context.xml

            <!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
            <Configure class="org.eclipse.jetty.webapp.WebAppContext">
                <Call name="prependServerClass">
                    <Arg>-org.eclipse.jetty.servlet.</Arg>
                </Call>
            </Configure>
            

             

            WEB-INF/jetty-env.xml

            <!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
            <Configure id="webAppCtx" class="org.eclipse.jetty.webapp.WebAppContext">
                <New id="BeanManager" class="org.eclipse.jetty.plus.jndi.Resource">
                    <Arg>
                        <Ref id="webAppCtx"/>
                    </Arg>
                    <Arg>BeanManager</Arg>
                    <Arg>
                        <New class="javax.naming.Reference">
                            <Arg>javax.enterprise.inject.spi.BeanManager</Arg>
                            <Arg>org.jboss.weld.resources.ManagerObjectFactory</Arg>
                            <Arg/>
                        </New>
                    </Arg>
                </New>
            </Configure>
            

             

            WEB-INF/jetty-web.xml - Not Needed

            <?xml version="1.0"  encoding="ISO-8859-1"?>
            <!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
            <Configure id="webAppCtx" class="org.eclipse.jetty.webapp.WebAppContext">
                <Call class="org.jboss.weld.environment.jetty.WeldDecorator" name="process">
                    <Arg>
                        <Ref id="webAppCtx"/>
                    </Arg>
                </Call>
            </Configure>
            

             

            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">
                <listener>
                    <listener-class>org.jboss.weld.environment.servlet.Listener</listener-class>
                </listener>
                <resource-env-ref>
                    <resource-env-ref-name>BeanManager</resource-env-ref-name>
                    <resource-env-ref-type>javax.enterprise.inject.spi.BeanManager</resource-env-ref-type>
                </resource-env-ref>
            </web-app>