5 Replies Latest reply on Nov 27, 2019 1:09 PM by kevindougan7

    JBoss 6 EAP - Can I Access a Deployed EJB From Within A Log4J Handler Module?

    kevindougan7

      Hello community!

       

      I have a custom Log4J Handler deployed under the JBoss "modules" directly and configured to watch for a specific type of log message.

      Once this custom Handler receives the log messages in the deployed handler JAR, I want to call an EJB that is deployed as a JAR found under the "deployments" folder and in a different context.

      I have found that the classloader and context of the module seems to be isolated from the deployments, so it appears to be impossible...

       

      Is there any way that I can lookup a deployment's EJB's and call an existing one from the "module" custom Handler code?

       

      Thanks!

      Kevin

        • 1. Re: JBoss 6 EAP - Can I Access a Deployed EJB From Within A Log4J Handler Module?
          kevindougan7

          I attempted to resolve this by adding a dependency to the module.xml file, in this way:

          <module xmlns="urn:jboss:module:1.0" name="com.mycompany.logging.handler">

              <resources>

                  <resource-root path="com.mycompany.logging.handler.jar"/>

              </resources>

              <dependencies>

                  <module name="deployment.myapplication.ear.com.mycompany.ejbs.jar"/>

                  <module name="org.jboss.logging"/>

                  <module name="org.slf4j" />

          </dependencies>

          </module>


          However, the Server refused to start when this "deployment" entry was processed!

          • 2. Re: JBoss 6 EAP - Can I Access a Deployed EJB From Within A Log4J Handler Module?
            jewellgm

            You could deploy the jar containing the remote interface as a module, and then have your log handler do a "manual" lookup of the remote EJB.  Both your log handler module, and the ear, would need to depend on the new module containing the remote interface.  Otherwise, when the log handler does the lookup, you'd get a ClassCastException.

            • 3. Re: JBoss 6 EAP - Can I Access a Deployed EJB From Within A Log4J Handler Module?
              kevindougan7

              Thanks for your suggestion, Greg!

               

              I think that the fundamental problem I am running into is that there is no way to have any "JBoss Module" (even if it contains a Remote EJB Interface) have a dependency on a deployed Application JAR/EJB. The Modules have their own isolated classloader, so instantiating a class instance from within that context does not refer to use the deployed application JARs at all. I actually was able to force the container to instantiate a Proxy for my EJB, but when I attempted to invoke the actual method I want, it threw an Exception because it couldn't actually resolve the remote dependency at runtime.

              • 4. Re: JBoss 6 EAP - Can I Access a Deployed EJB From Within A Log4J Handler Module?
                jewellgm

                I haven't personally done this, and maybe I'm not understanding what you are saying, but it seems like it should work.  If you deploy the interface as a jboss module (in the wildfly/modules area), then you would only be dependent on the interface.  The Java EE spec says that everything in the remote interface has to be Serializable.  You invoke a method on the interface, which goes through the proxy and serializes it to send it to the deployed application.  The log handler module would have no need for the actual implementing class (EJB) to be on its classloader, just like any non-JavaEE client.

                • 5. Re: JBoss 6 EAP - Can I Access a Deployed EJB From Within A Log4J Handler Module?
                  kevindougan7

                  I could not get any EJB lookups to work from within the Module code.

                  Nothing I read anywhere seems to indicate that this is possible.

                   

                  As a workaround, I am instead creating the reverse relationship by having an EJB (deployed within an EAR in the "deployments" folder) invoke a "register" method on a global JBoss Module and pass "this" to it, so the Module can later use the "this" reference to call out to that EJB and invoke Interface-defined methods on it.