After many hours, I finally traced my problem to an apparent bug.
(Workaround for the bug at the end.) The bug looks a lot like 1277 in Jira, which was a blocker and resolved for 1.0 (http://issues.apache.org/jira/browse/AXIS2-1277). Before I add a bug report, I would appreciate it if someone out there could reproduce what's below as a sanity check. It's about 10 lines added to one of the samples. Here's the story: My POJO-style client wasn't getting exceptions from its POJO-style service. So I went back to the samples/pojo example, and threw an exception from a method. The client got it. Hmm. I just couldn't figure out what the difference was between my code and the sample. Then I realized that my methods return void. So I added this to AddressBookService.java in samples/pojo, a method returning void, then a second returning String: public void test1(String s) throws Exception { throw new Exception("test1"); } public String test2(String s) throws Exception { throw new Exception("test2"); } And this to AddressBookADBClient.java: Test1 test1 = new Test1(); test1.setParam0("foo"); stub.test1(test1); Test2 test2 = new Test2(); test2.setParam0("bar"); stub.test2(test2); Here's a snippet from the server-side log: Apr 14, 2007 10:55:28 AM org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver invokeBusinessLogic SEVERE: test1 java.lang.reflect.InvocationTargetException Caused by: java.lang.Exception: test1 at sample.addressbook.service.AddressBookService.test1(Unknown Source) ... 35 more Apr 14, 2007 10:55:29 AM org.apache.axis2.rpc.receivers.RPCMessageReceiver invokeBusinessLogic SEVERE: test2 java.lang.reflect.InvocationTargetException Caused by: java.lang.Exception: test2 at sample.addressbook.service.AddressBookService.test2(Unknown Source) ... 35 more As you can see, both exceptions are thrown. Now here's the client (NOTICE: No evidence of an exception from the test1 method): adb.client.run: [java] Name :Abby Cadabby [java] Street :Sesame Street [java] City :Sesame City [java] State :Sesame State [java] Postal Code :11111 [java] org.apache.axis2.AxisFault: test2 [java] at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.jav a:271) [java] at org.apache.axis2.description.OutInAxisOperationClient.execute(OutInAxisOperation. java:202) [java] at sample.addressbook.stub.AddressBookServiceStub.test2(Unknown Source) So I guess that the workaround is that I'll have to have all of my methods return something: Perhaps a String, or maybe I'll create a JavaBean class called Nothing. Or maybe even Void with a capital V. This is a really awful bug. On 4/10/07, John G. Norman <[EMAIL PROTECTED]> wrote:
With a POJO Service: I have now tried the strategy here: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/integration/test/org/apache/axis2/engine/util/FaultThrowingService.java?view=markup Still not seeing the exception on the client that calls the service . . . Still getting: > FaultReason; nested exception is: > java.lang.Exception: This is a test Exception > java.lang.reflect.InvocationTargetException > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) > at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) > at java.lang.reflect.Method.invoke(Method.java:324) > [much deleted] > > Caused by: org.apache.axis2.AxisFault: FaultReason; nested exception is: > java.lang.Exception: This is a test Exception > at com.myco.Service.test(Service.java:45) > ... 48 more > Caused by: java.lang.Exception: This is a test Exception > ... 49 more > DEBUG 16:24:37,843 org.apache.axis2.AxisFault: FaultReason; nested > exception is: > java.lang.Exception: This is a test Exception > DEBUG 16:24:37,843 isReplyRedirected: FaultTo is null. Returning > isReplyRedirected > DEBUG 16:24:37,843 isReplyRedirected: ReplyTo is null. Returning false > On 4/9/07, John G. Norman <[EMAIL PROTECTED]> wrote: > Hi all. > > This is a great topic -- how to manage exceptions for services built > on POJOs. If it is as easy as the link Anne Manes provided > (http://wso2.org/library/171) then throwing exceptions might well be > included in the main Axis2 docs at > http://ws.apache.org/axis2/1_1_1/pojoguide.html). > > But I just tried throwing an exception out of a POJO's method (the > basis for a service as described here: > http://ws.apache.org/axis2/1_1_1/pojoguide.html), and the exception > doesn't seem to make it back to the client. > > Does the QName need to match one of the faults defined in the client stub? > > In any case, the code looks like this: > > public void test() throws AxisFault { > throw new AxisFault(new QName("http://test.org", "FaultCode", > "test"), "FaultReason", new Exception("This is a test Exception")); > } > > On the server, the trace looks like this: > > FaultReason; nested exception is: > java.lang.Exception: This is a test Exception > java.lang.reflect.InvocationTargetException > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) > at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) > at java.lang.reflect.Method.invoke(Method.java:324) > [much deleted] > > Caused by: org.apache.axis2.AxisFault: FaultReason; nested exception is: > java.lang.Exception: This is a test Exception > at com.myco.Service.test(Service.java:45) > ... 48 more > Caused by: java.lang.Exception: This is a test Exception > ... 49 more > DEBUG 16:24:37,843 org.apache.axis2.AxisFault: FaultReason; nested > exception is: > java.lang.Exception: This is a test Exception > DEBUG 16:24:37,843 isReplyRedirected: FaultTo is null. Returning > isReplyRedirected > DEBUG 16:24:37,843 isReplyRedirected: ReplyTo is null. Returning false > > On 4/3/07, Anne Thomas Manes <[EMAIL PROTECTED]> wrote: > > See http://wso2.org/library/171. > > > > On 4/3/07, Chan, Herman <[EMAIL PROTECTED]> wrote: > > > > > > > > > > > > > > > Hi all: > > > > > > > > > > > > I am relatively new to Axis 2 and web services in general, so please bear > > > with me if I ask any stupid questions. > > > > > > > > > > > > I am writing a very simple web service that would return a list of > > > directories on a server. However, if certain directories does not exists, > > > I'd like a throw an error back to the calling client. > > > > > > > > > > > > I am using the POJO approach to create web services using axis2, so is it > > > good enough for me to throw a plain Exception or do I have to do more? What > > > is the best practice in doing error handling in web services? > > > > > > > > > > > > Thanks in advance. > > > > > > > > > > > > Herman Chan > > > > > > > > > > --------------------------------------------------------------------- > > 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]
