You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by imorales <im...@ignos.com> on 2007/11/28 09:25:16 UTC

Custom exceptions in CXF web-service

Hi all. I developed a web service using CXF. The methods of the web service
throws Custom Exceptions. Something like that:

-----------------------------------------------------------------------------------------
@WebResult(name="ticket")
Long iniciaFormulario( @WebParam(name="xslt") String xslt) throws
MetaInformacionException;
-----------------------------------------------------------------------------------------

And MetaInformacionException extends of Exception.

The problem is that when in my server throw a new MetaInformacionException
the client never catch the exception because the excepction that occurs is a
"javax.xml.rpc.soap.SOAPFaultException" but with the message of my custom
Exception.

The client is developed with ant task WSDL2JAVA and this task generates a
class called "MetaInformacionException_Exception". Here is the code.

The MetaInformacionException that I developed:
-----------------------------------------------------------------------------------------
public class MetaInformacionException extends Exception{
    private static final long serialVersionUID = 1L;
    public MetaInformacionException() {
        super();
    }
    public MetaInformacionException(String msg) {
        super(msg);
    }
    public MetaInformacionException(String msg, Throwable cause) {
        super(msg, cause);
    }
}
-----------------------------------------------------------------------------------------

And the class that the WSDL2JAVA generate:
-----------------------------------------------------------------------------------------
@WebFault(name = "MetaInformacionException", targetNamespace =
"http://servicios.ignos.com/")

public class MetaInformacionException_Exception extends Exception {
    public static final long serialVersionUID = 20071108142126L;
    
    private com.servicios.MetaInformacionException metaInformacionException;

    public MetaInformacionException_Exception (String message) {
        super(message);
    }

    public MetaInformacionException_Exception (String message,
com.servicios.MetaInformacionException metaInformacionException) {
        super(message);
        this.metaInformacionException = metaInformacionException;
    }

    public MetaInformacionException_Exception (String message,
com.servicios.MetaInformacionException metaInformacionException, Throwable
cause) {
        super(message, cause);
        this.metaInformacionException = metaInformacionException;
    }

    public com.servicios.MetaInformacionException getFaultInfo() {
        return this.metaInformacionException;
    }
}
------------------------------------------------------------------------------------------
Why the exception that throws the server is never catched by the client ???

Any ideas?. Thanks in advance.
-- 
View this message in context: http://www.nabble.com/Custom-exceptions-in-CXF-web-service-tf4887017.html#a13987890
Sent from the cxf-user mailing list archive at Nabble.com.


Re: Custom exceptions in CXF web-service

Posted by imorales <im...@ignos.com>.
Well that it´s a bug --> https://issues.apache.org/jira/browse/CXF-1028
But I don´t understand because my cxf version is 2.0.2 and the bug is fixed
for that version.

imorales wrote:
> 
> Hi all. I developed a web service using CXF. The methods of the web
> service throws Custom Exceptions. Something like that:
> 
> -----------------------------------------------------------------------------------------
> @WebResult(name="ticket")
> Long iniciaFormulario( @WebParam(name="xslt") String xslt) throws
> MetaInformacionException;
> -----------------------------------------------------------------------------------------
> 
> And MetaInformacionException extends of Exception.
> 
> The problem is that when in my server throw a new MetaInformacionException
> the client never catch the exception because the excepction that occurs is
> a "javax.xml.rpc.soap.SOAPFaultException" but with the message of my
> custom Exception.
> 
> The client is developed with ant task WSDL2JAVA and this task generates a
> class called "MetaInformacionException_Exception". Here is the code.
> 
> The MetaInformacionException that I developed:
> -----------------------------------------------------------------------------------------
> public class MetaInformacionException extends Exception{
>     private static final long serialVersionUID = 1L;
>     public MetaInformacionException() {
>         super();
>     }
>     public MetaInformacionException(String msg) {
>         super(msg);
>     }
>     public MetaInformacionException(String msg, Throwable cause) {
>         super(msg, cause);
>     }
> }
> -----------------------------------------------------------------------------------------
> 
> And the class that the WSDL2JAVA generate:
> -----------------------------------------------------------------------------------------
> @WebFault(name = "MetaInformacionException", targetNamespace =
> "http://servicios.ignos.com/")
> 
> public class MetaInformacionException_Exception extends Exception {
>     public static final long serialVersionUID = 20071108142126L;
>     
>     private com.servicios.MetaInformacionException
> metaInformacionException;
> 
>     public MetaInformacionException_Exception (String message) {
>         super(message);
>     }
> 
>     public MetaInformacionException_Exception (String message,
> com.servicios.MetaInformacionException metaInformacionException) {
>         super(message);
>         this.metaInformacionException = metaInformacionException;
>     }
> 
>     public MetaInformacionException_Exception (String message,
> com.servicios.MetaInformacionException metaInformacionException, Throwable
> cause) {
>         super(message, cause);
>         this.metaInformacionException = metaInformacionException;
>     }
> 
>     public com.servicios.MetaInformacionException getFaultInfo() {
>         return this.metaInformacionException;
>     }
> }
> ------------------------------------------------------------------------------------------
> Why the exception that throws the server is never catched by the client
> ???
> 
> Any ideas?. Thanks in advance.
> 

-- 
View this message in context: http://www.nabble.com/Custom-exceptions-in-CXF-web-service-tf4887017.html#a13988371
Sent from the cxf-user mailing list archive at Nabble.com.


Re: Non-compliant Java exception class generation? (Was Re: Custom exceptions in CXF web-service)

Posted by Daniel Kulp <dk...@apache.org>.
On Friday 30 November 2007, Glen Mazza wrote:
> I'm not sure what you mean by "handle"--Was the top constructor
> removed from JAX-WS generation--if not, why do we still have it, what
> was the reason for moving beyond the spec to include it?

