List of usage examples for javax.servlet.http HttpServletRequest getServletContext
public ServletContext getServletContext();
From source file:net.javacrumbs.test.AbstractServlet.java
protected HttpGet createBackendRequest(HttpServletRequest req, int number) { HttpGet get = new HttpGet("http://localhost:8080/" + req.getServletContext().getContextPath() + "/" + getServletName() + "?max=" + getMax(req)); get.addHeader("number", Integer.toString(number + 1)); return get;//from www . j ava 2 s .c o m }
From source file:dijalmasilva.controllers.LugarController.java
@RequestMapping("/filtrar/tipo") public String filtrarPorTipo(TipoDaOcorrencia tipoFiltro, HttpServletRequest req) { List<Lugar> todasOcorrencias = service.buscarPorTipo(tipoFiltro); req.getServletContext().setAttribute("todasOcorrencias", todasOcorrencias); req.setAttribute("result", "Ocorrncias do tipo " + tipoFiltro.toString().toLowerCase()); req.getServletContext().setAttribute("existeFiltro", true); return "home"; }
From source file:cn.vlabs.umt.ui.tags.ConfigTag.java
public Config getConfig() { HttpServletRequest request = (HttpServletRequest) this.pageContext.getRequest(); BeanFactory beanFactory = (BeanFactory) request.getServletContext() .getAttribute(Attributes.APPLICATION_CONTEXT_KEY); return (Config) beanFactory.getBean(Config.BEAN_ID); }
From source file:com.evolveum.midpoint.web.security.MidPointAccessDeniedHandler.java
private String createUri(HttpServletRequest req, String uri) { StringBuilder sb = new StringBuilder(); ServletContext ctx = req.getServletContext(); String ctxPath = ctx.getContextPath(); if (StringUtils.isNotEmpty(ctxPath)) { sb.append(ctxPath);// w w w.j a v a2s. c o m } sb.append(uri); return sb.toString(); }
From source file:net.unit8.zurui.less.filter.ZuruiLessFilter.java
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) req; String zuruiLess = readZuruiLess(); String lessPath = request.getServletContext().getRealPath(request.getRequestURI()); String requestLess = FileUtils.readFileToString(new File(lessPath), "UTF-8"); LessCompiler lessCompiler = new LessCompiler(); try {//ww w .j a v a 2 s . c o m String css = lessCompiler.compile(zuruiLess + requestLess); res.getWriter().write(css); } catch (LessException e) { throw new ServletException(e); } }
From source file:org.b3log.solo.processor.InitProcessorTestCase.java
/** * showInit.// w w w. j a v a2 s .co m * * @throws Exception exception */ public void showInit() throws Exception { final HttpServletRequest request = mock(HttpServletRequest.class); when(request.getServletContext()).thenReturn(mock(ServletContext.class)); when(request.getRequestURI()).thenReturn("/init"); 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!</title>")); }
From source file:org.b3log.solo.processor.InitProcessorTestCase.java
/** * initSolo.//from ww w . ja v a 2 s . co m * * @throws Exception exception */ @Test(dependsOnMethods = "showInit") public void initSolo() throws Exception { final HttpServletRequest request = mock(HttpServletRequest.class); when(request.getServletContext()).thenReturn(mock(ServletContext.class)); when(request.getRequestURI()).thenReturn("/init"); when(request.getMethod()).thenReturn("POST"); final JSONObject requestJSON = new JSONObject(); requestJSON.put("userName", "test"); requestJSON.put("userEmail", "test@b3log.org"); requestJSON.put("userPassword", "1"); final BufferedReader reader = new BufferedReader(new StringReader(requestJSON.toString())); when(request.getReader()).thenReturn(reader); 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, "\"sc\":true")); }
From source file:org.springframework.web.socket.server.standard.AbstractStandardUpgradeStrategy.java
protected ServerContainer getContainer(HttpServletRequest request) { ServletContext servletContext = request.getServletContext(); String attrName = "javax.websocket.server.ServerContainer"; ServerContainer container = (ServerContainer) servletContext.getAttribute(attrName); Assert.notNull(container, "No 'javax.websocket.server.ServerContainer' ServletContext attribute. " + "Are you running in a Servlet container that supports JSR-356?"); return container; }
From source file:dijalmasilva.controllers.LugarController.java
@RequestMapping("/filtrar/data") public String filtrarPorData(Date dataFiltro, HttpServletRequest req) { List<Lugar> todasOcorrencias = service.buscarPorData(dataFiltro.toLocalDate()); req.getServletContext().setAttribute("todasOcorrencias", todasOcorrencias); req.setAttribute("result", "Ocorrncias ocorridas no dia " + dataFiltro.toLocalDate().format(DateTimeFormatter.ofPattern("dd/MM/yyyy"))); req.getServletContext().setAttribute("existeFiltro", true); return "home"; }
From source file:org.b3log.solo.processor.CaptchaProcessorTestCase.java
/** * get./*from ww w. j av a 2 s . c o m*/ * * @throws Exception exception */ @Test(dependsOnMethods = "init") public void get() throws Exception { final HttpServletRequest request = mock(HttpServletRequest.class); when(request.getServletContext()).thenReturn(mock(ServletContext.class)); when(request.getRequestURI()).thenReturn("/captcha.do"); when(request.getMethod()).thenReturn("GET"); final MockDispatcherServlet dispatcherServlet = new MockDispatcherServlet(); dispatcherServlet.init(); final HttpServletResponse response = mock(HttpServletResponse.class); when(response.getOutputStream()).thenReturn(new ServletOutputStream() { private long size; @Override public boolean isReady() { return true; } @Override public void setWriteListener(final WriteListener writeListener) { } @Override public void write(int b) throws IOException { size++; } @Override public String toString() { return "size: " + String.valueOf(size); } }); dispatcherServlet.service(request, response); Assert.assertTrue(StringUtils.startsWith(response.getOutputStream().toString(), "size: ")); }