001    package com.khubla.pragmatach.plugin.jcr;
002    
003    import java.io.ByteArrayInputStream;
004    import java.util.Map;
005    
006    import javax.servlet.http.HttpServletResponse;
007    
008    import org.apache.commons.io.IOUtils;
009    
010    import com.khubla.pragmatach.framework.api.PragmatachException;
011    import com.khubla.pragmatach.framework.controller.impl.AbstractResponse;
012    
013    /**
014     * @author tome
015     */
016    public class JCRResponse extends AbstractResponse {
017       /**
018        * JSON
019        */
020       private final String json;
021    
022       public JCRResponse(Map<String, String> cacheHeaders, String json) {
023          super(cacheHeaders);
024          this.json = json;
025       }
026    
027       @Override
028       public String getContentType() throws PragmatachException {
029          return "application/json";
030       }
031    
032       @Override
033       public Map<String, String> getHeaders() throws PragmatachException {
034          return super.getCacheHeaders();
035       }
036    
037       @Override
038       public void render(HttpServletResponse httpServletResponse) throws PragmatachException {
039          try {
040             final ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(json.getBytes());
041             IOUtils.copy(byteArrayInputStream, httpServletResponse.getOutputStream());
042          } catch (final Exception e) {
043             throw new PragmatachException("Exception in render", e);
044          }
045       }
046    }