Hi ! I'm trying to set up a XFire web service that throws a checked exception/soap fault if an error occurs. On the other side I'm trying to call it using a XFire dynamic client built upon the service's interface. Calling this service works fine, but whenever the exception is thrown, on client side it is wrapped inside a XFireRuntimeException. I tried using different methods to describe the service (with or without annotations), different styles (rpc, document, wrapped) even subclassing XFireFault did not solve the problem.
Using the sample case below, calling this web service prints out the following
stack trace.
----
Exception in thread "main" org.codehaus.xfire.XFireRuntimeException: Could not
invoke service.. Nested exception is org.codehaus.xfire.fault.XFireFault: 0 is
not a valid amount
org.codehaus.xfire.fault.XFireFault: 0 is not a valid amount
at
org.codehaus.xfire.fault.Soap11FaultSerializer.readMessage(Soap11FaultSerializer.java:31)
at
org.codehaus.xfire.fault.SoapFaultSerializer.readMessage(SoapFaultSerializer.java:28)
at
org.codehaus.xfire.soap.handler.ReadHeadersHandler.checkForFault(ReadHeadersHandler.java:111)
at
org.codehaus.xfire.soap.handler.ReadHeadersHandler.invoke(ReadHeadersHandler.java:67)
at
org.codehaus.xfire.handler.HandlerPipeline.invoke(HandlerPipeline.java:131)
at org.codehaus.xfire.client.Client.onReceive(Client.java:382)
at
org.codehaus.xfire.transport.http.HttpChannel.sendViaClient(HttpChannel.java:139)
at
org.codehaus.xfire.transport.http.HttpChannel.send(HttpChannel.java:48)
at
org.codehaus.xfire.handler.OutMessageSender.invoke(OutMessageSender.java:26)
at
org.codehaus.xfire.handler.HandlerPipeline.invoke(HandlerPipeline.java:131)
at org.codehaus.xfire.client.Invocation.invoke(Invocation.java:75)
at org.codehaus.xfire.client.Client.invoke(Client.java:335)
at
org.codehaus.xfire.client.XFireProxy.handleRequest(XFireProxy.java:77)
at org.codehaus.xfire.client.XFireProxy.invoke(XFireProxy.java:57)
at $Proxy0.buyShares(Unknown Source)
at
sample.xfireexceptions.ExceptionWSClient.main(ExceptionWSClient.java:20)
----
Do you have any hints, how to write a client / server that actually throws the
defined exception on client side, if there's an error ?
Thanks for your help.
Kind regards,
Mirko
--
Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen!
Ideal für Modem und ISDN: http://www.gmx.net/de/go/smartsurfer
package sample.xfireexceptions;
public interface ExceptionTestWS
{
public abstract String buyShares(int amount) throws InvalidAmountException;
}
package sample.xfireexceptions;
public class ExceptionTestWSDefImpl implements ExceptionTestWS
{
public String buyShares(int amount) throws InvalidAmountException
{
if (amount<1)
{
throw new InvalidAmountException("0 is not a valid amount");
}
return "You bought "+amount+" shares.";
}
}
package sample.xfireexceptions;
public class InvalidAmountException extends Exception
{
public InvalidAmountException()
{
super();
}
public InvalidAmountException(String message, Throwable cause)
{
super(message, cause);
}
public InvalidAmountException(String message)
{
super(message);
}
public InvalidAmountException(Throwable cause)
{
super(cause);
}
}
<beans xmlns="http://xfire.codehaus.org/config/1.0"> <service> <name>ExceptionTestWS</name> <namespace>http://xfireexceptions.sample/webservices</namespace> <serviceClass>sample.xfireexceptions.ExceptionTestWS</serviceClass> <implementationClass>sample.xfireexceptions.ExceptionTestWSDefImpl</implementationClass> </service> </beans>
package sample.xfireexceptions;
import java.net.MalformedURLException;
import org.apache.log4j.BasicConfigurator;
import org.codehaus.xfire.client.XFireProxyFactory;
import org.codehaus.xfire.service.Service;
import org.codehaus.xfire.service.binding.ObjectServiceFactory;
public class ExceptionWSClient
{
public static void main(String[] args) throws MalformedURLException, InvalidAmountException
{
BasicConfigurator.configure();
Service model = new ObjectServiceFactory().create(ExceptionTestWS.class);
ExceptionTestWS testws = (ExceptionTestWS)
new XFireProxyFactory().create(model, "http://localhost:8080/ffo_wstest/services/ExceptionTestWS");
System.out.println(testws.buyShares(0));
}
}
clientlog.txt
Description: Binary data
============== Listen Port: 9125 Target Host: 127.0.0.1 Target Port: 8080 ==== Request ==== POST http://localhost:8080/ffo_wstest/services/ExceptionTestWS HTTP/1.1 SOAPAction: "" Content-Type: text/xml; charset=UTF-8 User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; XFire Client +http://xfire.codehaus.org) Host: localhost:8080 Proxy-Connection: Keep-Alive Expect: 100-continue Content-Length: 319 <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <soap:Body> <buyShares xmlns="http://xfireexceptions.sample"> <in0 xmlns="http://xfireexceptions.sample">0</in0> </buyShares> </soap:Body></soap:Envelope>==== Response ==== HTTP/1.1 100 Continue HTTP/1.1 500 Internal Server Error Server: Apache-Coyote/1.1 Content-Type: text/xml;charset=UTF-8 Transfer-Encoding: chunked Date: Mon, 18 Dec 2006 16:30:25 GMT Connection: close 19a <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <soap:Body> <soap:Fault> <faultcode>soap:Server</faultcode> <faultstring>0 is not a valid amount</faultstring> <detail> <InvalidAmountException xmlns="http://xfireexceptions.sample/webservices" /> </detail> </soap:Fault> </soap:Body></soap:Envelope> 0 ==============
---------------------------------------------------------------------
To unsubscribe from this list please visit:
http://xircles.codehaus.org/manage_email