By handle, I mean it will "properly" get deserialized back into the 
appropriate exception on the client side and thrown.   Basically, if the 
details are "xsi:nil" on the wire, it will not "blow up".

The main reason for including it is that it's what most java developers 
expect.   It's a convienience.   The spec mandates the other two 
constructors, but it doesn't EXCLUDE additional constructors.   If you 
use them, you're out of the portability guarantees of the the JAX-WS 
spec, but they are nice to have.  

I think we generate a couple extra constructors on the client side 
Service objects as well for the same reason.

Dan



>
> Thanks,
> Glen
>
> Am Freitag, den 30.11.2007, 17:21 -0500 schrieb Daniel Kulp:
> > Glen,
> >
> > I think for 2.0.3, I fixed the reader/writer to hande the top
> > constructor and null details.   See:
> > https://issues.apache.org/jira/browse/CXF-1131
> >
> > Dan
> >
> > On Thursday 29 November 2007, Glen Mazza wrote:
> > > Team,
> > >
> > > If you look at [2] below, we are providing three constructors when
> > > we generate a Java exception class for a wsdl:fault element.
> > >
> > > However, the May 2007 JAX-WS 2.1 spec, bottom of page 22 and top
> > > of page 23, states that we should only be providing the bottom two
> > > constructors. Also, as [2] notes, Metro only provides those two
> > > constructors.
> > >
> > > The problem with the top constructor is the FaultBean, or custom
> > > exception, is not getting stored when you use it, causing the
> > > reader below (and the reader who had the bug at [1]) to be losing
> > > the custom exception and instead just getting a basic
> > > SOAPFaultException.  Also, it makes service code non-portable
> > > between Metro and CXF.
> > >
> > > I think we should stop supplying the top, one-parameter
> > > constructor from the list below.  (Deprecate it if necessary?)  It
> > > keeps us compliant with the spec and also prevents users from
> > > falling into the "Where's my custom exception?" trap below.
> > >
> > > Thoughts?
> > >
> > > Thanks,
> > > Glen
> > >
> > > Am Donnerstag, den 29.11.2007, 05:22 -0500 schrieb Glen Mazza:
> > > > Upgrade to the two or three parameter one, as you can see from
> > > > [2], they are the only versions that will incorporate your
> > > > custom exception:
> > > >
> > > > (Code from [2]:)
> > > >
> > > > // ignores custom exception:
> > > > public CustomException (String message) { super(message); }
> > > >
> > > > // absorbs custom exception:
> > > > public CustomException (String message,
> > > > demo.hw.company.CustomExceptionType customException) {
> > > >  super(message); -->this.customException = customException;<-- }
> > > >
> > > > // absorbs custom exception:
> > > > public CustomException (String message,
> > > > demo.hw.company.CustomExceptionType customException, Throwable
> > > > cause) { super(message, cause); -->this.customException =
> > > > customException;<-- }
> > > >
> > > > Am Donnerstag, den 29.11.2007, 01:45 -0800 schrieb imorales:
> > > > > I use the one parameter Constructor.
> > > > > --> throw new MetaInformacionException("Error in meta Info")
> > > > >
> > > > > Glen Mazza-2 wrote:
> > > > > > Am Mittwoch, den 28.11.2007, 00:25 -0800 schrieb imorales:
> > > > > >> Hi all. I developed a web service using CXF. The methods of
> > > > > >> the web service
> > > > > >> throws Custom Exceptions. Something like that:
> > > > > >>
> > > > > >> -----------------------------------------------------------
> > > > > >>---- -------------------------- @WebResult(name="ticket")
> > > > > >> Long iniciaFormulario( @WebParam(name="xslt") String xslt)
> > > > > >> throws MetaInformacionException;
> > > > > >> -----------------------------------------------------------
> > > > > >>---- --------------------------
> > > > > >>
> > > > > >> And MetaInformacionException extends of Exception.
> > > > > >>
> > > > > >> The problem is that when in my server throw a new
> > > > > >> MetaInformacionException
> > > > > >> the client never catch the exception because the excepction
> > > > > >> that occurs is a
> > > > > >> "javax.xml.rpc.soap.SOAPFaultException" but with the
> > > > > >> message of my custom Exception.
> > > > > >
> > > > > > I was able to get custom exceptions to work using a
> > > > > > WSDL-first approach[1].  From the web service, when you
> > > > > > construct your "new MetaInformationException", make sure you
> > > > > > are not using the no-parameter constructor version (in my
> > > > > > example[1], I use a two-parameter constructor.)  That
> > > > > > *might* be the problem you are having, someone else had a
> > > > > > similar issue[2].
> > > > > >
> > > > > > HTH,
> > > > > > Glen
> > > > > >
> > > > > > [1] http://www.jroller.com/gmazza/date/20071019#step6
> > > > > > [2]
> > > > > > http://issues.apache.org/jira/browse/CXF-1136#action_1253761
> > > > > >0



-- 
J. Daniel Kulp
Principal Engineer
IONA
P: 781-902-8727    C: 508-380-7194
daniel.kulp@iona.com
http://www.dankulp.com/blog

Re: Non-compliant Java exception class generation? (Was Re: Custom exceptions in CXF web-service)

Posted by Glen Mazza <gl...@verizon.net>.
I'm not sure what you mean by "handle"--Was the top constructor removed
from JAX-WS generation--if not, why do we still have it, what was the
reason for moving beyond the spec to include it?

Thanks,
Glen

