List of usage examples for javax.servlet.http HttpServletRequest getRequestURL
public StringBuffer getRequestURL();
From source file:com.jredrain.session.HttpSessionFilter.java
@Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws ServletException, IOException { String requestURL = request.getRequestURL().toString(); String requestName = requestURL.substring(requestURL.lastIndexOf("/") + 1); requestName = requestName.toLowerCase(); //???/*from www . j a va2 s. c om*/ if (requestName.matches(".*\\.js$") || requestName.matches(".*\\.css$") || requestName.matches(".*\\.swf$") || requestName.matches(".*\\.jpg$") || requestName.matches(".*\\.png$") || requestName.matches(".*\\.jpeg$") || requestName.matches(".*\\.html$") || requestName.matches(".*\\.htm$") || requestName.matches(".*\\.xml$") || requestName.matches(".*\\.txt$") || requestName.matches(".*\\.ico$")) { chain.doFilter(request, response); return; } response.setCharacterEncoding("UTF-8"); response.setContentType("text/html;charset=utf-8"); Cookie sessionIdCookie = getOrGenerateSessionId(request, response); String sessionId = sessionIdCookie.getValue(); HttpSession rawSession = request.getSession(); Map sessionData = loadSessionData(sessionId, rawSession); try { HttpSession sessionWrapper = new HttpSessionStoreWrapper(rawSession, sessionStore, sessionId, sessionData); chain.doFilter(new HttpServletRequestSessionWrapper(request, sessionWrapper), response); } finally { try { String token = (String) sessionData.get("token"); if (token != null) { //token sessionId = token; logger.info("login token=" + token); sessionData.remove("token"); } sessionStore.saveSession(sessionId, sessionData, rawSession.getMaxInactiveInterval()); } catch (Exception e) { logger.warn("save session data error,cause:" + e, e); } } }
From source file:io.apicurio.studio.fe.servlet.servlets.DownloadServlet.java
/** * Generates a URL that the caller can use to access the Hub API. * @param request// www . ja va2s . c o m */ private String generateHubApiUrl(HttpServletRequest request) { try { String url = this.uiConfig.getHubApiUrl(); if (url == null) { url = request.getRequestURL().toString(); url = new URI(url).resolve("/api-hub").toString(); } return url; } catch (URISyntaxException e) { throw new RuntimeException(e); } }
From source file:cec.easyshop.storefront.filters.UrlEncoderFilter.java
@Override protected void doFilterInternal(final HttpServletRequest request, final HttpServletResponse response, final FilterChain filterChain) throws ServletException, IOException { if (LOG.isDebugEnabled()) { LOG.debug(" The incoming URL : [" + request.getRequestURL().toString() + "]"); }/*from w ww .j av a 2 s. co m*/ final List<UrlEncoderData> currentUrlEncoderDatas = getUrlEncoderFacade().getCurrentUrlEncodingData(); if (currentUrlEncoderDatas != null && !currentUrlEncoderDatas.isEmpty()) { final String currentPattern = getSessionService().getAttribute(WebConstants.URL_ENCODING_ATTRIBUTES); final String newPattern = getUrlEncoderFacade().calculateAndUpdateUrlEncodingData( request.getRequestURI().toString(), request.getContextPath()); final String newPatternWithSlash = "/" + newPattern; if (!StringUtils.equalsIgnoreCase(currentPattern, newPatternWithSlash)) { getUrlEncoderFacade().updateSiteFromUrlEncodingData(); getSessionService().setAttribute(WebConstants.URL_ENCODING_ATTRIBUTES, newPatternWithSlash); } final UrlEncodeHttpRequestWrapper wrappedRequest = new UrlEncodeHttpRequestWrapper(request, newPattern); wrappedRequest.setAttribute(WebConstants.URL_ENCODING_ATTRIBUTES, newPatternWithSlash); wrappedRequest.setAttribute("originalContextPath", StringUtils.isBlank(request.getContextPath()) ? "/" : request.getContextPath()); if (LOG.isDebugEnabled()) { LOG.debug("ContextPath=[" + wrappedRequest.getContextPath() + "]" + " Servlet Path= [" + wrappedRequest.getServletPath() + "]" + " Request Url= [" + wrappedRequest.getRequestURL() + "]"); } filterChain.doFilter(wrappedRequest, response); } else { if (LOG.isDebugEnabled()) { LOG.debug(" No URL attributes defined"); } request.setAttribute(WebConstants.URL_ENCODING_ATTRIBUTES, ""); filterChain.doFilter(request, response); } }
From source file:com.jnj.b2b.storefront.filters.UrlEncoderFilter.java
@Override protected void doFilterInternal(final HttpServletRequest request, final HttpServletResponse response, final FilterChain filterChain) throws ServletException, IOException { if (LOG.isDebugEnabled()) { LOG.debug(" The incoming URL : [" + request.getRequestURL().toString() + "]"); }// ww w .ja v a 2 s.c o m final List<UrlEncoderData> currentUrlEncoderDatas = getUrlEncoderFacade().getCurrentUrlEncodingData(); if (currentUrlEncoderDatas != null && !currentUrlEncoderDatas.isEmpty()) { final String currentPattern = getSessionService().getAttribute(WebConstants.URL_ENCODING_ATTRIBUTES); final String newPattern = getUrlEncoderFacade().calculateAndUpdateUrlEncodingData( request.getRequestURI().toString(), request.getContextPath()); final String newPatternWithSlash = "/" + newPattern; if (!StringUtils.equalsIgnoreCase(currentPattern, newPatternWithSlash)) { getUrlEncoderFacade().updateSiteFromUrlEncodingData(); getSessionService().setAttribute(WebConstants.URL_ENCODING_ATTRIBUTES, newPatternWithSlash); } final UrlEncodeHttpRequestWrapper wrappedRequest = new UrlEncodeHttpRequestWrapper(request, newPattern); wrappedRequest.setAttribute(WebConstants.URL_ENCODING_ATTRIBUTES, newPatternWithSlash); wrappedRequest.setAttribute("originalContextPath", StringUtils.isBlank(request.getContextPath()) ? "/" : request.getContextPath()); if (LOG.isDebugEnabled()) { LOG.debug("ContextPath=[" + wrappedRequest.getContextPath() + "]" + " Servlet Path= [" + wrappedRequest.getServletPath() + "]" + " Request Url= [" + wrappedRequest.getRequestURL() + "]"); } filterChain.doFilter(wrappedRequest, response); } else { if (LOG.isDebugEnabled()) { LOG.debug(" No URL attributes defined"); } request.setAttribute(WebConstants.URL_ENCODING_ATTRIBUTES, ""); filterChain.doFilter(request, response); } }
From source file:io.kamax.mxisd.controller.identity.v1.SessionRestController.java
@RequestMapping(value = "/3pid/getValidated3pid") String check(HttpServletRequest request, HttpServletResponse response, @RequestParam String sid, @RequestParam("client_secret") String secret) { log.info("Requested: {}", request.getRequestURL(), request.getQueryString()); try {/*from ww w.j a va 2s .c om*/ ThreePidValidation pid = mgr.getValidated(sid, secret); JsonObject obj = new JsonObject(); obj.addProperty("medium", pid.getMedium()); obj.addProperty("address", pid.getAddress()); obj.addProperty("validated_at", pid.getValidation().toEpochMilli()); return gson.toJson(obj); } catch (SessionNotValidatedException e) { log.info("Session {} was requested but has not yet been validated", sid); throw e; } }
From source file:se.trillian.goodies.web.DisableSessionIdInUrlFilterTest.java
public void testSessionIdInRequestUrlIsRemoved() throws Exception { request.setServerName("www.example.com"); request.setRequestURI("/index.html;jsessionid=1047kv5xa62lf"); request.setRequestedSessionIdFromURL(true); final boolean[] called = new boolean[] { false }; filter.doFilter(request, response, new FilterChain() { public void doFilter(ServletRequest req, ServletResponse res) throws IOException, ServletException { HttpServletRequest request = (HttpServletRequest) req; assertFalse(request.isRequestedSessionIdFromURL()); assertEquals("/index.html", request.getRequestURI()); assertEquals("http://www.example.com:80/index.html", request.getRequestURL().toString()); called[0] = true;/*from ww w. jav a 2 s . c om*/ } }); assertTrue(called[0]); }
From source file:com.pawelniewiadomski.devs.jira.servlet.LicenseServlet.java
private void redirectToLogin(HttpServletRequest request, HttpServletResponse response) throws IOException { response.sendRedirect(//w w w .j a va2 s . com loginUriProvider.getLoginUri(URI.create(request.getRequestURL().toString())).toASCIIString()); }
From source file:controllerClasses.security.SiteuserControl.java
public void callEditor() { HttpServletRequest req = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext() .getRequest();//from www. j av a 2s . c o m String url = req.getRequestURL().toString(); url = url.substring(0, url.length() - req.getRequestURI().length()) + req.getContextPath() + "/index.xhtml"; String password = passGenerator(); Siteuser su = this.user; su.setPassword(encryptPassword(password)); suF.edit(su); String line = url + " Password: " + password + " Username: " + su.getUsername() + ""; setText(line); }
From source file:com.benfante.minimark.MinimarkExceptionResolver.java
@Override public ModelAndView resolveException(HttpServletRequest req, HttpServletResponse res, Object object, Exception e) {/*ww w .j av a 2s.c o m*/ try { if (!interceptedWithMinimalLogging(e)) { logger.error("Unexpected exception", e); } logger.info("Exception requesting URL: " + req.getRequestURL().toString()); logger.info(" request from " + req.getRemoteHost() + "(" + req.getRemoteAddr() + ")"); return super.resolveException(req, res, object, e); } catch (Exception ex) { logger.error("Error resolving exception", ex); } return new ModelAndView("redirect:/home/500page.html"); }
From source file:com.mir00r.interceptor.MaintenanceInterceptor.java
@Override public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception { //super.postHandle(request, response, handler, modelAndView); //To change body of generated methods, choose Tools | Templates. System.out.println("Request URL :: " + request.getRequestURL().toString() + "Sent to Handler :: Current Time = " + System.currentTimeMillis()); }