Stripes framework and EJB3

January 21st, 2008 by Samuel Santos Leave a reply »

Inspired by the Spring with Stripes integration I made a new one named EJB3 with Stripes.

This extension allows you to inject your EJB beans into your Action beans.

Please fell free to use it, and to visit the Stripes and EJB3 project at Google Code.

Don't be shellfish...Tweet about this on TwitterShare on FacebookShare on Google+Share on LinkedInPin on PinterestBuffer this pageEmail this to someone
Advertisement

18 comments

  1. kabel says:

    Hello,
    I tried to use the EJB Interceptor according to your article, but without success :( I’ve got an EJB modul with some entities and SessionBeans for these entities. Next I’ve got web application which uses stripes. But always I use annotation in my ActionBean, e.g.:

    @EJBBean(“PersonFacade”)
    private PersonFacade personFacade;

    I’m still getting an exception that it can’t find this EJBBean.
    Does it depend on any application server?

  2. The only server I tested with was JBoss AS.

    Sorry to ask, but have you confirmed that your bean is binded with the JNDI name “PersonFacade”?

    I usually rely on the annotation @LocalBinding for the JNDI binding. e.g.
    @LocalBinding(jndiBinding = “PersonFacade”)
    public class PersonFacade { … }

  3. Krzysztof says:

    Hello All,

    It doesn’t work for me either:( I’ve tried EJB Interceptor running on the jboss-4.2.2.GA and even on jboss-5.0.0.Beta4 (the latest one). I’ve got EJB (ear) application with web module and jar module. Same story as kabel described… can’t find this EJBBean.
    I’m sure that my beans are loaded by the Jboss server but I’m not under what names they are available.

    Samuel, could you tell me which exact version of the Jboss AS you were using.
    Did you add any additinal jar’s to the lib?
    In which jboss jar the @LocalBinding annotation is provided? I couldn’t find it.

    Thanks in advance!

    I wish you Happy Easter.

    Regards,
    Krzysztof

  4. org.jboss.annotation.ejb.LocalBinding class can be found in jboss-annotations-ejb3.jar that is in the \jboss-4.2.2.GA\server\default\deploy\ejb3.deployer folder.

    If you don’t use this annotation, JBoss will define the JNDI bindings for you.
    You can look at your server.log to check the JNDI bindings that were defined.

  5. Krzysztof says:

    Hi Samuel,

    I’ve tried to run it again on jboss-4.2.2.GA with @LocalBinding annotation…. and it worked!

    I’ve realized that it doesn’t work on the latest jboss-5.0.0.Beta4 even with @LocalBinding feature. You have to pass full jndi name: ear-app-name/YourBeanName/local (or remote) into @EJBBean.

    Regards,
    Krzysztof

  6. Hi Krzysztof,

    Thanks for the info.
    JBoss 5.x is yet too buggy.

    Cheers

  7. Hugo says:

    Hi Samuel,

    Thanks for your code, but i’m having a problem.
    The EJBInterceptor that I include in my package and that is deployed inside WEB-INF/classes of a WAR is crushing during deploy in JBoss 4.2.2 with Java 5. I’ve tried to compile with Java 6 and I get the same error. Could you help me?

    2008-06-25 17:55:46,722 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/adssimplex]] Exception starting filter StripesFilter
    java.lang.ClassFormatError: Invalid constant pool index 63 in class file pt/ptinovacao/adssimplex/util/EJBInterceptor
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
    at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:1814)
    at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:872)
    at org.jboss.web.tomcat.service.WebAppClassLoader.findClass(WebAppClassLoader.java:139)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1325)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1204)

  8. Hi Hugo,

    Can you please send me the complete stack trace by mail?

  9. simpatico says:

    I’ve been hardly trying to use stripejb3 plugin with stripes without success. I use JBoss 4.2.2 GA with JDK 1.6. Following your advices I use JBoss annotations @LocalBinding. Sadly Action Bean properties annotated with @EJBBean don’t work correctly. Stripejb3 plugin cannot invoke setter method because of invalid method arguments.
    The strange thing is, that I can see my binded local interfaces in JNDI view under configured names. I can lookup them in ActionBean by hand and get their proxies but I cannot cast them to the proper business interfaces because of class cast exception.

    Can anyone provide some example pom.xml for the web project to show me, what dependencies to use? Can anyone give some other helpful advice?

    Thanks.

    • If you can’t cast them to your business interfaces this has nothing to do neither with Stripes EJB3 Interceptor nor with Stripes framework.
      You should probably check your session bean definition.

      The only dependency you need in your pom in order to use the Stripes EJB3 Interceptor is the following:

      <dependency>
          <groupId>com.samaxes.stripejb3</groupId>
          <artifactId>stripejb3</artifactId>
          <version>1.0.1</version>
      </dependency>
      
  10. simpatico says:

    Thanks for reply Samuel.

    I checked once again my session bean definition and I don’t see anything wrong in there. It goes as folows:
    /* My business interface */
    public interface TestPlanning {

    }

    /* My business interface implementation */
    @Stateless
    @Local(TestPlanning.class)
    @LocalBinding(jndiBinding = “testPlanning”)
    public class TestPlanningService implements TestPlanning {

    }

    /* My action bean */
    @UrlBinding(“/testing/prepareTest.action”)
    public class PrepareTestActionBean extends SkillTestGenericActionBean {

    @EJBBean(“testPlanning”)
    protected TestPlanning testPlanning;

    public PrepareTestActionBean() {
    super();
    }

    @EJBBean(“testPlanning”)
    public void setTestPlanning(TestPlanning testPlanning) {
    this.testPlanning = testPlanning;
    }

    }

    I’ve dig through tons of posts since last week but have not found solution. I’ve also downloaded your sources and checked step by step to find out what’s going on. In line 121 of EJBInterceptor when invoking method setTestPlanning(pl.itkontrakt.skilltest.core.api.TestPlanning) on action bean the looked up TestPlanning proxy appears to be an invalid type argument for this call. It looks like this proxy doesn’t implement pl.itkontrakt.skilltest.core.api.TestPlanning interface though JBoss JNDI view tells that it does.

    Please help me if you can.

    Here is my stacktrace:

    10:13:05,838 ERROR [STDERR] net.sourceforge.stripes.exception.StripesRuntimeException: Exception while trying to lookup and inject an EJB bean into a bean of type PrepareTestActionBean using method public void pl.itkontrakt.skilltest.web.actions.testing.PrepareTestActionBean.setTestPlanning(pl.itkontrakt.skilltest.core.api.TestPlanning)
    10:13:05,839 ERROR [STDERR] at com.samaxes.stripejb3.EJBInterceptor.intercept(EJBInterceptor.java:123)
    10:13:05,839 ERROR [STDERR] at net.sourceforge.stripes.controller.ExecutionContext.proceed(ExecutionContext.java:155)
    10:13:05,839 ERROR [STDERR] at net.sourceforge.stripes.controller.BeforeAfterMethodInterceptor.intercept(BeforeAfterMethodInterceptor.java:113)
    10:13:05,839 ERROR [STDERR] at net.sourceforge.stripes.controller.ExecutionContext.proceed(ExecutionContext.java:155)
    10:13:05,840 ERROR [STDERR] at net.sourceforge.stripes.controller.ExecutionContext.wrap(ExecutionContext.java:74)
    10:13:05,840 ERROR [STDERR] at net.sourceforge.stripes.controller.DispatcherHelper.resolveActionBean(DispatcherHelper.java:102)
    10:13:05,840 ERROR [STDERR] at net.sourceforge.stripes.controller.DispatcherServlet.resolveActionBean(DispatcherServlet.java:238)
    10:13:05,840 ERROR [STDERR] at net.sourceforge.stripes.controller.DispatcherServlet.service(DispatcherServlet.java:141)
    10:13:05,840 ERROR [STDERR] at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    10:13:05,840 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    10:13:05,840 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    10:13:05,840 ERROR [STDERR] at net.sourceforge.stripes.controller.StripesFilter.doFilter(StripesFilter.java:247)
    10:13:05,841 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    10:13:05,841 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    10:13:05,841 ERROR [STDERR] at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
    10:13:05,841 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
    10:13:05,841 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    10:13:05,841 ERROR [STDERR] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
    10:13:05,841 ERROR [STDERR] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
    10:13:05,841 ERROR [STDERR] at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
    10:13:05,841 ERROR [STDERR] at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:524)
    10:13:05,841 ERROR [STDERR] at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
    10:13:05,842 ERROR [STDERR] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    10:13:05,842 ERROR [STDERR] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    10:13:05,842 ERROR [STDERR] at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
    10:13:05,842 ERROR [STDERR] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    10:13:05,842 ERROR [STDERR] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
    10:13:05,842 ERROR [STDERR] at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
    10:13:05,842 ERROR [STDERR] at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
    10:13:05,842 ERROR [STDERR] at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
    10:13:05,842 ERROR [STDERR] at java.lang.Thread.run(Thread.java:619)
    10:13:05,843 ERROR [STDERR] Caused by: java.lang.IllegalArgumentException: argument type mismatch
    10:13:05,843 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    10:13:05,843 ERROR [STDERR] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    10:13:05,843 ERROR [STDERR] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    10:13:05,843 ERROR [STDERR] at java.lang.reflect.Method.invoke(Method.java:597)
    10:13:05,843 ERROR [STDERR] at com.samaxes.stripejb3.EJBInterceptor.intercept(EJBInterceptor.java:121)

  11. It seems fine to me, except that you are injecting your bean twice.

    Try to remove one of the @EJBBean("testPlanning") annotations.

  12. simpatico says:

    It is still not working.

    Anyway, thanks for your help, Samuel.

    Greets

    • Can you check the JNDI binding name of your bean in the jmx-console and see if it matches “testPlanning”?
      And what version of JBoss are you using?
      The last time I checked JBoss 5 (I think it was 5.0 beta2) the annotation @LocalBinding did not work.

  13. simpatico says:

    I use JBoss 4.2.2 GA.
    I can see something like that in my JNDI view:


    +-testPlanning (proxy: $Proxy286 implements interface pl.itkontrakt.skilltest.core.api.TestPlanning,interface org.jboss.ejb3.JBossProxy)

    My web project .pom dependencies are:

    ${pom.parent.groupId}
    ${pom.parent.artifactId}-ejb
    ${pom.parent.version}

    net.sourceforge.stripes
    stripes
    1.5.1

    com.samaxes.stripejb3
    stripejb3
    1.0.1

    javax.servlet
    jstl
    1.2

    javax.servlet
    servlet-api
    2.4

    • It looks all fine to me.
      Can you try one last test?
      Try it with Stripes 1.5; I’ve never tested the interceptor with Stripes 1.5.1 because we use a lot of AJAX and that version of Stripes has a bug.

  14. simpatico says:

    Sure.

    I’ve built another app from scratch. One EJB, one Stripes bean, one jsp. All with maven.
    It’s 100% not about Stripes or stripejb3. It’s something about JBoss.

    This time I did not use JBoss annotations. My local is bound under stripestest/SomeInterfaceImpl/local.

    I’ve got one handler in Stripes action going like that:

    @DefaultHandler
    public Resolution start() {
    ForwardResolution resolution = new ForwardResolution(“/jsp/start.jsp”);

    try {
    javax.naming.InitialContext ctx = new javax.naming.InitialContext();

    Object o = ctx.lookup(“stripestest/SomeInterfaceImpl/local”);
    SomeInterface s = (SomeInterface) o;

    } catch (Exception e) {
    System.out.println(“exception = ” + e.getMessage());
    }

    return resolution;
    }

    This lookup just doesn’t work. Same thing. Proxy cannot be cast to my business interface. If it doesn’t, stripejb3 will not.
    :(

    Thanks for your patience.
    Tomorrow I’ll continue my effort.

    Thanks a lot once again.

  15. simpatico says:

    Maybe somebody will find this usefull and save his time.
    The solution is here: http://www.jboss.org/index.html?module=bb&op=viewtopic&t=66651

    Stupid me.

Leave a Reply