Am Freitag, den 30.11.2007, 17:21 -0500 schrieb Daniel Kulp:
> Glen,
> 
> I think for 2.0.3, I fixed the reader/writer to hande the top constructor 
> and null details.   See:
> https://issues.apache.org/jira/browse/CXF-1131
> 
> Dan
> 
> 
> 
> 
> On Thursday 29 November 2007, Glen Mazza wrote:
> > Team,
> >
> > If you look at [2] below, we are providing three constructors when we
> > generate a Java exception class for a wsdl:fault element.
> >
> > However, the May 2007 JAX-WS 2.1 spec, bottom of page 22 and top of
> > page 23, states that we should only be providing the bottom two
> > constructors. Also, as [2] notes, Metro only provides those two
> > constructors.
> >
> > The problem with the top constructor is the FaultBean, or custom
> > exception, is not getting stored when you use it, causing the reader
> > below (and the reader who had the bug at [1]) to be losing the custom
> > exception and instead just getting a basic SOAPFaultException.  Also,
> > it makes service code non-portable between Metro and CXF.
> >
> > I think we should stop supplying the top, one-parameter constructor
> > from the list below.  (Deprecate it if necessary?)  It keeps us
> > compliant with the spec and also prevents users from falling into the
> > "Where's my custom exception?" trap below.
> >
> > Thoughts?
> >
> > Thanks,
> > Glen
> >
> > Am Donnerstag, den 29.11.2007, 05:22 -0500 schrieb Glen Mazza:
> > > Upgrade to the two or three parameter one, as you can see from [2],
> > > they are the only versions that will incorporate your custom
> > > exception:
> > >
> > > (Code from [2]:)
> > >
> > > // ignores custom exception:
> > > public CustomException (String message) { super(message); }
> > >
> > > // absorbs custom exception:
> > > public CustomException (String message,
> > > demo.hw.company.CustomExceptionType customException) {
> > >  super(message); -->this.customException = customException;<-- }
> > >
> > > // absorbs custom exception:
> > > public CustomException (String message,
> > > demo.hw.company.CustomExceptionType customException, Throwable
> > > cause) { super(message, cause); -->this.customException =
> > > customException;<-- }
> > >
> > > Am Donnerstag, den 29.11.2007, 01:45 -0800 schrieb imorales:
> > > > I use the one parameter Constructor.
> > > > --> throw new MetaInformacionException("Error in meta Info")
> > > >
> > > > Glen Mazza-2 wrote:
> > > > > Am Mittwoch, den 28.11.2007, 00:25 -0800 schrieb imorales:
> > > > >> Hi all. I developed a web service using CXF. The methods of the
> > > > >> web service
> > > > >> throws Custom Exceptions. Something like that:
> > > > >>
> > > > >> ---------------------------------------------------------------
> > > > >>-------------------------- @WebResult(name="ticket")
> > > > >> Long iniciaFormulario( @WebParam(name="xslt") String xslt)
> > > > >> throws MetaInformacionException;
> > > > >> ---------------------------------------------------------------
> > > > >>--------------------------
> > > > >>
> > > > >> And MetaInformacionException extends of Exception.
> > > > >>
> > > > >> The problem is that when in my server throw a new
> > > > >> MetaInformacionException
> > > > >> the client never catch the exception because the excepction
> > > > >> that occurs is a
> > > > >> "javax.xml.rpc.soap.SOAPFaultException" but with the message of
> > > > >> my custom Exception.
> > > > >
> > > > > I was able to get custom exceptions to work using a WSDL-first
> > > > > approach[1].  From the web service, when you construct your "new
> > > > > MetaInformationException", make sure you are not using the
> > > > > no-parameter constructor version (in my example[1], I use a
> > > > > two-parameter constructor.)  That *might* be the problem you are
> > > > > having, someone else had a similar issue[2].
> > > > >
> > > > > HTH,
> > > > > Glen
> > > > >
> > > > > [1] http://www.jroller.com/gmazza/date/20071019#step6
> > > > > [2]
> > > > > http://issues.apache.org/jira/browse/CXF-1136#action_12537610
> 
> 
> 


Re: Non-compliant Java exception class generation? (Was Re: Custom exceptions in CXF web-service)

Posted by Daniel Kulp <dk...@apache.org>.
Glen,

I think for 2.0.3, I fixed the reader/writer to hande the top constructor 
and null details.   See:
https://issues.apache.org/jira/browse/CXF-1131

Dan




On Thursday 29 November 2007, Glen Mazza wrote:
> Team,
>
> If you look at [2] below, we are providing three constructors when we
> generate a Java exception class for a wsdl:fault element.
>
> However, the May 2007 JAX-WS 2.1 spec, bottom of page 22 and top of
> page 23, states that we should only be providing the bottom two
> constructors. Also, as [2] notes, Metro only provides those two
> constructors.
>
> The problem with the top constructor is the FaultBean, or custom
> exception, is not getting stored when you use it, causing the reader
> below (and the reader who had the bug at [1]) to be losing the custom
> exception and instead just getting a basic SOAPFaultException.  Also,
> it makes service code non-portable between Metro and CXF.
>
> I think we should stop supplying the top, one-parameter constructor
> from the list below.  (Deprecate it if necessary?)  It keeps us
> compliant with the spec and also prevents users from falling into the
> "Where's my custom exception?" trap below.
>
> Thoughts?
>
> Thanks,
> Glen
>
> Am Donnerstag, den 29.11.2007, 05:22 -0500 schrieb Glen Mazza:
> > Upgrade to the two or three parameter one, as you can see from [2],
> > they are the only versions that will incorporate your custom
> > exception:
> >
> > (Code from [2]:)
> >
> > // ignores custom exception:
> > public CustomException (String message) { super(message); }
> >
> > // absorbs custom exception:
> > public CustomException (String message,
> > demo.hw.company.CustomExceptionType customException) {
> >  super(message); -->this.customException = customException;<-- }
> >
> > // absorbs custom exception:
> > public CustomException (String message,
> > demo.hw.company.CustomExceptionType customException, Throwable
> > cause) { super(message, cause); -->this.customException =
> > customException;<-- }
> >
> > Am Donnerstag, den 29.11.2007, 01:45 -0800 schrieb imorales:
> > > I use the one parameter Constructor.
> > > --> throw new MetaInformacionException("Error in meta Info")
> > >
> > > Glen Mazza-2 wrote:
> > > > Am Mittwoch, den 28.11.2007, 00:25 -0800 schrieb imorales:
> > > >> Hi all. I developed a web service using CXF. The methods of the
> > > >> web service
> > > >> throws Custom Exceptions. Something like that:
> > > >>
> > > >> ---------------------------------------------------------------
> > > >>-------------------------- @WebResult(name="ticket")
> > > >> Long iniciaFormulario( @WebParam(name="xslt") String xslt)
> > > >> throws MetaInformacionException;
> > > >> ---------------------------------------------------------------
> > > >>--------------------------
> > > >>
> > > >> And MetaInformacionException extends of Exception.
> > > >>
> > > >> The problem is that when in my server throw a new
> > > >> MetaInformacionException
> > > >> the client never catch the exception because the excepction
> > > >> that occurs is a
> > > >> "javax.xml.rpc.soap.SOAPFaultException" but with the message of
> > > >> my custom Exception.
> > > >
> > > > I was able to get custom exceptions to work using a WSDL-first
> > > > approach[1].  From the web service, when you construct your "new
> > > > MetaInformationException", make sure you are not using the
> > > > no-parameter constructor version (in my example[1], I use a
> > > > two-parameter constructor.)  That *might* be the problem you are
> > > > having, someone else had a similar issue[2].
> > > >
> > > > HTH,
> > > > Glen
> > > >
> > > > [1] http://www.jroller.com/gmazza/date/20071019#step6
> > > > [2]
> > > > http://issues.apache.org/jira/browse/CXF-1136#action_12537610



