List of usage examples for javax.servlet.http HttpServletRequest getRequestURL
public StringBuffer getRequestURL();
From source file:com.ibm.rpe.web.template.ui.utils.Utils.java
public static String getTemplateServiceUrl(HttpServletRequest request, String systemProperty, String contextRoot) {/*w ww . j a v a 2 s.c o m*/ String serviceURL = getSystemProperty(systemProperty, null); if (CommonUtils.isNullOrEmpty(serviceURL)) { serviceURL = request.getRequestURL().toString(); serviceURL = serviceURL.substring(0, serviceURL.indexOf(request.getRequestURI())); if (!CommonUtils.isNullOrEmpty(serviceURL)) { if (serviceURL.endsWith("/")) //$NON-NLS-1$ { serviceURL = serviceURL + contextRoot; } else { serviceURL = serviceURL + "/" + contextRoot; //$NON-NLS-1$ } System.out.println("Template Service URL not set. Using " + serviceURL); //$NON-NLS-1$ } else { System.out.println("Template Service URL is not set and it cannot be derived. Failure....."); //$NON-NLS-1$ } } else { System.out.println("Template Service URL is " + serviceURL); //$NON-NLS-1$ } return serviceURL; }
From source file:de.metas.ui.web.config.ServletLoggingFilter.java
private static final String extractRequestInfo(final ServletRequest request) { String requestInfo;// w ww. java 2 s . c o m if (request instanceof HttpServletRequest) { final HttpServletRequest httpRequest = (HttpServletRequest) request; final String urlStr = httpRequest.getRequestURL().toString(); URI uri; try { uri = new URI(urlStr); } catch (final URISyntaxException e) { uri = null; } String path = null; if (uri != null) { path = uri.getPath(); } if (path == null) { path = urlStr; } final String queryString = httpRequest.getQueryString(); requestInfo = path + (queryString != null ? "?" + queryString : ""); } else { requestInfo = request.toString(); } return requestInfo; }
From source file:net.sf.ehcache.constructs.web.ResponseUtil.java
/** * Checks whether a gzipped body is actually empty and should just be zero. * When the compressedBytes is {@link #EMPTY_GZIPPED_CONTENT_SIZE} it should be zero. * * @param compressedBytes the gzipped response body * @param request the client HTTP request * @return true if the response should be 0, even if it is isn't. *//* www . j a v a 2 s. c o m*/ public static boolean shouldGzippedBodyBeZero(byte[] compressedBytes, HttpServletRequest request) { //Check for 0 length body if (compressedBytes.length == EMPTY_GZIPPED_CONTENT_SIZE) { if (LOG.isDebugEnabled()) { LOG.debug(request.getRequestURL() + " resulted in an empty response."); } return true; } else { return false; } }
From source file:com.vmware.identity.openidconnect.protocol.URIUtils.java
public static URI from(HttpServletRequest httpServletRequest) { Validate.notNull(httpServletRequest, "httpServletRequest"); try {/*from ww w .j av a 2 s . co m*/ return new URI(httpServletRequest.getRequestURL().toString()); } catch (URISyntaxException e) { throw new IllegalArgumentException("failed to construct uri off of HttpServletRequest", e); } }
From source file:org.duracloud.duradmin.spaces.controller.ContentItemController.java
public static String getBaseURL(HttpServletRequest request) throws MalformedURLException { URL url = new URL(request.getRequestURL().toString()); int port = url.getPort(); String baseURL = url.getProtocol() + "://" + url.getHost() + ":" + (port > 0 && port != 80 ? url.getPort() : "") + request.getContextPath(); return baseURL; }
From source file:net.sf.ehcache.constructs.web.ResponseUtil.java
/** * Performs a number of checks to ensure response saneness according to the rules of RFC2616: * <ol>/* w ww . ja v a2 s . c o m*/ * <li>If the response code is {@link javax.servlet.http.HttpServletResponse#SC_NO_CONTENT} then it is illegal for the body * to contain anything. See http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.2.5 * <li>If the response code is {@link javax.servlet.http.HttpServletResponse#SC_NOT_MODIFIED} then it is illegal for the body * to contain anything. See http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.5 * </ol> * * @param request the client HTTP request * @param responseStatus the responseStatus * @return true if the response should be 0, even if it is isn't. */ public static boolean shouldBodyBeZero(HttpServletRequest request, int responseStatus) { //Check for NO_CONTENT if (responseStatus == HttpServletResponse.SC_NO_CONTENT) { if (LOG.isDebugEnabled()) { LOG.debug(request.getRequestURL() + " resulted in a " + HttpServletResponse.SC_NO_CONTENT + " response. Removing message body in accordance with RFC2616."); } return true; } //Check for NOT_MODIFIED if (responseStatus == HttpServletResponse.SC_NOT_MODIFIED) { if (LOG.isDebugEnabled()) { LOG.debug(request.getRequestURL() + " resulted in a " + HttpServletResponse.SC_NOT_MODIFIED + " response. Removing message body in accordance with RFC2616."); } return true; } return false; }
From source file:com.meltmedia.cadmium.servlets.AbstractSecureRedirectStrategy.java
/** * Constructs a URI for request and calls changeProtocolAndPort(String, int, URI). * //from ww w . j av a2 s . c o m * @param protocol the new protocol (scheme) in the resulting URI. * @param port the new port in the resulting URI, or the default port if -1 is provided. * @param request the request to use as the URI template. * @return a new URI object with the updated protocol and port. * @throws URISyntaxException */ public static URI changeProtocolAndPort(String protocol, int port, HttpServletRequest request) throws URISyntaxException { return changeProtocolAndPort(protocol, port, URI.create(request.getRequestURL().append( (StringUtils.isEmpty(request.getQueryString()) ? "" : "?" + request.getQueryString())) .toString())); }
From source file:com.soolr.core.web.Servlets.java
public static String getHost(HttpServletRequest request) { String requestURL = request.getRequestURL().toString(); String requestURI = request.getRequestURI(); String host = StringUtils.substringBefore(requestURL, requestURI); return host;//from w w w .ja va 2 s. co m }
From source file:com.soolr.core.web.Servlets.java
public static String getBasePath(HttpServletRequest request) { String requestURL = request.getRequestURL().toString(); String requestURI = request.getRequestURI(); String host = StringUtils.substringBeforeLast(requestURL, requestURI); String contextPath = request.getContextPath(); return StringUtils.removeEnd(host + contextPath, "/"); }
From source file:org.bedework.util.http.HttpUtil.java
/** Returns the String url from the request. * * @param request incoming request * @return String url from the request */// w w w.ja v a 2s. c om public static String getUrl(final HttpServletRequest request) { try { final StringBuffer sb = request.getRequestURL(); if (sb != null) { return sb.toString(); } // Presumably portlet - see what happens with uri return request.getRequestURI(); } catch (Throwable t) { return "BogusURL.this.is.probably.a.portal"; } }