EJB 2.1在集群中抛出包装的远程异常

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了EJB 2.1在集群中抛出包装的远程异常相关的知识,希望对你有一定的参考价值。

我们正在处理将Weblogic 10.3.6应用程序移动到Weblogic 12.2.1.2。我们有许多构成应用程序一部分的EJB 2.1 bean。我们遇到了一些这些bean的奇怪问题。

当我们有1个ejb调用另一个并且这个bean抛出一个已检查的异常(例如RuleException extends Exception)时,它被抛出为RemoteExceptionRemoteEJBInvokeException)。仅当应用程序在群集中运行时才会出现这种情况。如果我针对独立的jvm部署它可以正常工作。

一般的EJB模式是Facade模式。在Facade bean中,我们使用标准JNDI查找来定位Home,然后运行create方法以返回业务接口/ impl

InitialContext ctx = new InitialContext();
ReportManagementHome reportManagementHome = (ReportManagementHome) ctx.lookup("ReportManagement");
ReportManagement reportManagement = reportManagementHome.create();

ReportManagement bean运行业务逻辑并抛出RuleException。

这是外观中调用第二个bean的示例方法:

public String doTest() {
    String s = null;
    try
    {
      s = reportManagement.doValidate();
    }
    catch ( RuleException re )
    {
      rollBack();
    } catch (RemoteException e)
    {
      e.printStackTrace();
    }

    return s;
  }

这是第二个bean中的doValidate()方法:

public String doValidate( )
      throws RuleException, CustomException
  {

    int test = 1;

    if (test == 1)
    {
      throw new RuleException();
    }

    return "Hello";

  }

虽然RuleException正确到达并抛出,但当立面捕获它时,它是一个RemoteException

这是ejbs / interfaces的示例列表:

ReportManagement
ReportManagementBean
ReportManagementFacade
ReportManagementFacadeBean
ReportManagementFacadeHome
ReportManagementFacadeLocal
ReportManagementFacadeLocalHome
ReportManagementHome
ReportManagementLocal
ReportManagementLocalHome

这是ejb-jar.xml

    <?xml version='1.0' encoding='UTF-8'?>
<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">
<enterprise-beans>
    <session>
      <display-name>ReportManagementFacade</display-name>
      <ejb-name>ReportManagementFacade</ejb-name>
      <home>com.ejb.ReportManagementFacadeHome</home>
      <remote>com.ejb.ReportManagementFacade</remote>
      <local-home>com.ejb.ReportManagementFacadeLocalHome</local-home>
      <local>com.ejb.ReportManagementFacadeLocal</local>
      <ejb-class>com.ejb.ReportManagementFacadeBean</ejb-class>
      <session-type>Stateless</session-type>
      <transaction-type>Container</transaction-type>
    </session>
    <session>
      <display-name>ReportManagement</display-name>
      <ejb-name>ReportManagement</ejb-name>
      <home>com.ejb.ReportManagementHome</home>
      <remote>com.ejb.ReportManagement</remote>
      <local-home>com.ejb.ReportManagementLocalHome</local-home>
      <local>com.ejb.ReportManagementLocal</local>
      <ejb-class>com.ejb.ReportManagementBean</ejb-class>
      <session-type>Stateless</session-type>
      <transaction-type>Container</transaction-type>
    </session>
  </enterprise-beans>
  <assembly-descriptor>
    <container-transaction>
      <method>
        <ejb-name>ReportManagementFacade</ejb-name>
        <method-name>*</method-name>
      </method>
      <trans-attribute>Required</trans-attribute>
    </container-transaction>
    <container-transaction>
      <method>
        <ejb-name>ReportManagement</ejb-name>
        <method-name>*</method-name>
      </method>
      <trans-attribute>Required</trans-attribute>
    </container-transaction>
  </assembly-descriptor>
</ejb-jar>

这是weblogic-ejb-jar.xml

    <?xml version='1.0' encoding='UTF-8'?>
<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">
  <weblogic-enterprise-bean>
    <ejb-name>ReportManagementFacade</ejb-name>
    <jndi-name>Destin8.ejb.reportmanagement.ReportManagementFacade</jndi-name>
    <local-jndi-name>Destin8.ejb.reportmanagement.ReportManagementFacadeLocal</local-jndi-name>
    <enable-call-by-reference>true</enable-call-by-reference>
  </weblogic-enterprise-bean>
  <weblogic-enterprise-bean>
    <ejb-name>ReportManagement</ejb-name>
    <jndi-name>Destin8.ejb.reportmanagement.ReportManagement</jndi-name>
    <local-jndi-name>Destin8.ejb.reportmanagement.ReportManagementLocal</local-jndi-name>
    <enable-call-by-reference>true</enable-call-by-reference>
  </weblogic-enterprise-bean>
  <weblogic-compatibility>
    <entity-always-uses-transaction>true</entity-always-uses-transaction>
  </weblogic-compatibility>
</weblogic-ejb-jar>

这是StackTrace:

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

任何有关此事的指导将不胜感激。

答案

这个:

 <enable-call-by-reference>true</enable-call-by-reference>

导致您在同一JVM中的远程调用具有本地调用语义,包括异常处理。

另一答案

Oracle已根据我的要求在修补程序中修复了此问题。该补丁的链接在这里Patch Link。您需要Oracle支持登录才能访问它。

以上是关于EJB 2.1在集群中抛出包装的远程异常的主要内容,如果未能解决你的问题,请参考以下文章

使用 sbt 和 testng 时,如何获取测试中抛出的异常的完整堆栈跟踪?

EJB3 事务回滚

特定网站在 QWebView 中抛出异常

为啥在析构函数中抛出异常时不调用重载删除?

为啥在构造函数中抛出异常会导致空引用?

如何捕获ctypes中抛出的异常?