-- 
J. Daniel Kulp
Principal Engineer
IONA
P: 781-902-8727    C: 508-380-7194
daniel.kulp@iona.com
http://www.dankulp.com/blog

Re: Custom exceptions in CXF web-service

Posted by imorales <im...@ignos.com>.
Yes but my problem is that I can´t throw MetaInfoException_Exception in the
web service code because the WSDL says that only throws MetaInfoException.
But in the port client auto-generated throws MetaInfoException_Exception and
that´s because I can´t throw MetaInfoException_Exception in the web service
code. 

Well I will spend more time thinking and reading all your links and my code
to better understand my problem. Thank you so much to help me.

Glen Mazza-2 wrote:
> 
> Errr...sorry, apparently we are discussing two different things.
> 
> There may be another issue with Exceptions, unrelated to yours, that I
> just submitted on the dev list[4].  I'm still a rather newbie committer
> so it could be just a misunderstanding on my part.  Apparently your
> problem is not related to this.
> 
> Still, I don't think you want to throw your MetaInfoException directly
> from the web service code, you should throw MetaInfoException_Exception
> (message, MetaInfoException), no?  Again, look at my example[5] here.
> 
> Glen
> 
> [4] http://tinyurl.com/2j5mrq
> [5] http://www.jroller.com/gmazza/date/20071019#step6
> 
> 
> Am Donnerstag, den 29.11.2007, 03:29 -0800 schrieb imorales:
>> Sorry but I´m missing something. My MetaInfoException have 3 methos as
>> you
>> can see in [1], and the server olny can throw this exception. 
>> 
>> I have auto-generated classes with the CXF tool WSDL2Java that generates
>> my
>> MetaInfoException and MetaInfoException_Exception that have 3 the methods
>> see from[2] and see how the MetaInfoException_Exception has a attribute
>> of
>> type MetaInfoException. 
>> 
>> The wsdl see code[3] says that the methos throws MetaInfoException but in
>> the cxf generated class Port the method throws the
>> MetaInfoException_Exception. I would have to change Port class to the
>> method
>> throw the MetaInfoException and not the MetaInfoException_Exception.
>> 
>> CODE[1]:
>> ------------------------------------------------------------------------------------------
>> public class MetaInformacionException extends Exception{
>>     private static final long serialVersionUID = 1L;
>>     public MetaInformacionException() {
>>         super();
>>     }
>>     public MetaInformacionException(String msg) {
>>         super(msg);
>>     }
>>     public MetaInformacionException(String msg, Throwable cause) {
>>         super(msg, cause);
>>     }
>> } 
>> ------------------------------------------------------------------------------------------
>> 
>> CODE[2]:
>> ------------------------------------------------------------------------------------------
>> @WebFault(name = "MetaInformacionException", targetNamespace =
>> "http://servicios.ignos.com/")
>> 
>> public class MetaInformacionException_Exception extends Exception {
>>     public static final long serialVersionUID = 20071108142126L;
>>    
>>     private com.servicios.MetaInformacionException
>> metaInformacionException;
>> 
>>     public MetaInformacionException_Exception (String message) {
>>         super(message);
>>     }
>> 
>>     public MetaInformacionException_Exception (String message,
>> com.servicios.MetaInformacionException metaInformacionException) {
>>         super(message);
>>         this.metaInformacionException = metaInformacionException;
>>     }
>> 
>>     public MetaInformacionException_Exception (String message,
>> com.servicios.MetaInformacionException metaInformacionException,
>> Throwable
>> cause) {
>>         super(message, cause);
>>         this.metaInformacionException = metaInformacionException;
>>     }
>> 
>>     public com.servicios.MetaInformacionException getFaultInfo() {
>>         return this.metaInformacionException;
>>     }
>> } 
>> ------------------------------------------------------------------------------------------
>> 
>> CODE[3]:
>> ------------------------------------------------------------------------------------------
>> <wsdl:operation name="iniciaFormulario">
>>       <wsdl:input name="iniciaFormulario" message="tns:iniciaFormulario">
>>     </wsdl:input>
>>       <wsdl:output name="iniciaFormularioResponse"
>> message="tns:iniciaFormularioResponse">
>>     </wsdl:output>
>>       <wsdl:fault name="MetaInformacionException"
>> message="tns:MetaInformacionException">
>>     </wsdl:fault>
>>     </wsdl:operation>
>> ------------------------------------------------------------------------------------------
>> 
>> Glen Mazza-2 wrote:
>> > 
>> > Upgrade to the two or three parameter one, as you can see from [2],
>> they
>> > are the only versions that will incorporate your custom exception:
>> > 
>> > (Code from [2]:)
>> > 
>> > // ignores custom exception:
>> > public CustomException (String message) { super(message); } 
>> > 
>> > // absorbs custom exception:
>> > public CustomException (String message,
>> > demo.hw.company.CustomExceptionType customException) { 
>> >  super(message); -->this.customException = customException;<-- } 
>> > 
>> > // absorbs custom exception:
>> > public CustomException (String message,
>> > demo.hw.company.CustomExceptionType customException, Throwable cause) { 
>> >  super(message, cause); -->this.customException = customException;<-- }
>> > 
>> > 
>> > Am Donnerstag, den 29.11.2007, 01:45 -0800 schrieb imorales:
>> >> I use the one parameter Constructor. 
>> >> --> throw new MetaInformacionException("Error in meta Info")
>> >> 
>> >> Glen Mazza-2 wrote:
>> >> > 
>> >> > Am Mittwoch, den 28.11.2007, 00:25 -0800 schrieb imorales:
>> >> >> Hi all. I developed a web service using CXF. The methods of the web
>> >> >> service
>> >> >> throws Custom Exceptions. Something like that:
>> >> >> 
>> >> >>
>> >>
>> -----------------------------------------------------------------------------------------
>> >> >> @WebResult(name="ticket")
>> >> >> Long iniciaFormulario( @WebParam(name="xslt") String xslt) throws
>> >> >> MetaInformacionException;
>> >> >>
>> >>
>> -----------------------------------------------------------------------------------------
>> >> >> 
>> >> >> And MetaInformacionException extends of Exception.
>> >> >> 
>> >> >> The problem is that when in my server throw a new
>> >> >> MetaInformacionException
>> >> >> the client never catch the exception because the excepction that
>> >> occurs
>> >> >> is a
>> >> >> "javax.xml.rpc.soap.SOAPFaultException" but with the message of my
>> >> custom
>> >> >> Exception.
>> >> >> 
>> >> > 
>> >> > I was able to get custom exceptions to work using a WSDL-first
>> >> > approach[1].  From the web service, when you construct your "new
>> >> > MetaInformationException", make sure you are not using the
>> no-parameter
>> >> > constructor version (in my example[1], I use a two-parameter
>> >> > constructor.)  That *might* be the problem you are having, someone
>> else
>> >> > had a similar issue[2].
>> >> > 
>> >> > HTH,
>> >> > Glen
>> >> > 
>> >> > [1] http://www.jroller.com/gmazza/date/20071019#step6
>> >> > [2] http://issues.apache.org/jira/browse/CXF-1136#action_12537610
>> >> > 
>> >> > 
>> >> > 
>> >> > 
>> >> 
>> > 
>> > 
>> > 
>> 
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Custom-exceptions-in-CXF-web-service-tf4887017.html#a14024593
Sent from the cxf-user mailing list archive at Nabble.com.


