Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

wsdl: how to generate exception with errorCode and errorMessage inlined?

I'm trying to use wsdl:fault, but can not generate expected java class (exception). The class I get generated (annotations and getters/setters removed):

public class ProjectException extends Exception {
    private com.home.project.generated.Fault fault;
}

public class Fault {
    protected String errorMessage;
    protected long errorCode;
}

The class I expect to get generated:

public class ProjectException extends Exception {
    protected String errorMessage;
    protected long errorCode;
}

My wsdl:

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions name="ProjectSoapServiceImplService"
                  targetNamespace="http://www.home.com/webservices/v1_0/project/"
                  xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
                  xmlns:tns="http://www.home.com/webservices/v1_0/project/"
                  xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
    <wsdl:types>
        <xs:schema xmlns:tns="http://www.home.com/webservices/v1_0/project/"
                   xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="unqualified"
                   targetNamespace="http://www.home.com/webservices/v1_0/project/" version="1.0">

            <xs:element name="createProject" type="tns:projectRequest"/>
            <xs:element name="projectResponse" type="tns:projectResponse"/>

            <xs:complexType name="projectRequest">
                <xs:sequence>
                    <xs:element minOccurs="0" name="projectName" type="xs:string"/>
                </xs:sequence>
            </xs:complexType>
            <xs:complexType name="projectResponse">
                <xs:sequence>
                    <xs:element minOccurs="0" name="projectId" type="xs:long"/>
                </xs:sequence>
            </xs:complexType>
            <xs:element name="fault">
                <xs:complexType>
                    <xs:sequence>
                        <xs:element name="errorMessage" type="xs:string"/>
                        <xs:element name="errorCode" type="xs:long"/>
                    </xs:sequence>
                </xs:complexType>
            </xs:element>
        </xs:schema>

    </wsdl:types>
    <wsdl:message name="createProject">
        <wsdl:part name="parameters" element="tns:createProject"/>
    </wsdl:message>
    <wsdl:message name="createProjectResponse">
        <wsdl:part name="parameters" element="tns:projectResponse">
        </wsdl:part>
    </wsdl:message>
    <wsdl:message name="projectException">
        <wsdl:part name="faultMessage" element="tns:fault"/>
    </wsdl:message>
    <wsdl:portType name="ProjectPort">
        <wsdl:operation name="createProject">
            <wsdl:input name="createProject" message="tns:createProject"/>
            <wsdl:output name="createProjectResponse" message="tns:createProjectResponse"/>
            <wsdl:fault name="fault" message="tns:projectException"/>
        </wsdl:operation>
    </wsdl:portType>
    <wsdl:binding name="ProjectSoapServiceImplServiceSoapBinding" type="tns:ProjectPort">
        <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
        <wsdl:operation name="createProject">
            <soap:operation soapAction="" style="document"/>
            <wsdl:input name="createProject">
                <soap:body use="literal"/>
            </wsdl:input>
            <wsdl:output name="createProjectResponse">
                <soap:body use="literal"/>
            </wsdl:output>
            <wsdl:fault name="fault">
                <soap:fault name="fault" use="literal"/>
            </wsdl:fault>
        </wsdl:operation>
    </wsdl:binding>
    <wsdl:service name="ProjectSoapServiceImplService">
        <wsdl:port name="ProjectPortPort" binding="tns:ProjectSoapServiceImplServiceSoapBinding">
            <soap:address location="http://localhost:9090/ProjectPortPort"/>
        </wsdl:port>
    </wsdl:service>
</wsdl:definitions>

Any ideas how to inline properties in class directly?

Thanks in advance

like image 962
Vi Matviichuk Avatar asked Oct 14 '15 08:10

Vi Matviichuk


People also ask

When SOAP fault exception occurs?

A SOAP fault is an error in a SOAP (Simple Object Access Protocol) communication resulting from incorrect message format, header-processing problems, or incompatibility between applications.

Which element can give information about service specific exceptions and their mapping to exception classes?

(1) Processing of service-specific exceptions The WSDL faults and Java exceptions are mapped according to the JAX-WS 2.2 specifications. The following figure shows an example of mapping between the WSDL faults and Java exception classes.


1 Answers

As far as I can tell you cannot achieve to generate what you expect.

According to the specification JAX-WS 2.1 http://download.oracle.com/otndocs/jcp/jaxws-2.1-mrel2-eval-oth-JSpec/ a mapped fault needs an Exception that contains the fault bean. Using tools that implement the specification will always give you an Exception wrapper annotated with @WebFault that contain the Java Fault bean.

like image 179
Mads Hoel Avatar answered Oct 15 '22 15:10

Mads Hoel