You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by Marko Sormunen <Ma...@uku.fi> on 2005/05/16 09:31:38 UTC
Problem with custom Fault handling
Hi,
I've had a rather long time problem with custom Faults in Java Axis 1.2. The
problem is properly handling a custom Fault in client. Here's the original WSDL
describing the web service:
<?xml version="1.0" encoding="UTF-8"?>
<definitions targetNamespace="urn:serapi:SOAPExample"
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:serapi="urn:serapi:SOAPExample"
xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<types>
<schema elementFormDefault="qualified"
targetNamespace="urn:serapi:SOAPExample" xmlns="http://www.w3.org/2001/XMLSchema">
<element name="echoText">
<complexType>
<sequence>
<element name="text" type="xsd:string"/>
</sequence>
</complexType>
</element>
<element name="echoTextResponse">
<complexType>
<sequence>
<element name="echoedText" type="xsd:string"/>
</sequence>
</complexType>
</element>
<element name="noEchoTextProvided"/>
</schema>
</types>
<message name="echoTextRequestMessage">
<part element="serapi:echoText" name="parameters"/>
</message>
<message name="echoTextResponseMessage">
<part element="serapi:echoTextResponse" name="parameters"/>
</message>
<message name="noEchoTextProvided">
<part element="serapi:noEchoTextProvided" name="fault"/>
</message>
<portType name="EchoServiceOperations">
<operation name="echoText">
<input message="serapi:echoTextRequestMessage"/>
<output message="serapi:echoTextResponseMessage"/>
<fault name="noEchoTextProvided" message="serapi:noEchoTextProvided"/>
</operation>
</portType>
<binding name="EchoServiceBinding" type="serapi:EchoServiceOperations">
<wsdlsoap:binding style="document"
transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="echoText">
<wsdlsoap:operation soapAction="urn:serapi:SOAPExample#echoText"/>
<input>
<wsdlsoap:body use="literal"/>
</input>
<output>
<wsdlsoap:body use="literal"/>
</output>
<fault name="noEchoTextProvided">
<wsdlsoap:fault name="noEchoTextProvided" use="literal"/>
</fault>
</operation>
</binding>
This is pretty much WS-I Basic Profile 1.1 compliant stuff. The Fault element
(noEchoTextProvided) is defined as an Element in the message instead of Type.
When I run this through wsdl2java everything seems to be fine. But when I create
a simple implementation for the service and throw a NoEchoTextProvided fault
from there, the problems begin. Here's the SOAP message containing the Fault:
<?xml version="1.0" encoding="utf-8"?><soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<soapenv:Fault>
<faultcode>soapenv:Server.generalException</faultcode>
<faultstring>Echoed text seems to be an empty value, which is not allowed.
</faultstring>
<detail>
<ns1:noEchoTextProvided xmlns:ns1="urn:serapi:SOAPExample">No
value</ns1:noEchoTextProvided>
<ns2:exceptionName
xmlns:ns2="http://xml.apache.org/axis/">org.serapi.SOAPExample.NoEchoTextProvided</ns2:exceptionName>
<ns3:hostname xmlns:ns3="http://xml.apache.org/axis/">laivuri27</ns3:hostname>
</detail>
</soapenv:Fault>
</soapenv:Body>
</soapenv:Envelope>
The SOAP message seems fine. But in the Axis client this always ends up in a
NullPointerException:
AxisFault
faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException
faultSubcode:
faultString: java.lang.NullPointerException
faultActor:
faultNode:
faultDetail:
{http://xml.apache.org/axis/}stackTrace:java.lang.NullPointerException
at org.apache.axis.client.Call.invokeEngine(Call.java:2797)
at org.apache.axis.client.Call.invoke(Call.java:2748)
at org.apache.axis.client.Call.invoke(Call.java:2424)
at org.apache.axis.client.Call.invoke(Call.java:2347)
at org.apache.axis.client.Call.invoke(Call.java:1804)
at
org.serapi.SOAPExample.EchoServiceBindingStub.echoText(EchoServiceBindingStub.java:168)
at org.serapi.SOAPClient.EchoTextClient.<init>(EchoTextClient.java:15)
at org.serapi.SOAPClient.EchoTextClient.main(EchoTextClient.java:24)
{http://xml.apache.org/axis/}hostname:laivuri27
java.lang.NullPointerException
at org.apache.axis.AxisFault.makeFault(AxisFault.java:101)
at org.apache.axis.client.Call.invoke(Call.java:2427)
at org.apache.axis.client.Call.invoke(Call.java:2347)
at org.apache.axis.client.Call.invoke(Call.java:1804)
at
org.serapi.SOAPExample.EchoServiceBindingStub.echoText(EchoServiceBindingStub.java:168)
at org.serapi.SOAPClient.EchoTextClient.<init>(EchoTextClient.java:15)
at org.serapi.SOAPClient.EchoTextClient.main(EchoTextClient.java:24)
Caused by: java.lang.NullPointerException
at org.apache.axis.client.Call.invokeEngine(Call.java:2797)
at org.apache.axis.client.Call.invoke(Call.java:2748)
at org.apache.axis.client.Call.invoke(Call.java:2424)
... 5 more
It would seem that the client does not correctly deserialize the Fault element.
If I use AxisFaults instead of a custom Fault class, everything is fine. Do I
have to put something in the client-config.wsdd to properly deserialize the
Fault or something similar?
--
Marko Sormunen, M.Sc.
Messenger: msormune@hotmail.com
HIS-research unit, Centek, Computing Centre
University of Kuopio
Re: Problem with custom Fault handling
Posted by Marko Sormunen <Ma...@uku.fi>.
Anne Thomas Manes wrote the following on 16.5.2005 15:25:
> You need to define a type for your noEchoTextProvided element. This definition:
>
> <element name="noEchoTextProvided"/>
>
> defaults to type="xsd:anyType", and therefore Axis is looking for a
> deserializer. If you want to return an empty element, then you should
> define it like this:
>
> <element name="noEchoTextProvided">
> <complexType>
> <sequence/>
> </complexType>
> </element>
>
> Anne
>
Thanks a lot for your answer! I did resolve the matter by creating a small &
dirty typeMapping in the client-config.wsdd. I include it here in case anyone is
interested:
<typeMapping
xmlns:ns="http://www.w3.org/2001/XMLSchema"
qname="ns:anyType"
type="java:java.lang.String"
serializer="org.apache.axis.encoding.ser.SimpleSerializerFactory"
deserializer="org.apache.axis.encoding.ser.SimpleDeserializerFactory"
encodingStyle=""
/>
A real piece of "art", you may agree... The typeMapping maps the Fault element
(anyType) as a String. This approach seems to work, however. It's good to know
also about the WSDL-changing solution you provided. It does seem a lot more elegant.
--
Marko Sormunen, M.Sc.
Messenger: msormune@hotmail.com
HIS-research unit, Centek, Computing Centre
University of Kuopio
Re: Problem with custom Fault handling
Posted by Anne Thomas Manes <at...@gmail.com>.
You need to define a type for your noEchoTextProvided element. This definition:
<element name="noEchoTextProvided"/>
defaults to type="xsd:anyType", and therefore Axis is looking for a
deserializer. If you want to return an empty element, then you should
define it like this:
<element name="noEchoTextProvided">
<complexType>
<sequence/>
</complexType>
</element>
Anne
On 5/16/05, Marko Sormunen <Ma...@uku.fi> wrote:
>
> Hi,
>
> I've had a rather long time problem with custom Faults in Java Axis 1.2. The
> problem is properly handling a custom Fault in client. Here's the original WSDL
> describing the web service:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <definitions targetNamespace="urn:serapi:SOAPExample"
> xmlns="http://schemas.xmlsoap.org/wsdl/"
> xmlns:serapi="urn:serapi:SOAPExample"
> xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/"
> xmlns:xsd="http://www.w3.org/2001/XMLSchema">
> <types>
> <schema elementFormDefault="qualified"
> targetNamespace="urn:serapi:SOAPExample" xmlns="http://www.w3.org/2001/XMLSchema">
> <element name="echoText">
> <complexType>
> <sequence>
> <element name="text" type="xsd:string"/>
> </sequence>
> </complexType>
> </element>
>
> <element name="echoTextResponse">
> <complexType>
> <sequence>
> <element name="echoedText" type="xsd:string"/>
> </sequence>
> </complexType>
> </element>
>
> <element name="noEchoTextProvided"/>
> </schema>
> </types>
>
> <message name="echoTextRequestMessage">
> <part element="serapi:echoText" name="parameters"/>
> </message>
> <message name="echoTextResponseMessage">
> <part element="serapi:echoTextResponse" name="parameters"/>
> </message>
> <message name="noEchoTextProvided">
> <part element="serapi:noEchoTextProvided" name="fault"/>
> </message>
>
> <portType name="EchoServiceOperations">
> <operation name="echoText">
> <input message="serapi:echoTextRequestMessage"/>
> <output message="serapi:echoTextResponseMessage"/>
> <fault name="noEchoTextProvided" message="serapi:noEchoTextProvided"/>
> </operation>
> </portType>
>
> <binding name="EchoServiceBinding" type="serapi:EchoServiceOperations">
> <wsdlsoap:binding style="document"
> transport="http://schemas.xmlsoap.org/soap/http"/>
> <operation name="echoText">
> <wsdlsoap:operation soapAction="urn:serapi:SOAPExample#echoText"/>
> <input>
> <wsdlsoap:body use="literal"/>
> </input>
> <output>
> <wsdlsoap:body use="literal"/>
> </output>
> <fault name="noEchoTextProvided">
> <wsdlsoap:fault name="noEchoTextProvided" use="literal"/>
> </fault>
> </operation>
> </binding>
>
> This is pretty much WS-I Basic Profile 1.1 compliant stuff. The Fault element
> (noEchoTextProvided) is defined as an Element in the message instead of Type.
>
> When I run this through wsdl2java everything seems to be fine. But when I create
> a simple implementation for the service and throw a NoEchoTextProvided fault
> from there, the problems begin. Here's the SOAP message containing the Fault:
>
> <?xml version="1.0" encoding="utf-8"?><soapenv:Envelope
> xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
> xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
> <soapenv:Body>
> <soapenv:Fault>
> <faultcode>soapenv:Server.generalException</faultcode>
> <faultstring>Echoed text seems to be an empty value, which is not allowed.
> </faultstring>
> <detail>
> <ns1:noEchoTextProvided xmlns:ns1="urn:serapi:SOAPExample">No
> value</ns1:noEchoTextProvided>
> <ns2:exceptionName
> xmlns:ns2="http://xml.apache.org/axis/">org.serapi.SOAPExample.NoEchoTextProvided</ns2:exceptionName>
> <ns3:hostname xmlns:ns3="http://xml.apache.org/axis/">laivuri27</ns3:hostname>
> </detail>
> </soapenv:Fault>
> </soapenv:Body>
> </soapenv:Envelope>
>
> The SOAP message seems fine. But in the Axis client this always ends up in a
> NullPointerException:
>
> AxisFault
> faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException
> faultSubcode:
> faultString: java.lang.NullPointerException
> faultActor:
> faultNode:
> faultDetail:
> {http://xml.apache.org/axis/}stackTrace:java.lang.NullPointerException
> at org.apache.axis.client.Call.invokeEngine(Call.java:2797)
> at org.apache.axis.client.Call.invoke(Call.java:2748)
> at org.apache.axis.client.Call.invoke(Call.java:2424)
> at org.apache.axis.client.Call.invoke(Call.java:2347)
> at org.apache.axis.client.Call.invoke(Call.java:1804)
> at
> org.serapi.SOAPExample.EchoServiceBindingStub.echoText(EchoServiceBindingStub.java:168)
> at org.serapi.SOAPClient.EchoTextClient.<init>(EchoTextClient.java:15)
> at org.serapi.SOAPClient.EchoTextClient.main(EchoTextClient.java:24)
>
> {http://xml.apache.org/axis/}hostname:laivuri27
>
> java.lang.NullPointerException
> at org.apache.axis.AxisFault.makeFault(AxisFault.java:101)
> at org.apache.axis.client.Call.invoke(Call.java:2427)
> at org.apache.axis.client.Call.invoke(Call.java:2347)
> at org.apache.axis.client.Call.invoke(Call.java:1804)
> at
> org.serapi.SOAPExample.EchoServiceBindingStub.echoText(EchoServiceBindingStub.java:168)
> at org.serapi.SOAPClient.EchoTextClient.<init>(EchoTextClient.java:15)
> at org.serapi.SOAPClient.EchoTextClient.main(EchoTextClient.java:24)
> Caused by: java.lang.NullPointerException
> at org.apache.axis.client.Call.invokeEngine(Call.java:2797)
> at org.apache.axis.client.Call.invoke(Call.java:2748)
> at org.apache.axis.client.Call.invoke(Call.java:2424)
> ... 5 more
>
> It would seem that the client does not correctly deserialize the Fault element.
> If I use AxisFaults instead of a custom Fault class, everything is fine. Do I
> have to put something in the client-config.wsdd to properly deserialize the
> Fault or something similar?
>
> --
> Marko Sormunen, M.Sc.
> Messenger: msormune@hotmail.com
> HIS-research unit, Centek, Computing Centre
> University of Kuopio
>