Re: Custom exceptions in CXF web-service

Posted by Glen Mazza <gl...@verizon.net>.
Errr...sorry, apparently we are discussing two different things.

There may be another issue with Exceptions, unrelated to yours, that I
just submitted on the dev list[4].  I'm still a rather newbie committer
so it could be just a misunderstanding on my part.  Apparently your
problem is not related to this.

Still, I don't think you want to throw your MetaInfoException directly
from the web service code, you should throw MetaInfoException_Exception
(message, MetaInfoException), no?  Again, look at my example[5] here.

Glen

[4] http://tinyurl.com/2j5mrq
[5] http://www.jroller.com/gmazza/date/20071019#step6


Am Donnerstag, den 29.11.2007, 03:29 -0800 schrieb imorales:
> Sorry but I´m missing something. My MetaInfoException have 3 methos as you
> can see in [1], and the server olny can throw this exception. 
> 
> I have auto-generated classes with the CXF tool WSDL2Java that generates my
> MetaInfoException and MetaInfoException_Exception that have 3 the methods
> see from[2] and see how the MetaInfoException_Exception has a attribute of
> type MetaInfoException. 
> 
> The wsdl see code[3] says that the methos throws MetaInfoException but in
> the cxf generated class Port the method throws the
> MetaInfoException_Exception. I would have to change Port class to the method
> throw the MetaInfoException and not the MetaInfoException_Exception.
> 
> CODE[1]:
> ------------------------------------------------------------------------------------------
> public class MetaInformacionException extends Exception{
>     private static final long serialVersionUID = 1L;
>     public MetaInformacionException() {
>         super();
>     }
>     public MetaInformacionException(String msg) {
>         super(msg);
>     }
>     public MetaInformacionException(String msg, Throwable cause) {
>         super(msg, cause);
>     }
> } 
> ------------------------------------------------------------------------------------------
> 
> CODE[2]:
> ------------------------------------------------------------------------------------------
> @WebFault(name = "MetaInformacionException", targetNamespace =
> "http://servicios.ignos.com/")
> 
> public class MetaInformacionException_Exception extends Exception {
>     public static final long serialVersionUID = 20071108142126L;
>    
>     private com.servicios.MetaInformacionException metaInformacionException;
> 
>     public MetaInformacionException_Exception (String message) {
>         super(message);
>     }
> 
>     public MetaInformacionException_Exception (String message,
> com.servicios.MetaInformacionException metaInformacionException) {
>         super(message);
>         this.metaInformacionException = metaInformacionException;
>     }
> 
>     public MetaInformacionException_Exception (String message,
> com.servicios.MetaInformacionException metaInformacionException, Throwable
> cause) {
>         super(message, cause);
>         this.metaInformacionException = metaInformacionException;
>     }
> 
>     public com.servicios.MetaInformacionException getFaultInfo() {
>         return this.metaInformacionException;
>     }
> } 
> ------------------------------------------------------------------------------------------
> 
> CODE[3]:
> ------------------------------------------------------------------------------------------
> <wsdl:operation name="iniciaFormulario">
>       <wsdl:input name="iniciaFormulario" message="tns:iniciaFormulario">
>     </wsdl:input>
>       <wsdl:output name="iniciaFormularioResponse"
> message="tns:iniciaFormularioResponse">
>     </wsdl:output>
>       <wsdl:fault name="MetaInformacionException"
> message="tns:MetaInformacionException">
>     </wsdl:fault>
>     </wsdl:operation>
> ------------------------------------------------------------------------------------------
> 
> Glen Mazza-2 wrote:
> > 
> > Upgrade to the two or three parameter one, as you can see from [2], they
> > are the only versions that will incorporate your custom exception:
> > 
> > (Code from [2]:)
> > 
> > // ignores custom exception:
> > public CustomException (String message) { super(message); } 
> > 
> > // absorbs custom exception:
> > public CustomException (String message,
> > demo.hw.company.CustomExceptionType customException) { 
> >  super(message); -->this.customException = customException;<-- } 
> > 
> > // absorbs custom exception:
> > public CustomException (String message,
> > demo.hw.company.CustomExceptionType customException, Throwable cause) { 
> >  super(message, cause); -->this.customException = customException;<-- }
> > 
> > 
> > Am Donnerstag, den 29.11.2007, 01:45 -0800 schrieb imorales:
> >> I use the one parameter Constructor. 
> >> --> throw new MetaInformacionException("Error in meta Info")
> >> 
> >> Glen Mazza-2 wrote:
> >> > 
> >> > Am Mittwoch, den 28.11.2007, 00:25 -0800 schrieb imorales:
> >> >> Hi all. I developed a web service using CXF. The methods of the web
> >> >> service
> >> >> throws Custom Exceptions. Something like that:
> >> >> 
> >> >>
> >> -----------------------------------------------------------------------------------------
> >> >> @WebResult(name="ticket")
> >> >> Long iniciaFormulario( @WebParam(name="xslt") String xslt) throws
> >> >> MetaInformacionException;
> >> >>
> >> -----------------------------------------------------------------------------------------
> >> >> 
> >> >> And MetaInformacionException extends of Exception.
> >> >> 
> >> >> The problem is that when in my server throw a new
> >> >> MetaInformacionException
> >> >> the client never catch the exception because the excepction that
> >> occurs
> >> >> is a
> >> >> "javax.xml.rpc.soap.SOAPFaultException" but with the message of my
> >> custom
> >> >> Exception.
> >> >> 
> >> > 
> >> > I was able to get custom exceptions to work using a WSDL-first
> >> > approach[1].  From the web service, when you construct your "new
> >> > MetaInformationException", make sure you are not using the no-parameter
> >> > constructor version (in my example[1], I use a two-parameter
> >> > constructor.)  That *might* be the problem you are having, someone else
> >> > had a similar issue[2].
> >> > 
> >> > HTH,
> >> > Glen
> >> > 
> >> > [1] http://www.jroller.com/gmazza/date/20071019#step6
> >> > [2] http://issues.apache.org/jira/browse/CXF-1136#action_12537610
> >> > 
> >> > 
> >> > 
> >> > 
> >> 
> > 
> > 
> > 
> 


