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