1 25 package org.ofbiz.webapp.view; 26 27 import java.io.IOException ; 28 import javax.servlet.ServletContext ; 29 import javax.servlet.http.HttpServletRequest ; 30 import javax.servlet.http.HttpServletResponse ; 31 32 import org.ofbiz.base.util.Debug; 33 import org.ofbiz.base.util.HttpClient; 34 import org.ofbiz.base.util.HttpClientException; 35 36 43 public class HttpViewHandler implements ViewHandler { 44 45 public static final String module = HttpViewHandler.class.getName(); 46 47 protected ServletContext context; 48 49 public void init(ServletContext context) throws ViewHandlerException { 50 this.context = context; 51 } 52 53 public void render(String name, String page, String info, String contentType, String encoding, HttpServletRequest request, HttpServletResponse response) throws ViewHandlerException { 54 57 if (request == null) 58 throw new ViewHandlerException("Null HttpServletRequest object"); 59 if (page == null || page.length() == 0) 60 throw new ViewHandlerException("Null or empty source"); 61 62 if (Debug.infoOn()) Debug.logInfo("Retreiving HTTP resource at: " + page, module); 63 try { 64 HttpClient httpClient = new HttpClient(page); 65 String pageText = httpClient.get(); 66 67 response.getWriter().print(pageText); 69 } catch (IOException e) { 70 throw new ViewHandlerException("IO Error in view", e); 71 } catch (HttpClientException e) { 72 throw new ViewHandlerException(e.getNonNestedMessage(), e.getNested()); 73 } 74 } 75 } 76 | Popular Tags |