Re: Custom exceptions in CXF web-service

Posted by imorales <im...@ignos.com>.
Sorry but I´m missing something. My MetaInfoException have 3 methos as you
can see in [1], and the server olny can throw this exception. 

I have auto-generated classes with the CXF tool WSDL2Java that generates my
MetaInfoException and MetaInfoException_Exception that have 3 the methods
see from[2] and see how the MetaInfoException_Exception has a attribute of
type MetaInfoException. 

The wsdl see code[3] says that the methos throws MetaInfoException but in
the cxf generated class Port the method throws the
MetaInfoException_Exception. I would have to change Port class to the method
throw the MetaInfoException and not the MetaInfoException_Exception.

CODE[1]:
------------------------------------------------------------------------------------------
public class MetaInformacionException extends Exception{
    private static final long serialVersionUID = 1L;
    public MetaInformacionException() {
        super();
    }
    public MetaInformacionException(String msg) {
        super(msg);
    }
    public MetaInformacionException(String msg, Throwable cause) {
        super(msg, cause);
    }
} 
------------------------------------------------------------------------------------------

CODE[2]:
------------------------------------------------------------------------------------------
@WebFault(name = "MetaInformacionException", targetNamespace =
"http://servicios.ignos.com/")

public class MetaInformacionException_Exception extends Exception {
    public static final long serialVersionUID = 20071108142126L;
   
    private com.servicios.MetaInformacionException metaInformacionException;

    public MetaInformacionException_Exception (String message) {
        super(message);
    }

    public MetaInformacionException_Exception (String message,
com.servicios.MetaInformacionException metaInformacionException) {
        super(message);
        this.metaInformacionException = metaInformacionException;
    }

    public MetaInformacionException_Exception (String message,
com.servicios.MetaInformacionException metaInformacionException, Throwable
cause) {
        super(message, cause);
        this.metaInformacionException = metaInformacionException;
    }

    public com.servicios.MetaInformacionException getFaultInfo() {
        return this.metaInformacionException;
    }
} 
------------------------------------------------------------------------------------------

CODE[3]:
------------------------------------------------------------------------------------------
<wsdl:operation name="iniciaFormulario">
      <wsdl:input name="iniciaFormulario" message="tns:iniciaFormulario">
    </wsdl:input>
      <wsdl:output name="iniciaFormularioResponse"
