aspose file tools*
The moose likes Web Services and the fly likes Custom Exception in WebService Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "Custom Exception in WebService" Watch "Custom Exception in WebService" New topic
Author

Custom Exception in WebService

Zaid Ansari
Greenhorn

Joined: Dec 29, 2003
Posts: 10
I want my WebService to throw Custom Defined Exception 'AuthorizationFailedException' like
@WebMethod
ManageUserResponse ManageUser(@WebParam(name = "ManageUser") ManageUser body) throws AuthorizationFailedException;

the issue is i am using xsd Schema and i am not able to generate 'AuthorizationFailedException' class that extends java.lang.Exception.
how can i define type of any xsd elemet to Java.lang.Exception.

I need smething like
<xsd:element name="AuthorizationFailedException" type="java.lang.Exception"></xsd:element>

Zaid Ansari
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
If you want to map an exception to a fault bean, then take a look at the @WebFault annotation.
Otherwise, I am not entirely clear if you do Java first or WSDL first development?
Perhaps it is even meet-in-the-middle?
Have you tried using XJC, the JAXB tool, to generate Java bean classes from the XML schema?
Best wishes!
Zaid Ansari
Greenhorn

Joined: Dec 29, 2003
Posts: 10
thanks for reply,
@WebFault annotation is part of WSDL rigth?
The issue is i am usign xFire Codehaus to generate my WSDL and schema classes. and i don't know what settign are required so generated WSDL contain @WebFault annotation.
I need help in generating WSDL with @WebFault.
Rahul Juneja
Ranch Hand

Joined: Aug 03, 2002
Posts: 425
Can you post you Exception class code as most of the times the problem with such case is that either you have field defined private in the exception which is used in the constructor.

We would be able to understand your problem if you paste your Exception defination code here.

Thanks,
Rahul

Rahul Juneja
ThoughtClicks - http://techlabs.thoughtclicks.com
Zaid Ansari
Greenhorn

Joined: Dec 29, 2003
Posts: 10
Well i don't have any separate class there for exception, what i all did is that i created a complex type with name 'AuthorizationFailedException' and when xFire Generator generated its JAXB class i added 'extends Exception' to that. I know that it must be wrong but i am doing it first time so i have no such idea how we can use User Defined Exception. After that i added thorws AuthorizationFailedException in my WS methods. when i made request it showed error that illegalAnnotationExcetion and that no default Constructor found.

So I want to know that how can i make xsd that will generate a valid wsdl:fault in WSDL on generation. i will be grateful if someone provide us sample code of xsd schema that generates a valid wsdl:fault element. Or explain how we can use user defined exception in WS.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Custom Exception in WebService
 
Similar Threads
Adding attributes to an XML schema
How to generate wsdl:fault from XSD
Exception while deploying webservice on jboss 4.2.1 using jax-ws
problem with validating sax parser
how to convert XMLGregorianCalendar datatype to java.util.Calendar datatype in JAX-W