/** * web应用绝对路径 * * @param request 请求对象 * @return 绝对路径 */ public static String getBasePath(HttpServletRequest request) { String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/"; return basePath; }
/** * 获取请求basePath * @param request * @return */ public static String getBasePath(HttpServletRequest request) { StringBuffer basePath = new StringBuffer(); String scheme = request.getScheme(); String domain = request.getServerName(); int port = request.getServerPort(); basePath.append(scheme); basePath.append("://"); basePath.append(domain); if("http".equalsIgnoreCase(scheme) && 80 != port) { basePath.append(":").append(String.valueOf(port)); } else if("https".equalsIgnoreCase(scheme) && port != 443) { basePath.append(":").append(String.valueOf(port)); } return basePath.toString(); }
public RequestDTOImpl(HttpServletRequest request) { requestURI = request.getRequestURI(); fullUrlWithQueryString = request.getRequestURL().toString(); if (StringUtils.isNotEmpty(request.getQueryString())) { fullUrlWithQueryString += "?" + request.getQueryString(); } secure = ("HTTPS".equalsIgnoreCase(request.getScheme()) || request.isSecure()); for(Object key : request.getParameterMap().keySet()) { String paramKey = key.toString(); requestContextAttributes.put(paramKey, request.getParameter(paramKey)); } }
@Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String redirectHost = regionServerHostname; if(redirectHost == null) { redirectHost = request.getServerName(); if(!Addressing.isLocalAddress(InetAddress.getByName(redirectHost))) { LOG.warn("Couldn't resolve '" + redirectHost + "' as an address local to this node and '" + MASTER_HOSTNAME_KEY + "' is not set; client will get a HTTP 400 response. If " + "your HBase deployment relies on client accessible names that the region server process " + "can't resolve locally, then you should set the previously mentioned configuration variable " + "to an appropriate hostname."); // no sending client provided input back to the client, so the goal host is just in the logs. response.sendError(400, "Request was to a host that I can't resolve for any of the network interfaces on " + "this node. If this is due to an intermediary such as an HTTP load balancer or other proxy, your HBase " + "administrator can set '" + MASTER_HOSTNAME_KEY + "' to point to the correct hostname."); return; } } // TODO this scheme should come from looking at the scheme registered in the infoserver's http server for the // host and port we're using, but it's buried way too deep to do that ATM. String redirectUrl = request.getScheme() + "://" + redirectHost + ":" + regionServerInfoPort + request.getRequestURI(); response.sendRedirect(redirectUrl); } }
public String getResetPasswordUrl(HttpServletRequest request) { String url = request.getScheme() + "://" + request.getServerName() + getResetPasswordPort(request, request.getScheme() + "/"); if (request.getContextPath() != null && ! "".equals(request.getContextPath())) { url = url + request.getContextPath() + getResetPasswordView(); } else { url = url + getResetPasswordView(); } return url; }
String scheme = request.getScheme(); String host = request.getHeader("Host"); String contextPath = request.getContextPath(); String resultPath = scheme + "://" + host + contextPath; String redirect = "redirect:" + definition.getAuthUrl() + "?client_id=" + definition.getRelyingPartyId() + "&response_type=code" + "&redirect_uri=" + resultPath + "/login/callback/" + provider.getOriginKey();
public void render() { String finalUrl = buildFinalUrl(); // 支持 https 协议下的重定向 if (!finalUrl.startsWith("http")) { // 跳过 http/https 已指定过协议类型的 url if (request.getScheme().equals("https")) { if (finalUrl.charAt(0) != '/') { finalUrl = "https://" + request.getServerName() + "/" + finalUrl; } else { finalUrl = "https://" + request.getServerName() + finalUrl; } } } try { response.sendRedirect(finalUrl); // always 302 } catch (IOException e) { throw new RenderException(e); } } }
public String getRequestInfo(HttpServletRequest request) { return String.format("URI: %s; Scheme: %s; Host: %s; Port: %s; Origin: %s; Method: %s", request.getRequestURI(), request.getScheme(), request.getServerName(), request.getServerPort(), request.getHeader("Origin"), request.getMethod()); }
@RequestMapping("/auth") public String sendToAuthorization(HttpServletRequest request) { String baseUrl = String.format("%s://%s:%d/tasks/",request.getScheme(), request.getServerName(), request.getServerPort()); return "redirect:" + auth.getAuthorizationUrl(baseUrl); }
@Override public void sendRedirect(String location) throws IOException { UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(location); UriComponents uriComponents = builder.build(); // Absolute location if (uriComponents.getScheme() != null) { super.sendRedirect(location); return; } // Network-path reference if (location.startsWith("//")) { String scheme = this.request.getScheme(); super.sendRedirect(builder.scheme(scheme).toUriString()); return; } String path = uriComponents.getPath(); if (path != null) { // Relative to Servlet container root or to current request path = (path.startsWith(FOLDER_SEPARATOR) ? path : StringUtils.applyRelativePath(this.request.getRequestURI(), path)); } String result = UriComponentsBuilder .fromHttpRequest(new ServletServerHttpRequest(this.request)) .replacePath(path) .replaceQuery(uriComponents.getQuery()) .fragment(uriComponents.getFragment()) .build().normalize().toUriString(); super.sendRedirect(result); } }
/** * 获取当前的url * * @param inv * @return */ private String getGotoUrl(Invocation inv) { HttpServletRequest req = inv.getController().getRequest(); // 获取用户将要去的路径 String queryString = req.getQueryString(); // 被拦截前的请求URL String url = req.getScheme() + "://" + req.getServerName() + req.getRequestURI(); if (StrUtils.isNotBlank(queryString)) { url = url.concat("?").concat(queryString); } return StrUtils.urlEncode(url); } }
public void index() { String gotoUrl = getPara("goto"); String uid = EncryptCookieUtils.get(this, JPressConsts.COOKIE_UID); //说明当前用户已经登录 if (StrUtils.isNotBlank(uid)) { redirect(StrUtils.urlDecode(gotoUrl)); return; } String appId = JPressOptions.get(JPressConsts.OPTION_WECHAT_APPID); if (StrUtils.isBlank(appId)) { renderText("管理员的微信APPID配置错误,请联系管理在后台 -> 微信 -> 基础设置 配置正确的APPID。"); return; } String domain = JPressOptions.get(JPressConsts.OPTION_WEB_DOMAIN); if (StrUtils.isBlank(domain)) { domain = getRequest().getScheme() + "://" + getRequest().getServerName(); } if (StrUtils.isNotBlank(JFinal.me().getContextPath())) { domain = domain + JFinal.me().getContextPath(); } //这个url是微信执行完毕之后跳转回来的url //也是下方的这个 action String redirecturi = domain + "/wechat/authorization/back?goto=" + gotoUrl; String wechatUrl = AUTHORIZE_URL.replace("{appid}", appId).replace("{redirecturi}", redirecturi); redirect(wechatUrl); }
/** * 获取当前上下文路径 * * @param request * @return */ private String getLocalUrl(HttpServletRequest request) { return new StringBuilder().append(request.getScheme()).append("://").append(request.getServerName()).append(":") .append(request.getServerPort() == 80 ? "" : request.getServerPort()).append(request.getContextPath()) .toString(); }
/** * 获取请求basePath */ public static String getBasePath(HttpServletRequest request) { StringBuffer basePath = new StringBuffer(); String scheme = request.getScheme(); String domain = request.getServerName(); int port = request.getServerPort(); basePath.append(scheme); basePath.append("://"); basePath.append(domain); if("http".equalsIgnoreCase(scheme) && 80 != port) { basePath.append(":").append(String.valueOf(port)); } else if("https".equalsIgnoreCase(scheme) && port != 443) { basePath.append(":").append(String.valueOf(port)); } return basePath.toString(); }
@Override public void sendRedirect(String location) throws IOException { UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(location); UriComponents uriComponents = builder.build(); // Absolute location if (uriComponents.getScheme() != null) { super.sendRedirect(location); return; } // Network-path reference if (location.startsWith("//")) { String scheme = this.request.getScheme(); super.sendRedirect(builder.scheme(scheme).toUriString()); return; } String path = uriComponents.getPath(); if (path != null) { // Relative to Servlet container root or to current request path = (path.startsWith(FOLDER_SEPARATOR) ? path : StringUtils.applyRelativePath(this.request.getRequestURI(), path)); } String result = UriComponentsBuilder .fromHttpRequest(new ServletServerHttpRequest(this.request)) .replacePath(path) .replaceQuery(uriComponents.getQuery()) .fragment(uriComponents.getFragment()) .build().normalize().toUriString(); super.sendRedirect(result); } }
/** * Pulls out the base url ( from the client point of view ), from the given request object. * * @return A String of the form "<scheme>://<server>:<port>/<context>/" */ public static String baseURL(HttpServletRequest req) { StringBuffer sb = new StringBuffer(req.getScheme()); sb.append("://") .append(req.getServerName()) .append(":") .append(req.getServerPort()) .append(req.getContextPath()) .append("/"); return sb.toString(); }
/** * Initialize a builder with a scheme, host,and port (but not path and query). */ private static ServletUriComponentsBuilder initFromRequest(HttpServletRequest request) { String scheme = request.getScheme(); String host = request.getServerName(); int port = request.getServerPort(); ServletUriComponentsBuilder builder = new ServletUriComponentsBuilder(); builder.scheme(scheme); builder.host(host); if (("http".equals(scheme) && port != 80) || ("https".equals(scheme) && port != 443)) { builder.port(port); } return builder; }
out.println("Request Scheme: " + pRequest.getScheme()); out.println("Request URI: " + pRequest.getRequestURI()); out.println("Request URL: " + pRequest.getRequestURL().toString()); out.println("Request PathInfo: " + pRequest.getPathInfo());
public static String getURL(HttpServletRequest req) { String scheme = req.getScheme(); // http String serverName = req.getServerName(); // hostname.com int serverPort = req.getServerPort(); // 80 String contextPath = req.getContextPath(); // /mywebapp String servletPath = req.getServletPath(); // /servlet/MyServlet String pathInfo = req.getPathInfo(); // /a/b;c=123 String queryString = req.getQueryString(); // d=789 // Reconstruct original requesting URL StringBuilder url = new StringBuilder(); url.append(scheme).append("://").append(serverName); if (serverPort != 80 && serverPort != 443) { url.append(":").append(serverPort); } url.append(contextPath).append(servletPath); if (pathInfo != null) { url.append(pathInfo); } if (queryString != null) { url.append("?").append(queryString); } return url.toString(); }
/** * Convenience method to obtain the server prefix of the current request. * Useful for many modules that configure Relative URL's and need to send absolute URL's * to Third Party Gateways. */ public static String getRequestedServerPrefix() { HttpServletRequest request = BroadleafRequestContext.getBroadleafRequestContext().getRequest(); String scheme = request.getScheme(); StringBuilder serverPrefix = new StringBuilder(scheme); serverPrefix.append("://"); serverPrefix.append(request.getServerName()); if ((scheme.equalsIgnoreCase("http") && request.getServerPort() != 80) || (scheme.equalsIgnoreCase("https") && request.getServerPort() != 443)) { serverPrefix.append(":"); serverPrefix.append(request.getServerPort()); } return serverPrefix.toString(); }