axis-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <Eirik.W...@bravida.no>
Subject Catching the correct Exception in an Axis client when namespace-mapping is different than server. (WAS: RE: service specific exception - HOWTO?)
Date Fri, 26 Jul 2002 12:05:48 GMT

I have a problem with catching the correct Exception on my Axis client, I am just getting
exceptions of type AxisFault. The reason for this is probably that I change the package name
of the Exception on the server side, but not on the client side. Thus I am creating a name-mismatch
between the Exception in the server code and the Exception in the client code. Can this be
fixed? (I don't want to change the package names, the server-side classes generated by Axis
must be in another package-structure than the default.)

A more detailed explanation:

An Exception is thrown at an Axis service and sent to the client as e.g.

    <ns2:exceptionName xmlns:ns2="http://xml.apache.org/axis/">no.geomatikk.soap.axis.NoAccessException</ns2:exceptionName>

I have a problem with this, because when generating my server-side Axis code, I don't use
the default package names, I spesify to change some package names like this:

	java org.apache.axis.wsdl.WSDL2Java -v -s -d Application -f..\build\NStoPkg.properties ..\..\geomatikk.jar-addon\deploy\PoiAccess.wsdl

Where one of the entries in my file "..\build\NStoPkg.properties" is:

	http\://soap.geomatikk.no=no.geomatikk.soap.axis

When I am generating the client-side code, I am using the DEFAULT namespace-to-java package
mapping, so the Exception class generated on my client side (with wsdl2java) is of the type
no.geomatikk.soap.NoAccessException.

I am wondering if there is a way to change/map the exception name on the server side so that
it would (correctly) send

    <ns2:exceptionName xmlns:ns2="http://xml.apache.org/axis/">no.geomatikk.soap.NoAccessException</ns2:exceptionName>

Maby this should be done automatically, and is a bug in Axis?

Any help would be greatly appreciated!

Eirik Wahl
Bravida Geomatikk AS


-----Original Message-----
From: Robert Herold [mailto:herold@cotagesoft.com]
Sent: 24. juli 2002 18:56
To: axis-user@xml.apache.org
Cc: tomj@macromedia.com
Subject: RE: service specific exception - HOWTO?


Tom, thanks for your reply.  The exception class is available on the client
side, but it still is not getting thrown.

Does my exception have to extend RemoteException?  AxisFault?

To demonstrate that the class is available, I modifed the test code to
construct a dummy instance of the exception (and I also removed the message
from the exception class):

public class BobHExceptionTest
{
  public static void main(String[] args)
  {
    BobHException proveIt = new BobHException();
    try {
      BobH b = new BobHServiceLocator().getBobH();
      b.throwException();
    } catch (BobHException be) {
      System.out.println("got it");
      System.out.println("exception class name is " +
        be.getClass().getName());
    } catch (org.apache.axis.AxisFault af) {
      System.out.println("Hmmm, got AxisFault");
    } catch (Exception e) {
      System.out.println("Didn't get it");
      System.out.println("exception class name is " +
        e.getClass().getName());
    }
  }
}

-----Original Message-----
From: axis-user-return-5670-herold=cotagesoft.com@xml.apache.org
[mailto:axis-user-return-5670-herold=cotagesoft.com@xml.apache.org]On
Behalf Of Tom Jordahl
Sent: Wednesday, July 24, 2002 9:15 AM
To: 'axis-user@xml.apache.org'
Subject: RE: service specific exception - HOWTO?



Robert,

This should work as the exception class is getting passed in the
faultDetails:
 <ns2:exceptionName xmlns:ns2="http://xml.apache.org/axis/">
  com.cotagesoft.test.webservices.bobh.BobHException
 </ns2:exceptionName>

Do you have this class available on the client side?  If not, Axis will just
create an AxisFault instead of a fault of this class.

NOTE: We currently do not pass along the exception data ("psycho monkey").

--
Tom Jordahl
Macromedia


-----Original Message-----
From: Robert Herold [mailto:herold@cotagesoft.com]
Sent: Tuesday, July 23, 2002 7:20 PM
To: axis-user@xml.apache.org
Subject: service specific exception - HOWTO?


How do I make a service that throws a service-specific exception, and make a
java client that can catch that exception?

I wrote a very simple test case (see below).  The fault transmitted on the
wire seems to be OK (see response, captured by TCPMon, at the end of this
message), but the axis client code does not throw my service specific
exception - it only throws an AxisFault.

Has anyone been able to do this?  If so, how?


The details:

I am using Tomcat 4.0.4, Axis Beta 3 on Windows XP.  I compiled the
interface, then ran java2wsdl to get the wsdl, then wsdl2java to get the
client stub/service/servicelocator classes.

The service is very simple:

public interface BobH extends java.rmi.Remote {
  public void throwException()
    throws BobHException,java.rmi.RemoteException;
}

and

public class BobHSoapBindingImpl implements BobH {
  public void throwException() throws BobHException {
    throw new BobHException("psycho monkey");
  }
}

and

public class BobHException extends Exception {
  public BobHException (String msg) {
    super(msg);
  }
}

On the client side:

public class BobHExceptionTest
{
  public static void main(String[] args)
  {
    try {
      BobH b = new BobHServiceLocator().getBobH();
      b.throwException();
    } catch (BobHException be) {
      System.out.println("got it, msg is " + be.getMessage());
      System.out.println("exception class name is " +
        be.getClass().getName());
    } catch (Exception e) {
      System.out.println("Didn't get it");
      System.out.println("exception class name is " +
        e.getClass().getName());
    }
  }
}


