You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cxf.apache.org by JE <ne...@weseewhathappens.com> on 2013/07/13 02:51:44 UTC

CXF Handling errors at the Client.

I am using the CXF Rest Client with Spring and need some help dealing with
exceptions.  The problem is I have no ability to change the code calling
the service, the idea is that I can swap out a SOAP implementation for a
REST implementation via Spring config

I have a service client created with spring and am calling it as follows.

try{

      this.myService.getCustomer(customerName);

}catch(MyCustomNotFoundException e){


}

Everything works great on the positive case but my requirement is that
"myService" may throw an exception.  I'd like to use an interceptor to grab
the rest fault and convert it. Assuming an intercepter is the best place to
do this.

my spring.xml has

  <jaxrs:client id="myService"

       address="http://${test.remote.hostname}:8888/${test.remote.service.rs
}"

       serviceClass="com.Customer"

       inheritHeaders="true">

       <jaxrs:headers>

           <entry key="Accept" value="application/json"/>

           <entry key="Content-Type" value="application/json"/>

        </jaxrs:headers>

       <jaxrs:providers>

           <ref bean="jsonProvider" />

       </jaxrs:providers>

            <jaxrs:inFaultInterceptors>

                <bean class="com.FaultHandler"/>

            </jaxrs:inFaultInterceptors>

</jaxrs:client>


I am stuck as to what to do inside the faulthandler.


When I get a 404 from the server the body contains some details in JSON
that i need to marshall to an object.


public void handleMessage(Message message) throws Fault {

        //psuedo code

        if (response.getStatus() == 404){

        ServiceError error = response.readEntity(ServiceError.class);

        throw new MyCustomNotFoundException(error);

       }

    }


Anyone ever try and do anything like this?

Re: CXF Handling errors at the Client.

Posted by JE <ne...@weseewhathappens.com>.
Figured it out.  ResponseExceptionMapper does the trick nicely


On Fri, Jul 12, 2013 at 8:51 PM, JE <ne...@weseewhathappens.com> wrote:

> I am using the CXF Rest Client with Spring and need some help dealing with
> exceptions.  The problem is I have no ability to change the code calling
> the service, the idea is that I can swap out a SOAP implementation for a
> REST implementation via Spring config
>
> I have a service client created with spring and am calling it as follows.
>
> try{
>
>       this.myService.getCustomer(customerName);
>
> }catch(MyCustomNotFoundException e){
>
>
> }
>
> Everything works great on the positive case but my requirement is that
> "myService" may throw an exception.  I'd like to use an interceptor to grab
> the rest fault and convert it. Assuming an intercepter is the best place to
> do this.
>
> my spring.xml has
>
>   <jaxrs:client id="myService"
>
>        address="http://${test.remote.hostname}:8888/${
> test.remote.service.rs}"
>
>        serviceClass="com.Customer"
>
>        inheritHeaders="true">
>
>        <jaxrs:headers>
>
>            <entry key="Accept" value="application/json"/>
>
>            <entry key="Content-Type" value="application/json"/>
>
>         </jaxrs:headers>
>
>        <jaxrs:providers>
>
>            <ref bean="jsonProvider" />
>
>        </jaxrs:providers>
>
>             <jaxrs:inFaultInterceptors>
>
>                 <bean class="com.FaultHandler"/>
>
>             </jaxrs:inFaultInterceptors>
>
> </jaxrs:client>
>
>
> I am stuck as to what to do inside the faulthandler.
>
>
> When I get a 404 from the server the body contains some details in JSON
> that i need to marshall to an object.
>
>
> public void handleMessage(Message message) throws Fault {
>
>         //psuedo code
>
>         if (response.getStatus() == 404){
>
>         ServiceError error = response.readEntity(ServiceError.class);
>
>         throw new MyCustomNotFoundException(error);
>
>        }
>
>     }
>
>
> Anyone ever try and do anything like this?
>