• Post Reply Bookmark Topic Watch Topic
  • New Topic

Exception Handling

 
siraj baig
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my .wsdl file i am restricting some vehicles according to requirements.

<xsd:simpleType name="VehicleType">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="sedan"/>
<xsd:enumeration value="suv"/>
</xsd:restriction>
</xsd:simpleType>

If the user provides other than these vehicles server throws exception which no one can understand what is that exception.
I want to send a meaningful message to the user saying " vehicle not allowed" ..

Can you tell me How to Handle the Exception

Thanks for your response
siraj
 
vikram karne
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi sairaj

For you to send any useful message to the user you have to create your own exception type in your code first. you can then use this exception in your handler class where you can instantiate it to send a useful message to the user.
i think you may have to embed that exception type in your .wsdl file if you are hand editing the wsdl other wise it can be directly generated from the .wsdd file.
rest you can refer any sample .wsdl file on the net.

hope this is useful

Regards
Vikram K
 
siraj baig
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi vikram,
I have already exception class defined and throwing in my handler.
But the problam is the request is not going till that point(handler).
At the ui level itself is breaking me.
 
Peer Reynders
Bartender
Posts: 2968
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by siraj baig:
server throws exception which no one can understand what is that exception.


Are you certain that the server actually generates a SOAP fault which is then translated on the client side to an exception?

But the problam is the request is not going till that point(handler). At the ui level itself is breaking me


This suggests that the request is never sent. The error on the enumeration could be detected by the client side marshalling code that was generated by the client wsdl-to-java tool. So the exception would be generated entirely on the client side - the request would never be completely built and couldn�t reach the client or server handler chain. Web service toolkits often throw exceptions similar to those based on actual SOAP faults even if there is no SOAP fault present in order to "unify their exception interface".

If that is the case then you have handle this entirely on the client side. Catch the exception thrown by the client stub method and then throw your own exception class.
 
siraj baig
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Peer,
Can you tell me how to catch the exception at client side and throw
meaningful exception.
please provide sample code.

Thanks for your response
siraj.
 
Peer Reynders
Bartender
Posts: 2968
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Example Axis 1.3
WSDL:



Interface after WSDL2Java:



Custom Checked Exception:



Command line client:



Resulting exception:

Exception in thread "main" xmlenum.InvalidVehicleTypeException: "saloon" is not a valid vehicle type.
at xmlenum.XmlEnumTester.main(XmlEnumTester.java:22)
Caused by: java.lang.IllegalArgumentException
at xmlenum.ws.VehicleType.fromValue(VehicleType.java:29)
at xmlenum.XmlEnumTester.main(XmlEnumTester.java:17)
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!