001 package com.khubla.pragmatach.framework.controller.impl.trivial; 002 003 import java.io.PrintWriter; 004 import java.util.Map; 005 006 import javax.servlet.http.HttpServletResponse; 007 008 import com.khubla.pragmatach.framework.api.PragmatachException; 009 import com.khubla.pragmatach.framework.controller.impl.AbstractResponse; 010 011 /** 012 * @author tome 013 */ 014 public class TrivialResponse extends AbstractResponse { 015 /** 016 * http code 017 */ 018 private final int httpCode; 019 /** 020 * response 021 */ 022 private final String response; 023 024 /** 025 * ctor 026 */ 027 public TrivialResponse(Map<String, String> cacheHeaders, int httpCode) { 028 super(cacheHeaders); 029 response = null; 030 this.httpCode = httpCode; 031 } 032 033 /** 034 * ctor 035 */ 036 public TrivialResponse(Map<String, String> cacheHeaders, String response, 037 int httpCode) { 038 super(cacheHeaders); 039 this.response = response; 040 this.httpCode = httpCode; 041 } 042 043 @Override 044 public String getContentType() throws PragmatachException { 045 // dunno 046 return null; 047 } 048 049 @Override 050 public Map<String, String> getHeaders() throws PragmatachException { 051 return getCacheHeaders(); 052 } 053 054 @Override 055 public int getHTTPCode() { 056 return httpCode; 057 } 058 059 @Override 060 public void render(HttpServletResponse httpServletResponse) 061 throws PragmatachException { 062 try { 063 if (null != response) { 064 final PrintWriter printWriter = new PrintWriter( 065 httpServletResponse.getOutputStream()); 066 printWriter.write(response); 067 printWriter.flush(); 068 printWriter.close(); 069 } 070 } catch (final Exception e) { 071 throw new PragmatachException("Exception in render", e); 072 } 073 } 074 }