3

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:

@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$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"/>

...

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?

4

3 回答 3

6

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 :

Effectively we need to configure the WLS server to include the following option on startup:

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

For WLS 10.3 this entry should be included in your startWebLogic.cmd file.

For a standalone WLS this file is found under:

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

For the integrated WLS within JDeveloper 11g it's found under:

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

Locate the following entry in the startWebLogic.cmd file:

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.

于 2012-10-16T10:56:49.013 回答
2

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.

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");

.

.

.

}

于 2014-05-08T12:09:20.900 回答
2

This worked for me, after trying all the other methods...

import com.sun.xml.ws.fault.SOAPFaultBuilder to your class

Declare a variable for SOAPFaultBuilder ie: SOAPFaultBuilder soapFaultBuilder;

In your constructor, set the soapFaultBuilder.captureStackTrace = false;

于 2014-07-17T08:23:50.523 回答