WebFault和Web Service在不同的命名空间中

时间:2016-03-17 18:38:18

标签: java web-services wsdl cxf jax-ws

我需要在不同的命名空间中定义自定义异常而不是Web服务。但是当我生成一个wsdl时,一些包装器出现在webservice的命名空间中。是否可以在没有此包装器的情况下使用来自另一个命名空间的异常?

例外:

@WebFault(targetNamespace = "http://somenamespace/server/faults",
faultBean = "my.package.SoapBadRequestException.FaultBean")
    public class SoapBadRequestException extends Exception {
    private FaultBean faultBean;

    @XmlType(name = "FaultBean", namespace = "http://somenamespace/server/faults")
    public static class FaultBean {}

    public SoapBadRequestException() { super(); }

    public SoapBadRequestException(String message, FaultBean faultBean, Throwable cause) {
        super(message, cause);
        this.faultBean = faultBean;
    }

    public SoapBadRequestException(String message, FaultBean faultBean) {
        super(message);
        this.faultBean = faultBean;
    }

    public FaultBean getFaultInfo() { return faultBean; }
}

网络服务:

@WebService(targetNamespace = "http://somenamespace/server/ws")
public interface MyWebService {

void someOperation(
        @WebParam(name = "param1") String param1,
        @WebParam(name = "param2") String param2) throws SoapBadRequestException;
}

产生的wsdl(FaultBean未定义,也不知道原因):

<wsdl:definitions xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
              xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" 
              xmlns:tns="http://somenamespace/server/ws" 
              xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" 
              xmlns:ns1="http://somenamespace/server/faults" 
              name="MyWebServiceImpl" 
              targetNamespace="http://somenamespace/server/ws">
<wsdl:types>
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
                xmlns:tns="http://somenamespace/server/faults" 
                attributeFormDefault="unqualified" 
                elementFormDefault="unqualified" 
                targetNamespace="http://somenamespace/server/faults">
        <xsd:element name="SoapBadRequestFault" nillable="true" type="tns:FaultBean"/>
    </xsd:schema>
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
                xmlns:tns="http://somenamespace/server/ws" 
                attributeFormDefault="unqualified" 
                elementFormDefault="unqualified" 
                targetNamespace="http://somenamespace/server/ws">
        <xsd:element name="someOperation" type="tns:someOperation"/>
        <xsd:complexType name="someOperation">
            <xsd:sequence>
                <xsd:element name="param1" type="xsd:string"/>
                <xsd:element name="param2" type="xsd:string"/>
            </xsd:sequence>
        </xsd:complexType>
        <xsd:element name="someOperationResponse" type="tns:someOperationResponse"/>
        <xsd:complexType name="someOperationResponse">
            <xsd:sequence/>
        </xsd:complexType>
    </xsd:schema>
</wsdl:types>
<wsdl:message name="someOperationResponse">
    <wsdl:part element="tns:someOperationResponse" name="parameters"></wsdl:part>
</wsdl:message>

<!-- This is the redundant wrapper in the web service namespece -->
<wsdl:message name="SoapBadRequestException">
    <wsdl:part element="ns1:SoapBadRequestFault" name="SoapBadRequestException"></wsdl:part>
</wsdl:message>
<wsdl:message name="someOperation">
    <wsdl:part element="tns:someOperation" name="parameters"></wsdl:part>
</wsdl:message>
<wsdl:portType name="MyWebService">
    <wsdl:operation name="someOperation">
        <wsdl:input message="tns:someOperation" name="someOperation"></wsdl:input>
        <wsdl:output message="tns:someOperationResponse" name="someOperationResponse"></wsdl:output>
        <wsdl:fault message="tns:SoapBadRequestException" name="SoapBadRequestException"></wsdl:fault>
    </wsdl:operation>
</wsdl:portType>
<wsdl:binding name="MyWebServiceImplSoapBinding" type="tns:MyWebService">
    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
    <wsdl:operation name="someOperation">
        <soap:operation soapAction="" style="document"/>
        <wsdl:input name="someOperation">
            <soap:body use="literal"/>
        </wsdl:input>
        <wsdl:output name="someOperationResponse">
            <soap:body use="literal"/>
        </wsdl:output>
        <wsdl:fault name="SoapBadRequestException">
            <soap:fault name="SoapBadRequestException" use="literal"/>
        </wsdl:fault>
    </wsdl:operation>
</wsdl:binding>
<wsdl:service name="MyWebServiceImpl">...</wsdl:service>

我看到thisthis但没有任何帮助。

0 个答案:

没有答案