I have developed Rest Application (JAX RS) using Apache CXF.
CXF configuration:
<jaxrs:server id="InternalRS" address="/V1">
<jaxrs:serviceBeans>
<ref bean="InternalService" />
</jaxrs:serviceBeans>
<jaxrs:providers>
<ref bean="jsonProvider" />
</jaxrs:providers>
<jaxrs:inInterceptors>
<bean id="CustomInterceptor"
class="com.test.web.interceptor.CustomInterceptor">
</bean>
</jaxrs:inInterceptors>
</jaxrs:server>
Inbound Interceptor:
public class CustomInterceptor extends AbstractPhaseInterceptor<Message> {
public CustomInterceptor() {
super(Phase.READ);
}
@Override
public void handleMessage(Message message) throws Fault {
HttpServletRequest request = (HttpServletRequest) message.get(AbstractHTTPDestination.HTTP_REQUEST);
Transaction transaction = new Transaction();
String id = request.getHeader("id");
transaction.setId(id);
message.getExchange().put("transaction", transaction);
}
}
Is there any way so that I could convert the business exception thrown by my application to its equivalent HTTP Status Codes by modifying the JSON response with an outbound interceptor.