You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by Al Eridani <al...@gmail.com> on 2014/02/10 19:49:23 UTC
Automatic exception conversion?
Hello, all my web service methods follow the same pattern:
public ... someMethod() throws MyWebServicesFault {
try {
...
} catch (Exception e) {
throw new MyWebServicesFault(e);
}
}
Is it possible to simplify them by eliminating the try/catch and somehow
tell the CXF framework to catch any exception thrown and to wrap it into my
custom MyWebServicesFault?
I'm using 2.6.2, if it matters.
Thanks!
RE: Automatic exception conversion?
Posted by Andrei Shakirin <as...@talend.com>.
Great that you got it working, you welcome :)
Andrei.
From: Al Eridani [mailto:al.eridani@gmail.com]
Sent: Donnerstag, 13. Februar 2014 20:24
To: Andrei Shakirin
Subject: Re: Automatic exception conversion?
Thank you, Andrei, that was very helpful.
On Wed, Feb 12, 2014 at 6:36 AM, Andrei Shakirin <as...@talend.com>> wrote:
Hi,
The interceptor should looks like:
public class ClientSoapFaultInterceptor extends AbstractPhaseInterceptor<SoapMessage> {
public ClientSoapFaultInterceptor() {
super(Phase.PRE_LOGICAL);
}
@Override
public void handleMessage(SoapMessage message) throws Fault {
Exception e = message.getContent(Exception.class);
if (e != null) {
message.setContent(Exception.class, new IllegalArgumentException("my test"));
}
}
}
Instead new IllegalArgumentException("my test") you can put your own exception.
Configuration of interceptor using spring will be the following:
<jaxws:client id="customerService"
serviceName="customer:CustomerServiceService"
endpointName="customer:CustomerServiceEndpoint"
address="http://localhost:9090/CustomerServicePort"
serviceClass="com.example.customerservice.CustomerService">
<jaxws:inFaultInterceptors>
<bean class="com.example.customerservice.client.ClientSoapFaultInterceptor"/>
</jaxws:inFaultInterceptors>
</jaxws:client>
Regards,
Andrei.
> -----Original Message-----
> From: Al Eridani [mailto:al.eridani@gmail.com<ma...@gmail.com>]
> Sent: Dienstag, 11. Februar 2014 18:50
> To: users@cxf.apache.org<ma...@cxf.apache.org>
> Subject: Re: Automatic exception conversion?
>
> Thank you for your reply, Andrei.
> This is for JAX-WS. Do you have any pointers to documentation or examples
> about how do I write my own interceptor and how to I place it in the fault
> chain?
> Regards,
>
>
>
> On Mon, Feb 10, 2014 at 10:41 PM, Andrei Shakirin
> <as...@talend.com>>wrote:
>
> > Hi,
> >
> > Do you speak about JAX-RS or JAX-WS service?
> > In former case it is possible to achieve that with Exception Mapper.
> > For JAX-WS you likely need to write own interceptor and put it into fault
> chain.
> >
> > Regards,
> > Andrei.
> >
> > > -----Original Message-----
> > > From: Al Eridani [mailto:al.eridani@gmail.com<ma...@gmail.com>]
> > > Sent: Montag, 10. Februar 2014 19:49
> > > To: users@cxf.apache.org<ma...@cxf.apache.org>
> > > Subject: Automatic exception conversion?
> > >
> > > Hello, all my web service methods follow the same pattern:
> > >
> > > public ... someMethod() throws MyWebServicesFault {
> > > try {
> > > ...
> > > } catch (Exception e) {
> > > throw new MyWebServicesFault(e);
> > > }
> > > }
> > >
> > > Is it possible to simplify them by eliminating the try/catch and
> > > somehow
> > tell the
> > > CXF framework to catch any exception thrown and to wrap it into my
> > > custom MyWebServicesFault?
> > >
> > > I'm using 2.6.2, if it matters.
> > >
> > > Thanks!
> >
RE: Automatic exception conversion?
Posted by Andrei Shakirin <as...@talend.com>.
Hi,
The interceptor should looks like:
public class ClientSoapFaultInterceptor extends AbstractPhaseInterceptor<SoapMessage> {
public ClientSoapFaultInterceptor() {
super(Phase.PRE_LOGICAL);
}
@Override
public void handleMessage(SoapMessage message) throws Fault {
Exception e = message.getContent(Exception.class);
if (e != null) {
message.setContent(Exception.class, new IllegalArgumentException("my test"));
}
}
}
Instead new IllegalArgumentException("my test") you can put your own exception.
Configuration of interceptor using spring will be the following:
<jaxws:client id="customerService"
serviceName="customer:CustomerServiceService"
endpointName="customer:CustomerServiceEndpoint"
address="http://localhost:9090/CustomerServicePort"
serviceClass="com.example.customerservice.CustomerService">
<jaxws:inFaultInterceptors>
<bean class="com.example.customerservice.client.ClientSoapFaultInterceptor"/>
</jaxws:inFaultInterceptors>
</jaxws:client>
Regards,
Andrei.
> -----Original Message-----
> From: Al Eridani [mailto:al.eridani@gmail.com]
> Sent: Dienstag, 11. Februar 2014 18:50
> To: users@cxf.apache.org
> Subject: Re: Automatic exception conversion?
>
> Thank you for your reply, Andrei.
> This is for JAX-WS. Do you have any pointers to documentation or examples
> about how do I write my own interceptor and how to I place it in the fault
> chain?
> Regards,
>
>
>
> On Mon, Feb 10, 2014 at 10:41 PM, Andrei Shakirin
> <as...@talend.com>wrote:
>
> > Hi,
> >
> > Do you speak about JAX-RS or JAX-WS service?
> > In former case it is possible to achieve that with Exception Mapper.
> > For JAX-WS you likely need to write own interceptor and put it into fault
> chain.
> >
> > Regards,
> > Andrei.
> >
> > > -----Original Message-----
> > > From: Al Eridani [mailto:al.eridani@gmail.com]
> > > Sent: Montag, 10. Februar 2014 19:49
> > > To: users@cxf.apache.org
> > > Subject: Automatic exception conversion?
> > >
> > > Hello, all my web service methods follow the same pattern:
> > >
> > > public ... someMethod() throws MyWebServicesFault {
> > > try {
> > > ...
> > > } catch (Exception e) {
> > > throw new MyWebServicesFault(e);
> > > }
> > > }
> > >
> > > Is it possible to simplify them by eliminating the try/catch and
> > > somehow
> > tell the
> > > CXF framework to catch any exception thrown and to wrap it into my
> > > custom MyWebServicesFault?
> > >
> > > I'm using 2.6.2, if it matters.
> > >
> > > Thanks!
> >
Re: Automatic exception conversion?
Posted by Al Eridani <al...@gmail.com>.
Thank you for your reply, Andrei.
This is for JAX-WS. Do you have any pointers to documentation or examples
about how do I write my own interceptor and how to I place it in the fault
chain?
Regards,
On Mon, Feb 10, 2014 at 10:41 PM, Andrei Shakirin <as...@talend.com>wrote:
> Hi,
>
> Do you speak about JAX-RS or JAX-WS service?
> In former case it is possible to achieve that with Exception Mapper. For
> JAX-WS you likely need to write own interceptor and put it into fault chain.
>
> Regards,
> Andrei.
>
> > -----Original Message-----
> > From: Al Eridani [mailto:al.eridani@gmail.com]
> > Sent: Montag, 10. Februar 2014 19:49
> > To: users@cxf.apache.org
> > Subject: Automatic exception conversion?
> >
> > Hello, all my web service methods follow the same pattern:
> >
> > public ... someMethod() throws MyWebServicesFault {
> > try {
> > ...
> > } catch (Exception e) {
> > throw new MyWebServicesFault(e);
> > }
> > }
> >
> > Is it possible to simplify them by eliminating the try/catch and somehow
> tell the
> > CXF framework to catch any exception thrown and to wrap it into my custom
> > MyWebServicesFault?
> >
> > I'm using 2.6.2, if it matters.
> >
> > Thanks!
>
RE: Automatic exception conversion?
Posted by Andrei Shakirin <as...@talend.com>.
Hi,
Do you speak about JAX-RS or JAX-WS service?
In former case it is possible to achieve that with Exception Mapper. For JAX-WS you likely need to write own interceptor and put it into fault chain.
Regards,
Andrei.
> -----Original Message-----
> From: Al Eridani [mailto:al.eridani@gmail.com]
> Sent: Montag, 10. Februar 2014 19:49
> To: users@cxf.apache.org
> Subject: Automatic exception conversion?
>
> Hello, all my web service methods follow the same pattern:
>
> public ... someMethod() throws MyWebServicesFault {
> try {
> ...
> } catch (Exception e) {
> throw new MyWebServicesFault(e);
> }
> }
>
> Is it possible to simplify them by eliminating the try/catch and somehow tell the
> CXF framework to catch any exception thrown and to wrap it into my custom
> MyWebServicesFault?
>
> I'm using 2.6.2, if it matters.
>
> Thanks!