aspose file tools*
The moose likes Web Services and the fly likes Exception Handling with Webservices Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "Exception Handling with Webservices" Watch "Exception Handling with Webservices" New topic
Author

Exception Handling with Webservices

M Kethi
Greenhorn

Joined: Aug 01, 2008
Posts: 15
I am creating a webservice using the tool( WSAD 5).
I am not sure how to pass on the Exception caught at the server side to the client. Suppose I catch an 'GenericJDBCException' on the server side. How can I send the message to the client? So the client would know what Exception was caught and act accordingly.

Thanks,
MK.
Akhilesh Trivedi
Ranch Hand

Joined: Jun 22, 2005
Posts: 1535
Kethi, what would you want to give to your clients a service or an exception? It would be much better if you handle this exception on server-side itself and rather pass an error-message and write code according on client. I feel , exceptions are meant to be caught and buried then and there instead of passing on ahead.


Keep Smiling Always — My life is smoother when running silent. -paul
[FAQs] [Certification Guides] [The Linux Documentation Project]
Akhilesh Trivedi
Ranch Hand

Joined: Jun 22, 2005
Posts: 1535
By the way is it checked or unchecked?
M Kethi
Greenhorn

Joined: Aug 01, 2008
Posts: 15
Thankyou for your inputs.

I was talking about checked exceptions. If not showing the actual message, atleast show that an exception occurred? Suppose, if there is a jdbc connection failure, I would catch that exception at the server side. But at the same time I want to pass a message to the client that an exception occured. If I dont do that, all the checked exceptions caught at the server side, are turned to Remote exceptions at the client side. And the developer writing the client code would see it as a remote exception no matter what kind of exception was caught at the server side.
If I am not very clear please refer to the below text.

"Exceptions could be thrown inside a Web Service for various reasons. The possible types of exceptions that could be thrown are RuntimeException, RemoteException, SOAPFaultException and User Defined Exception.

The Web Service developer might try throwing a RuntimeException such as NullPointerException or ArrayIndexOutOfBoundsException inside the Web Service. But, throwing RuntimeException inside the Web Service is considered to be a bad exercise because RuntimeException will always be converted into RemoteException at the client side. While the client is waiting to catch the RuntimeException after invoking a Web Service, he will get only the RemoteException instead of RuntimeException. Eventually, he cannot perform proper error handling for RuntimeException."


Also, I am the person who has to implement the service as well as the client. Suppose, if the service is down, how should I handle it at the client side.

Thanks,
MK.
Akhilesh Trivedi
Ranch Hand

Joined: Jun 22, 2005
Posts: 1535
Never mind, even I am newbie to WS. I am yet to understand this.

Originally posted by M Kethi:
... But at the same time I want to pass a message to the client that an exception occured. If I dont do that, all the checked exceptions caught at the server side, are turned to Remote exceptions at the client side...


If the exception is caught and handled then its caught and handled. It's all over there. Isn't it? Do you expect after the catch block (at server) the exception will still propagate ahead to the client (as RemoteException)? I suspect it may not.

Coming to client, i dont think it should consider in terms of what exactly the exception was thrown on server, all it should be interested is on very abstract level. Just like you said, "Service is not ready" or "Database not connected."
Did the service run, if yes then the result, if not then, the reason.

If your service is up and runnig, you can try adding simple class say MyException by extending Exception, try throwing it explicitly, catch it immediately and see if it gets propagated.

Back to "service not ready"... we will have to try that as well.
M Kethi
Greenhorn

Joined: Aug 01, 2008
Posts: 15
Thankq again..

I am working on it. Creating a Custom exception. Will let you if that works. Keep checking.
M Kethi
Greenhorn

Joined: Aug 01, 2008
Posts: 15
http://www.theserverside.com/tt/articles/article.tss?l=Systinet-web-services-part-2

something like this...
but it doesn't work for me...
the message is not being propagated to the client side...
Akhilesh Trivedi
Ranch Hand

Joined: Jun 22, 2005
Posts: 1535
Greetings. Let me read on and try, i'll be back.
Akhilesh Trivedi
Ranch Hand

Joined: Jun 22, 2005
Posts: 1535
I could follow through tutorials, but systinet server either seems to be down or is not accessible from here.


