Почему мой обработчик ошибок JAXWS не обрабатывает мое пользовательское исключение? - PullRequest
0 голосов
/ 26 декабря 2018

Я должен вернуть 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>

Для проверки, работайте это или нет, я добавил System.out.println ("handleFault") в метод 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:

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.Я вижу исключение в журнале, но мой обработчик не обрабатывает его.

Почему это?Как я могу проверить или отладить его проблему?

...