【问题标题】:Mule 3 webservice does not return stacktraceMule 3 web 服务不返回堆栈跟踪
【发布时间】:2012-04-28 16:30:54
【问题描述】:

我最近从 Mule 2.2.1 切换到 Mule 3.x

要点是 Mule 3 不返回堆栈跟踪,但 Mule 2 会,我如何复制 Mule 2 的行为?

更多细节:

一些 Web 服务被包装在一个 try-catch 中,我们在其中抛出一个 ServiceException

@WebFault(name = "ServiceException")
    public class ServiceException extends Exception {
    private static final long serialVersionUID = 1L;
    private Integer errorNumber;

public ServiceException(Exception e, User user) {
    super(makeMessage(e));
    LoggingDao.logException(this.getMessage(), e.toString());
    this.setStackTrace(e.getStackTrace());
    this.errorNumber = LoggingDao.getLogId();
} ... etc

我们捕获异常的目的是将堆栈跟踪返回给 Web 服务调用者,顺便说一下,LoggingDao 记录堆栈跟踪但 Web 服务不返回它。

在路上的某个地方,我们跳转到 DefaultComponentLifecycleAdapter.java,它会抛出一个 MuleException,它会覆盖堆栈跟踪并返回

  <soap:Fault>
     <faultcode>soap:Server</faultcode>
     <faultstring>Component that caused exception is: org.mule.component.DefaultJavaComponent component for: SedaService{...}. Message payload is of type: Object[]</faultstring>
  </soap:Fault>

我将如何在 Mule 3.x 中返回堆栈跟踪

附: 我正在使用 Mule 3.0.1,它似乎与我上面提供的链接不兼容。

也来自:http://www.mulesoft.org/documentation/display/MULE3USER/Error+Handling

如果流程交换模式是请求-响应,则在执行后将不同的消息返回给调用者。该消息将 org.mule.transport.NullPayload 作为其有效负载,并且 exceptionPayload 属性设置为以下内容: org.mule.api.ExceptionPayload .

从 mule 2 mule-config.xml 的不同之处在于交换模式不是“请求-响应”

【问题讨论】:

    标签: java spring cxf mule


    【解决方案1】:

    有人告诉我这是 Mule 3.x 托马斯·布洛姆

    public class CustomSoapFaultOutInterceptor extends AbstractSoapInterceptor {
        private static final Log logger = LogFactory.getLog(CustomSoapFaultOutInterceptor.class);
    
    public CustomSoapFaultOutInterceptor() {
            super(Phase.MARSHAL);
            getAfter().add(Soap11FaultOutInterceptor.class.getName());
        }
        @Override
        public void handleMessage(SoapMessage message) throws Fault {
            Fault fault = (Fault) message.getContent(Exception.class);
            logger.error(fault.getMessage(), fault);
        //delete the Mule Exception to have the one throw by the component in the SoapMessage
            Throwable t = getOriginalCause(fault.getCause());
            fault.setMessage(t.getMessage());
        }
        private Throwable getOriginalCause(Throwable t) {
            if (t.getCause() == null || t.getCause().equals(t))
                return t;
            else
                return getOriginalCause(t.getCause());
        }
    }
    
    //And then this into mule-config.
    <cxf:jaxws-service>
       <cxf:outFaultInterceptors>
          <spring:bean class="is.tr.mule.interceptor.CustomSoapFaultOutInterceptor"/>
       </cxf:outFaultInterceptors>
    </cxf:jaxws-service>
    

    【讨论】:

      猜你喜欢
      • 2011-05-22
      • 1970-01-01
      • 1970-01-01
      • 2021-03-23
      • 2018-07-02
      • 1970-01-01
      • 2011-05-25
      • 2011-05-13
      • 1970-01-01
      相关资源
      最近更新 更多