-
1. Re: Return error payload with RESTEasy binding
mageshbk Nov 20, 2014 7:05 AM (in response to tungtd)Hi,
Could you explain what type of errors you are interested in? You could register your own ErrorInterceptor and register it in the providerfactory. But notice that this can only be re-thrown as Exceptions as shown in the example.
-
2. Re: Re: Return error payload with RESTEasy binding
tungtd Nov 20, 2014 8:52 AM (in response to mageshbk)Hi master,
I need to return a error message when some exception thrown. Maybe it's some kind of Exception Mapper's result. It doesn't need to work similarly as Exception Mapper but It need to produced the same result.
<error> <errorCode/> </errorMessage/> </error>
And I also need to change the returned HTTP status code as well.
Another thing, I tried to change the returned HTTP status code in decompose() method body. But it doesn't work as the quick start example. It seems weird.
public class RESTCustomMessageComposer extends RESTEasyMessageComposer { private static Logger logger = Logger .getLogger(RESTCustomMessageComposer.class); @Override public Message compose(RESTEasyBindingData source, Exchange exchange) throws Exception { return super.compose(source, exchange); } @Override public RESTEasyBindingData decompose(Exchange exchange, RESTEasyBindingData target) throws Exception { // target = super.decompose(exchange, target); Object content = exchange.getMessage().getContent(); logger.info("Changing HTTP Status code..."); System.out.println("Changing HTTP Status code..."); exchange.getContext().setProperty(RESTEasyContextMapper.HTTP_RESPONSE_STATUS, 541).addLabels(new String[]{EndpointLabel.HTTP.label()}); target = super.decompose(exchange, target); return target; } }
-
3. Re: Return error payload with RESTEasy binding
tungtd Nov 22, 2014 3:37 AM (in response to tungtd)Finally, I find out the way to solve this. My REST interface just return a POJO object. So the target's status overriding won't work. I have to change the return type of the REST interface's method to javax.ws.rs.core.Response. And that's it.