List of usage examples for javax.servlet.http HttpServletRequest getScheme
public String getScheme();
From source file:org.jahia.services.render.URLGenerator.java
/** * Returns the server URL, including scheme, host and port, depending on the current site. The URL is in the form <code><scheme><host>:<port></code>, e.g. <code>http://www.jahia.org:8080</code>. The port is omitted in case of standard * HTTP (80) and HTTPS (443) ports.//from w w w .j a v a 2 s . c om * <p/> * If the site's server name is configured to be "localhost", then take the servername from the request. * * @return the server URL, including scheme, host and port, depending on the current site */ public String getServer() { if (server == null) { StringBuilder url = new StringBuilder(255); // use a greater than default (16) allocated StringBuilder to avoid having to resize it final HttpServletRequest request = context.getRequest(); String scheme = request.getScheme(); String host = context.getSite().getServerName(); if (Url.isLocalhost(host)) { host = request.getServerName(); } int port = SettingsBean.getInstance().getSiteURLPortOverride(); if (port == 0) { port = request.getServerPort(); } url.append(scheme).append("://").append(host); if (!(port == 80 && "http".equals(scheme) || port == 443 && "https".equals(scheme))) { url.append(":").append(port); } server = url.toString(); } return server; }
From source file:br.com.flucianofeijao.security.JsfLoginUrlAuthenticationEntryPoint.java
protected String buildRedirectUrlToLoginPage(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) { String loginForm = determineUrlToUseForThisRequest(request, response, authException); if (UrlUtils.isAbsoluteUrl(loginForm)) { return loginForm; }/*ww w . ja v a2s .co m*/ int serverPort = portResolver.getServerPort(request); String scheme = request.getScheme(); RedirectUrlBuilder urlBuilder = new RedirectUrlBuilder(); urlBuilder.setScheme(scheme); urlBuilder.setServerName(request.getServerName()); urlBuilder.setPort(serverPort); urlBuilder.setContextPath(request.getContextPath()); urlBuilder.setPathInfo(loginForm); if (forceHttps && "http".equals(scheme)) { Integer httpsPort = portMapper.lookupHttpsPort(Integer.valueOf(serverPort)); if (httpsPort != null) { // Overwrite scheme and port in the redirect URL urlBuilder.setScheme("https"); urlBuilder.setPort(httpsPort.intValue()); } else { logger.warn("Unable to redirect to HTTPS as no port mapping found for HTTP port " + serverPort); } } return urlBuilder.getUrl(); }
From source file:com.sap.cloudlabs.connectivity.proxy.ProxyServlet.java
/** * Returns the URL to the proxy servlet and used destination. *///from www . j a v a2 s. c o m private String getProxyUrl(HttpServletRequest request) throws MalformedURLException { URL url = new URL(request.getRequestURL().toString()); String proxyUrl = request.getScheme() + "://" + url.getAuthority() + request.getContextPath() + request.getServletPath(); return proxyUrl; }
From source file:com.rxx.base.interceptor.ActionInterceptor.java
/** * action,basebasepath//from w w w. j a v a 2 s . c om * @param request HttpServletRequest * @param response HttpServletResponse * @param handler * @throws Exception * @return true */ @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { String modelId = request.getParameter(MODEL_ID); // if (StringUtil.isInteger(modelId)) { request.getSession().setAttribute(SessionConst.MODEL_ID_SESSION.toString(), modelId); request.getSession().setAttribute(SessionConst.MODEL_TITLE_SESSION.toString(), request.getParameter("modelTitle")); } request.setAttribute(BASE, Const.BASE); request.setAttribute(BASE_PATH, request.getScheme() + "://" + request.getServerName() + (request.getServerPort() == 80 ? "" : ":" + request.getServerPort()) + Const.BASE); request.setAttribute(BASE_URL, request.getScheme() + "://" + request.getServerName() + (request.getServerPort() == 80 ? "" : ":" + request.getServerPort()) + request.getContextPath() + request.getServletPath() + (request.getQueryString() == null ? "" : "?" + request.getQueryString())); return true; }
From source file:org.infoglue.calendar.actions.ViewEventSearchAction.java
/** * This is the entry point for the main listing. *//*from w ww. j a va 2 s .c o m*/ public String execute() throws Exception { Session session = getSession(true); if (startDateTime != null && startDateTime.length() > 0) startCalendar = getCalendar(startDateTime + " " + startTime, "yyyy-MM-dd HH:mm", true); if (endDateTime != null && endDateTime.length() > 0) endCalendar = getCalendar(endDateTime + " " + endTime, "yyyy-MM-dd HH:mm", true); log.info("price:" + price); this.events = EventController.getController().getEventList(name, startCalendar, endCalendar, organizerName, lecturer, customLocation, alternativeLocation, contactName, contactEmail, contactPhone, price, maximumParticipants, sortAscending, categoryId, calendarId, locationId, stateId, session); // should we create result files? if (this.events.size() > 0 && exportResult) { Map parameters = new HashMap(); parameters.put("headLine", "Events found"); HttpServletRequest request = ServletActionContext.getRequest(); EventSearchResultfilesConstructor results = new EventSearchResultfilesConstructor(parameters, this.events, getTempFilePath(), request.getScheme(), request.getServerName(), request.getServerPort(), resultValues, (CalendarAbstractAction) this); searchResultFiles = results.getResults(); } return Action.SUCCESS; }
From source file:controllers.UrlController.java
@RequestMapping(value = { "/*", "/*/*", "/*/*/*" }) public void AnyURL(@PathVariable String link, ModelMap model, HttpServletRequest request, HttpServletResponse response) throws SQLException, IOException, ServletException { String url1 = request.getRequestURI(); String url2 = request.getScheme() + "://" + // "http" + ":// request.getServerName() + // "myhost" ":" + request.getServerPort() + // ":" + "8080" request.getRequestURI() + // "/people" (request.getQueryString() != null ? "?" + request.getQueryString() : ""); //request.getRequestDispatcher("").forward(request, response); // response.sendRedirect(""); }
From source file:fr.paris.lutece.portal.service.util.AppPathService.java
/** * Return the url of the webapp, built from the request * * @param request The HttpServletRequest * @return strBase the webapp url// ww w. jav a 2 s . c om */ public static String getBaseUrl(HttpServletRequest request) { if (request == null) { return getBaseUrl(); } String strBase; // Search for a Virtual Host Base Url defined in the request strBase = getVirtualHostBaseUrl(request); // If not found, get the base url from session if ((strBase == null) || strBase.equals(StringUtils.EMPTY)) { HttpSession session = request.getSession(false); if (session != null) { Object oBase = session.getAttribute(SESSION_BASE_URL); if (oBase != null) { strBase = (String) oBase; } } } // If not found, get the base url from the config.properties if ((strBase == null) || (strBase.equals(StringUtils.EMPTY))) { strBase = AppPropertiesService.getProperty(PROPERTY_BASE_URL); } if ((strBase == null) || (strBase.equals(StringUtils.EMPTY))) { // Dynamic base URL if not defined in the properties strBase = request.getScheme() + DOUBLE_POINTS + SLASH + SLASH + request.getServerName(); int nPort = request.getServerPort(); if (nPort != PORT_NUMBER_HTTP) { strBase += (DOUBLE_POINTS + nPort); } strBase += request.getContextPath(); } if (!strBase.endsWith(SLASH)) { strBase += SLASH; } return strBase; }
From source file:br.com.gerenciapessoal.security.JsfLoginUrlAuthenticationEntryPoint.java
protected String buildRedirectUrlToLoginPage(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) { String loginForm = determineUrlToUseForThisRequest(request, response, authException); if (UrlUtils.isAbsoluteUrl(loginForm)) { return loginForm; }/*from w w w . j a v a 2 s. c o m*/ int serverPort = portResolver.getServerPort(request); String scheme = request.getScheme(); RedirectUrlBuilder urlBuilder = new RedirectUrlBuilder(); urlBuilder.setScheme(scheme); urlBuilder.setServerName(request.getServerName()); urlBuilder.setPort(serverPort); urlBuilder.setContextPath(request.getContextPath()); urlBuilder.setPathInfo(loginForm); if (forceHttps && "http".equals(scheme)) { Integer httpsPort = portMapper.lookupHttpsPort(serverPort); if (httpsPort != null) { // Overwrite scheme and port in the redirect URL urlBuilder.setScheme("https"); urlBuilder.setPort(httpsPort); } else { logger.warn("Unable to redirect to HTTPS as no port mapping found for HTTP port " + serverPort); } } return urlBuilder.getUrl(); }
From source file:svnserver.ext.web.server.WebServer.java
@NotNull public URI getUrl(@NotNull HttpServletRequest req) { if (config.getBaseUrl() != null) { return URI.create(config.getBaseUrl()).resolve(req.getRequestURI()); }// www . jav a 2 s. c o m String host = req.getHeader(HttpHeaders.HOST); if (host == null) { host = req.getServerName() + ":" + req.getServerPort(); } return URI.create(req.getScheme() + "://" + host + req.getRequestURI()); }
From source file:org.imsglobal.lti2.LTI2Servlet.java
public String getServiceURL(HttpServletRequest request) { String scheme = request.getScheme(); // http String serverName = request.getServerName(); // localhost int serverPort = request.getServerPort(); // 80 String contextPath = request.getContextPath(); // /imsblis String servletPath = request.getServletPath(); // /ltitest String url = scheme + "://" + serverName + ":" + serverPort + contextPath + servletPath + "/"; return url;/*from w ww.ja v a 2 s.co m*/ }