4 Replies Latest reply on Dec 13, 2016 3:57 PM by Ravi Soni

    lookup remote bean from JBoss AS 6.0.0.GA (ejb3) to Spring application (JBoss 7.1.1. Final)

    Vladimir Andreev Newbie

      Hello everyone!

       

      I faced with the problem listed below. I have two different JBoss (standalone) servers in my corporate intra-network. No problems with networks, firewalls, etc. It works good.

       

      1st - JBoss AS 7.1.1. Final

       

      this server contains a SpringMVC war application. MyTest.war

       

      my MVC class:

      WebControler.java

      @Controller
      public class WebController {
      
        String jndi = "myapplication/BusinessFormLBean/remote-com.mycompany.example.dao.BusinessFormRB";
        InitialContext context;
      
                BusinessFormRB businessFormRB;
      
              @RequestMapping(value = "/testing", method = RequestMethod.GET)
              public void testing() throws NamingException {
                   context = new InitialContext(getProperties());
                   businessFormRB = (BusinessFormRB) context.lookup(jndi);
                  System.out.println(businessFormRB);
             }
      
         private Properties getProperties() {
                  Properties props = new Properties();
                  props.put(context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
                  props.put(context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
                  props.put(context.PROVIDER_URL, "jnp://192.25.189.109:1099");
                  props.put("jboss.naming.client.ejb.context", true);
              return props;
        }
      }
      

       

      2st - JBoss AS 6.

      Contains some beans with local and remote interfaces:

       

      BusinessFormLB.java

      package com.mycompany.example.dao;
      
      import com.mycompany.example.entity.BusinessForm;
      
      import javax.ejb.Local;
      import java.util.List;
      
      @Local
      
      public interface BusinessFormLB {
      
        List<BusinessForm> findAllReplyType();
      }
      

      BusinessFormRB.java

      package com.mycompany.example.dao;
      
      import com.mycompany.example.entity.BusinessForm;
      
      import javax.ejb.Remote;
      import java.util.List;
      
      @Remote
      public interface BusinessFormRB {
        List<BusinessForm> findAllReplyType();
      }
      

      BusinessFormLBean.java

      package com.mycompany.example.dao;
      
      imports....
      
      @Stateless
      @Remote(BusinessFormRB.class)
      public class BusinessFormLBean implements BusinessFormLB, BusinessFormRB {
      
         @PersistenceContext(unitName = "exampleDBManager")
         protected EntityManager em;
      
         public void delete(Abbreviation src) {
         em.remove(src);
        }
      
         @Override
         public List<BusinessForm> findAllReplyType() {
        List<BusinessForm> result = null;
      .....
         return result;
        }
      }
      

      When I try to call a method testing() from WebController class, I got an error:

       

      exception
      org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.ClassCastException: javax.naming.Reference cannot be cast to com.mycompany.example.dao.BusinessFormRB org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:982) org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861) javax.servlet.http.HttpServlet.service(HttpServlet.java:734) org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846) javax.servlet.http.HttpServlet.service(HttpServlet.java:847) com.mycmopany.ef.example.backend.configuration.CorsFilter.doFilterInternal(CorsFilter.java:19) org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346) org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:262) 
      
      root cause
      java.lang.ClassCastException: javax.naming.Reference cannot be cast to com.mycompany.example.dao.BusinessFormRB com.mycmopany.ef.example.backend.controllers.WebController.testing(WebController.java:34) sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) java.lang.reflect.Method.invoke(Method.java:601) org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:220) org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:134) org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:116) org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827) org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738) org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963) org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897) org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970) org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861) javax.servlet.http.HttpServlet.service(HttpServlet.java:734) org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846) javax.servlet.http.HttpServlet.service(HttpServlet.java:847) ru.alfabank.ef.questionnarie.backend.configuration.CorsFilter.doFilterInternal(CorsFilter.java:19) org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346) org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:262) 
      

       

      Also I imported a jar file to my Spring project, that contains all remote interfaces from EJB project.

       

      What may be wrong???

       

      Thank you in advance!