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 David Brooks <da...@ombiel.com> on 2012/01/11 11:30:42 UTC

Improving faultstring messages for type restrictions

Hi,

I'm a relative newcomer to Axis2 and this is my first encounter with
this list. I'm pretty sure this is a question you've had
time-and-again, although I've had no joy in the list archives - I
probably don't know the correct terminology to frame my question.

I am using Axis2 to support web-services.  I define these through
WSDL/XSD and use wsdl2java to generate Java classes (ADBs?) for
request/response types, then write web-service code in Java to process
them.  I'm trying to add some restrictions to my XSDs and have the
ADBs process them, but I'm not getting quite the behaviour I expect.

I've tried adding a couple of type restrictions to my web-services:
[1] A Yes/No type that is a string with an enumeration restriction;
[2] A star-rating type that is a number from 1-5 inclusive.

Here's the XSD snippet for the latter:

	<xsd:simpleType name="Rating">
		<xsd:restriction base="xsd:int">
			<xsd:minInclusive value="1" />
			<xsd:maxInclusive value="5" />
		</xsd:restriction>
	</xsd:simpleType>

Using soapUI I can test that my services work for correct values, and
indeed they do.  However, when I enter a value that violates one of my
restrictions I get a simple axis fault message with the following:

   <soapenv:Fault
      <faultcode>soapenv:Server</faultcode>
      <faultstring>unknown</faultstring>
   </soapenv:Fault>

What I'd like to do is make the "unknown" part more meaningful in
light of these restrictions, similar to its behaviour if I omit a
required element:

   <soapenv:Fault>
      <faultcode>soapenv:Server</faultcode
      <faultstring>org.apache.axis2.databinding.ADBException:
Unexpected subelement thisIsRequired</faultstring>
   </soapenv:Fault>

For instance, entering 6 for a star rating might give:

   <soapenv:Fault>
      <faultcode>soapenv:Server</faultcode
      <faultstring>WhateverException: 1 <= "rating" <= 6 violated:
found 6</faultstring>
   </soapenv:Fault>

I realise I can configure axis2.xml to include stacktraces, but they
are of limited use because the exceptions generated for these
restrictions (IllegalArgumentException for YesNo; RuntimeException for
Rating) don't seem to have meaningful error messages.

Is it possible to improve these exception messages and/or the
faultstring messages for restrictions? (... without doing the
validation manually in Java)

Many thanks,
David
--
David Brooks

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@axis.apache.org
For additional commands, e-mail: java-user-help@axis.apache.org


Re: Improving faultstring messages for type restrictions

Posted by David Brooks <da...@ombiel.com>.
Hi Sagara,

On 11 January 2012 11:35, Sagara Gunathunga <sa...@gmail.com> wrote:
> I think your point is valid but I'm not sure whether we can improve fault
> strings up to your expectation.  BTW we can improve this up to some level
> instead of sending "unknown". Please fill a JIRA issue for this and will try
> to target next major release.

I'll do just that.

Thanks for the response,
D
-- 
David Brooks
http://www.ombiel.com
Office: 01902 837451

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@axis.apache.org
For additional commands, e-mail: java-user-help@axis.apache.org


Re: Improving faultstring messages for type restrictions

Posted by Sagara Gunathunga <sa...@gmail.com>.
Hi David,

I think your point is valid but I'm not sure whether we can improve fault
strings up to your expectation.  BTW we can improve this up to some level
instead of sending "unknown". Please fill a JIRA issue for this and will
try to target next major release.

Thanks !

On Wed, Jan 11, 2012 at 4:00 PM, David Brooks <da...@ombiel.com>wrote:

> Hi,
>
> I'm a relative newcomer to Axis2 and this is my first encounter with
> this list. I'm pretty sure this is a question you've had
> time-and-again, although I've had no joy in the list archives - I
> probably don't know the correct terminology to frame my question.
>
> I am using Axis2 to support web-services.  I define these through
> WSDL/XSD and use wsdl2java to generate Java classes (ADBs?) for
> request/response types, then write web-service code in Java to process
> them.  I'm trying to add some restrictions to my XSDs and have the
> ADBs process them, but I'm not getting quite the behaviour I expect.
>
> I've tried adding a couple of type restrictions to my web-services:
> [1] A Yes/No type that is a string with an enumeration restriction;
> [2] A star-rating type that is a number from 1-5 inclusive.
>
> Here's the XSD snippet for the latter:
>
>        <xsd:simpleType name="Rating">
>                <xsd:restriction base="xsd:int">
>                        <xsd:minInclusive value="1" />
>                        <xsd:maxInclusive value="5" />
>                </xsd:restriction>
>        </xsd:simpleType>
>
> Using soapUI I can test that my services work for correct values, and
> indeed they do.  However, when I enter a value that violates one of my
> restrictions I get a simple axis fault message with the following:
>
>   <soapenv:Fault
>      <faultcode>soapenv:Server</faultcode>
>      <faultstring>unknown</faultstring>
>   </soapenv:Fault>
>
> What I'd like to do is make the "unknown" part more meaningful in
> light of these restrictions, similar to its behaviour if I omit a
> required element:
>
>   <soapenv:Fault>
>      <faultcode>soapenv:Server</faultcode
>      <faultstring>org.apache.axis2.databinding.ADBException:
> Unexpected subelement thisIsRequired</faultstring>
>   </soapenv:Fault>
>
> For instance, entering 6 for a star rating might give:
>
>   <soapenv:Fault>
>      <faultcode>soapenv:Server</faultcode
>      <faultstring>WhateverException: 1 <= "rating" <= 6 violated:
> found 6</faultstring>
>   </soapenv:Fault>
>
> I realise I can configure axis2.xml to include stacktraces, but they
> are of limited use because the exceptions generated for these
> restrictions (IllegalArgumentException for YesNo; RuntimeException for
> Rating) don't seem to have meaningful error messages.
>
> Is it possible to improve these exception messages and/or the
> faultstring messages for restrictions? (... without doing the
> validation manually in Java)
>
> Many thanks,
> David
> --
> David Brooks
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@axis.apache.org
> For additional commands, e-mail: java-user-help@axis.apache.org
>
>


-- 
Sagara Gunathunga

Blog      - http://ssagara.blogspot.com
Web      - http://people.apache.org/~sagara/
LinkedIn - http://www.linkedin.com/in/ssagara

Re: Improving faultstring messages for type restrictions

Posted by David Brooks <da...@ombiel.com>.
Hi Sven,

I considered modifying the ADBs, but we regenerate ours on each build.

We're already using the basic pattern of a custom fault type for
user-level validation (with localisation), but I wanted to keep this
faultstring mechanism separate, for low-level API faults.  I guess I
could just add a second fault type, however...

Thanks for the suggestion,
D
-- 
David Brooks
http://www.ombiel.com
Office: 01902 837451

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@axis.apache.org
For additional commands, e-mail: java-user-help@axis.apache.org


RE: Improving faultstring messages for type restrictions

Posted by Schlarb Sven <sv...@onb.ac.at>.
Hi David,

 
that is something I was running into as well.

 
I did not have a quick solution for that and therefore did what you should not do: I hacked the generated code. I hope others have a more sophisticated and Axis2-like solution to that.

 
In the WSDL, I created a WrongArgumentFaultType:

 
    <wsdl:types>
        <xsd:schema ...>

        ...

            <xsd:complexType name="WrongArgumentFaultType">
                <xsd:sequence>
                    <xsd:element minOccurs="0" maxOccurs="1" name="argument" type="xsd:string" />
                </xsd:sequence>
            </xsd:complexType>
            <xsd:element name="WrongArgumentFault" type="tns:WrongArgumentFaultType" />

        ...
        </xsd:schema>
    </wsdl:types>

 
a fault message:


    <wsdl:message name="WrongArgumentFaultMessage">
        <wsdl:part name="fault" element="tns:WrongArgumentFault" />
    </wsdl:message>

 
an operation:

 
         <wsdl:operation name="someOperation">
            <wsdl:input message="tns:Request" wsaw:Action="someOperation">
               ..
            </wsdl:input>
            <wsdl:output message="tns:Response"
               ...
            </wsdl:output>
            <wsdl:fault message="tns:WrongArgumentFaultMessage" name="WrongArgumentException"/>
        </wsdl:operation>

 
