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 Olivier Gauwin <ga...@campus.dtrd.de> on 2003/01/22 16:47:05 UTC

user-defined Exceptions

Hi,

I have a WSDL file with an exception defined as a complexType. A message 
based on this exception is also defined, and used in a <fault 
message=...> field of an operation.

I try to implement the server. I've already read this thread : 
http://marc.theaimsgroup.com/?l=axis-user&m=103712254801803&w=2 but the 
conclusion is not clear... If I throw my exception in the server code, 
then an AxisFault is created, and the client receives a 
Server.userException, not my Exception (and its fields...) :

<soapenv:Body>
 <soapenv:Fault>
  <faultcode>soapenv:Server.userException</faultcode>
  <faultstring>MyExceptions.BadRecord</faultstring>
  <detail>
         ...

Is there an easy way to do that ??
(I've tried with Axis1.0 and the CVS sources too).

Thanks a lot,
Olivier


Re: user-defined Exceptions

Posted by Steve Loughran <st...@iseran.com>.
----- Original Message -----
From: "Olivier Gauwin" <ga...@campus.dtrd.de>
To: <ax...@xml.apache.org>
Sent: Wednesday, January 29, 2003 00:56
Subject: Re: user-defined Exceptions



> >
> Thanks, Steve, but I still have a problem...
>
> I've tried this (with Axis CVS) :
>           AxisFault af = new AxisFault(code, faultString, actor, null);
>           af.addFaultDetail(new QName(Constants.NS_URI_AXIS, "why"),
e.why);
>           throw af;
>
> It compiles, but when I call it, it raises this exception :
>
> java.lang.reflect.InvocationTargetException
>         at org.apache.axis.AxisFault.makeFault(AxisFault.java:127)
>         (...)
>         at java.lang.Thread.run(Thread.java:536)
> Caused by: java.lang.reflect.InvocationTargetException
>         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>          (...)
>         at
> org.apache.axis.providers.java.JavaProvider.invoke(JavaProvider.java:332)
>         ... 38 more
> Caused by: java.lang.NoSuchMethodError:
>
org.apache.axis.AxisFault.addFaultDetail(Ljavax/xml/namespace/QName;Ljava/la
ng/String;)V
>         at ProxyExceptions.bar(ProxyExceptions.java:191)
>         ... 45 more
>
> I think it's not a classpath problem, because it compiles... I don't
> know if the problem comes from me or from Axis (have you already tested
> this method ?).

If something compiles but at run time fails with a no such method then there
is a diff between what you compiled with and what you run with.

conclusion: there is >1 copy of axis.jar in your system. Have happyaxis.jsp
tell you where axis is being loaded from

>
> And another point :
> With this "addFaultDetail" method, it seems impossible to use a tree for
> the detail elements :
> <detail>
>    <why>
>         <reason>Because it's out of bound</reason>
>     </why>
> </detail>

You can still add elements you create yourself


Re: user-defined Exceptions

Posted by Olivier Gauwin <ga...@campus.dtrd.de>.
Steve Loughran wrote:

>>I've also tried to use child nodes for "why" and it works. The only
>>thing is that I would like to have :
>>    <why>Just to test BadRecord</why>
>>instead of :
>>    <why value="Just to test BadRecord"/>
>>but I can't find a way to do that (I've tried with setUserObject and
>>setNodeValue but it doesn't work).
>>    
>>
>
>in CVS_HEAD, AxisFault has a method to take a Qname "foo:mydetail" and a
>string "not enough data" and create an element <foo:mydetail>not enough
>data</foo:mydetail>, then add it to the detail list. If you cant use axis1.1
>you can always steal the code and use it in your axis1.0 service. There is
>also some code to look up an element in the fault detail given the qname,
>which is kind of useful too.
>  
>
Thanks, Steve, but I still have a problem...

I've tried this (with Axis CVS) :
          AxisFault af = new AxisFault(code, faultString, actor, null);
          af.addFaultDetail(new QName(Constants.NS_URI_AXIS, "why"), e.why);
          throw af;

It compiles, but when I call it, it raises this exception :

java.lang.reflect.InvocationTargetException
        at org.apache.axis.AxisFault.makeFault(AxisFault.java:127)
        (...)
        at java.lang.Thread.run(Thread.java:536)
Caused by: java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         (...)
        at 
org.apache.axis.providers.java.JavaProvider.invoke(JavaProvider.java:332)
        ... 38 more
Caused by: java.lang.NoSuchMethodError: 
org.apache.axis.AxisFault.addFaultDetail(Ljavax/xml/namespace/QName;Ljava/lang/String;)V
        at ProxyExceptions.bar(ProxyExceptions.java:191)
        ... 45 more

I think it's not a classpath problem, because it compiles... I don't 
know if the problem comes from me or from Axis (have you already tested 
this method ?).

And another point :
With this "addFaultDetail" method, it seems impossible to use a tree for 
the detail elements :
<detail>
   <why>
        <reason>Because it's out of bound</reason>
    </why>
</detail>

Thanks,
Olivier

Re: user-defined Exceptions

Posted by Steve Loughran <st...@iseran.com>.
----- Original Message -----
From: "Olivier Gauwin" <ga...@campus.dtrd.de>
To: <ax...@xml.apache.org>
Sent: Friday, January 24, 2003 07:01
Subject: Re: user-defined Exceptions


> I've found the beginning of a solution for this problem, but I still
> have questions.
>
> Now my server code looks like :
>
>       try{
>            ...
>       } catch (MyException e) {
>       String code = "Server";
>       String faultString = "The following exception has been raised by
> the server : " + e.getClass().getName();
>       String actor = "Server";
>
>       IIOMetadataNode[] elements = new IIOMetadataNode[1];
>       IIOMetadataNode element1 = new IIOMetadataNode("why");
>       element1.setAttribute("value", e.why);
>       elements[0] = element1;
>       throw new org.apache.axis.AxisFault(code, faultString, actor,
> elements);
>       }
>

> I've also tried to use child nodes for "why" and it works. The only
> thing is that I would like to have :
>     <why>Just to test BadRecord</why>
> instead of :
>     <why value="Just to test BadRecord"/>
> but I can't find a way to do that (I've tried with setUserObject and
> setNodeValue but it doesn't work).

in CVS_HEAD, AxisFault has a method to take a Qname "foo:mydetail" and a
string "not enough data" and create an element <foo:mydetail>not enough
data</foo:mydetail>, then add it to the detail list. If you cant use axis1.1
you can always steal the code and use it in your axis1.0 service. There is
also some code to look up an element in the fault detail given the qname,
which is kind of useful too.


Re: user-defined Exceptions

Posted by Olivier Gauwin <ga...@campus.dtrd.de>.
I've found the beginning of a solution for this problem, but I still 
have questions.

Now my server code looks like :

      try{
           ...
      } catch (MyException e) {
      String code = "Server";
      String faultString = "The following exception has been raised by 
the server : " + e.getClass().getName();
      String actor = "Server";

      IIOMetadataNode[] elements = new IIOMetadataNode[1];
      IIOMetadataNode element1 = new IIOMetadataNode("why");
      element1.setAttribute("value", e.why);
      elements[0] = element1;
      throw new org.apache.axis.AxisFault(code, faultString, actor, 
elements);
      }

The SOAP message I receive is :

 <soapenv:Body>
  <soapenv:Fault>
   <faultcode xmlns:ns1="http://xml.apache.org/axis/">ns1:Server</faultcode>
   <faultstring>The following exception has been raised by the server : 
MyException</faultstring>
   <faultactor>Server</faultactor>
   <detail>
    <why value="Just to test MyException"/>
   </detail>
  </soapenv:Fault>
 </soapenv:Body>

I've also tried to use child nodes for "why" and it works. The only 
thing is that I would like to have :
    <why>Just to test BadRecord</why>
instead of :
    <why value="Just to test BadRecord"/>
but I can't find a way to do that (I've tried with setUserObject and 
setNodeValue but it doesn't work).

So it works quite well if the exception has simple fields (here "e.why" 
is a String).
I think that if the exception contains a "complex-type" field (arrays, 
enumeration...), we have to convert this attribute of the exception to 
an Element[]. Or is there a better way to do that ??

Thanks,
Olivier


Olivier Gauwin wrote:

> Hi,
>
> I have a WSDL file with an exception defined as a complexType. A 
> message based on this exception is also defined, and used in a <fault 
> message=...> field of an operation.
>
> I try to implement the server. I've already read this thread : 
> http://marc.theaimsgroup.com/?l=axis-user&m=103712254801803&w=2 but 
> the conclusion is not clear... If I throw my exception in the server 
> code, then an AxisFault is created, and the client receives a 
> Server.userException, not my Exception (and its fields...) :
>
> <soapenv:Body>
> <soapenv:Fault>
>  <faultcode>soapenv:Server.userException</faultcode>
>  <faultstring>MyExceptions.BadRecord</faultstring>
>  <detail>
>         ...
>
> Is there an easy way to do that ??
> (I've tried with Axis1.0 and the CVS sources too).
>
> Thanks a lot,
> Olivier
>
>
>