message="tns:iniciaFormularioResponse">
    </wsdl:output>
      <wsdl:fault name="MetaInformacionException"
message="tns:MetaInformacionException">
    </wsdl:fault>
    </wsdl:operation>
------------------------------------------------------------------------------------------

Glen Mazza-2 wrote:
> 
> Upgrade to the two or three parameter one, as you can see from [2], they
> are the only versions that will incorporate your custom exception:
> 
> (Code from [2]:)
> 
> // ignores custom exception:
> public CustomException (String message) { super(message); } 
> 
> // absorbs custom exception:
> public CustomException (String message,
> demo.hw.company.CustomExceptionType customException) { 
>  super(message); -->this.customException = customException;<-- } 
> 
> // absorbs custom exception:
> public CustomException (String message,
> demo.hw.company.CustomExceptionType customException, Throwable cause) { 
>  super(message, cause); -->this.customException = customException;<-- }
> 
> 
> Am Donnerstag, den 29.11.2007, 01:45 -0800 schrieb imorales:
>> I use the one parameter Constructor. 
>> --> throw new MetaInformacionException("Error in meta Info")
>> 
>> Glen Mazza-2 wrote:
>> > 
>> > Am Mittwoch, den 28.11.2007, 00:25 -0800 schrieb imorales:
>> >> Hi all. I developed a web service using CXF. The methods of the web
>> >> service
>> >> throws Custom Exceptions. Something like that:
>> >> 
>> >>
>> -----------------------------------------------------------------------------------------
>> >> @WebResult(name="ticket")
>> >> Long iniciaFormulario( @WebParam(name="xslt") String xslt) throws
>> >> MetaInformacionException;
>> >>
>> -----------------------------------------------------------------------------------------
>> >> 
>> >> And MetaInformacionException extends of Exception.
>> >> 
>> >> The problem is that when in my server throw a new
>> >> MetaInformacionException
>> >> the client never catch the exception because the excepction that
>> occurs
>> >> is a
>> >> "javax.xml.rpc.soap.SOAPFaultException" but with the message of my
>> custom
>> >> Exception.
>> >> 
>> > 
>> > I was able to get custom exceptions to work using a WSDL-first
>> > approach[1].  From the web service, when you construct your "new
>> > MetaInformationException", make sure you are not using the no-parameter
>> > constructor version (in my example[1], I use a two-parameter
>> > constructor.)  That *might* be the problem you are having, someone else
>> > had a similar issue[2].
>> > 
>> > HTH,
>> > Glen
>> > 
>> > [1] http://www.jroller.com/gmazza/date/20071019#step6
>> > [2] http://issues.apache.org/jira/browse/CXF-1136#action_12537610
>> > 
>> > 
>> > 
>> > 
>> 
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Custom-exceptions-in-CXF-web-service-tf4887017.html#a14023745
Sent from the cxf-user mailing list archive at Nabble.com.


Non-compliant Java exception class generation? (Was Re: Custom exceptions in CXF web-service)

Posted by Glen Mazza <gl...@verizon.net>.
Team, 

If you look at [2] below, we are providing three constructors when we
generate a Java exception class for a wsdl:fault element.  

However, the May 2007 JAX-WS 2.1 spec, bottom of page 22 and top of page
23, states that we should only be providing the bottom two constructors.
Also, as [2] notes, Metro only provides those two constructors.

The problem with the top constructor is the FaultBean, or custom
exception, is not getting stored when you use it, causing the reader
below (and the reader who had the bug at [1]) to be losing the custom
exception and instead just getting a basic SOAPFaultException.  Also, it
makes service code non-portable between Metro and CXF.

I think we should stop supplying the top, one-parameter constructor from
the list below.  (Deprecate it if necessary?)  It keeps us compliant
with the spec and also prevents users from falling into the "Where's my
custom exception?" trap below.

Thoughts?

Thanks,
Glen


Am Donnerstag, den 29.11.2007, 05:22 -0500 schrieb Glen Mazza:
> Upgrade to the two or three parameter one, as you can see from [2], they
> are the only versions that will incorporate your custom exception:
> 
> (Code from [2]:)
> 
> // ignores custom exception:
> public CustomException (String message) { super(message); } 
> 
> // absorbs custom exception:
> public CustomException (String message,
> demo.hw.company.CustomExceptionType customException) { 
>  super(message); -->this.customException = customException;<-- } 
> 
> // absorbs custom exception:
> public CustomException (String message,
> demo.hw.company.CustomExceptionType customException, Throwable cause) { 
>  super(message, cause); -->this.customException = customException;<-- }
> 
> 
> Am Donnerstag, den 29.11.2007, 01:45 -0800 schrieb imorales:
> > I use the one parameter Constructor. 
> > --> throw new MetaInformacionException("Error in meta Info")
> > 
> > Glen Mazza-2 wrote:
> > > 
> > > Am Mittwoch, den 28.11.2007, 00:25 -0800 schrieb imorales:
> > >> Hi all. I developed a web service using CXF. The methods of the web
> > >> service
> > >> throws Custom Exceptions. Something like that:
> > >> 
> > >> -----------------------------------------------------------------------------------------
> > >> @WebResult(name="ticket")
> > >> Long iniciaFormulario( @WebParam(name="xslt") String xslt) throws
> > >> MetaInformacionException;
> > >> -----------------------------------------------------------------------------------------
> > >> 
> > >> And MetaInformacionException extends of Exception.
> > >> 
> > >> The problem is that when in my server throw a new
> > >> MetaInformacionException
> > >> the client never catch the exception because the excepction that occurs
> > >> is a
> > >> "javax.xml.rpc.soap.SOAPFaultException" but with the message of my custom
> > >> Exception.
> > >> 
> > > 
> > > I was able to get custom exceptions to work using a WSDL-first
> > > approach[1].  From the web service, when you construct your "new
> > > MetaInformationException", make sure you are not using the no-parameter
> > > constructor version (in my example[1], I use a two-parameter
> > > constructor.)  That *might* be the problem you are having, someone else
> > > had a similar issue[2].
> > > 
> > > HTH,
> > > Glen
> > > 
> > > [1] http://www.jroller.com/gmazza/date/20071019#step6
> > > [2] http://issues.apache.org/jira/browse/CXF-1136#action_12537610
> > > 
> > > 
> > > 
> > > 
> > 
> 


