java 如何从 SOAP 错误中禁用堆栈跟踪?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11674222/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to disabling the Stack Trace from the SOAP Fault?
提问by Icaro
i have a web service with Spring and jaxb and i try to throw one exception in some cases, for this I use the anotation @WebFault. just like this:
我有一个带有 Spring 和 jaxb 的 Web 服务,在某些情况下我尝试抛出一个异常,为此我使用注释@WebFault。像这样:
@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;
}
}
}
and it's work fine, this is the output:
它工作正常,这是输出:
<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" file="InstanceResolver.java" line="246" method="invoke"/>
<ns2:frame class="com.sun.xml.ws.server.InvokerTube" 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"/>
...
...
so the problem is that does not seem correct show the stacktrace of the error, because the client does not care about those details, but can not find the way to do this, any ideas?
所以问题是显示错误的堆栈跟踪似乎不正确,因为客户端不关心这些细节,但找不到这样做的方法,有什么想法吗?
回答by Naveenkumar K
Propagation of Stack trace is on by default. If you think its not safe for your Web Service Application to send the complete stack trace, you can turn off this functionality. I am sure you want to set it in the server's VM.If yes :
默认情况下,堆栈跟踪的传播处于启用状态。如果您认为您的 Web 服务应用程序发送完整的堆栈跟踪不安全,您可以关闭此功能。我确定你想在服务器的 VM 中设置它。如果是:
Effectively we need to configure the WLS server to include the following option on startup:
实际上,我们需要配置 WLS 服务器以在启动时包含以下选项:
-Dcom.sun.xml.ws.fault.SOAPFaultBuilder.disableCaptureStackTrace=false
For WLS 10.3 this entry should be included in your startWebLogic.cmd file.
对于 WLS 10.3,此条目应包含在 startWebLogic.cmd 文件中。
For a standalone WLS this file is found under:
对于独立的 WLS,此文件位于:
<WLS_HOME>/user_projects/domains/<YOUR_DOMAIN>/bin
For the integrated WLS within JDeveloper 11g it's found under:
对于 JDeveloper 11g 中的集成 WLS,它位于:
<JDEV_HOME>\system\system11.1.1.0.31.51.88\DefaultDomain\bin
Locate the following entry in the startWebLogic.cmd file:
在 startWebLogic.cmd 文件中找到以下条目:
set JAVA_OPTIONS=%SAVE_JAVA_OPTIONS%
..and change it to:
..并将其更改为:
set JAVA_OPTIONS=-Dcom.sun.xml.ws.fault.SOAPFaultBuilder.disableCaptureStackTrace=false %SAVE_JAVA_OPTIONS%
Restart the WLS server, and reinvoking the web service with an invalid SOAP payload.
重新启动 WLS 服务器,并使用无效的 SOAP 负载重新调用 Web 服务。
回答by saravp
You can also set it in system properties in your java code, which is simple and does not depend on the type of server deployed. Just add the below line(in bold) at the very beginning of your service implementation call. Hope that helps.
你也可以在你的java代码的系统属性中设置它,这很简单,不依赖于部署的服务器类型。只需在服务实现调用的最开始添加以下行(粗体)。希望有帮助。
Example:
例子:
@WebService(endpointInterface="com.service.IMyService") public class MyServiceImpl implements IMyService {
@Override public List myService(String pnr) throws MyException {
System.setProperty("com.sun.xml.ws.fault.SOAPFaultBuilder.disableCaptureStackTrace", "false");
.
.
.
}
@WebService(endpointInterface="com.service.IMyService") 公共类 MyServiceImpl 实现了 IMyService {
@Override 公共列表 myService(String pnr) 抛出 MyException {
System.setProperty("com.sun.xml.ws.fault.SOAPFaultBuilder.disableCaptureStackTrace", "false");
.
.
.
}
回答by geepho
This worked for me, after trying all the other methods...
在尝试了所有其他方法之后,这对我有用......
import com.sun.xml.ws.fault.SOAPFaultBuilder
to your class
import com.sun.xml.ws.fault.SOAPFaultBuilder
到你的班级
Declare a variable for SOAPFaultBuilder ie: SOAPFaultBuilder soapFaultBuilder;
为 SOAPFaultBuilder 声明一个变量,即: SOAPFaultBuilder soapFaultBuilder;
In your constructor, set the soapFaultBuilder.captureStackTrace = false;
在您的构造函数中,设置 soapFaultBuilder.captureStackTrace = false;