You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by "Petr V." <gr...@yahoo.com> on 2009/03/04 19:29:32 UTC

Exception Inheritance Model

I have inheritance model in exception hierarchy but published wsdl via CXF does not show that.

I did lil google and found that it is as per spec

Dan replied below on following thread 

http://mail-archives.apache.org/mod_mbox/cxf-users/200803.mbox/%3C200803310933.26880.dkulp@apache.org%3E

"As Glen mentioned, this is completely per spec.   

You can work around it SLIGHTLY by refactoring your exceptions to store 
all their data in JAXB specified java beans (grabbed via getFaultInfo()) 
that implement the same heiarchy.   That said, when you run wsdl2java on 
the wsdl to generate code from it, that heiarchy would not be honored in 
the exceptions themselves. 

In anycase, this is all per spec."
So this raises new question. Since I am writing java first so all my methods throw the top exception class so in case if I need to throw some sub classes, I wont have to change function signature. But if service publish does not maintain hierarchy model so what would happen if some exception is thrown from service which is actuall ysub class of super class but not specified in wsdl, Crash ? Run Time Exception ?

class TopException {
}

class subException1 extends TopException {
}

class subException2 extends TopException {

}

Method in service is

public void foo() throws subException1 , TopException{
.....
}

So generated wsdl would show that two exceptions could be thrown.

So far so good but as we know that subException2 is inherited from TopException1 so there is no stopping for throwing it from foo()

So what if client calls service method foo() and foo() throws subException2 (java compiler wont complain as well as outside web services, code would work fine) but wsdl and generated proxy won't have no idea that subException2 is inherited from TopException1 so would it crash at run time?

