Package br.com.caelum.vraptor.actioncache

Source Code of br.com.caelum.vraptor.actioncache.CachedHttpResponseFactory

package br.com.caelum.vraptor.actioncache;

import javax.annotation.Priority;
import javax.enterprise.context.RequestScoped;
import javax.enterprise.inject.Alternative;
import javax.enterprise.inject.Produces;
import javax.inject.Inject;
import javax.interceptor.Interceptor;

import br.com.caelum.vraptor.core.MethodInfo;
import br.com.caelum.vraptor.http.MutableResponse;
import br.com.caelum.vraptor.ioc.cdi.CDIRequestFactories;

@RequestScoped
@Alternative
@Priority(Interceptor.Priority.LIBRARY_AFTER)
public class CachedHttpResponseFactory{

  @Inject
  private CDIRequestFactories requestFactories;
  @Inject
  private MethodInfo methodInfo;

  @Produces @javax.enterprise.context.RequestScoped
  public MutableResponse getInstance(){
    MutableResponse response = requestFactories.getResponse();
    if(!methodInfo.getControllerMethod().containsAnnotation(Cached.class)){
      return response;
    }
    return new CharArrayWriterResponse(response);
  }
}
TOP

Related Classes of br.com.caelum.vraptor.actioncache.CachedHttpResponseFactory

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.