2012-07-26 52 views
3

我有一个使用Spring和jaxb的web服务,我尝试在某些情况下抛出一个异常,为此我使用了@WebFault的注解。就像这样:如何从SOAP错误中禁用堆栈跟踪?

@WebFault 
public class ServiceException extends Exception { 

private static final long serialVersionUID = -5307754615848423430L; 
private FaultBean faultBean; 

public ServiceException(String message, ServiceErrorCode serviceErrorCode) { 
     super(message); 
     this.faultBean = new FaultBean(); 
     this.faultBean.setMessage(message); 
     this.faultBean.setErrorCode(serviceErrorCode); 
} 

public FaultBean getFaultInfo() { 
    return faultBean; 
} 

}

,它的做工精细,这是输出:

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"> 
    <S:Body> 
     <S:Fault xmlns:ns3="http://www.w3.org/2003/05/soap-envelope"> 
     <faultcode>S:Server</faultcode> 
     <faultstring>myException</faultstring> 
     <detail> 
      <ns2:ServiceException xmlns:ns2="http://soap.service.test/"> 
      <errorCode>UNRECOGNIZED_ERROR</errorCode> 
      <message>myException</message> 
     </ns2:ServiceException> 
     <ns2:exception class="ServiceException" note="To disable this feature, set com.sun.xml.ws.fault.SOAPFaultBuilder.disableCaptureStackTrace system property to false" xmlns:ns2="http://jax-ws.dev.java.net/"> 
      <message>myException</message> 
      <ns2:stackTrace> 
       <ns2:frame class="myWebService" file="myWebService.java" line="50" method="listTickets"/> 
       <ns2:frame class="sun.reflect.NativeMethodAccessorImpl" file="NativeMethodAccessorImpl.java" line="native" method="invoke0"/> 
       <ns2:frame class="sun.reflect.NativeMethodAccessorImpl" file="NativeMethodAccessorImpl.java" line="39" method="invoke"/> 
       <ns2:frame class="sun.reflect.DelegatingMethodAccessorImpl" file="DelegatingMethodAccessorImpl.java" line="25" method="invoke"/> 
       <ns2:frame class="java.lang.reflect.Method" file="Method.java" line="597" method="invoke"/> 
       <ns2:frame class="com.sun.xml.ws.api.server.InstanceResolver$1" file="InstanceResolver.java" line="246" method="invoke"/> 
       <ns2:frame class="com.sun.xml.ws.server.InvokerTube$2" file="InvokerTube.java" line="146" method="invoke"/> 
       <ns2:frame class="com.sun.xml.ws.server.sei.EndpointMethodHandler" file="EndpointMethodHandler.java" line="257" method="invoke"/> 
       <ns2:frame class="com.sun.xml.ws.server.sei.SEIInvokerTube" file="SEIInvokerTube.java" line="93" method="processRequest"/> 
       <ns2:frame class="com.sun.xml.ws.api.pipe.Fiber" file="Fiber.java" line="595" method="__doRun"/> 
       <ns2:frame class="com.sun.xml.ws.api.pipe.Fiber" file="Fiber.java" line="554" method="_doRun"/> 
       <ns2:frame class="com.sun.xml.ws.api.pipe.Fiber" file="Fiber.java" line="539" method="doRun"/> 

...

所以问题是,似乎没有正确显示错误的堆栈跟踪,因为客户端不关心这些细节,但无法找到方法来做到这一点,任何想法?

回答

6

堆栈跟踪的传播默认为打开。 如果您认为Web Service应用程序发送完整堆栈跟踪并不安全,则可以关闭此功能。 我肯定要设置在服务器的VM.If是:

有效,我们需要的WLS服务器配置为包括启动下列选项:

-Dcom.sun.xml.ws.fault.SOAPFaultBuilder.disableCaptureStackTrace=false 

对于WLS 10.3此项应包含在startWebLogic.cmd文件中。

对于独立WLS这个文件下找到:

<WLS_HOME>/user_projects/domains/<YOUR_DOMAIN>/bin 

针对JDeveloper11克内部集成WLS它的发现下:

<JDEV_HOME>\system\system11.1.1.0.31.51.88\DefaultDomain\bin 

找到的文件的startWebLogic.cmd以下条目:

set JAVA_OPTIONS=%SAVE_JAVA_OPTIONS% 

..并将其更改为:

set JAVA_OPTIONS=-Dcom.sun.xml.ws.fault.SOAPFaultBuilder.disableCaptureStackTrace=false %SAVE_JAVA_OPTIONS% 

重新启动WLS服务器,并用无效的SOAP有效负载重新启动Web服务。

+1

实际我使用tomcat,但是同样在starup脚本中添加参数-Dcom.sun.xml.ws.fault.SOAPFaultBuilder.disableCaptureStackTrace = false:D – Icaro 2012-10-17 16:21:17

2

您也可以在java代码中的系统属性中设置它,这很简单,并且不依赖于部署的服务器的类型。只需在服务实施调用的最开始添加以下行(粗体)即可。希望有所帮助。

实施例:

@WebService(endpointInterface = “com.service.IMyService”) 公共类MyServiceImpl实现IMyService {

@Override 公共列表为myService(字符串PNR)抛出MyException {

System.setProperty(“com.sun.xml.ws.fault.SOAPFaultBuilder.disableCaptureStackTrace”,“false”);

}

1

这为我工作,尝试所有其他方法后...

import com.sun.xml.ws.fault.SOAPFaultBuilder到类

声明一个变量SOAPFaultBuilder即:SOAPFaultBuilder soapFaultBuilder;

在你的构造函数,设置soapFaultBuilder.captureStackTrace = false;