Re: Custom exceptions in CXF web-service

Posted by Glen Mazza <gl...@verizon.net>.
Upgrade to the two or three parameter one, as you can see from [2], they
are the only versions that will incorporate your custom exception:

(Code from [2]:)

// ignores custom exception:
public CustomException (String message) { super(message); } 

// absorbs custom exception:
public CustomException (String message,
demo.hw.company.CustomExceptionType customException) { 
 super(message); -->this.customException = customException;<-- } 

// absorbs custom exception:
public CustomException (String message,
demo.hw.company.CustomExceptionType customException, Throwable cause) { 
 super(message, cause); -->this.customException = customException;<-- }


Am Donnerstag, den 29.11.2007, 01:45 -0800 schrieb imorales:
> I use the one parameter Constructor. 
> --> throw new MetaInformacionException("Error in meta Info")
> 
> Glen Mazza-2 wrote:
> > 
> > Am Mittwoch, den 28.11.2007, 00:25 -0800 schrieb imorales:
> >> Hi all. I developed a web service using CXF. The methods of the web
> >> service
> >> throws Custom Exceptions. Something like that:
> >> 
> >> -----------------------------------------------------------------------------------------
> >> @WebResult(name="ticket")
> >> Long iniciaFormulario( @WebParam(name="xslt") String xslt) throws
> >> MetaInformacionException;
> >> -----------------------------------------------------------------------------------------
> >> 
> >> And MetaInformacionException extends of Exception.
> >> 
> >> The problem is that when in my server throw a new
> >> MetaInformacionException
> >> the client never catch the exception because the excepction that occurs
> >> is a
> >> "javax.xml.rpc.soap.SOAPFaultException" but with the message of my custom
> >> Exception.
> >> 
> > 
> > I was able to get custom exceptions to work using a WSDL-first
> > approach[1].  From the web service, when you construct your "new
> > MetaInformationException", make sure you are not using the no-parameter
> > constructor version (in my example[1], I use a two-parameter
> > constructor.)  That *might* be the problem you are having, someone else
> > had a similar issue[2].
> > 
> > HTH,
> > Glen
> > 
> > [1] http://www.jroller.com/gmazza/date/20071019#step6
> > [2] http://issues.apache.org/jira/browse/CXF-1136#action_12537610
> > 
> > 
> > 
> > 
> 


Re: Custom exceptions in CXF web-service

Posted by imorales <im...@ignos.com>.
I use the one parameter Constructor. 
--> throw new MetaInformacionException("Error in meta Info")

Glen Mazza-2 wrote:
> 
> Am Mittwoch, den 28.11.2007, 00:25 -0800 schrieb imorales:
>> Hi all. I developed a web service using CXF. The methods of the web
>> service
>> throws Custom Exceptions. Something like that:
>> 
>> -----------------------------------------------------------------------------------------
>> @WebResult(name="ticket")
>> Long iniciaFormulario( @WebParam(name="xslt") String xslt) throws
>> MetaInformacionException;
>> -----------------------------------------------------------------------------------------
>> 
>> And MetaInformacionException extends of Exception.
>> 
>> The problem is that when in my server throw a new
>> MetaInformacionException
>> the client never catch the exception because the excepction that occurs
>> is a
>> "javax.xml.rpc.soap.SOAPFaultException" but with the message of my custom
>> Exception.
>> 
> 
> I was able to get custom exceptions to work using a WSDL-first
> approach[1].  From the web service, when you construct your "new
> MetaInformationException", make sure you are not using the no-parameter
> constructor version (in my example[1], I use a two-parameter
> constructor.)  That *might* be the problem you are having, someone else
> had a similar issue[2].
> 
> HTH,
> Glen
> 
> [1] http://www.jroller.com/gmazza/date/20071019#step6
> [2] http://issues.apache.org/jira/browse/CXF-1136#action_12537610
> 
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Custom-exceptions-in-CXF-web-service-tf4887017.html#a14022517
Sent from the cxf-user mailing list archive at Nabble.com.


Re: Custom exceptions in CXF web-service

Posted by Glen Mazza <gl...@verizon.net>.
Am Mittwoch, den 28.11.2007, 00:25 -0800 schrieb imorales:
> Hi all. I developed a web service using CXF. The methods of the web service
> throws Custom Exceptions. Something like that:
> 
> -----------------------------------------------------------------------------------------
> @WebResult(name="ticket")
> Long iniciaFormulario( @WebParam(name="xslt") String xslt) throws
> MetaInformacionException;
> -----------------------------------------------------------------------------------------
> 
> And MetaInformacionException extends of Exception.
> 
> The problem is that when in my server throw a new MetaInformacionException
> the client never catch the exception because the excepction that occurs is a
> "javax.xml.rpc.soap.SOAPFaultException" but with the message of my custom
> Exception.
> 

I was able to get custom exceptions to work using a WSDL-first
approach[1].  From the web service, when you construct your "new
MetaInformationException", make sure you are not using the no-parameter
constructor version (in my example[1], I use a two-parameter
constructor.)  That *might* be the problem you are having, someone else
had a similar issue[2].

HTH,
Glen

[1] http://www.jroller.com/gmazza/date/20071019#step6
[2] http://issues.apache.org/jira/browse/CXF-1136#action_12537610