private void render(HttpServletRequest req, HttpServletResponse resp, UriStatus urlstatus) throws IOException { if (req.getHeader(HttpRequest.DOS_PREVENTION_HEADER) != null) { // Refuse to render for any request that came from us. // TODO: Is this necessary for any other type of request? Rendering seems to be the only one // that can potentially result in an infinite loop. resp.sendError(HttpServletResponse.SC_FORBIDDEN); return; } resp.setContentType("text/html"); resp.setCharacterEncoding("UTF-8"); GadgetContext context = new HttpGadgetContext(req); RenderingResults results = renderer.render(context); // process the rendering results postGadgetRendering(new PostGadgetRenderingParams(req, resp, urlstatus, context, results)); }
public HttpGadgetContext(HttpServletRequest request) { this.request = request; container = getContainer(request); debug = getDebug(request); ignoreCache = getIgnoreCache(request); locale = getLocale(request); moduleId = getModuleId(request); renderingContext = getRenderingContext(request); url = getUrl(request); userPrefs = getUserPrefs(request); view = getView(request); }
public HttpGadgetContext(HttpServletRequest request) { this.request = request; container = getContainer(request); debug = getDebug(request); ignoreCache = getIgnoreCache(request); locale = getLocale(request); moduleId = getModuleId(request); renderingContext = getRenderingContext(request); url = getUrl(request); userPrefs = getUserPrefs(request); view = getView(request); }
private void render(HttpServletRequest req, HttpServletResponse resp, UriStatus urlstatus) throws IOException { if (req.getHeader(HttpRequest.DOS_PREVENTION_HEADER) != null) { // Refuse to render for any request that came from us. // TODO: Is this necessary for any other type of request? Rendering seems to be the only one // that can potentially result in an infinite loop. resp.sendError(HttpServletResponse.SC_FORBIDDEN); return; } resp.setContentType("text/html"); resp.setCharacterEncoding("UTF-8"); GadgetContext context = new HttpGadgetContext(req); RenderingResults results = renderer.render(context); // process the rendering results postGadgetRendering(new PostGadgetRenderingParams(req, resp, urlstatus, context, results)); }
public HttpGadgetContext(HttpServletRequest request) { this.request = request; container = getContainer(request); debug = getDebug(request); ignoreCache = getIgnoreCache(request); locale = getLocale(request); moduleId = getModuleId(request); renderingContext = getRenderingContext(request); url = getUrl(request); userPrefs = getUserPrefs(request); view = getView(request); referer = getReferer(); }
private void render(HttpServletRequest req, HttpServletResponse resp, UriStatus urlstatus) throws IOException { if (req.getHeader(HttpRequest.DOS_PREVENTION_HEADER) != null) { // Refuse to render for any request that came from us. // TODO: Is this necessary for any other type of request? Rendering seems to be the only one // that can potentially result in an infinite loop. resp.sendError(HttpServletResponse.SC_FORBIDDEN); return; } resp.setContentType("text/html"); resp.setCharacterEncoding("UTF-8"); GadgetContext context = new HttpGadgetContext(req); RenderingResults results = renderer.render(context); // process the rendering results postGadgetRendering(new PostGadgetRenderingParams(req, resp, urlstatus, context, results)); }
@Test public void testLocale() { expect(request.getParameter("lang")).andReturn(Locale.CHINA.getLanguage()); expect(request.getParameter("country")).andReturn(Locale.CHINA.getCountry()); replay(); GadgetContext context = new HttpGadgetContext(request); assertEquals(Locale.CHINA, context.getLocale()); }
@Test public void testLocale() { expect(request.getParameter("lang")).andReturn(Locale.CHINA.getLanguage()); expect(request.getParameter("country")).andReturn(Locale.CHINA.getCountry()); replay(); GadgetContext context = new HttpGadgetContext(request); assertEquals(Locale.CHINA, context.getLocale()); }
@Test public void testLocale() { expect(request.getParameter("lang")).andReturn(Locale.CHINA.getLanguage()); expect(request.getParameter("country")).andReturn(Locale.CHINA.getCountry()); replay(); GadgetContext context = new HttpGadgetContext(request); assertEquals(Locale.CHINA, context.getLocale()); }
@Test public void testIgnoreCacheParam() { expect(request.getParameter("nocache")).andReturn(Integer.toString(Integer.MAX_VALUE)); replay(); GadgetContext context = new HttpGadgetContext(request); assertTrue(context.getIgnoreCache()); }
@Test public void testIgnoreCacheParam() { expect(request.getParameter("nocache")).andReturn(Integer.toString(Integer.MAX_VALUE)); replay(); GadgetContext context = new HttpGadgetContext(request); assertTrue(context.getIgnoreCache()); }
@Test public void testIgnoreCacheParam() { expect(request.getParameter("nocache")).andReturn(Integer.toString(Integer.MAX_VALUE)); replay(); GadgetContext context = new HttpGadgetContext(request); assertTrue(context.getIgnoreCache()); }
@Test public void testGetParameter() { expect(request.getParameter("foo")).andReturn("bar"); replay(); GadgetContext context = new HttpGadgetContext(request); assertEquals("bar", context.getParameter("foo")); }
@Test public void testGetUserAgent() throws Exception { expect(request.getHeader("User-Agent")).andReturn("Mozilla/4.0"); replay(); GadgetContext context = new HttpGadgetContext(request); assertEquals("Mozilla/4.0", context.getUserAgent()); } }
@Test public void testGetUserIp() { expect(request.getRemoteAddr()).andReturn("2.3.4.5"); replay(); GadgetContext context = new HttpGadgetContext(request); assertEquals("2.3.4.5", context.getUserIp()); }
@Test public void testGetHost() { expect(request.getHeader("Host")).andReturn("foo.org"); replay(); GadgetContext context = new HttpGadgetContext(request); assertEquals("foo.org", context.getHost()); }
@Test public void testGetUserIp() { expect(request.getRemoteAddr()).andReturn("2.3.4.5"); replay(); GadgetContext context = new HttpGadgetContext(request); assertEquals("2.3.4.5", context.getUserIp()); }
@Test public void testGetParameter() { expect(request.getParameter("foo")).andReturn("bar"); replay(); GadgetContext context = new HttpGadgetContext(request); assertEquals("bar", context.getParameter("foo")); }
@Test public void testGetHost() { expect(request.getHeader("Host")).andReturn("foo.org"); replay(); GadgetContext context = new HttpGadgetContext(request); assertEquals("foo.org", context.getHost()); }
@Test public void testGetUserAgent() throws Exception { expect(request.getHeader("User-Agent")).andReturn("Mozilla/4.0"); replay(); GadgetContext context = new HttpGadgetContext(request); assertEquals("Mozilla/4.0", context.getUserAgent()); } }