On 1/4/2013 4:56 AM, ignou_mca wrote:
> Hi folks,
>
> I am working on a poc using resteasy framework and  resteasy's
> MessageBodyWriterInterceptor
>
> the resource looks like this
>
>      @GET
>      @Path("/{id}")
>      public Response getUserDetails(@PathParam("id") String id);
>
>
> The business logic is implemented using a stateless ejb  below is the
> implementation
>
>
>    @Override
>      public Response getUserDetails(HttpRequest request, String id) {
>
>    -----  business logic -------
>
>          ResponseBuilder builder = Response.ok());
>          return builder.build();
>
>
>      }
>
>
> The interceptor class code is mentioned below
> ==============================
>
>
> @Provider
> @ServerInterceptor
> public class ResponseInterceptor implements MessageBodyWriterInterceptor{
>      private static final Logger logger =
> Logger.getLogger(ResponseInterceptor.class);
>      ResponseBuilder builder = null;
>      @Override
>      public void write(MessageBodyWriterContext context) throws IOException,
> WebApplicationException {
>          Object entity = context.getEntity();
>          logger.debug("Response interceptor: "+entity.getClass());
>
>       if (entity != null) {
>
>       if ( entity instanceof User){
>
>             User entls = (User)entity;
>
>             if (entls !=null && entls.getErrorCode()!=null) {
>
>               if (entls.getErrorCode() == Status.BAD_REQUEST.getStatusCode()){
>
>                   logger.debug("Response interceptor: "+entls.getErrorCode());
>               throw new BadRequestException("Bad request",Response.status(400)
>                           .entity(entls).header("Bad request", "400")
>                        .type("application/xml")
>                        .build());
>
>
>    }
>
>
>
> My question are the following
>
> 1. Whether it's good to create all the response from the interceptor class
> i.e . for htpp 200, 40*, 50* etc..or we should handle only exceptional cases
> which are then Handel by the Exception mappers
>

You should probably not do business login within interceptors.  For 
error conditions that are business logic, either handle them in your 
business logic (jaxrs methods) or throw an exception and write an 
exception mapper.


> 2. What is the advantage of PostProcessorInterceptors over
> MessageBodyWriterInterceptor ?
>

MessageBodyXXXInterceptors are for intercepting and processing the 
marshalling and unmarshalling of http message bodies.  The will not be 
invoked if there is no http method body.  PostProcessInterceptors always 
get invoked after the jax-rs method call and befor marshalling.

> 3. Could you please provide some sample use case?
>

The below blog is about JAX-RS 2.0 but the concepts map 1to1 to 
Resteasy's old interceptor model

http://bill.burkecentral.com/2011/05/24/interceptors-in-jax-rs-2-0/

If you can, switch to Resteasy 3.0 beta 1dardized interceptor model.


> 4. out of Resteasy interceptor and  Ejb interceptor which one is good in terms
> of performance ?
>

resteasy interceptor is for massaging incoming and outgoing HTTP 
requests.  EJB interceptors are for massaging business logic.


-- 
Bill Burke
JBoss, a division of Red Hat
http://bill.burkecentral.com

------------------------------------------------------------------------------
Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
MVPs and experts. SALE $99.99 this month only -- learn more at:
http://p.sf.net/sfu/learnmore_122912
_______________________________________________
Resteasy-users mailing list
Resteasy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/resteasy-users

Reply via email to