Does it mean that I need to explictly define every exception that could be thrown from web services so it can show up in wsdl and should not rely on inheritance model of exception. It would mean that I just flatten my exception model and live with that :-(. 

Is my understanding coprrect ? Am I missin gsoem thing?

Any help would be appreciated to clarify my understanding and how to avoid the current situation.

Thanks,

Petr



      

Re: Exception Inheritance Model

Posted by Glen Mazza <gl...@gmail.com>.

Petr V. wrote:
> 
> Daniel, can you please look into this issue. :-(
> 
> Thanks Glen for your response.I believe your BasicFault class is simple
> POJO which is not inheriting from java Exception class, Right ? Can you
> please confirm it.
> 

Yes.  This is all defined in the JAX-WS 2.1 specification, I think--no
difference between us and Metro.  I don't think you can have the hierarchy
that you want to JAX-WS.

Glen

-- 
View this message in context: http://www.nabble.com/Exception-Inheritance-Model-tp22336256p22362995.html
Sent from the cxf-user mailing list archive at Nabble.com.


Re: Exception Inheritance Model

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

I really don't think JAX-WS allows this too well.   :-(


On Thu March 5 2009 6:10:07 pm Petr V. wrote:
> Daniel, can you please look into this issue. :-(
>
> Thanks Glen for your response.I believe your BasicFault class is simple
> POJO which is not inheriting from java Exception class, Right ? Can you
> please confirm it.
>
> I have another issue.
>
> My web service calls some other business functions which throws exceptions.
> The business exceptions has its own hierarchy so if I pass them to client
> as it is then client gets only the child class elements.

Most likely, the JAXB context doesn't know about the subclasses.   We just 
walk the actual referenced types from the service interface.   If the 
interface doesn't reference them directly, we don't know about them and JAXB 
won't pick them up.   Thus, only the base class elements get processed.

The "fix" with 2.1.x is to add @XmlSeeAlso annotations onto the base classes 
or SEI interface to point it at the subclasses.   JAXB picks up those 
annotations to learn where the subclasses are and it can then use them.

Dan


>
> So now suggestion is that I wrap the exception object in fault but I
> believe the Fault can wrap only POJOs and not other exception object.
>
> Let me write a code to explain
>
> Business Model Exceptions
>
> class BusinessParentException  extends Exception {
>
> ...........
>
> }
>
>
>
> class BusinessChildException extends BsuinessParentException {
>
> ..........
>
>
> }
>
>
>
> ---------------------------------------------------------------------------
>----------------------------
>
> Service Layer Exception POJO Hierarchy
>
> class ServiceParentException { // note it is not extending Exception
> ...........
> }
>
> class ServiceChildException extends ServiceParentException {
> ..........
>
> }
>
>
> class CustomException {
>     ServiceChildException ce ;
>      ........
>
> }
>
>
>
> Service Method
>
> public void foo() throws CustomException {
>
>    try {
>        calling business function
>    } catch (BusinessChildException e ) {
>       //convert e (of type BusinessChildException) to f of type
> ServiceChildException    throw new CustomException(" XXX " , f ) ;
>   }
> }
>   }
>
> If I dont convert BusinessChildException to ServiceChildException and try
> to wrap it in CustomException then I get following Exception
>
> Caused by: org.apache.cxf.interceptor.Fault: Could not find JAXB
> information for bean class exceptions.BusinessChildException in context.  
> Make sure it follows JAXB conventions. at
> org.apache.cxf.jaxb.JAXBSchemaInitializer.end(JAXBSchemaInitializer.java:29
>5) at
> org.apache.cxf.service.ServiceModelVisitor.visitOperation(ServiceModelVisit
>or.java:124) at
> org.apache.cxf.service.ServiceModelVisitor.walk(ServiceModelVisitor.java:74
>) at
> org.apache.cxf.jaxb.JAXBDataBinding.initialize(JAXBDataBinding.java:366) at
> org.apache.cxf.service.factory.ReflectionServiceFactoryBean.buildServiceFro
>mClass(ReflectionServiceFactoryBean.java:345) at
> org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean.buildServiceFromClass(
>JaxWsServiceFactoryBean.java:513) at
> org.apache.cxf.service.factory.ReflectionServiceFactoryBean.initializeServi
>ceModel(ReflectionServiceFactoryBean.java:396) at
> org.apache.cxf.service.factory.ReflectionServiceFactoryBean.create(Reflecti
>onServiceFactoryBean.java:181) at
> org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean.create(JaxWsServiceFac
>toryBean.java:163) at
> org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory.createEndpoint(Abs
>tractWSDLBasedEndpointFactory.java:79) at
> org.apache.cxf.frontend.ClientFactoryBean.create(ClientFactoryBean.java:51)
> at
> org.apache.cxf.frontend.ClientProxyFactoryBean.create(ClientProxyFactoryBea
>n.java:97) at
> org.apache.cxf.jaxws.JaxWsProxyFactoryBean.create(JaxWsProxyFactoryBean.jav
>a:93) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:3
>9) at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImp
>l.java:25) at java.lang.reflect.Method.invoke(Method.java:597)
>     at
> org.springframework.beans.factory.support.SimpleInstantiationStrategy.insta
>ntiate(SimpleInstantiationStrategy.java:115) ... 39 more
>
> It looks like that you can't wrap object of type Exception in any exception
> that is thrown over the wire. This would mean I have to create duplicate
> hierarchy of exception pojo just for web services. Is there any way I can
> avoid it and wrap exception object in Fault thrown over wire.
>
> Thanks,
>
> Petr
>
>
>
>
>
>
>
> --- On Fri, 3/6/09, Glen Mazza <gl...@gmail.com> wrote:
> From: Glen Mazza <gl...@gmail.com>
> Subject: Re: Exception Inheritance Model
> To: users@cxf.apache.org
> Date: Friday, March 6, 2009, 1:44 AM
>
> FWIW, this is what I did when I had several types of different error
> messages to handle:
> http://www.jroller.com/gmazza/entry/database_crud_actions_with_web
>
> HTH,
> Glen
>
> Petr V. wrote:
> > Any one please ?
> >
> > Thanks,
> >
> > Petr
> >
> > --- On Wed, 3/4/09, Petr V. <gr...@yahoo.com> wrote:
> > From: Petr V. <gr...@yahoo.com>
> > Subject: Exception Inheritance Model
> > To: users@cxf.apache.org
> > Date: Wednesday, March 4, 2009, 11:29 PM
> >
> > I have inheritance model in exception hierarchy but published wsdl via
> > CXF does
> > not show that.
> >
> > I did lil google and found that it is as per spec
> >
> > Dan replied below on following thread
>
> http://mail-archives.apache.org/mod_mbox/cxf-users/200803.mbox/%3C200803310
>933.26880.dkulp@apache.org%3E
>
> > "As Glen mentioned, this is completely per spec.
> >
> > You can work around it SLIGHTLY by refactoring your exceptions to store
> > all their data in JAXB specified java beans (grabbed via getFaultInfo())
> > that implement the same heiarchy.   That said, when you run wsdl2java on
> > the wsdl to generate code from it, that heiarchy would not be honored in
> > the exceptions themselves.
> >
> > In anycase, this is all per spec."
> > So this raises new question. Since I am writing java first so all my
> > methods
> > throw the top exception class so in case if I need to throw some sub
> > classes, I
> > wont have to change function signature. But if service publish does not
> > maintain
> > hierarchy model so what would happen if some exception is thrown from
> > service
> > which is actuall ysub class of super class but not specified in wsdl,
> > Crash ?
> > Run Time Exception ?
> >
> > class TopException {
> > }
> >
> > class subException1 extends TopException {
> > }
> >
> > class subException2 extends TopException {
> >
> > }
> >
> > Method in service is
> >
> > public void foo() throws subException1 , TopException{
> > .....
> > }
> >
> > So generated wsdl would show that two exceptions could be thrown.
> >
> > So far so good but as we know that subException2 is inherited from
> > TopException1 so there is no stopping for throwing it from foo()
> >
> > So what if client calls service method foo() and foo() throws
> > subException2
> > (java compiler wont complain as well as outside web services, code would
> > work
> > fine) but wsdl and generated proxy won't have no idea that
>
> subException2
>
> > is
> > inherited from TopException1 so would it crash at run time?
> >
> > Does it mean that I need to explictly define every exception that could
> > be thrown from web services so it can show up in wsdl and should not rely
> > on inheritance model of exception. It would mean that I just flatten my
> > exception
> > model and live with that :-(.
> >
> > Is my understanding coprrect ? Am I missin gsoem thing?
> >
> > Any help would be appreciated to clarify my understanding and how to
> > avoid the
> > current situation.
> >
> > Thanks,
> >
> > Petr

-- 
Daniel Kulp
dkulp@apache.org
http://www.dankulp.com/blog

Re: Exception Inheritance Model

Posted by "Petr V." <gr...@yahoo.com>.
Daniel, can you please look into this issue. :-(

Thanks Glen for your response.I believe your BasicFault class is simple POJO which is not inheriting from java Exception class, Right ? Can you please confirm it.

I have another issue.

My web service calls some other business functions which throws exceptions. 
The business exceptions has its own hierarchy so if I pass them to client as it is then client gets only the child class elements.

So now suggestion is that I wrap the exception object in fault but I believe the Fault can wrap only POJOs and not other exception object.

Let me write a code to explain

Business Model Exceptions

class BusinessParentException  extends Exception {

...........

}



class BusinessChildException extends BsuinessParentException {

..........


}



-------------------------------------------------------------------------------------------------------

Service Layer Exception POJO Hierarchy 

class ServiceParentException { // note it is not extending Exception 
...........
}

class ServiceChildException extends ServiceParentException {
..........

}


class CustomException {
    ServiceChildException ce ;
     ........

}



Service Method

public void foo() throws CustomException {

   try {
       calling business function
   } catch (BusinessChildException e ) {
      //convert e (of type BusinessChildException) to f of type ServiceChildException    
      throw new CustomException(" XXX " , f ) ;
  }
}
  }

If I dont convert BusinessChildException to ServiceChildException and try to wrap it in CustomException then I get following Exception

Caused by: org.apache.cxf.interceptor.Fault: Could not find JAXB information for bean class exceptions.BusinessChildException in context.   Make sure it follows JAXB conventions.
    at org.apache.cxf.jaxb.JAXBSchemaInitializer.end(JAXBSchemaInitializer.java:295)
    at org.apache.cxf.service.ServiceModelVisitor.visitOperation(ServiceModelVisitor.java:124)
    at org.apache.cxf.service.ServiceModelVisitor.walk(ServiceModelVisitor.java:74)
    at org.apache.cxf.jaxb.JAXBDataBinding.initialize(JAXBDataBinding.java:366)
    at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.buildServiceFromClass(ReflectionServiceFactoryBean.java:345)
    at org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean.buildServiceFromClass(JaxWsServiceFactoryBean.java:513)
    at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.initializeServiceModel(ReflectionServiceFactoryBean.java:396)
    at org.apache.cxf.service.factory.ReflectionServiceFactoryBean.create(ReflectionServiceFactoryBean.java:181)
    at org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean.create(JaxWsServiceFactoryBean.java:163)
    at org.apache.cxf.frontend.AbstractWSDLBasedEndpointFactory.createEndpoint(AbstractWSDLBasedEndpointFactory.java:79)
    at org.apache.cxf.frontend.ClientFactoryBean.create(ClientFactoryBean.java:51)
    at org.apache.cxf.frontend.ClientProxyFactoryBean.create(ClientProxyFactoryBean.java:97)
    at org.apache.cxf.jaxws.JaxWsProxyFactoryBean.create(JaxWsProxyFactoryBean.java:93)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:115)
    ... 39 more

