4 Replies Latest reply on Sep 28, 2017 4:33 PM by Srinivas Vittal

    We are attempting to expose our existing JavaEE SessionBeans as a REST interface and encountering some trouble. Most examples encourage us to put our EJBs into the REST .war but we want to retain the JavaEE functionalities and have them deployed as Sessio

    Srinivas Vittal Newbie

      We are attempting to expose our existing JavaEE SessionBeans as a REST interface and encountering some trouble. Most examples encourage us to put our EJBs into the REST .war but we want to retain the JavaEE functionalities and have them deployed as SessionBean, which I believe means they have to stay in the root of the EAR.

       

      Unable to connect to local Interface of the SessionBean for exposing EJB’s as a REST service using RESTEasy and Wildly 11

       

      I am able to invoke the ExampleSessionLocal interface with a JNDI lookup for the same in a custom class. This is okay. But I do not want this as I would have to add classes and would make the code base bigger. All the solutions I read are close but do not quite answer all of it. Is there a definitive way to add all of this into the local interface? Any help is appreciated. Please find the code below.

       

      Code:

       

      1. ExampleSessionBean.java

       

        @Stateless(name = “ExampleSession”)

        @Remote(ExampleSessionRemote.class)

        @Local(ExampleSessionLocal.class)

        @TransactionManagement(TransactionManagementType.CONTAINER)

        @TransactionAttribute(TransactionAttributeType.REQUIRED)

        public class ExampleSessionBean extends ParentExampleBean implements ExampleExternalBI{

       

        }

       

      2.   ExampleSessionLocal.java

       

        @Local

        @Path(“/api”)

        public interface ExampleSessionLocal extends ParentExampleSessionLocal, ExampleExternalBI, RLocalSession

                  {

       

        @GET

          @Path("/examples")

          @Produces("application/json")

          @Override

          List<ExampleDTO> getExampleData() throws ParentExampleException;

        }

       

      3.  ExampleExternalBI.java

       

        public interface ExampleExternalBI extends BusinessInterface, ParentExampleBI

        {

        List<ExampleDTO> getExampleData()

                  throws ParentExampleException;

        }

       

       

      4.  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">

       

          <!-- Auto scan REST service -->

          <context-param>

              <param-name>resteasy.jndi.resources</param-name>

              <param-value>ExampleSessionBean/local</param-value>

          </context-param>

       

       

          <listener>

              <listener-class>

                  org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap

              </listener-class>

          </listener>

       

          <servlet>

              <servlet-name>Resteasy</servlet-name>

              <servlet-class>

                  org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher

              </servlet-class>

          </servlet>

       

          <servlet-mapping>

              <servlet-name>Resteasy</servlet-name>

              <url-pattern>/*</url-pattern>

          </servlet-mapping>

       

       

      </web-app>

        • 1. Re: We are attempting to expose our existing JavaEE SessionBeans as a REST interface and encountering some trouble. Most examples encourage us to put our EJBs into the REST .war but we want to retain the JavaEE functionalities and have them deployed as Se
          jaikiran pai Master

          In its current form, it's very difficult to understand what you are asking. To make it easier, please paste the exact exception stacktrace that you are seeing and the snippet of the code where you are doing the lookup and invocation on the bean. Also which exact version of WildFly 11 is this?

          • 2. Re: We are attempting to expose our existing JavaEE SessionBeans as a REST interface and encountering some trouble. Most examples encourage us to put our EJBs into the REST .war but we want to retain the JavaEE functionalities and have them deployed as Se
            Srinivas Vittal Newbie

            This is WildFly 11.0.0. I need to know the exact way to expose the Beans as REST services. If I just mark the LocalInterface as @Local and try annotating the methods that this interface extends, pass in the path-param to look for the Local as mentioned above. I get a NameNotFoundException. I am pretty sure I am missing something very small. The code snippet looks exactly like the one I have given above. Please let me know if you need more info.

             

             

            2017-09-27 16:58:54,635 ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool -- 165) MSC000001: Failed to start service jboss.undertow.deployment.default-server.default-host./rest: org.jboss.msc.service.StartException in service jboss.undertow.deployment.default-server.default-host./rest: java.lang.RuntimeException: java.lang.RuntimeException: javax.naming.NameNotFoundException: McsToteSessionBean/local -- service jboss.naming.context.java.McsToteSessionBean.local

                    at org.wildfly.extension.undertow.deployment.UndertowDeploymentService$1.run(UndertowDeploymentService.java:84)

                    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)

                    at java.util.concurrent.FutureTask.run(FutureTask.java:266)

                    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)

                    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)

                    at java.lang.Thread.run(Thread.java:748)

                    at org.jboss.threads.JBossThread.run(JBossThread.java:320)

            Caused by: java.lang.RuntimeException: java.lang.RuntimeException: javax.naming.NameNotFoundException: McsToteSessionBean/local -- service jboss.naming.context.java.McsToteSessionBean.local

                    at io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:241)

                    at org.wildfly.extension.undertow.deployment.UndertowDeploymentService.startContext(UndertowDeploymentService.java:99)

                    at org.wildfly.extension.undertow.deployment.UndertowDeploymentService$1.run(UndertowDeploymentService.java:81)

                    ... 6 more

            Caused by: java.lang.RuntimeException: javax.naming.NameNotFoundException: McsToteSessionBean/local -- service jboss.naming.context.java.McsToteSessionBean.local

                    at org.jboss.resteasy.plugins.server.resourcefactory.JndiResourceFactory.getScannableClass(JndiResourceFactory.java:62)

                    at org.jboss.resteasy.core.ResourceMethodRegistry.addResourceFactory(ResourceMethodRegistry.java:172)

                    at org.jboss.resteasy.core.ResourceMethodRegistry.addResourceFactory(ResourceMethodRegistry.java:160)

                    at org.jboss.resteasy.core.ResourceMethodRegistry.addJndiResource(ResourceMethodRegistry.java:127)

                    at org.jboss.resteasy.spi.ResteasyDeployment.registration(ResteasyDeployment.java:428)

                    at org.jboss.resteasy.spi.ResteasyDeployment.start(ResteasyDeployment.java:258)

                    at org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap.contextInitialized(ResteasyBootstrap.java:28)

                    at io.undertow.servlet.core.ApplicationListeners.contextInitialized(ApplicationListeners.java:187)

                    at io.undertow.servlet.core.DeploymentManagerImpl$1.call(DeploymentManagerImpl.java:205)

                    at io.undertow.servlet.core.DeploymentManagerImpl$1.call(DeploymentManagerImpl.java:174)

                    at io.undertow.servlet.core.ServletRequestContextThreadSetupAction$1.call(ServletRequestContextThreadSetupAction.java:42)

                    at io.undertow.servlet.core.ContextClassLoaderSetupAction$1.call(ContextClassLoaderSetupAction.java:43)

                    at org.wildfly.extension.undertow.security.SecurityContextThreadSetupAction.lambda$create$0(SecurityContextThreadSetupAction.java:105)

                    at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1508)

                    at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1508)

                    at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1508)

                    at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1508)

                    at org.wildfly.extension.undertow.deployment.UndertowDeploymentInfoService$UndertowThreadSetupAction.lambda$create$0(UndertowDeploymentInfoService.java:1508)

                    at io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:239)

                    ... 8 more

            Caused by: javax.naming.NameNotFoundException: McsToteSessionBean/local -- service jboss.naming.context.java.McsToteSessionBean.local

                    at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:106)

                    at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:207)

                    at org.jboss.as.naming.InitialContext$DefaultInitialContext.lookup(InitialContext.java:237)

                    at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:193)

                    at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:189)

                    at javax.naming.InitialContext.lookup(InitialContext.java:417)

                    at javax.naming.InitialContext.lookup(InitialContext.java:417)

                    at org.jboss.resteasy.plugins.server.resourcefactory.JndiResourceFactory.getScannableClass(JndiResourceFactory.java:57)

            • 3. Re: We are attempting to expose our existing JavaEE SessionBeans as a REST interface and encountering some trouble. Most examples encourage us to put our EJBs into the REST .war but we want to retain the JavaEE functionalities and have them deployed as Se
              Carl Walker Newbie

              Hi,

               

              I separate the EJB from the RESTful service so that the EJB can be used in other contexts like scheduled jobs and in other EJBs.  So, I'd break this apart so that you have the following classes

               

              ExampleResource.java packed in example-rs.war

               

              @Path("/example") 
              class ExampleResource {   
                @EJB   private Example exampleEJB;
                 ...

               

              Example.java packed in example-ejb.jar

              interface Example {
              ...

               

              ExampleBean.java packaged in example-ejb.jar

              @Stateless 
              class ExampleBean implements Example {
              ...

              Put example-ejb.jar and example-rs.war in an example-ear.ear file with the modules defined in the application.xml

              • 4. Re: We are attempting to expose our existing JavaEE SessionBeans as a REST interface and encountering some trouble. Most examples encourage us to put our EJBs into the REST .war but we want to retain the JavaEE functionalities and have them deployed as Se
                Srinivas Vittal Newbie

                I have mentioned this in my initial post that I took this approach and it works fine. But I want to integrate it without having extra classes as this would increase the code base and increases the maintenance burden of doing so. Please let me know if there is any way to do it. If there is none I would stick to this approach I already have. Thank you for the help.