• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Exception Handling with RESTEasy's client proxy framework

 
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, i would like to use resteasys client proxy framework as its nice to have an interface to communicate with.
My interface on the server side looks like:



The code on the client (interface definition) is:


The client code is:


When i try to use the client, i do not get an exception as expected. The server throws the exception and puts it into the responses entity. This is working as expected. But on the client side, it seems like the exception is simply ignored. I would at least expect a string representation inside the response's entity of the exception. But there is nothing, it is null.
So i tried to tell resteasy it should use my exceptionmapper (the lines above which are commented), but that does not work neither. I did not find any documentation how to create such a (valid) ClientConfiguration.
The exceptionmapper i created is:


Can someone tell me how i can register this mapper so i can use the client code like this:


Thanks in advance!
 
Sheriff
Posts: 22819
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Unfortunately, RESTeasy, Jersey and probably any JAX-RS implementation does not handle server side exceptions the way we would like to. Instead, the code throws an implementation specific exception. In RESTeasy that's (I think) a RedirectionException (3xx), a ClientErrorException (4xx) or a ServerErrorException (5xx). For all, you can get the response from the exception, which you may need to parse to convert into the original exception. Using an ExceptionMapper makes that step easier because you can turn exceptions into responses you can more easily convert back.
 
olze oli
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Rob, can you show me how to register (or where) the ClientErrorException in the client? I use Vaadin as UI technology with jetty. I guess i have to have something like:

But it is not running into the ExceptionMapper:

Any idea why? Did i register the mapper wrong? I would prefer to configure all this in java, not in .xml, if possible.
 
olze oli
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I also tried to use ClientErrorException for the Mapper - but its also not executing it. Also the log shows nothing of that class, what i would expect when it gets registered
 
Rob Spoor
Sheriff
Posts: 22819
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ExceptionMapper is a server-side mechanism - it turns an exception into a response. On the client side it no longer exists. You will need to catch the ClientErrorException separately, and manually convert it back to the proper exception (convert the response back into an exception). There is no mechanism for that in JAX-RS.
 
olze oli
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, but how? The response's entity is null.

The code on the server is:


This is executed as expected.
But on the client side when i set a breakpoint after:

I see nothing of "Invalid Captcha" in the response to identify what has caused it on the server side. The entity is null. And i dont know why. This is my main problem. Can you tell me why?
 
Rob Spoor
Sheriff
Posts: 22819
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you sure it's really null when you retrieve it? The response's entity may be lazily loaded. What happens if you try to actually retrieve the entity using response.getEntity()?
 
olze oli
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
response.getEntity() also returns null
 
Maybe he went home and went to bed. And took this tiny ad with him:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic