List of usage examples for javax.servlet.http HttpServletRequest getContextPath
public String getContextPath();
From source file:edu.cornell.mannlib.vedit.controller.BaseEditController.java
public String getDefaultLandingPage(HttpServletRequest request) { return (request.getContextPath() + DEFAULT_LANDING_PAGE); }
From source file:org.onebusaway.webapp.impl.WebappArrivalsAndDeparturesModel.java
public SituationsPresentation getSituations() { if (_situations == null) { _situations = new SituationsPresentation(); HttpServletRequest request = ServletActionContext.getRequest(); Map<String, Object> config = _configurationService.getConfiguration(false, request.getContextPath()); String key = (String) config.get("apiKey"); if (key != null) _situations.setApiKey(key);/*from ww w . jav a 2 s . c o m*/ _situations.setSituations(_result.getSituations()); _situations.setUser(_user); } return _situations; }
From source file:cn.vlabs.duckling.api.umt.sso.configable.servlet.LogoutServlet.java
/** * urlcontextPath/*from w ww . j a v a2 s . c o m*/ * @param request http * */ private String getRootUrlWithContextPath(HttpServletRequest request) { String url = getRootUrlWithOutContextPath(request); String contextPath = request.getContextPath(); if (!StringUtils.isBlank(contextPath)) { url += contextPath; } return url; }
From source file:csns.web.filter.DepartmentFilter.java
@Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { String contextPath = request.getContextPath(); String path = request.getRequestURI().substring(contextPath.length()); Cookie cookie = WebUtils.getCookie(request, "default-dept"); if (path.startsWith("/department/")) { int beginIndex = "/department/".length(); int endIndex = path.indexOf("/", beginIndex); if (endIndex < 0) endIndex = path.length();/*from w ww .ja v a2 s .c om*/ String dept = path.substring(beginIndex, endIndex); request.setAttribute("dept", dept); logger.debug(path + " -> " + dept); if (cookie == null) { cookie = new Cookie("default-dept", dept); cookie.setPath("/"); cookie.setMaxAge(100000000); response.addCookie(cookie); } } else { if (cookie != null) request.setAttribute("dept", cookie.getValue()); } filterChain.doFilter(request, response); }
From source file:com.atlassian.jira.security.xsrf.SimpleXsrfTokenGenerator.java
private String getRequestContext(HttpServletRequest httpServletRequest) { String contextPath = httpServletRequest.getContextPath(); return StringUtils.isBlank(contextPath) ? "/" : contextPath; }
From source file:org.jamwiki.servlets.ImageServlet.java
/** * If a file corresponding to the request is on the filesystem return it, * otherwise return <code>null</code>. *///from ww w.ja va 2 s. c o m private File retrieveFile(HttpServletRequest request) { String filename = request.getRequestURI().substring(request.getContextPath().length()); try { filename = URLDecoder.decode(filename, "UTF-8"); } catch (UnsupportedEncodingException e) { // this doesn't happen - UTF-8 is always supported } File file = new File(Environment.getValue(Environment.PROP_BASE_FILE_DIR), filename); return (file.exists()) ? file : null; }
From source file:info.magnolia.voting.voters.BasePatternVoter.java
protected String resolveURIFromValue(Object value) { String uri = null;/*from w w w . j a va2 s .co m*/ if (value instanceof String) { uri = (String) value; } else { if (MgnlContext.hasInstance()) { uri = MgnlContext.getAggregationState().getCurrentURI(); } else { if (value instanceof HttpServletRequest) { HttpServletRequest request = (HttpServletRequest) value; uri = StringUtils.substringAfter(request.getRequestURI(), request.getContextPath()); } } } return uri; }
From source file:com.googlecode.psiprobe.controllers.jsp.DiscardCompiledJspController.java
protected ModelAndView handleContext(String contextName, Context context, HttpServletRequest request, HttpServletResponse response) throws Exception { getContainerWrapper().getTomcatContainer().discardWorkDir(context); return new ModelAndView( new RedirectView(request.getContextPath() + getViewName() + "?" + request.getQueryString())); }
From source file:net.solarnetwork.node.setup.web.SolarInHttpProxy.java
/** * Proxy an HTTP request to SolarIn and return the result on a given HTTP * response./*from w w w. j ava 2 s . c o m*/ * * @param request * the request to proxy * @param response * the response to return the proxy response to * @throws IOException * if an IO error occurs */ @RequestMapping(value = { "/api/v1/sec/location", "/api/v1/sec/location/price", "/api/v1/sec/location/weather" }, method = RequestMethod.GET) public void proxy(HttpServletRequest request, HttpServletResponse response) throws IOException { String context = request.getContextPath(); String path = request.getRequestURI(); if (path.startsWith(context)) { path = path.substring(context.length()); } String query = request.getQueryString(); String url = getIdentityService().getSolarInBaseUrl() + path; if (query != null) { url += '?' + query; } String accept = request.getHeader("Accept"); if (accept == null) { accept = ACCEPT_JSON; } try { URLConnection conn = getURLConnection(url, request.getMethod(), accept); if (conn instanceof HttpURLConnection) { final HttpURLConnection httpConn = (HttpURLConnection) conn; for (Map.Entry<String, List<String>> me : httpConn.getHeaderFields().entrySet()) { final String headerName = me.getKey(); if (headerName == null) { continue; } for (String val : me.getValue()) { response.addHeader(headerName, val); } } final String msg = httpConn.getResponseMessage(); if (msg != null && !msg.equalsIgnoreCase("OK")) { response.sendError(httpConn.getResponseCode(), msg); } else { response.setStatus(httpConn.getResponseCode()); } } FileCopyUtils.copy(conn.getInputStream(), response.getOutputStream()); response.flushBuffer(); } catch (IOException e) { log.debug("Error proxying SolarIn URL [{}]", url, e); response.sendError(502, "Problem communicating with SolarIn: " + e.getMessage()); } }
From source file:ar.com.zauber.commons.spring.web.controllers.InformationController.java
/** * @see AbstractController#handleRequest(HttpServletRequest, * HttpServletResponse)/*from w ww .j a va 2 s .c om*/ */ @Override protected final ModelAndView handleRequestInternal(final HttpServletRequest request, final HttpServletResponse response) throws Exception { final String uri = request.getRequestURI().substring(request.getContextPath().length()); if (uri.contains("..")) { throw new IllegalArgumentException(".."); } final int i = uri.lastIndexOf('.'); String view = (i == -1) ? uri : uri.substring(1, i); while (view.startsWith("/")) { view = view.substring(1); } while (view.endsWith("/")) { view = view.substring(0, view.length() - 1); } final Resource r = getApplicationContext() .getResource("/WEB-INF/templates/jsp/" + baseView + view + ".jsp"); final ModelAndView ret; if (r.exists()) { ret = new ModelAndView(baseView + view); } else { response.sendError(404); ret = null; } return ret; }