0

I've wrote some simple service that consists of several files (wsdl, xsd). In xsd file I've got following definition:

<xs:complexType name="ServerMessage">
    <xs:sequence>
        <xs:element name="type" type="xs:int"/>
        <xs:element name="info" type="xs:string"/>
    </xs:sequence>
</xs:complexType>
<xs:element name="ServerMessage" type="tns:ServerMessage"/>

Then this element is referenced in wsdl file like this

<wsdl:message name="createItemFault">
    <wsdl:part name="createItemFault" element="tns:ServerMessage"/>
</wsdl:message>

<wsdl:portType name="Service">
    <wsdl:operation name="createItem">
        <wsdl:input message="tns:createItemRequest"/>
        <wsdl:output message="tns:createItemResponse"/>
        <wsdl:fault name="Fault" message="tns:createItemFault"/>
    </wsdl:operation>

And at last

<wsdl:binding name="ServiceBinding" type="intf:Service">
    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>

    <wsdl:operation name="createItem">
        <soap:operation soapAction="http://test.com/createItem"/>
        <wsdl:input>
            <soap:body use="literal"/>
        </wsdl:input>
        <wsdl:output>
            <soap:body use="literal"/>
        </wsdl:output>
        <wsdl:fault name="Fault">
            <soap:fault name="Fault" use="literal"/>
        </wsdl:fault>
    </wsdl:operation>

After launching WSDL2Java I receive the following code

public interface ServerMessage extends org.apache.xmlbeans.XmlObject
{

How come ServerMessage becomes defined like this? When I've used WSDL2Java provided by Axis1 final definition in java file was like this

 public class ServerMessage extends org.apache.axis.AxisFault  implements java.io.Serializable

And after Axis2 generation resulting "item" is drastically differs, it's not even throwable. What am I doing wrong?

Machavity
  • 30,841
  • 27
  • 92
  • 100
BSen
  • 187
  • 2
  • 16

1 Answers1

1

From that WSDL you should get a CreateItemFault (due to the wsdl:message name) that looks something like:

public class CreateItemFault extends java.lang.Exception {
    private org.example.www.service.ServerMessageDocument faultMessage;
    ...
}

That ServerMessageDocument probably looks like:

public interface ServerMessageDocument extends org.apache.xmlbeans.XmlObject {
    ...
    org.example.www.service.ServerMessage getServerMessage();

    void setServerMessage(org.example.www.service.ServerMessage serverMessage);

    org.example.www.service.ServerMessage addNewServerMessage();
    ...
}

And here's where we get to your ServerMessage:

public interface ServerMessage extends org.apache.xmlbeans.XmlObject {
    ...
}

The method signature should throw a CreateItemFault, though.

davidfmatheson
  • 3,539
  • 19
  • 27
  • But what if I want ServerMessage type to be throwable? To use it in non-generated code as typical exception – BSen Aug 24 '12 at 06:30
  • Depends what else you want to do with it. You could always change the names in your WSDL such that your `wsdl:message` name was `ServerMessage` (and change the `xsd:type` and `xsd:element` names to avoid naming conflicts). The resulting object would be throwable, but would not contain the `type` and `info` attributes you defined in the schema. Those would be present in the object that represents the type definition. – davidfmatheson Aug 24 '12 at 12:35