It looks like that you can't wrap object of type Exception in any exception that is thrown over the wire. This would mean I have to create duplicate hierarchy of exception pojo just for web services. Is there any way I can avoid it and wrap exception object in Fault thrown over wire.

Thanks,

Petr







--- On Fri, 3/6/09, Glen Mazza <gl...@gmail.com> wrote:
From: Glen Mazza <gl...@gmail.com>
Subject: Re: Exception Inheritance Model
To: users@cxf.apache.org
Date: Friday, March 6, 2009, 1:44 AM

FWIW, this is what I did when I had several types of different error messages
to handle:
http://www.jroller.com/gmazza/entry/database_crud_actions_with_web

HTH,
Glen


Petr V. wrote:
> 
> Any one please ?
> 
> Thanks,
> 
> Petr
> 
> --- On Wed, 3/4/09, Petr V. <gr...@yahoo.com> wrote:
> From: Petr V. <gr...@yahoo.com>
> Subject: Exception Inheritance Model
> To: users@cxf.apache.org
> Date: Wednesday, March 4, 2009, 11:29 PM
> 
> I have inheritance model in exception hierarchy but published wsdl via CXF
> does
> not show that.
> 
> I did lil google and found that it is as per spec
> 
> Dan replied below on following thread 
> 
>
http://mail-archives.apache.org/mod_mbox/cxf-users/200803.mbox/%3C200803310933.26880.dkulp@apache.org%3E
> 
> "As Glen mentioned, this is completely per spec.   
> 
> You can work around it SLIGHTLY by refactoring your exceptions to store 
> all their data in JAXB specified java beans (grabbed via getFaultInfo()) 
> that implement the same heiarchy.   That said, when you run wsdl2java on 
> the wsdl to generate code from it, that heiarchy would not be honored in 
> the exceptions themselves. 
> 
> In anycase, this is all per spec."
> So this raises new question. Since I am writing java first so all my
> methods
> throw the top exception class so in case if I need to throw some sub
> classes, I
> wont have to change function signature. But if service publish does not
> maintain
> hierarchy model so what would happen if some exception is thrown from
> service
> which is actuall ysub class of super class but not specified in wsdl,
> Crash ?
> Run Time Exception ?
> 
> class TopException {
> }
> 
> class subException1 extends TopException {
> }
> 
> class subException2 extends TopException {
> 
> }
> 
> Method in service is
> 
> public void foo() throws subException1 , TopException{
> .....
> }
> 
> So generated wsdl would show that two exceptions could be thrown.
> 
> So far so good but as we know that subException2 is inherited from
> TopException1 so there is no stopping for throwing it from foo()
> 
> So what if client calls service method foo() and foo() throws
> subException2
> (java compiler wont complain as well as outside web services, code would
> work
> fine) but wsdl and generated proxy won't have no idea that
subException2
> is
> inherited from TopException1 so would it crash at run time?
> 
> Does it mean that I need to explictly define every exception that could be
> thrown from web services so it can show up in wsdl and should not rely on
> inheritance model of exception. It would mean that I just flatten my
> exception
> model and live with that :-(. 
> 
> Is my understanding coprrect ? Am I missin gsoem thing?
> 
> Any help would be appreciated to clarify my understanding and how to avoid
> the
> current situation.
> 
> Thanks,
> 
> Petr
> 
> 
> 
>       
> 
> 
>       
> 

-- 
View this message in context:
http://www.nabble.com/Exception-Inheritance-Model-tp22336256p22360240.html
Sent from the cxf-user mailing list archive at Nabble.com.




      

Re: Exception Inheritance Model

Posted by Glen Mazza <gl...@gmail.com>.
FWIW, this is what I did when I had several types of different error messages
to handle:
http://www.jroller.com/gmazza/entry/database_crud_actions_with_web

HTH,
Glen


Petr V. wrote:
> 
> Any one please ?
> 
> Thanks,
> 
> Petr
> 
> --- On Wed, 3/4/09, Petr V. <gr...@yahoo.com> wrote:
> From: Petr V. <gr...@yahoo.com>
> Subject: Exception Inheritance Model
> To: users@cxf.apache.org
> Date: Wednesday, March 4, 2009, 11:29 PM
> 
> I have inheritance model in exception hierarchy but published wsdl via CXF
> does
> not show that.
> 
> I did lil google and found that it is as per spec
> 
> Dan replied below on following thread 
> 
> http://mail-archives.apache.org/mod_mbox/cxf-users/200803.mbox/%3C200803310933.26880.dkulp@apache.org%3E
> 
> "As Glen mentioned, this is completely per spec.   
> 
> You can work around it SLIGHTLY by refactoring your exceptions to store 
> all their data in JAXB specified java beans (grabbed via getFaultInfo()) 
> that implement the same heiarchy.   That said, when you run wsdl2java on 
> the wsdl to generate code from it, that heiarchy would not be honored in 
> the exceptions themselves. 
> 
> In anycase, this is all per spec."
> So this raises new question. Since I am writing java first so all my
> methods
> throw the top exception class so in case if I need to throw some sub
> classes, I
> wont have to change function signature. But if service publish does not
> maintain
> hierarchy model so what would happen if some exception is thrown from
> service
> which is actuall ysub class of super class but not specified in wsdl,
> Crash ?
> Run Time Exception ?
> 
> class TopException {
> }
> 
> class subException1 extends TopException {
> }
> 
> class subException2 extends TopException {
> 
> }
> 
> Method in service is
> 
> public void foo() throws subException1 , TopException{
> .....
> }
> 
> So generated wsdl would show that two exceptions could be thrown.
> 
> So far so good but as we know that subException2 is inherited from
> TopException1 so there is no stopping for throwing it from foo()
> 
> So what if client calls service method foo() and foo() throws
> subException2
> (java compiler wont complain as well as outside web services, code would
> work
> fine) but wsdl and generated proxy won't have no idea that subException2
> is
> inherited from TopException1 so would it crash at run time?
> 
> Does it mean that I need to explictly define every exception that could be
> thrown from web services so it can show up in wsdl and should not rely on
> inheritance model of exception. It would mean that I just flatten my
> exception
> model and live with that :-(. 
> 
> Is my understanding coprrect ? Am I missin gsoem thing?
> 
> Any help would be appreciated to clarify my understanding and how to avoid
> the
> current situation.
> 
> Thanks,
> 
> Petr
> 
> 
> 
>       
> 
> 
>       
> 

-- 
View this message in context: http://www.nabble.com/Exception-Inheritance-Model-tp22336256p22360240.html
Sent from the cxf-user mailing list archive at Nabble.com.


Re: Exception Inheritance Model

Posted by "Petr V." <gr...@yahoo.com>.
Any one please ?

Thanks,

Petr

--- On Wed, 3/4/09, Petr V. <gr...@yahoo.com> wrote:
From: Petr V. <gr...@yahoo.com>
Subject: Exception Inheritance Model
To: users@cxf.apache.org
Date: Wednesday, March 4, 2009, 11:29 PM

I have inheritance model in exception hierarchy but published wsdl via CXF does
not show that.

I did lil google and found that it is as per spec

Dan replied below on following thread 

http://mail-archives.apache.org/mod_mbox/cxf-users/200803.mbox/%3C200803310933.26880.dkulp@apache.org%3E

"As Glen mentioned, this is completely per spec.   

You can work around it SLIGHTLY by refactoring your exceptions to store 
all their data in JAXB specified java beans (grabbed via getFaultInfo()) 
that implement the same heiarchy.   That said, when you run wsdl2java on 
the wsdl to generate code from it, that heiarchy would not be honored in 
the exceptions themselves. 

In anycase, this is all per spec."
So this raises new question. Since I am writing java first so all my methods
throw the top exception class so in case if I need to throw some sub classes, I
wont have to change function signature. But if service publish does not maintain
hierarchy model so what would happen if some exception is thrown from service
which is actuall ysub class of super class but not specified in wsdl, Crash ?
Run Time Exception ?

class TopException {
}

class subException1 extends TopException {
}

class subException2 extends TopException {

}

Method in service is

public void foo() throws subException1 , TopException{
.....
}

So generated wsdl would show that two exceptions could be thrown.

So far so good but as we know that subException2 is inherited from
TopException1 so there is no stopping for throwing it from foo()

So what if client calls service method foo() and foo() throws subException2
(java compiler wont complain as well as outside web services, code would work
fine) but wsdl and generated proxy won't have no idea that subException2 is
inherited from TopException1 so would it crash at run time?

Does it mean that I need to explictly define every exception that could be
thrown from web services so it can show up in wsdl and should not rely on
inheritance model of exception. It would mean that I just flatten my exception
model and live with that :-(. 

Is my understanding coprrect ? Am I missin gsoem thing?

Any help would be appreciated to clarify my understanding and how to avoid the
current situation.

Thanks,

Petr