发生自定义异常时,我必须从Web服务返回500状态。我将错误的xml标记添加到了WSDL中。
<xsd:element name="ProductionOrder" type="ProductionOrder"/>
<xsd:element name="ProductionOrder_InFault" type="ProductionOrder_InFault"/>
<xsd:complexType name="ProductionOrder">
</xsd:complexType>
<xsd:complexType name="ProductionOrder_InFault">
<xsd:sequence>
<xsd:element name="status" type="xsd:int"/>
<xsd:element name="message" type="xsd:string"/>
<xsd:element name="detail" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
</wsdl:types>
<wsdl:message name="ProductionOrder">
<wsdl:documentation/>
<wsdl:part name="ProductionOrder" element="p1:ProductionOrder"/>
</wsdl:message>
<wsdl:message name="ProductionOrderException">
<wsdl:part name="ProductionOrder_InFault" element="p1:ProductionOrder_InFault"/>
<wsdl:portType name="ProductionOrder_In">
<wsdl:documentation/>
<wsdl:operation name="ProductionOrder_In">
<wsdl:documentation/>
<wsp:Policy>
<wsp:PolicyReference URI="#OP_ProductionOrder_In"/>
</wsp:Policy>
<wsdl:input message="p1:ProductionOrder"/>
<wsdl:output message="ProductionOrder"/>
<wsdl:fault name="ProductionOrderException" message="p1:ProductionOrderException"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="ProductionOrder_InBinding" type="p1:ProductionOrder_In">
<soap:binding xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="ProductionOrder_In">
<soap:operation xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" soapAction="http://sap.com/xi/WebService/soap1.1"/>
<wsdl:input>
<soap:body xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" use="literal"/>
</wsdl:input>
<wsdl:fault name="ProductionOrder_InFault">
<soap12:fault name="ProductionOrder_InFault" use="literal"/>
</wsdl:fault>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="ProductionOrder_InService">
<wsdl:port binding="p1:ProductionOrder_InBinding" name="ProductionOrder_In">
<soap:address xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" location="http://localhost:8080/services/ProductionOrder"/>
</wsdl:port>
</wsdl:service>
要检查是否工作,我在处理程序的handleFault()方法中添加了System.out.println(“ handleFault”)。并创建了自定义异常。 我将System.out.println(“ handleMessage”)添加到handleMessage()方法,并将System.out.println(“ close”)添加到close()方法。而且我知道,它有效。
@WebFault(name = "ProductionOrder_InFault", targetNamespace = "http://esb.z-t-z.ru/Integration/SAP")
public class ProductionOrderException extends Exception {
private ProductionOrderFault productionOrderFault;
...
}
我有ProductionOrderFault bean:
public class ProductionOrderFault {
protected int status;
@XmlElement(required = true)
protected String message;
@XmlElement(required = true)
protected String detail;
// setters, getters and constructor
...
然后我在实现中生成异常:
@javax.jws.WebService(serviceName = "ProductionOrder_InService",
portName =“ ProductionOrder_In”,endpointInterface =“ ProductionOrderIn”)
@HandlerChain(name = "ServerSOAPHandler", file = "ProductionOrderSOAPHandler.xml")
public class ProductionOrder_InImpl implements ProductionOrderIn {
private static final Logger LOG = Logger.getLogger(ProductionOrder_InImpl.class.getName());
public void productionOrderIn(ProductionOrder productionOrder) throws ProductionOrderException {
LOG.debug("ProductionOrder_InImpl:: " + productionOrder.toString());
LOG.info("Executing operation productionOrderIn");
throw new ProductionOrderException("error during executing web service implementation", new ProductionOrderFault());
我不理解为什么在Tomcat上运行Web服务时,其异常未由我的处理程序处理。我在日志中看到异常,但是我的处理程序无法处理它。
这是为什么?如何检查或调试问题?