ERROR
The requested URL could not be retrieved

--------------------------------------------------------------------------------

While trying to retrieve the URL: http://www.systinet.com/products/wasp_advanced/index.html

The following error was encountered:

Connection Failed
The system returned:

(110) Connection timed out
The remote host or network may be down. Please try the request again.



Were you able to finish up with part-I? what all you were able to follow and where did you stuck up?
Akhilesh Trivedi
Ranch Hand

Joined: Jun 22, 2005
Posts: 1535
Well, i had a web-service here which returned a 'result'(String), "success" or "failure". Now, I added these lines in the service method in the very end.

There are no exceptions on my client rather i have the value 'Exception occured.' string returned. !
M Kethi
Greenhorn

Joined: Aug 01, 2008
Posts: 15
yes. I created a custom exception and my service method throws that custom exception. my client method catches that exception. I am able to get the message i sent. but, when i run the client, it logs the remote exception as well bcos of the checked exception thrown by the server. how could you prevent that?
public java.util.Vector getParticipant(int id) throws java.rmi.RemoteException, CustomException

let me know if i am right

thanks
MK
Bhavin Acharya
Greenhorn

Joined: Sep 18, 2008
Posts: 4
Hi,
I am very new about web service,i want to enter a lead in Oracle Siebel On Demand(OSOD) through java programming, i got a ref. from below link:

http://wiki.netbeans.org/attach/J1PodDemoWebservices/jaxws_service_designer.html

I am using Netbeans6.1 IDE, i followed all steps and incorporate .wsdl file with my Java Project.

My Problems:

* i got all classess made by IDE but i donot know which class i should use to enter lead and how?

Please help me to solve this problem, if you want a review of my incomplete project, email me on bhavin1277@gmail.com . i will send it to you.

Waiting for your reply...

Thank you very much in advance.


Regards, <br />Bhavin.<br />SCJP1.5
Akhilesh Trivedi
Ranch Hand

Joined: Jun 22, 2005
Posts: 1535
Originally posted by M Kethi:
...yes. I created a custom exception and my service method throws that custom exception. my client method catches that exception...


Exception thrown by service and caught at client method? Please explain.
Akhilesh Trivedi
Ranch Hand

Joined: Jun 22, 2005
Posts: 1535
Originally posted by Bhavin Acharya:
Hi,
I am very new about web service,i want to enter a lead in Oracle Siebel On Demand(OSOD) through java programming, i got a ref. from below link:

http://wiki.netbeans.org/attach/J1PodDemoWebservices/jaxws_service_designer.html

I am using Netbeans6.1 IDE, i followed all steps and incorporate .wsdl file with my Java Project.

My Problems:

* i got all classess made by IDE but i donot know which class i should use to enter lead and how?

Please help me to solve this problem, if you want a review of my incomplete project, email me on bhavin1277@gmail.com . i will send it to you.

Waiting for your reply...

Thank you very much in advance.


http://www.coderanch.com/t/225459/Web-Services/java/Oracle-Siebel-Demand-Web-Service
Taariq San
Ranch Hand

Joined: Nov 20, 2007
Posts: 192
Here's a nice tip on exception handling.

I tweaked it a lot for our purposes but the tip is solid.

Think about how you would like to use a web service, would you really want to evaluate the returned value to check if it contains the message "Exception occured"?
Let your code get on with its business, if an exception cocurs it deals with it appropriately.

Using the example...


That looks better than checking the result to ensure success.

Now you might not have a fault for every possible thing that could go wrong, you might have 1 for all your internal errors, like network, database, etc etc. This could contain a unique reference number that your client can query, you look up the number and see the database is down and deal with that. The client doesn't need to know the internals.

You might then have another that deals with specific business validation failures, like that InsufficientFundFault but something generic that could have a code for each type of exception. This is better in some ways and worse in others than a fault for every possible scenario.

Choose what works for you but you can't fatally fault the fault, its pretty useful.
Razi Abbas
Greenhorn

Joined: Dec 10, 2006
Posts: 18
Originally posted by Taariq San:
Here's a nice tip on exception handling.


Nice article indeed ...

Razi
 
Don't get me started about those stupid light bulbs.
 
subject: Exception Handling with Webservices