In general, you cannot send arbitrary exceptions to remote clients, since Axis (or most other client/server communication protocols) has no idea how to serialize/deserialize an arbitrary exception that you might have created so that it can be transmitted to a remote client. You should probably only be sending subclasses of RemoteException, and probably should include very limited, if any, additional information in the exception class itself. I suggest that you make sure that your TestException extends RemoteException, not just Exception.
I am not sure how this works if a RemoteException has a 'cause' field which is not a RemoteException. I am not an expert in what RemoteException is capable of, but I think I know enough to understand that what you are trying to do (throw an exception that is not derived from RemoteException from server to client) is not, in general, possible. Derek > -----Original Message----- > From: Eric Borisow [mailto:[EMAIL PROTECTED] > Sent: Thursday, August 03, 2006 6:33 AM > To: [email protected] > Subject: Re: Question about handling custom exceptions in Axis 1.3 > > > I tried using this line: > > TestException myEx = (TestException) gbe; > > But, it won't even compile. It gives me the error: > Cannot cast from RemoteException to TestException. Is > there something I am missing? > > Thanks, > Eric > > --- xu cai <[EMAIL PROTECTED]> wrote: > > > AxisFault extends from RemoteException, I think you > > can simply cast > > RemoteException to your customized exception. hope > > it works. > > > > -jeff > > > > > > On 8/3/06, Eric Borisow <[EMAIL PROTECTED]> wrote: > > > > > > Hi, > > > > > > I have been trying to piece together the best way > > to > > > generate and consume a custom exception with Axis > > > 1_3. I have created a test with an interface, a > > > service implementation of the interface and an > > > Exception. > > > > > > When I generate the wsdl using java2wsdl, the wsdl > > > contains a reference to the TestException class as > > a > > > fault of the service. When I call the service, it > > > returns an AxisFault containing information about > > the > > > fault. My question is... what can I do with that > RemoteException to > > > get my exception out of it? I > > have > > > seen some other articles where it seems you should > > > just be able to catch your custom exception but > > all I > > > ever get is RemoteException which I then have to > > > convert to an AxisFault but I still don't get > > access > > > to my exception per se. See below for my code. > > > > > > Thanks, > > > Eric > > > > > > Interface: > > > > > > public interface IServiceTest > > > { > > > public void throwError() throws TestException; > > > } > > > > > > Service implementation: > > > > > > public class Service implements IServiceTest > > > { > > > > > > public void throwError() throws TestException > > > { > > > throw new TestException(); > > > } > > > > > > } > > > > > > Exception: > > > > > > import java.io.Serializable; > > > > > > public class TestException extends Exception > > > implements Serializable > > > { > > > private String someError; > > > > > > public TestException() {} > > > > > > public TestException(String someError) > > > { > > > this.someError = someError; > > > } > > > > > > public String getSomeError() > > > { > > > return someError; > > > } > > > > > > public void setSomeError(String someError) > > > { > > > this.someError = someError; > > > } > > > > > > > > > } > > > > > > wsdl: > > > > > > <?xml version="1.0" encoding="UTF-8"?> > > > <wsdl:definitions > > > targetNamespace="http://services.spx.com" > > > xmlns:impl="http://services.spx.com" > > > xmlns:intf="http://services.spx.com" > > > xmlns:apachesoap="http://xml.apache.org/xml-soap" > > > > > > xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" > > > > > > xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" > > > xmlns:xsd="http://www.w3.org/2001/XMLSchema" > > > xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"> > > > <!--WSDL created by Apache Axis version: 1.3 > > > Built on Oct 05, 2005 (05:23:37 EDT)--> > > > <wsdl:types> > > > <schema xmlns="http://www.w3.org/2001/XMLSchema" > > > targetNamespace="http://services.spx.com"> > > > <import > > > > > > namespace="http://schemas.xmlsoap.org/soap/encoding/"/> > > > <complexType name="TestException"> > > > <sequence> > > > <element name="someError" nillable="true" type="xsd:string"/> > > > </sequence> > > > </complexType> > > > </schema> > > > </wsdl:types> > > > <wsdl:message name="TestException"> > > > <wsdl:part name="fault" > > > type="impl:TestException"/> > > > </wsdl:message> > > > <wsdl:message name="throwErrorRequest"> > > > </wsdl:message> > > > <wsdl:message name="throwErrorResponse"> > > > </wsdl:message> > > > <wsdl:portType name="Service"> > > > <wsdl:operation name="throwError"> > > > <wsdl:input name="throwErrorRequest" > > > message="impl:throwErrorRequest"/> > > > <wsdl:output name="throwErrorResponse" > > > message="impl:throwErrorResponse"/> > > > <wsdl:fault name="TestException" > > > message="impl:TestException"/> > > > </wsdl:operation> > > > </wsdl:portType> > > > <wsdl:binding > > name="axisexceptiontestSoapBinding" > > > type="impl:Service"> > > > <wsdlsoap:binding style="rpc" > > > transport="http://schemas.xmlsoap.org/soap/http"/> > > > <wsdl:operation name="throwError"> > > > <wsdlsoap:operation soapAction=""/> > > > <wsdl:input name="throwErrorRequest"> > > > <wsdlsoap:body use="encoded" > > > > > > encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" > > > namespace="http://services.spx.com"/> > > > </wsdl:input> > > > <wsdl:output name="throwErrorResponse"> > > > <wsdlsoap:body use="encoded" > > > > > > encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" > > > namespace="http://services.spx.com"/> > > > </wsdl:output> > > > <wsdl:fault name="TestException"> > > > <wsdlsoap:fault name="TestException" use="encoded" > > > > > > encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" > > > namespace="http://services.spx.com"/> > > > </wsdl:fault> > > > </wsdl:operation> > > > </wsdl:binding> > > > <wsdl:service name="ServiceService"> > > > <wsdl:port name="axisexceptiontest" > > > binding="impl:axisexceptiontestSoapBinding"> > > > <wsdlsoap:address > > > location=" > > > > > > http://localhost:7080/axisexceptiontest/services/axisexceptiontest"/> > > > </wsdl:port> > > > </wsdl:service> > > > </wsdl:definitions> > > > > > > And finally, the text client code: > > > > > > import java.io.StringWriter; > > > import java.rmi.RemoteException; > > > > > > import javax.xml.namespace.QName; > > > import javax.xml.rpc.soap.SOAPFaultException; > > > > > > import org.apache.axis.AxisFault; > > > import org.apache.axis.client.Call; > > > import org.apache.axis.client.Service; > > > import org.apache.xml.serialize.OutputFormat; > > > import org.apache.xml.serialize.XMLSerializer; > > > import org.w3c.dom.Document; > > > import org.w3c.dom.Element; > > > > > > public class ManualServiceTest > > > { > > > > > > /** > > > * @param args > > > */ > > > public static void main(String[] args) > > > { > > > try > > > { > > > Service service = new Service(); > > > === message truncated === > > > __________________________________________________ > Do You Yahoo!? > Tired of spam? Yahoo! Mail has the best spam protection around > http://mail.yahoo.com > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
