I think you have two options:
1) Make the exception look like a normal JAX-WS generated exception. That
would basically mean defining a JAXB bean for the data that has all the
getter/setters and such for the data and making the exception look like:
@WebFault
public class MyException extends Exception {
MyFaultInfo faultInfo;
public MyException(String msg, MyFaultInfo mfi) {
...
}
public MyFaultInfo getFaultInfo() {
return faultInfo;
}
}
That is basically the "JAX-WS" standard way of doing it and would be portable.
The entire schema for the exception is defined in the JAXB MyFaultInfo bean.
2) For CXF, you can add a setter for your extra data and a constructor of
just:
public MyException(String msg) {...}
I think CXF will then call that constructor (maybe also need a no-args, but I
think the single arg works) and then call the setters for anything it finds.
Dan
On Sunday 02 November 2008 6:43:06 am Josef Bajada wrote:
> I am using CXF on Tomcat 6.0.18 and have created my webservice using
> JAX-WS annotations. I need to throw my own exception from this
> webservice because I need to have custom fields in it.
>
> However, in the WSDL being created by CXF my custom exception is not
> including the extra fields. What am I doing wrong?
>
> My exception looks something like this:
>
>
>
> public class MyException extends Exception
>
> {
>
> int faultCode;
>
>
>
> public MyException(String desc, int faultCode)
>
> {
>
> super (desc);
>
> this.faultCode = faultCode;
>
> }
>
>
>
> public int getFaultCode()
>
> {
>
> return faultCode;
>
> }
>
> }
>
>
>
>
>
> My Webservice looks like this:
>
>
>
> @WebService
>
> public class MyWebservice
>
> {
>
> @WebMethod
>
> public void myMethod()
>
> throws MyException
>
> }
>
>
>
> Isnt this the proper way to throw an exception with JAX-WS? Is CXF doing
> something it shouldn't or am I missing something?
>
>
>
> Thanks,
>
>
>
> Josef
--
Daniel Kulp
[EMAIL PROTECTED]
http://dankulp.com/blog