List of usage examples for javax.servlet.http HttpServletRequest getContextPath
public String getContextPath();
From source file:pivotal.au.se.gemfirexdweb.controller.PrefsController.java
@RequestMapping(value = "/preferences", method = RequestMethod.POST) public String updatePreferences(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 ww. j a v a 2 s .com*/ 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 update preferences"); UserPref userPrefs = (UserPref) session.getAttribute("prefs"); userPrefs.setRecordsToDisplay(Integer.parseInt(request.getParameter("recordsToDisplay"))); userPrefs.setMaxRecordsinSQLQueryWindow( Integer.parseInt(request.getParameter("maxRecordsinSQLQueryWindow"))); userPrefs.setAutoCommit((String) request.getParameter("autoCommit")); userPrefs.setJolokiaURL((String) request.getParameter("jolokiaURL")); ConnectionManager cm = ConnectionManager.getInstance(); Connection conn = AdminUtil.getConnection((String) session.getAttribute("user_key")); if (request.getParameter("autoCommit").equals("Y")) { conn.setAutoCommit(true); } else { conn.setAutoCommit(false); } cm.updateConnection(conn, (String) session.getAttribute("user_key")); model.addAttribute("saved", "Successfully saved application preferences"); session.setAttribute("userPref", userPrefs); // This will resolve to /WEB-INF/jsp/preferences.jsp return "preferences"; }
From source file:org.socialhistoryservices.pid.ws.WsdlAdapter.java
/** * We override this method because we need to be able to return absolute URLs. * * @param location Location of the wsdl/* w w w.j a v a 2 s . co m*/ * @param request Http request * @return The absolute url */ @Override protected String transformLocation(String location, HttpServletRequest request) { if (!location.startsWith("/")) return location; StringBuilder url = new StringBuilder(request.getScheme()); url.append("://").append(request.getServerName()).append(':').append(request.getServerPort()); // a relative path, prepend the context path url.append(request.getContextPath()).append(location); return url.toString(); }
From source file:grails.plugin.springsecurity.web.access.intercept.AbstractFilterInvocationDefinition.java
protected String calculateUri(final HttpServletRequest request) { String url = request.getRequestURI().substring(request.getContextPath().length()); int semicolonIndex = url.indexOf(";"); return semicolonIndex == -1 ? url : url.substring(0, semicolonIndex); }
From source file:com.scooterframework.web.controller.ScooterRequestFilter.java
/** * Returns request path of the HttpServletRequest <tt>request</tt>. A * request path is a combination of the <tt>request</tt>'s servletPath and pathInfo. * // w w w . j a v a2 s . c o m * @param request HttpServletRequest * @return request path */ protected String getRequestPath(HttpServletRequest request) { String contextPath = request.getContextPath(); String requestURI = decode(cleanJsessionid(request.getRequestURI())); CurrentThreadCache.set(Constants.REQUEST_URI, requestURI); String requestPath = requestURI.substring(contextPath.length()); if (requestPath.length() > 1 && (requestURI.endsWith("/") || requestURI.endsWith("\\"))) { requestPath = requestPath.substring(0, requestPath.length() - 1); } return requestPath; }
From source file:org.jnap.core.mvc.i18n.CompositeLocaleResolver.java
/** * TODO doc//from ww w . j ava 2 s. c om * @param localeResolver * @param request */ private void configCookieScope(LocaleResolver localeResolver, HttpServletRequest request) { if (localeResolver instanceof CookieGenerator) { CookieGenerator cookieGenerator = CookieGenerator.class.cast(localeResolver); cookieGenerator.setCookieDomain(request.getServerName()); cookieGenerator.setCookiePath(request.getContextPath()); } }
From source file:com.pontecultural.flashcards.CardController.java
@RequestMapping(method = RequestMethod.GET) public String getUploadForm(HttpServletRequest req, Locale locale, Model model, @RequestParam("id") Integer aId) { logger.info("get cards for deck"); // compute base URL to allow client to call us back. String callbackURL = req.getScheme() + "://" + req.getServerName() + ":" + req.getServerPort() + req.getContextPath() + "/deckId/" + aId.toString() + "/cards.json"; model.addAttribute("callbackURL", callbackURL); model.addAttribute("deckname", jdbcFlashcardsDao.fetchDeckname(aId)); model.addAttribute("deckId", aId.toString()); return "viewCards"; }
From source file:org.beanfuse.security.monitor.SecurityFilter.java
public void redirectTo(HttpServletRequest request, HttpServletResponse response, String path) throws IOException { if (!path.startsWith("/")) { String contextPath = request.getContextPath(); ((HttpServletResponse) response) .sendRedirect((contextPath.equals("/") ? "" : (contextPath + "/")) + path); } else {//from ww w. j a va 2 s . c om ((HttpServletResponse) response).sendRedirect(path); } }
From source file:org.mitre.openid.connect.filter.MultiUrlRequestMatcher.java
@Override public boolean matches(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); }/* ww w .ja va 2 s .c o m*/ if ("".equals(request.getContextPath())) { // if any one of the URLs match, return true for (String filterProcessesUrl : filterProcessesUrls) { if (uri.endsWith(filterProcessesUrl)) { return true; } } return false; } for (String filterProcessesUrl : filterProcessesUrls) { if (uri.endsWith(request.getContextPath() + filterProcessesUrl)) { return true; } } return false; }
From source file:net.fenyo.mail4hotspot.web.BrowserServlet.java
@Override protected void doGet(final HttpServletRequest request, final HttpServletResponse response) throws IOException { // debug informations log.debug("doGet"); log.debug("context path: " + request.getContextPath()); log.debug("character encoding: " + request.getCharacterEncoding()); log.debug("content length: " + request.getContentLength()); log.debug("content type: " + request.getContentType()); log.debug("local addr: " + request.getLocalAddr()); log.debug("local name: " + request.getLocalName()); log.debug("local port: " + request.getLocalPort()); log.debug("method: " + request.getMethod()); log.debug("path info: " + request.getPathInfo()); log.debug("path translated: " + request.getPathTranslated()); log.debug("protocol: " + request.getProtocol()); log.debug("query string: " + request.getQueryString()); log.debug("requested session id: " + request.getRequestedSessionId()); log.debug("Host header: " + request.getServerName()); log.debug("servlet path: " + request.getServletPath()); log.debug("request URI: " + request.getRequestURI()); @SuppressWarnings("unchecked") final Enumeration<String> header_names = request.getHeaderNames(); while (header_names.hasMoreElements()) { final String header_name = header_names.nextElement(); log.debug("header name: " + header_name); @SuppressWarnings("unchecked") final Enumeration<String> header_values = request.getHeaders(header_name); while (header_values.hasMoreElements()) log.debug(" " + header_name + " => " + header_values.nextElement()); }//from ww w. ja v a2s . co m if (request.getCookies() != null) for (Cookie cookie : request.getCookies()) { log.debug("cookie:"); log.debug("cookie comment: " + cookie.getComment()); log.debug("cookie domain: " + cookie.getDomain()); log.debug("cookie max age: " + cookie.getMaxAge()); log.debug("cookie name: " + cookie.getName()); log.debug("cookie path: " + cookie.getPath()); log.debug("cookie value: " + cookie.getValue()); log.debug("cookie version: " + cookie.getVersion()); log.debug("cookie secure: " + cookie.getSecure()); } @SuppressWarnings("unchecked") final Enumeration<String> parameter_names = request.getParameterNames(); while (parameter_names.hasMoreElements()) { final String parameter_name = parameter_names.nextElement(); log.debug("parameter name: " + parameter_name); final String[] parameter_values = request.getParameterValues(parameter_name); for (final String parameter_value : parameter_values) log.debug(" " + parameter_name + " => " + parameter_value); } // parse request String target_scheme = null; String target_host; int target_port; // request.getPathInfo() is url decoded final String[] path_info_parts = request.getPathInfo().split("/"); if (path_info_parts.length >= 2) target_scheme = path_info_parts[1]; if (path_info_parts.length >= 3) { target_host = path_info_parts[2]; try { if (path_info_parts.length >= 4) target_port = new Integer(path_info_parts[3]); else target_port = 80; } catch (final NumberFormatException ex) { log.warn(ex); target_port = 80; } } else { target_scheme = "http"; target_host = "www.google.com"; target_port = 80; } log.debug("remote URL: " + target_scheme + "://" + target_host + ":" + target_port); // create forwarding request final URL target_url = new URL(target_scheme + "://" + target_host + ":" + target_port); final HttpURLConnection target_connection = (HttpURLConnection) target_url.openConnection(); // be transparent for accept-language headers @SuppressWarnings("unchecked") final Enumeration<String> accepted_languages = request.getHeaders("accept-language"); while (accepted_languages.hasMoreElements()) target_connection.setRequestProperty("Accept-Language", accepted_languages.nextElement()); // be transparent for accepted headers @SuppressWarnings("unchecked") final Enumeration<String> accepted_content = request.getHeaders("accept"); while (accepted_content.hasMoreElements()) target_connection.setRequestProperty("Accept", accepted_content.nextElement()); }
From source file:com.truthbean.demo.ssm.controller.UserSessionFilter.java
@Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { Object object = request.getSession().getAttribute("user"); if (object != null && object instanceof User) { filterChain.doFilter(request, response); } else {/*from w ww.j a va 2s .c om*/ response.sendRedirect(request.getContextPath() + "/login.html"); } }