List of usage examples for javax.servlet.http HttpServletRequest getScheme
public String getScheme();
From source file:org.easyrec.util.core.Web.java
/** * This function returns a relative servlet url into a complete one. e.g. * /peppi?id=43 --> http://localhost:8080/sat-xxx/peppi?id=43 * * @param request HttpServletRequest//from w ww . ja v a 2 s . co m * @param servlet String * @return String */ @SuppressWarnings({ "UnusedDeclaration" }) public static String createRequestFromServlet(HttpServletRequest request, String servlet) { return request.getScheme() + "://" + request.getLocalAddr() + ":" + request.getLocalPort() + request.getContextPath() + servlet; }
From source file:alpha.portal.webapp.util.RequestUtil.java
/** * Convenience method to get the application's URL based on request * variables./*from w ww . j av a 2 s . co m*/ * * @param request * the current request * @return URL to application */ public static String getAppURL(final HttpServletRequest request) { if (request == null) return ""; final StringBuffer url = new StringBuffer(); int port = request.getServerPort(); if (port < 0) { port = 80; // Work around java.net.URL bug } final String scheme = request.getScheme(); url.append(scheme); url.append("://"); url.append(request.getServerName()); if ((scheme.equals("http") && (port != 80)) || (scheme.equals("https") && (port != 443))) { url.append(':'); url.append(port); } url.append(request.getContextPath()); return url.toString(); }
From source file:ee.ria.xroad.proxy.clientproxy.AbstractClientProxyHandler.java
protected static IsAuthenticationData getIsAuthenticationData(HttpServletRequest request) { X509Certificate[] certs = (X509Certificate[]) request.getAttribute("javax.servlet.request.X509Certificate"); return new IsAuthenticationData(certs != null && certs.length != 0 ? certs[0] : null, !"https".equals(request.getScheme()) // if not HTTPS, it's plaintext );//from w ww. j a va 2 s . c om }
From source file:com.jslsolucoes.tagria.lib.util.TagUtil.java
public static String getScheme(HttpServletRequest request) { if (request.getHeader("X-Forwarded-Protocol") != null) { return request.getHeader("X-Forwarded-Protocol"); } else {// www . j ava 2s . co m return request.getScheme(); } }
From source file:com.rantop.web.util.web.ServletUtils.java
/** * Convenience method to get the application's URL based on request * variables.//from ww w .jav a 2s. co m */ public static String getAppURL(HttpServletRequest request) { StringBuffer url = new StringBuffer(); int port = request.getServerPort(); if (port < 0) { port = 80; // Work around java.net.URL bug } String scheme = request.getScheme(); url.append(scheme); url.append("://"); url.append(request.getServerName()); if ((scheme.equals("http") && (port != 80)) || (scheme.equals("https") && (port != 443))) { url.append(':'); url.append(port); } url.append(request.getContextPath()); return url.toString(); }
From source file:ch.entwine.weblounge.common.url.UrlUtils.java
/** * Returns the request url as a string./* w w w . j av a2 s.co m*/ * * @param request * the request * @param includePath * <code>true</code> to also include the request uri * @param includeQuery * <code>true</code> to include the query string * @return the url as a string */ public static URL toURL(HttpServletRequest request, boolean includePath, boolean includeQuery) { try { StringBuffer buf = new StringBuffer(request.getScheme()); buf.append("://"); buf.append(request.getServerName()); if (request.getServerPort() != 80) buf.append(":").append(request.getServerPort()); if (includePath && request.getRequestURI() != null) buf.append(request.getRequestURI()); if (includeQuery && StringUtils.isNotBlank(request.getQueryString())) buf.append(request.getQueryString()); return new URL(buf.toString()); } catch (MalformedURLException e) { throw new IllegalStateException(e); } }
From source file:org.craftercms.commons.http.HttpUtils.java
/** * Returns the portion from the URL that includes the scheme, server name and port number, without the server * path./*from www . j a va2 s. co m*/ * * @param request the request object used to build the base URL * @param forceHttps if HTTPS should be enforced * * @return the base request URL */ public static StringBuilder getBaseRequestUrl(HttpServletRequest request, boolean forceHttps) { String scheme = forceHttps ? HTTPS_SCHEME : request.getScheme(); String serverName = request.getServerName(); int serverPort = request.getServerPort(); StringBuilder url = new StringBuilder(); url.append(scheme).append("://").append(serverName); if (!(scheme.equals(HTTP_SCHEME) && serverPort == DEFAULT_HTTP_PORT) && !(scheme.equals(HTTPS_SCHEME) && serverPort == DEFAULT_HTTPS_PORT)) { url.append(":").append(serverPort); } return url; }
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:de.betterform.agent.web.WebUtil.java
public static String getRequestURI(HttpServletRequest request) { StringBuffer buffer = new StringBuffer(request.getScheme()); buffer.append("://"); buffer.append(request.getServerName()); buffer.append(":"); buffer.append(request.getServerPort()); buffer.append(request.getContextPath()); return buffer.toString(); }
From source file:org.artifactory.util.HttpUtils.java
public static String getServerUrl(HttpServletRequest httpRequest) { int port = httpRequest.getServerPort(); String scheme = httpRequest.getScheme(); if (isDefaultPort(scheme, port)) { return scheme + "://" + httpRequest.getServerName(); }// ww w.j a v a2s. c om return scheme + "://" + httpRequest.getServerName() + ":" + port; }