and in a binding:

 
   <wsdl:binding name="SomeBinding"
        type="tns:SomeType">

         <wsdl:operation name="someOperation">
            <soap:operation soapAction="someOperation" style="document" />
            <wsdl:input>
                <soap:body use="literal" />
            </wsdl:input>
            <wsdl:output>
                <soap:body use="literal" />
            </wsdl:output>
            <wsdl:fault name="WrongArgumentException">
                <soap:fault name="WrongArgumentException" use="literal"/>
            </wsdl:fault>
        </wsdl:operation>
    </wsdl:binding>

 
So Axis2 provides a way of mapping an exeption to a SOAP fault, but my problem was that the generated code for the kind of XSD types you describe throws an IllegalArgumentException, and I was not able to map that exception to a customized SOAP fault message. I don't know if this is generally possible, I would be keen on knowing if one can generally do this kind of mapping.

 
So what I did as a quick hack was to modify the generated code and let it throw my custom exception (throw new WrongArgumentFaultMessage(message)) instead of the generated IllegalArgumentException. Axis2 always exits gently and wraps the IllegalArgumentException into a generic AxisFault and, as you report, for me as well it was not possible to see at the client what actually goes wrong. Using the hack I was at least able to give a SOAP fault message with concrete information about the error back.

 
I hope this helps you, I am also interested in knowing what is the Axis2-way of addressing this.

 
Best regards,

 
Sven

-----Original message-----
To:java-user@axis.apache.org; 
From:David Brooks <da...@ombiel.com>
Sent:Wed 11-01-2012 11:31
Subject:Improving faultstring messages for type restrictions
Hi,

I'm a relative newcomer to Axis2 and this is my first encounter with
this list. I'm pretty sure this is a question you've had
time-and-again, although I've had no joy in the list archives - I
probably don't know the correct terminology to frame my question.

I am using Axis2 to support web-services.  I define these through
WSDL/XSD and use wsdl2java to generate Java classes (ADBs?) for
request/response types, then write web-service code in Java to process
them.  I'm trying to add some restrictions to my XSDs and have the
ADBs process them, but I'm not getting quite the behaviour I expect.

I've tried adding a couple of type restrictions to my web-services:
[1] A Yes/No type that is a string with an enumeration restriction;
[2] A star-rating type that is a number from 1-5 inclusive.

Here's the XSD snippet for the latter:

<xsd:simpleType name="Rating">
<xsd:restriction base="xsd:int">
<xsd:minInclusive value="1" />
<xsd:maxInclusive value="5" />
</xsd:restriction>
</xsd:simpleType>

Using soapUI I can test that my services work for correct values, and
indeed they do.  However, when I enter a value that violates one of my
restrictions I get a simple axis fault message with the following:

   <soapenv:Fault
      <faultcode>soapenv:Server</faultcode>
      <faultstring>unknown</faultstring>
   </soapenv:Fault>

What I'd like to do is make the "unknown" part more meaningful in
light of these restrictions, similar to its behaviour if I omit a
required element:

   <soapenv:Fault>
      <faultcode>soapenv:Server</faultcode
      <faultstring>org.apache.axis2.databinding.ADBException:
Unexpected subelement thisIsRequired</faultstring>
   </soapenv:Fault>

For instance, entering 6 for a star rating might give:

   <soapenv:Fault>
      <faultcode>soapenv:Server</faultcode
      <faultstring>WhateverException: 1 <= "rating" <= 6 violated:
found 6</faultstring>
   </soapenv:Fault>

I realise I can configure axis2.xml to include stacktraces, but they
are of limited use because the exceptions generated for these
restrictions (IllegalArgumentException for YesNo; RuntimeException for
Rating) don't seem to have meaningful error messages.

Is it possible to improve these exception messages and/or the
faultstring messages for restrictions? (... without doing the
validation manually in Java)

Many thanks,
David
--
David Brooks

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@axis.apache.org
For additional commands, e-mail: java-user-help@axis.apache.org