List of usage examples for javax.servlet.http HttpServletRequest getContextPath
public String getContextPath();
From source file:au.edu.anu.orcid.security.OrcidAuthenticationSuccessHandler.java
@Override public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException { LOGGER.debug("User {} has authenticated", authentication.getName()); if (authentication.getName().startsWith("u")) { String newPath = request.getContextPath() + "/rest/uid/" + authentication.getName() + "/import"; LOGGER.debug("User {} logged in, redirecting the user to: {}", authentication.getName(), newPath); response.sendRedirect(newPath);//from www . j av a 2s . c o m } else { response.sendRedirect(request.getContextPath() + "/"); } }
From source file:com.exxonmobile.ace.hybris.storefront.filters.AcceleratorAddOnFilter.java
protected String getFullPathNameFromRequest(final HttpServletRequest request) { final String ctxPath = request.getContextPath(); String requestUri = request.getRequestURI(); if (requestUri.startsWith(ctxPath)) { requestUri = requestUri.substring(ctxPath.length()); }//from w ww .j ava 2 s . com final String realPath = FilenameUtils .normalize(request.getSession().getServletContext().getRealPath(requestUri), true); return realPath; }
From source file:com.meltmedia.cadmium.servlets.MaintenanceFilter.java
@Override public void doFilter(HttpServletRequest httpReq, HttpServletResponse httpRes, FilterChain chain) throws IOException, ServletException { try {/*from w w w.j a va2 s . co m*/ String contextPath = httpReq.getContextPath(); String uri = httpReq.getRequestURI(); if (contextPath != null && contextPath.trim().length() > 0 && uri.startsWith(contextPath)) { uri = uri.substring(contextPath.length()); } if (!on || (ignorePath != null && uri.startsWith(ignorePath))) { logger.trace("Serving request server:{}, uri:{}", httpReq.getServerName(), uri); chain.doFilter(httpReq, httpRes); return; } httpRes.setStatus(HttpServletResponse.SC_SERVICE_UNAVAILABLE); httpRes.setContentType(MediaType.TEXT_HTML); InputStream in = null; InputStreamReader reader = null; try { in = MaintenanceFilter.class.getResourceAsStream("/maintenance.html"); if (in == null) { in = MaintenanceFilter.class.getResourceAsStream("./maintenance.html"); } reader = new InputStreamReader(in, "UTF-8"); IOUtils.copy(reader, httpRes.getWriter()); } finally { IOUtils.closeQuietly(reader); IOUtils.closeQuietly(in); IOUtils.closeQuietly(httpRes.getWriter()); } } catch (IOException ioe) { logger.trace("Failed in maint filter.", ioe); throw ioe; } catch (ServletException se) { logger.trace("Failed in maint filter.", se); throw se; } catch (Throwable t) { logger.trace("Failed in maint filter.", t); throw new ServletException(t); } }
From source file:net.sourceforge.fenixedu.presentationTier.servlets.filters.AnnualTeachingCreditsDocumentFilter.java
private void patchLinks(Document doc, HttpServletRequest request) { // build basePath String appContext = request.getContextPath(); // patch css link nodes NodeList linkNodes = doc.getElementsByTagName("link"); for (int i = 0; i < linkNodes.getLength(); i++) { Element link = (Element) linkNodes.item(i); String href = link.getAttribute("href"); if (appContext.length() > 0 && href.contains(appContext)) { href = href.substring(appContext.length()); }//from w w w .j a v a 2s. c o m try { String realPath = servletContext.getResource(href).toString(); link.setAttribute("href", realPath); } catch (MalformedURLException e) { logger.error(e.getMessage(), e); } } // patch image nodes NodeList imageNodes = doc.getElementsByTagName("img"); for (int i = 0; i < imageNodes.getLength(); i++) { Element img = (Element) imageNodes.item(i); String src = img.getAttribute("src"); if (appContext != null && appContext.length() > 0 && src.contains(appContext)) { src = src.substring(appContext.length() + 1); } try { String realPath = servletContext.getResource(src).toString(); img.setAttribute("src", realPath); } catch (MalformedURLException e) { logger.error(e.getMessage(), e); } } }
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:com.myjeeva.spring.security.securechannel.AbstractCrossDomainRetryEntryPoint.java
/** * {@inheritDoc}/*w w w . j a v a 2 s .c om*/ */ public void commence(ServletRequest req, ServletResponse res) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) req; String pathInfo = request.getPathInfo(); String queryString = request.getQueryString(); String contextPath = request.getContextPath(); String destination = request.getServletPath() + ((pathInfo == null) ? "" : pathInfo) + ((queryString == null) ? "" : ("?" + queryString)); String redirectUrl = contextPath; Integer currentPort = new Integer(portResolver.getServerPort(request)); Integer redirectPort = getMappedPort(currentPort); if (redirectPort != null) { boolean includePort = redirectPort.intValue() != standardPort; redirectUrl = scheme + getMappedDomain(request.getServerName()) + ((includePort) ? (":" + redirectPort) : "") + contextPath + destination; } LOG.debug(" Cross Domain EntryPoint Redirecting to: " + redirectUrl); ((HttpServletResponse) res).sendRedirect(((HttpServletResponse) res).encodeRedirectURL(redirectUrl)); }
From source file:pivotal.au.se.gemfirexdweb.controller.PrefsController.java
@RequestMapping(value = "/preferences", method = RequestMethod.GET) public String showPreferences(Model model, HttpServletResponse response, HttpServletRequest request, HttpSession session) throws Exception { if (session.getAttribute("user_key") == null) { logger.debug("user_key is null new Login required"); response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login"); return null; } else {/*w w w . jav a 2s .c om*/ Connection conn = AdminUtil.getConnection((String) session.getAttribute("user_key")); if (conn == null) { response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login"); return null; } else { if (conn.isClosed()) { response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login"); return null; } } } logger.debug("Received request to show preferences"); model.addAttribute("userPref", (UserPref) session.getAttribute("prefs")); // This will resolve to /WEB-INF/jsp/preferences.jsp return "preferences"; }
From source file:com.pamarin.income.security.JsfRedirectStrategy.java
/** * {@inheritDoc}/*from w w w .ja v a2s. co m*/ */ @Override public void onInvalidSessionDetected(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { boolean ajaxRedirect = "partial/ajax".equals(request.getHeader(FACES_REQUEST_HEADER)); if (ajaxRedirect) { String contextPath = request.getContextPath(); String redirectUrl = contextPath + invalidSessionUrl; LOG.debug("Session expired due to ajax request, redirecting to '{}'", redirectUrl); String ajaxRedirectXml = createAjaxRedirectXml(redirectUrl); LOG.debug("Ajax partial response to redirect: {}", ajaxRedirectXml); response.setContentType("text/xml"); response.getWriter().write(ajaxRedirectXml); } else { String requestURI = getRequestUrl(request); LOG.debug( "Session expired due to non-ajax request, starting a new session and redirect to requested url '{}'", requestURI); request.getSession(true); response.sendRedirect(requestURI); } }
From source file:net.duckling.ddl.web.interceptor.access.FetchCodeInterceptor.java
private void sendToDoEerror(HttpServletRequest request, HttpServletResponse response, String errorCode) throws ServletException, IOException { String requestURI = request.getRequestURI(); String content = request.getContextPath(); if (StringUtils.isNotEmpty(content)) { requestURI = requestURI.substring(content.length()); }// ww w. java 2s .co m request.getRequestDispatcher(requestURI + "?func=doError&error=" + errorCode).forward(request, response); }
From source file:grails.plugin.springsecurity.web.authentication.FilterProcessUrlRequestMatcher.java
public boolean matches(final HttpServletRequest request) { String uri = request.getRequestURI(); int pathParamIndex = uri.indexOf(';'); if (pathParamIndex > 0) { // strip everything after the first semi-colon uri = uri.substring(0, pathParamIndex); }//from w w w.ja v a2s . co m if ("".equals(request.getContextPath())) { return uri.endsWith(filterProcessesUrl); } return uri.endsWith(request.getContextPath() + filterProcessesUrl); }