Running this, I get:

- Mapping Exception to AxisFault
AxisFault
 faultCode: {http://xml.apache.org/axis/}Server.generalException
 faultString: psycho monkey
 faultActor: null
 faultDetail:
        exceptionName: com.cotagesoft.test.webservices.bobh.BobHException
        stackTrace: AxisFault
 faultCode: {http://xml.apache.org/axis/}Server.generalException
 faultString: psycho monkey
 faultActor: null
 faultDetail:
        exceptionName: com.cotagesoft.test.webservices.bobh.BobHException

psycho monkey
        at
com.cotagesoft.test.webservices.bobh.BobHSoapBindingImpl.throwExcepti
on(BobHSoapBindingImpl.java:87)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
        ### rest of stack trace omitted ###

psycho monkey
        at
org.apache.axis.message.SOAPFaultBuilder.endElement(SOAPFaultBuilder.
java:135)
        ### more omitted stack trace ###
        at org.apache.axis.client.Call.invoke(Call.java:1251)
        at
com.cotagesoft.test.webservices.bobh.BobHSoapBindingStub.throwExcepti
on(BobHSoapBindingStub.java:121)
        at
com.cotagesoft.test.webservices.bobh.BobHExceptionTest.main(BobHExcep
tionTest.java:27)
Didn't get it
exception class name is org.apache.axis.AxisFault



The generated WSDL is:

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions
targetNamespace="http://bobh.webservices.test.cotagesoft.com"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:apachesoap="http://xml.apache.org/xml-soap"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:intf="http://bobh.webservices.test.cotagesoft.com"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:impl="http://bobh.webservices.test.cotagesoft.com-impl"
xmlns="http://schemas.xmlsoap.org/wsdl/">
 <wsdl:types>
  <schema xmlns="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://bobh.webservices.test.cotagesoft.com">
   <import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
   <complexType name="BobHException">
    <sequence/>
   </complexType>
   <element name="BobHException" nillable="true" type="intf:BobHException"/>
  </schema>
 </wsdl:types>

   <wsdl:message name="throwExceptionRequest">

   </wsdl:message>

   <wsdl:message name="BobHException">

      <wsdl:part name="fault" type="intf:BobHException"/>

   </wsdl:message>

   <wsdl:message name="throwExceptionResponse">

   </wsdl:message>

   <wsdl:portType name="BobH">

      <wsdl:operation name="throwException">

         <wsdl:input name="throwExceptionRequest"
message="intf:throwExceptionRequest"/>

         <wsdl:output name="throwExceptionResponse"
message="intf:throwExceptionResponse"/>

         <wsdl:fault name="BobHException" message="intf:BobHException"/>

      </wsdl:operation>

   </wsdl:portType>

   <wsdl:binding name="BobHSoapBinding" type="intf:BobH">

      <wsdlsoap:binding style="rpc"
transport="http://schemas.xmlsoap.org/soap/http"/>

      <wsdl:operation name="throwException">

         <wsdlsoap:operation soapAction=""/>

         <wsdl:input name="throwExceptionRequest">

            <wsdlsoap:body use="encoded"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
namespace="http://bobh.webservices.test.cotagesoft.com"/>

         </wsdl:input>

         <wsdl:output name="throwExceptionResponse">

            <wsdlsoap:body use="encoded"
encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
namespace="http://bobh.webservices.test.cotagesoft.com"/>

         </wsdl:output>

      </wsdl:operation>

   </wsdl:binding>

   <wsdl:service name="BobHService">

      <wsdl:port name="BobH" binding="intf:BobHSoapBinding">

         <wsdlsoap:address
location="http://localhost:8080/bobh/services/BobH"/>

      </wsdl:port>

   </wsdl:service>

</wsdl:definitions>


The response, captured by TCPMon, is:

HTTP/1.1 500 Internal Server Error
Content-Type: text/xml; charset=utf-8
Connection: close
Date: Tue, 23 Jul 2002 22:54:56 GMT
Server: Apache Tomcat/4.0.4 (HTTP/1.1 Connector)

<?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
xmlns:ns1="http://xml.apache.org/axis/">ns1:Server.generalException</faultco
de>
   <faultstring>psycho monkey</faultstring>
   <detail>
    <ns2:exceptionName
xmlns:ns2="http://xml.apache.org/axis/">com.cotagesoft.test.webservices.bobh
.BobHException</ns2:exceptionName>
    <ns3:stackTrace xmlns:ns3="http://xml.apache.org/axis/">AxisFault&#xd;
 faultCode: {http://xml.apache.org/axis/}Server.generalException&#xd;
 faultString: psycho monkey&#xd;
 faultActor: null&#xd;
 faultDetail: &#xd;
	exceptionName: com.cotagesoft.test.webservices.bobh.BobHException&#xd;
&#xd;
psycho monkey&#xd;
	at
com.cotagesoft.test.webservices.bobh.BobHSoapBindingImpl.throwException(BobH
SoapBindingImpl.java:87)&#xd;
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)&#xd;
	### more omitted stack trace ###	at
org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1125
)&#xd;
	at java.lang.Thread.run(Thread.java:536)&#xd;
</ns3:stackTrace>
   </detail>
  </soapenv:Fault>
 </soapenv:Body>
</soapenv:Envelope>

----------
Robert Herold
Cotagesoft, Inc.
650 474 9013 x808



Mime
View raw message