List of usage examples for javax.servlet.http HttpServletRequest getScheme
public String getScheme();
From source file:com.twinsoft.convertigo.engine.servlets.GenericServlet.java
protected static String getServletBaseUrl(HttpServletRequest request) { String base = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort(); String requestURI = request.getRequestURI(); int i = requestURI.lastIndexOf('/'); return base + requestURI.substring(0, i); }
From source file:net.cloudfree.apps.shop.internal.app.JsonListingServlet.java
private static StringBuilder getBaseUrl(final HttpServletRequest req) { final StringBuilder builder = new StringBuilder(50); builder.append(req.getScheme()); builder.append("://"); builder.append(req.getServerName()); if ((req.getScheme().equals("http") && (req.getServerPort() != 80)) || (req.getScheme().equals("https") && (req.getServerPort() != 443))) { builder.append(":"); builder.append(req.getServerPort()); }/*from w w w. j av a2s .c om*/ builder.append(req.getContextPath()); builder.append(req.getServletPath()); builder.append("/"); return builder; }
From source file:org.geowebcache.util.ServletUtils.java
/** * Generate the base url of the request, minus the context path * @param req servlet request//from w ww . ja va 2s . com * @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:com.zimbra.cs.service.ExternalUserProvServlet.java
private static void setCookieAndRedirect(HttpServletRequest req, HttpServletResponse resp, Account grantee) throws ServiceException, IOException { AuthToken authToken = AuthProvider.getAuthToken(grantee); authToken.encode(resp, false, req.getScheme().equals("https")); resp.sendRedirect("/"); }
From source file:com.tc.utils.XSPUtils.java
public static String getAppURL() { HttpServletRequest req = XSPUtils.getRequest(); String scheme = req.getScheme(); StringBuffer url = new StringBuffer(); url.append(scheme).append("://").append(XSPUtils.hostName()).append('/').append(XSPUtils.webPath()); return url.toString(); }
From source file:com.tc.utils.XSPUtils.java
public static String getURL() { HttpServletRequest req = XSPUtils.getRequest(); 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 StringBuffer url = new StringBuffer(); url.append(scheme).append("://").append(serverName); if ((serverPort != 80) && (serverPort != 443)) { url.append(":").append(serverPort); }//from w w w .java2s.co m url.append(contextPath).append(servletPath); if (pathInfo != null) { url.append(pathInfo); } if (queryString != null) { url.append("?").append(queryString); } return url.toString(); }
From source file:org.apache.wookie.controller.WidgetInstancesController.java
public static String checkProxy(HttpServletRequest request) { // set the proxy url. if (urlWidgetProxyServer == null) { Configuration properties = (Configuration) request.getSession().getServletContext() .getAttribute("properties"); //$NON-NLS-1$ String scheme = request.getScheme(); String serverName = request.getServerName(); int serverPort = request.getServerPort(); if (!properties.getString("widget.proxy.scheme").trim().equals("")) //$NON-NLS-1$//$NON-NLS-2$ scheme = properties.getString("widget.proxy.scheme"); //$NON-NLS-1$ if (!properties.getString("widget.proxy.hostname").trim().equals("")) //$NON-NLS-1$//$NON-NLS-2$ serverName = properties.getString("widget.proxy.hostname"); //$NON-NLS-1$ if (!properties.getString("widget.proxy.port").trim().equals("")) //$NON-NLS-1$//$NON-NLS-2$ serverPort = Integer.parseInt(properties.getString("widget.proxy.port")); //$NON-NLS-1$ try {/*from ww w . j ava 2s . co m*/ urlWidgetProxyServer = new URL(scheme, serverName, serverPort, properties.getString("widget.proxy.path")); } catch (MalformedURLException e) { // ignore errors } } return urlWidgetProxyServer.toExternalForm(); }
From source file:nl.b3p.kaartenbalie.service.servlet.GeneralServlet.java
public static StringBuffer createBaseUrl(HttpServletRequest request, boolean useInternal) { String scheme = request.getScheme(); String serverName = request.getServerName(); int serverPort = request.getServerPort(); String contextPath;// w w w . j a v a 2 s. com if (useInternal) { contextPath = KBConfiguration.KB_SERVICES_INTERNAL_CONTEXT_PATH; } else { contextPath = KBConfiguration.KB_SERVICES_CONTEXT_PATH; } if (contextPath == null || contextPath.length() == 0) { contextPath = request.getContextPath(); } StringBuffer theUrl = new StringBuffer(); String serverURI; if (useInternal) { serverURI = KBConfiguration.KB_SERVICES_INTERNAL_SERVER_URI; } else { serverURI = KBConfiguration.KB_SERVICES_SERVER_URI; } if (serverURI != null && serverURI.length() > 5) { theUrl.append(serverURI); } else { theUrl.append(scheme); theUrl.append("://"); theUrl.append(serverName); if ((scheme.equals("http") && serverPort != 80) || (scheme.equals("https") && serverPort != 443)) { theUrl.append(":"); theUrl.append(serverPort); } } theUrl.append(contextPath); return theUrl; }
From source file:com.googlecode.fascinator.portal.services.impl.CachingDynamicPageServiceImpl.java
public static String getURL(HttpServletRequest req, JsonSimpleConfig config) { // Sometimes when proxying https behind apache or another web server, if // this is managed by the web server the scheme may be reported // incorrectly to Fascinator String scheme = config.getString(req.getScheme(), "urlSchemeName"); String serverName = req.getServerName(); // hostname.com int serverPort = req.getServerPort(); // 80 String contextPath = req.getContextPath(); // /redbox // Reconstruct original requesting URL StringBuilder url = new StringBuilder(); url.append(scheme).append("://").append(serverName); if ((serverPort != 80) && (serverPort != 443)) { url.append(":").append(serverPort); }//from w ww. j a va 2 s.c om url.append(contextPath).append("/"); return url.toString(); }
From source file:org.easyrec.util.core.Web.java
/** * This method trims a http-request with the given parameter. e.g. request: * /myServlet?id=1&desc=hallo --> trimRequest(request, "id") --> * /myServlet?desc=hallo//from w w w. j a va2 s.c om * * @param request HttpServletRequest * @param parameter String * @return String */ @SuppressWarnings({ "unchecked", "UnusedDeclaration" }) public static String trimRequest(HttpServletRequest request, String parameter) { String query = ""; if (!Strings.isNullOrEmpty(parameter) && request.getParameterMap() != null) { for (final Object o : request.getParameterMap().entrySet()) { Entry<String, String[]> m = (Entry<String, String[]>) o; if (!parameter.equals(m.getKey())) { query += m.getKey() + "=" + m.getValue()[0] + "&"; } } return request.getScheme() + "://" + request.getLocalAddr() + ":" + request.getLocalPort() + request.getContextPath() + request.getServletPath() + "?" + Text.removeLast(query); } else return null; }