List of usage examples for javax.servlet.http HttpServletRequest getServerPort
public int getServerPort();
From source file:com.beginner.core.utils.ProjectUtil.java
/** * ?//from w ww .j a v a2 s .com * @return String http://ip?:??/??/ */ public static String basePath() { HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()) .getRequest(); String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/"; return basePath; }
From source file:com.flexive.war.filter.FxRequestUtils.java
/** * Returns the server name as seen by the client. Takes into account proxies * like Apache2 which may alter the server name in their requests. * * @param request the request/* ww w . j a v a 2 s. c o m*/ * @return the server name as seen by the client */ public static String getExternalServerName(HttpServletRequest request) { if (request.getHeader("x-forwarded-host") != null) { // use external (forwarded) host - FX-330 return request.getHeader("x-forwarded-host"); } else { // use our own server name return request.getServerName() + (request.getServerPort() == 80 || (request.isSecure() && request.getServerPort() == 443) ? "" : ":" + request.getServerPort()); } }
From source file:eionet.util.SecurityUtil.java
/** * * @return//from ww w . j a v a 2 s . com */ private static String getUrlWithContextPath(HttpServletRequest request) { StringBuffer url = new StringBuffer(request.getScheme()); url.append("://").append(request.getServerName()); if (request.getServerPort() > 0) { url.append(":").append(request.getServerPort()); } url.append(request.getContextPath()); return url.toString(); }
From source file:org.encuestame.core.security.util.WidgetUtil.java
/** * * @param request//from w w w . j a v a2 s . co m * @return */ public static final String getRelativeDomain(final HttpServletRequest request) { //FIXME: and HTTPS? final StringBuffer domain = new StringBuffer(); domain.append(request.getServerName()); if (request.getServerPort() != WidgetUtil.REQUEST_SERVER_PORT) { domain.append(":"); domain.append(request.getServerPort()); } domain.append(request.getContextPath()); return domain.toString(); }
From source file:info.magnolia.cms.util.ServletUtil.java
/** * Returns the original request url. If the request has been forwarded it reconstructs the url from request * attributes. The returned url is not decoded. *//*from w w w .jav a2 s .co m*/ public static String getOriginalRequestURLIncludingQueryString(HttpServletRequest request) { if (request.getAttribute(FORWARD_REQUEST_URI_ATTRIBUTE) != null) { StringBuilder builder = new StringBuilder(); String scheme = request.getScheme(); builder.append(scheme).append("://").append(request.getServerName()); int port = request.getServerPort(); if ((scheme.equalsIgnoreCase("http") && port == 80) || (scheme.equalsIgnoreCase("https") && port == 443)) { // adding port is not necessary } else { builder.append(":").append(port); } String requestUri = (String) request.getAttribute(FORWARD_REQUEST_URI_ATTRIBUTE); builder.append(requestUri); String queryString = (String) request.getAttribute(FORWARD_QUERY_STRING_ATTRIBUTE); if (StringUtils.isNotEmpty(queryString)) { builder.append("?").append(queryString); } return builder.toString(); } StringBuilder builder = new StringBuilder(); builder.append(request.getRequestURL()); String queryString = request.getQueryString(); if (StringUtils.isNotEmpty(queryString)) { builder.append("?").append(queryString); } return builder.toString(); }
From source file:org.encuestame.core.security.util.WidgetUtil.java
/** * Get Domain.// ww w . j a v a 2 s . c om * @param request * @return */ public static final String getDomain(final HttpServletRequest request) { //FIXME: and HTTPS? final StringBuffer domain = new StringBuffer(WidgetUtil.URL); domain.append(request.getServerName()); if (request.getServerPort() != WidgetUtil.REQUEST_SERVER_PORT) { domain.append(":"); domain.append(request.getServerPort()); } // buffer.append("//"); domain.append(request.getContextPath()); return domain.toString(); }
From source file:org.geowebcache.util.ServletUtils.java
/** * Generate the base url of the request, minus the context path * @param req servlet request//from ww w .j a v a 2 s . c om * @return Base url of request, minus the context path */ public static String getServletBaseURL(HttpServletRequest req, String servletPrefix) { String result; if (req.getServerPort() == 80 || req.getServerPort() == 443) { result = req.getScheme() + "://" + req.getServerName(); } else { result = req.getScheme() + "://" + req.getServerName() + ":" + req.getServerPort(); } if (servletPrefix == null) { return result; } else { // If the servlet is embeded within another, include the context path of the parent // servlet in the base. String reqUrl = req.getContextPath(); return result + reqUrl; } }
From source file:org.encuestame.core.security.util.WidgetUtil.java
/** * * @param request/* w w w. jav a2 s .co m*/ * @param addHttp * @return */ public static final String getDomain(final HttpServletRequest request, final Boolean addHttp) { final StringBuffer domain = new StringBuffer(addHttp ? WidgetUtil.URL : ""); domain.append(request.getServerName()); if (request.getServerPort() != WidgetUtil.REQUEST_SERVER_PORT) { domain.append(":"); domain.append(request.getServerPort()); } // buffer.append("//"); domain.append(request.getContextPath()); return domain.toString(); }
From source file:org.dd4t.core.util.HttpUtils.java
public static String getFullUrl(final HttpServletRequest request, final String location) { String contextPath = "/".equals(request.getContextPath()) ? "" : request.getContextPath(); return String.format("%s://%s:%d%s%s", request.getScheme(), request.getServerName(), request.getServerPort(), contextPath, location); }
From source file:net.naijatek.myalumni.util.utilities.ParamUtil.java
public static String getServer(final HttpServletRequest request) { StringBuffer server = new StringBuffer(128); String scheme = request.getScheme(); int port = request.getServerPort(); if (port < 0) { port = 80; // Work around java.net.URL bug }/*from ww w . jav a2 s .c o m*/ server.append(scheme); server.append("://"); server.append(request.getServerName()); if (scheme.equals("http") && port != 80 || scheme.equals("https") && port != 443) { server.append(':'); server.append(port); } return server.toString(); }