/** * 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(); }
@Override public void sendRedirect(HttpServletRequest request, HttpServletResponse response, String url) throws IOException { if (!url.startsWith("/")) { if (StringUtils.equals(request.getParameter("successUrl"), url) || StringUtils.equals(request.getParameter("failureUrl"), url)) { validateRedirectUrl(request.getContextPath(), url, request.getServerName(), request.getServerPort()); } } String redirectUrl = calculateRedirectUrl(request.getContextPath(), url); redirectUrl = response.encodeRedirectURL(redirectUrl); if (LOG.isDebugEnabled()) { LOG.debug("Redirecting to '" + url + "'"); } response.sendRedirect(redirectUrl); }
buff.append(httpRequest.getServerName()) .append(":") .append(sslPort) .append(httpRequest.getContextPath()) .append(httpRequest.getServletPath()); if (httpRequest.getQueryString() != null) { for (String kvpString : httpRequest.getQueryString().split("&")) { String[] kvpArray = kvpString.split("="); if (kvpArray == null || kvpArray.length != 2) {
@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; }
/** * Return the global scope to use for the given request. * * @param req * http request * @return scope */ protected IGlobalScope getGlobalScope(HttpServletRequest req) { String path = req.getContextPath() + req.getServletPath(); log.debug("getGlobalScope path: {}", path); if (path.startsWith("/")) { path = path.substring(1); } else { log.debug("Path length: {} Servlet name length: {}", path.length(), getServletName().length()); path = path.substring(0, path.length() - getServletName().length() - 1); } IGlobalScope global = server.lookupGlobal(req.getServerName(), path); if (global == null) { global = server.lookupGlobal(req.getLocalName(), path); if (global == null) { global = server.lookupGlobal(req.getLocalAddr(), path); } } return global; }
static public String dumpHeaders(HttpServletRequest request) { StringBuilder sb = new StringBuilder(); Enumeration<?> em = request.getHeaderNames(); sb.append('\n'); sb.append("<HEADERS request=\"" + request.getRequestURL().toString()); if (null != request.getQueryString()) sb.append("?" + request.getQueryString()); sb.append("\""); sb.append('\n' + "SESSIONid=\"" + request.getSession().getId() + "\""); sb.append('\n' + "ServerName=\"" + request.getServerName() + "\""); sb.append('\n' + "ServerPort=\"" + request.getServerPort() + "\""); sb.append('\n' + "localAddr=\"" + request.getLocalAddr() + "\""); sb.append('\n' + "localName=\"" + request.getLocalName() + "\""); sb.append('\n' + "localPort=\"" + request.getLocalPort() + "\""); sb.append('\n' + "RemoteAddr=\"" + request.getRemoteAddr() + "\""); sb.append('\n' + "RemoteHost=\"" + request.getRemoteHost() + "\""); sb.append('\n' + "RemotePort=\"" + request.getRemotePort() + "\""); sb.append('\n' + "Encoding=\"" + request.getCharacterEncoding() + "\""); sb.append('\n' + "Method=\"" + request.getMethod() + "\""); sb.append(">"); while (em.hasMoreElements()) { String name = (String) em.nextElement(); sb.append('\n'); sb.append("[" + name + "]:"); sb.append(request.getHeader(name)); } sb.append('\n'); sb.append("</HEADERS>"); return sb.toString(); }
SysSite site = siteComponent.getSite(request.getServerName()); SysUser user = initUser(ControllerUtils.getAdminFromSession(session), LogLoginService.CHANNEL_WEB_MANAGER, CommonConstants.getCookiesAdmin(), site, request, response); if (null == user) { try { redirectLogin(ctxPath, path, request.getQueryString(), request.getHeader("X-Requested-With"), response); return false; } catch (IllegalStateException | IOException e) { || site.getId() != entity.getSiteId()) { try { redirectLogin(ctxPath, path, request.getQueryString(), request.getHeader("X-Requested-With"), response); return false; } catch (IllegalStateException | IOException e) {
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); }
rb.setScheme("https"); rb.setPort(httpsPort); rb.setContextPath(request.getContextPath()); rb.setServletPath(request.getServletPath()); rb.setPathInfo(request.getPathInfo()); rb.setQuery(request.getQueryString()); rb.setServerName(request.getServerName());
@Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws ServletException { HttpSession session = request.getSession(); SysSite site = siteComponent.getSite(request.getServerName()); SysUser user = initUser(ControllerUtils.getUserFromSession(session), LogLoginService.CHANNEL_WEB, CommonConstants.getCookiesUser(), site, request, response); ControllerUtils.clearUserToSession(request.getContextPath(), session, response);
SysSite site = siteComponent.getSite(request.getServerName()); SysUser user = initUser(ControllerUtils.getAdminFromSession(session), LogLoginService.CHANNEL_WEB_MANAGER, CommonConstants.getCookiesAdmin(), site, request, response); if (null == user) { try { redirectLogin(ctxPath, path, request.getQueryString(), request.getHeader("X-Requested-With"), response); return false; } catch (IllegalStateException | IOException e) { || site.getId() != entity.getSiteId()) { try { redirectLogin(ctxPath, path, request.getQueryString(), request.getHeader("X-Requested-With"), response); return false; } catch (IllegalStateException | IOException e) {
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 boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws ServletException { HttpSession session = request.getSession(); SysSite site = siteComponent.getSite(request.getServerName()); SysUser user = initUser(ControllerUtils.getUserFromSession(session), LogLoginService.CHANNEL_WEB, CommonConstants.getCookiesUser(), site, request, response); ControllerUtils.clearUserToSession(request.getContextPath(), session, response);
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(); }