title: EJB 2.1 throwing wrapped remote exception in cluster
body: <p>We're in the processing of moving a Weblogic 10.3.6 app to Weblogic 12.2.1.2. We have many EJB 2.1 beans that form part of the app.  We've hit a strange problem with some of these beans.</p>
  
  <p>When we have 1 ejb call another and this bean throws a checked exception (e.g. <code>RuleException extends Exception</code>) this is thrown as a <code>RemoteException</code> (<code>RemoteEJBInvokeException</code>).  This only occurs if the app is running in a cluster.  If I deploy against a standalone jvm it works fine.</p>
  
  <p>The general EJB pattern is a Facade pattern.  In the Facade bean we use a standard JNDI lookup to locate the Home and then run the create method to return the business interface/impl</p>
  
  <pre><code>InitialContext ctx = new InitialContext();
  ReportManagementHome reportManagementHome = (ReportManagementHome) ctx.lookup("ReportManagement");
  ReportManagement reportManagement = reportManagementHome.create();
  </code></pre>
  
  <p><code>ReportManagement</code> bean runs the business logic and throws a RuleException.</p>
  
  <p>This is an example method in the facade that calls the 2nd bean:</p>
  
  <pre><code>public String doTest() {
      String s = null;
      try
      {
        s = reportManagement.doValidate();
      }
      catch ( RuleException re )
      {
        rollBack();
      } catch (RemoteException e)
      {
        e.printStackTrace();
      }
  
      return s;
    }
  </code></pre>
  
  <p>Here is the <code>doValidate()</code> method in the 2nd bean:</p>
  
  <pre><code>public String doValidate( )
        throws RuleException, CustomException
    {
  
      int test = 1;
  
      if (test == 1)
      {
        throw new RuleException();
      }
  
      return "Hello";
  
    }
  </code></pre>
  
  <p>Although the <code>RuleException</code> is correctly reached and thrown, by the time the facade catches it it is a <code>RemoteException</code>.</p>
  
  <p>This is an example list of the ejbs/interfaces:</p>
  
  <pre><code>ReportManagement
  ReportManagementBean
  ReportManagementFacade
  ReportManagementFacadeBean
  ReportManagementFacadeHome
  ReportManagementFacadeLocal
  ReportManagementFacadeLocalHome
  ReportManagementHome
  ReportManagementLocal
  ReportManagementLocalHome
  </code></pre>
  
  <p>Here is the <code>ejb-jar.xml</code></p>
  
  <pre><code>    &lt;?xml version='1.0' encoding='UTF-8'?&gt;
  &lt;ejb-jar xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd"
           version="2.1"&gt;
  &lt;enterprise-beans&gt;
      &lt;session&gt;
        &lt;display-name&gt;ReportManagementFacade&lt;/display-name&gt;
        &lt;ejb-name&gt;ReportManagementFacade&lt;/ejb-name&gt;
        &lt;home&gt;com.ejb.ReportManagementFacadeHome&lt;/home&gt;
        &lt;remote&gt;com.ejb.ReportManagementFacade&lt;/remote&gt;
        &lt;local-home&gt;com.ejb.ReportManagementFacadeLocalHome&lt;/local-home&gt;
        &lt;local&gt;com.ejb.ReportManagementFacadeLocal&lt;/local&gt;
        &lt;ejb-class&gt;com.ejb.ReportManagementFacadeBean&lt;/ejb-class&gt;
        &lt;session-type&gt;Stateless&lt;/session-type&gt;
        &lt;transaction-type&gt;Container&lt;/transaction-type&gt;
      &lt;/session&gt;
      &lt;session&gt;
        &lt;display-name&gt;ReportManagement&lt;/display-name&gt;
        &lt;ejb-name&gt;ReportManagement&lt;/ejb-name&gt;
        &lt;home&gt;com.ejb.ReportManagementHome&lt;/home&gt;
        &lt;remote&gt;com.ejb.ReportManagement&lt;/remote&gt;
        &lt;local-home&gt;com.ejb.ReportManagementLocalHome&lt;/local-home&gt;
        &lt;local&gt;com.ejb.ReportManagementLocal&lt;/local&gt;
        &lt;ejb-class&gt;com.ejb.ReportManagementBean&lt;/ejb-class&gt;
        &lt;session-type&gt;Stateless&lt;/session-type&gt;
        &lt;transaction-type&gt;Container&lt;/transaction-type&gt;
      &lt;/session&gt;
    &lt;/enterprise-beans&gt;
    &lt;assembly-descriptor&gt;
      &lt;container-transaction&gt;
        &lt;method&gt;
          &lt;ejb-name&gt;ReportManagementFacade&lt;/ejb-name&gt;
          &lt;method-name&gt;*&lt;/method-name&gt;
        &lt;/method&gt;
        &lt;trans-attribute&gt;Required&lt;/trans-attribute&gt;
      &lt;/container-transaction&gt;
      &lt;container-transaction&gt;
        &lt;method&gt;
          &lt;ejb-name&gt;ReportManagement&lt;/ejb-name&gt;
          &lt;method-name&gt;*&lt;/method-name&gt;
        &lt;/method&gt;
        &lt;trans-attribute&gt;Required&lt;/trans-attribute&gt;
      &lt;/container-transaction&gt;
    &lt;/assembly-descriptor&gt;
  &lt;/ejb-jar&gt;
  </code></pre>
  
  <p>Here is the weblogic-ejb-jar.xml</p>
  
  <pre><code>    &lt;?xml version='1.0' encoding='UTF-8'?&gt;
  &lt;weblogic-ejb-jar xmlns="http://xmlns.oracle.com/weblogic/weblogic-ejb-jar"
                    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                    xsi:schemaLocation="http://xmlns.oracle.com/weblogic/weblogic-ejb-jar http://xmlns.oracle.com/weblogic/weblogic-ejb-jar/1.2/weblogic-ejb-jar.xsd"&gt;
    &lt;weblogic-enterprise-bean&gt;
      &lt;ejb-name&gt;ReportManagementFacade&lt;/ejb-name&gt;
      &lt;jndi-name&gt;Destin8.ejb.reportmanagement.ReportManagementFacade&lt;/jndi-name&gt;
      &lt;local-jndi-name&gt;Destin8.ejb.reportmanagement.ReportManagementFacadeLocal&lt;/local-jndi-name&gt;
      &lt;enable-call-by-reference&gt;true&lt;/enable-call-by-reference&gt;
    &lt;/weblogic-enterprise-bean&gt;
    &lt;weblogic-enterprise-bean&gt;
      &lt;ejb-name&gt;ReportManagement&lt;/ejb-name&gt;
      &lt;jndi-name&gt;Destin8.ejb.reportmanagement.ReportManagement&lt;/jndi-name&gt;
      &lt;local-jndi-name&gt;Destin8.ejb.reportmanagement.ReportManagementLocal&lt;/local-jndi-name&gt;
      &lt;enable-call-by-reference&gt;true&lt;/enable-call-by-reference&gt;
    &lt;/weblogic-enterprise-bean&gt;
    &lt;weblogic-compatibility&gt;
      &lt;entity-always-uses-transaction&gt;true&lt;/entity-always-uses-transaction&gt;
    &lt;/weblogic-compatibility&gt;
  &lt;/weblogic-ejb-jar&gt;
  </code></pre>
  
  <p>And here is the StackTrace:</p>
  
  <pre><code>weblogic.rmi.RemoteEJBInvokeException: null; nested exception is: 
      com.exception.RuleException
      at weblogic.ejb.container.internal.SessionRemoteMethodInvoker.invoke(SessionRemoteMethodInvoker.java:27)
      at com.ejb.ReportManagement_tq6u66_EOImpl.doLUMValidate(Unknown Source)
      at com.ejb.ReportManagementFacadeBean.doLUM(ReportManagementFacadeBean.java:82)
      at com.ejb.ReportManagementFacade_sidvua_EOImpl.__WL_invoke(Unknown Source)
      at weblogic.ejb.container.internal.SessionRemoteMethodInvoker.invokeInternal(SessionRemoteMethodInvoker.java:54)
      at weblogic.ejb.container.internal.SessionRemoteMethodInvoker.invoke(SessionRemoteMethodInvoker.java:21)
      at com.ejb.ReportManagementFacade_sidvua_EOImpl.doLUM(Unknown Source)
      at com.ajf.Page1ManagedBean.refreshDate(Page1ManagedBean.java:105)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      at java.lang.reflect.Method.invoke(Method.java:498)
      at com.sun.el.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:181)
      at com.sun.el.parser.AstValue.invoke(AstValue.java:289)
      at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:304)
      at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:40)
      at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:50)
      at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:40)
      at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:50)
      at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
      at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:87)
      at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
      at javax.faces.component.UICommand.broadcast(UICommand.java:315)
      at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
      at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
      at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
      at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
      at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
      at javax.faces.webapp.FacesServlet.service(FacesServlet.java:650)
      at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:286)
      at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:260)
      at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:137)
      at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:350)
      at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:25)
      at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:78)
      at weblogic.servlet.internal.RequestEventsFilter.doFilter(RequestEventsFilter.java:32)
      at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:78)
      at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3683)
      at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3649)
      at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:326)
      at weblogic.security.service.SecurityManager.runAsForUserCode(SecurityManager.java:197)
      at weblogic.servlet.provider.WlsSecurityProvider.runAsForUserCode(WlsSecurityProvider.java:203)
      at weblogic.servlet.provider.WlsSubjectHandle.run(WlsSubjectHandle.java:71)
      at weblogic.servlet.internal.WebAppServletContext.doSecuredExecute(WebAppServletContext.java:2433)
      at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2281)
      at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2259)
      at weblogic.servlet.internal.ServletRequestImpl.runInternal(ServletRequestImpl.java:1691)
      at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1651)
      at weblogic.servlet.provider.ContainerSupportProviderImpl$WlsRequestExecutor.run(ContainerSupportProviderImpl.java:270)
      at weblogic.invocation.ComponentInvocationContextManager._runAs(ComponentInvocationContextManager.java:348)
      at weblogic.invocation.ComponentInvocationContextManager.runAs(ComponentInvocationContextManager.java:333)
      at weblogic.work.LivePartitionUtility.doRunWorkUnderContext(LivePartitionUtility.java:54)
      at weblogic.work.PartitionUtility.runWorkUnderContext(PartitionUtility.java:41)
      at weblogic.work.SelfTuningWorkManagerImpl.runWorkUnderContext(SelfTuningWorkManagerImpl.java:640)
      at weblogic.work.ExecuteThread.execute(ExecuteThread.java:406)
      at weblogic.work.ExecuteThread.run(ExecuteThread.java:346)
  Caused by: com.exception.RuleException
      at com.ejb.ReportManagementBean.doLUMValidate(ReportManagementBean.java:92)
      at com.ejb.ReportManagement_tq6u66_EOImpl.__WL_invoke(Unknown Source)
      at weblogic.ejb.container.internal.SessionRemoteMethodInvoker.invokeInternal(SessionRemoteMethodInvoker.java:54)
      at weblogic.ejb.container.internal.SessionRemoteMethodInvoker.invoke(SessionRemoteMethodInvoker.java:21)
      ... 55 more
  </code></pre>
  
  <p>Any guidance in this matter will be much appreciated.</p>