List of usage examples for javax.servlet.http HttpServletRequest getServletContext
public ServletContext getServletContext();
From source file:org.eclipse.virgo.snaps.sample.cat.CatController.java
@RequestMapping("/meow") public ModelAndView cat(HttpServletRequest request) throws IOException { URL host = request.getServletContext().getResource("host:/WEB-INF/sample.properties"); Properties host_props = new Properties(); if (host != null) { host_props.load(host.openStream()); }//from w w w . ja v a 2 s . c om URL snap = request.getServletContext().getResource("/WEB-INF/sample.properties"); Properties snap_props = new Properties(); if (snap != null) { snap_props.load(snap.openStream()); } return new ModelAndView("index").addObject("host", host_props.getProperty("some.property")) .addObject("snap", snap_props.getProperty("some.property")); }
From source file:dijalmasilva.controllers.Session.java
@RequestMapping("/home") public String home(HttpServletRequest req) { List<Lugar> todasOcorrencias = lugarService.buscarTodos(); req.getServletContext().setAttribute("todasOcorrencias", todasOcorrencias); return "home"; }
From source file:com.freemarker.mail.GMail.java
public String getTemplateLocation(HttpServletRequest req) { return req.getServletContext().getRealPath("index.html").substring(0, req.getServletContext().getRealPath("index.html").indexOf("FreeMarkerPOC") + 14) + "src\\main\\webapp\\FreeMarkerTemplates\\"; }
From source file:com.freemarker.mail.GMail.java
public String getXMLocation(HttpServletRequest req) { return req.getServletContext().getRealPath("index.html").substring(0, req.getServletContext().getRealPath("index.html").indexOf("FreeMarkerPOC") + 14) + "src\\main\\webapp\\FreeMarkerTemplates\\"; }
From source file:gumga.framework.presentation.api.AbstractReportAPI.java
protected InputStream getResourceAsInputStream(HttpServletRequest request, String reportName) { return request.getServletContext().getResourceAsStream(getFullPath(reportsFolder, reportName)); }
From source file:inet.util.FileStorage.java
public FileStorage(inet.common.jsf.request.MultipartRequest multipartRequest, String targe) { this.multipartRequest = multipartRequest; HttpServletRequest request = (HttpServletRequest) multipartRequest.getRequest(); realPath = request.getServletContext().getRealPath("/"); realUri = "http://" + request.getServerName() + (request.getServerPort() == 80 ? "" : ":" + request.getServerPort()) + request.getContextPath(); this.targe = targe; }
From source file:dijalmasilva.controllers.LugarController.java
@RequestMapping("/noFilter") public String tirandoFiltrosDeBusca(HttpServletRequest req) { List<Lugar> todasOcorrencias = service.buscarTodos(); req.getServletContext().setAttribute("todasOcorrencias", todasOcorrencias); req.getServletContext().setAttribute("existeFiltro", false); return "home"; }
From source file:org.b3log.solo.processor.SitemapProcessorTestCase.java
/** * blogArticlesAtom./* w ww.j a va 2s .co m*/ * * @throws Exception exception */ @Test(dependsOnMethods = "init") public void blogArticlesAtom() throws Exception { final HttpServletRequest request = mock(HttpServletRequest.class); when(request.getServletContext()).thenReturn(mock(ServletContext.class)); when(request.getRequestURI()).thenReturn("/sitemap.xml"); when(request.getMethod()).thenReturn("GET"); final MockDispatcherServlet dispatcherServlet = new MockDispatcherServlet(); dispatcherServlet.init(); final StringWriter stringWriter = new StringWriter(); final PrintWriter printWriter = new PrintWriter(stringWriter); final HttpServletResponse response = mock(HttpServletResponse.class); when(response.getWriter()).thenReturn(printWriter); dispatcherServlet.service(request, response); final String content = stringWriter.toString(); Assert.assertTrue(StringUtils.startsWith(content, "<?xml version=\"1.0\"")); }
From source file:org.b3log.solo.processor.ErrorProcessorTestCase.java
/** * showErrorPage./* ww w .j a va 2 s . c om*/ * * @throws Exception exception */ @Test(dependsOnMethods = "init") public void showErrorPage() throws Exception { final HttpServletRequest request = mock(HttpServletRequest.class); when(request.getServletContext()).thenReturn(mock(ServletContext.class)); when(request.getRequestURI()).thenReturn("/error/403.html"); when(request.getAttribute(Keys.TEMAPLTE_DIR_NAME)).thenReturn("next"); when(request.getMethod()).thenReturn("GET"); when(request.getAttribute(Keys.HttpRequest.START_TIME_MILLIS)).thenReturn(System.currentTimeMillis()); final MockDispatcherServlet dispatcherServlet = new MockDispatcherServlet(); dispatcherServlet.init(); final StringWriter stringWriter = new StringWriter(); final PrintWriter printWriter = new PrintWriter(stringWriter); final HttpServletResponse response = mock(HttpServletResponse.class); when(response.getWriter()).thenReturn(printWriter); dispatcherServlet.service(request, response); final String content = stringWriter.toString(); Assert.assertTrue(StringUtils.contains(content, "<title>Solo - 403 Forbidden!</title>")); }
From source file:org.b3log.solo.processor.TagProcessorTestCase.java
/** * showTagArticles.//from w ww . j av a 2 s .co m * * @throws Exception exception */ @Test(dependsOnMethods = "init") public void showTagArticles() throws Exception { final HttpServletRequest request = mock(HttpServletRequest.class); when(request.getServletContext()).thenReturn(mock(ServletContext.class)); when(request.getRequestURI()).thenReturn("/tags/Solo"); when(request.getMethod()).thenReturn("GET"); when(request.getAttribute(Keys.TEMAPLTE_DIR_NAME)).thenReturn("next"); when(request.getAttribute(Keys.HttpRequest.START_TIME_MILLIS)).thenReturn(System.currentTimeMillis()); final MockDispatcherServlet dispatcherServlet = new MockDispatcherServlet(); dispatcherServlet.init(); final StringWriter stringWriter = new StringWriter(); final PrintWriter printWriter = new PrintWriter(stringWriter); final HttpServletResponse response = mock(HttpServletResponse.class); when(response.getWriter()).thenReturn(printWriter); dispatcherServlet.service(request, response); final String content = stringWriter.toString(); Assert.assertTrue(StringUtils.contains(content, "<title>Solo - Solo </title>")); }