• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Exception Handling with Webservices

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 1609
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Akhilesh Trivedi
Ranch Hand
Posts: 1609
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
By the way is it checked or unchecked?
 
M Kethi
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1609
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thankq again..

I am working on it. Creating a Custom exception. Will let you if that works. Keep checking.
 
M Kethi
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1609
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Greetings. Let me read on and try, i'll be back.
 
Akhilesh Trivedi
Ranch Hand
Posts: 1609
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1609
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Akhilesh Trivedi
Ranch Hand
Posts: 1609
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 1609
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.



https://coderanch.com/t/225459/Web-Services/java/Oracle-Siebel-Demand-Web-Service
 
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Taariq San:
Here's a nice tip on exception handling.



Nice article indeed ...

Razi
reply
    Bookmark Topic Watch Topic
  • New Topic