List of usage examples for javax.servlet.http HttpServletRequest getScheme
public String getScheme();
From source file:org.apache.hadoop.gateway.filter.rewrite.impl.UrlRewriteResponseTest.java
@Test public void testResolveGatewayParams() throws Exception { UrlRewriteProcessor rewriter = EasyMock.createNiceMock(UrlRewriteProcessor.class); ServletContext context = EasyMock.createNiceMock(ServletContext.class); EasyMock.expect(context.getAttribute(UrlRewriteServletContextListener.PROCESSOR_ATTRIBUTE_NAME)) .andReturn(rewriter).anyTimes(); FilterConfig config = EasyMock.createNiceMock(FilterConfig.class); EasyMock.expect(config.getServletContext()).andReturn(context).anyTimes(); HttpServletRequest request = EasyMock.createNiceMock(HttpServletRequest.class); EasyMock.expect(request.getScheme()).andReturn("mock-scheme").anyTimes(); EasyMock.expect(request.getLocalName()).andReturn("mock-host").anyTimes(); EasyMock.expect(request.getLocalPort()).andReturn(42).anyTimes(); EasyMock.expect(request.getContextPath()).andReturn("/mock-path").anyTimes(); HttpServletResponse response = EasyMock.createNiceMock(HttpServletResponse.class); EasyMock.replay(rewriter, context, config, request, response); UrlRewriteResponse rewriteResponse = new UrlRewriteResponse(config, request, response); List<String> url = rewriteResponse.resolve("gateway.url"); assertThat(url, hasItems(new String[] { "mock-scheme://mock-host:42/mock-path" })); List<String> scheme = rewriteResponse.resolve("gateway.scheme"); assertThat(scheme, hasItems(new String[] { "mock-scheme" })); List<String> host = rewriteResponse.resolve("gateway.host"); assertThat(host, hasItems(new String[] { "mock-host" })); List<String> port = rewriteResponse.resolve("gateway.port"); assertThat(port, hasItems(new String[] { "42" })); List<String> addr = rewriteResponse.resolve("gateway.addr"); assertThat(addr, hasItems(new String[] { "mock-host:42" })); List<String> address = rewriteResponse.resolve("gateway.addr"); assertThat(address, hasItems(new String[] { "mock-host:42" })); List<String> path = rewriteResponse.resolve("gateway.path"); assertThat(path, hasItems(new String[] { "/mock-path" })); }
From source file:com.amediamanager.controller.VideoController.java
@RequestMapping(value = "/video/upload", method = RequestMethod.GET) public String videoUpload(ModelMap model, HttpServletRequest request, @ModelAttribute User user) { // Video redirect URL String redirectUrl = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath() + "/video/ingest"; // Prepare S3 form upload VideoUploadFormSigner formSigner = new VideoUploadFormSigner( config.getProperty(ConfigProps.S3_UPLOAD_BUCKET), config.getProperty(ConfigProps.S3_UPLOAD_PREFIX), user, config, redirectUrl);//from w w w. j ava2s .com model.addAttribute("formSigner", formSigner); model.addAttribute("templateName", "video_upload"); return "base"; }
From source file:com.enonic.cms.web.main.UpgradeController.java
/** * Return the base path.// w ww . j a v a2 s . co m */ private String createBaseUrl(HttpServletRequest req) { StringBuffer str = new StringBuffer(); str.append(req.getScheme()).append("://").append(req.getServerName()); if (req.getServerPort() != 80) { str.append(":").append(req.getServerPort()); } str.append(req.getContextPath()); return str.toString(); }
From source file:br.com.insula.spring.security.janrain.Janrain.java
public String getTokenUrl(HttpServletRequest request, String path) { Assert.notNull(request, "'request' cannot be null"); Assert.notNull(request, "'path' cannot be null"); Assert.isTrue(path.startsWith("/"), "path must start with '/'"); String scheme = request.getScheme(); int serverPort = request.getServerPort(); if (isRequestInDefaultPort(scheme, serverPort)) { return String.format("%s://%s%s", scheme, request.getServerName(), path); } else {/*w w w . j a v a2s.c o m*/ return String.format("%s://%s:%d%s", scheme, request.getServerName(), serverPort, path); } }
From source file:com.twocharts.www.samples.apps.marketplace.OpenIdServlet.java
/** * Dynamically constructs the base URL for the application based on the current request * * @param request Current servlet request * @return Base URL (path to servlet context) */// w w w .j av a 2 s .c om String baseUrl(HttpServletRequest request) { StringBuffer url = new StringBuffer(request.getScheme()).append("://").append(request.getServerName()); if ((request.getScheme().equalsIgnoreCase("http") && request.getServerPort() != 80) || (request.getScheme().equalsIgnoreCase("https") && request.getServerPort() != 443)) { url.append(":").append(request.getServerPort()); } return url.toString(); }
From source file:org.apache.hadoop.hdfs.server.namenode.DfsServlet.java
/** Create a URI for redirecting request */ protected URI createRedirectUri(String servletpath, UserGroupInformation ugi, DatanodeID host, HttpServletRequest request, String tokenString) throws URISyntaxException { final String hostname = host instanceof DatanodeInfo ? ((DatanodeInfo) host).getHostName() : host.getHost(); final String scheme = request.getScheme(); final int port = "https".equals(scheme) ? (Integer) getServletContext().getAttribute("datanode.https.port") : host.getInfoPort();/*from w ww. ja va 2s .co m*/ final String filename = request.getPathInfo(); String dt = ""; if (tokenString != null) { dt = JspHelper.getDelegationTokenUrlParam(tokenString); } return new URI(scheme, null, hostname, port, servletpath, "filename=" + filename + "&ugi=" + ugi.getShortUserName() + dt, null); }
From source file:com.seajas.search.utilities.tags.URLTag.java
/** * Rewrite a URL.//from www. j av a 2 s .c om * * @param context * @param request * @param url * @param fullUrl * @return String */ public static String rewriteURL(final ServletContext context, final HttpServletRequest request, final String url, final Boolean fullUrl) { String rewrittenURL = url; String contextName = context.getContextPath(); if (contextName == null) contextName = System.getProperty(SYSTEM_DEFAULT_CONTEXT); if (contextName.startsWith("/")) contextName = contextName.substring(1); if (Boolean.getBoolean(SYSTEM_REWRITTEN_URLS)) { if (rewrittenURL.startsWith(contextName)) rewrittenURL = rewrittenURL.substring(contextName.length()); if (rewrittenURL.startsWith("/" + contextName)) rewrittenURL = rewrittenURL.substring(contextName.length() + 1); // Make sure the index link redirects to '/' if (rewrittenURL.equals("/index.html")) rewrittenURL = "/"; } else if (!rewrittenURL.startsWith("/" + contextName)) rewrittenURL = "/" + contextName + rewrittenURL; if (fullUrl) { String forwardedFor = request.getHeader("X-Forwarded-Host"); rewrittenURL = request.getScheme() + "://" + (StringUtils.isEmpty(forwardedFor) ? request.getServerName() + (request.getServerPort() != 80 ? ":" + request.getServerPort() : "") : forwardedFor) + (rewrittenURL.startsWith("/") ? rewrittenURL : "/" + rewrittenURL); } return rewrittenURL; }
From source file:edu.usc.lunchnlearn.elasticsearch.interceptor.BreadCrumbInterceptor.java
private Crumb createIndexCrumb(Crumb firstCrumb, HttpServletRequest request) { Crumb indexCrumb = new Crumb(); StringBuffer sb = new StringBuffer(); if (request.getScheme().equals("http") && request.getHeader("x-forwarded-proto") != null) { sb.append("https://"); } else {// w w w. ja va 2 s. c o m sb.append(request.getScheme()).append("://"); } sb.append(request.getServerName()); if (request.getServerPort() != 80 && request.getServerPort() != 443) { sb.append(":").append(request.getServerPort()); } sb.append(request.getContextPath()); sb.append(request.getServletPath()); sb.append("/index.html"); indexCrumb.setUrl(sb.toString()); indexCrumb.setDisplayText("Index"); indexCrumb.setX(firstCrumb.getX() - 100L); return indexCrumb; }
From source file:org.apache.struts.faces.renderer.BaseRenderer.java
/** * <p>Return an absolute URI for the current page suitable for use * in a servlet environment.</p>/*from w w w. j ava 2 s. c o m*/ * * @param context <code>FacesContext</code> for the current request */ protected String servletUri(FacesContext context) { HttpServletRequest request = (HttpServletRequest) context.getExternalContext().getRequest(); StringBuffer sb = new StringBuffer(request.getScheme()); sb.append("://"); sb.append(request.getServerName()); if ("http".equals(request.getScheme()) && (80 == request.getServerPort())) { ; } else if ("https".equals(request.getScheme()) && (443 == request.getServerPort())) { ; } else { sb.append(":" + request.getServerPort()); } sb.append(request.getContextPath()); sb.append(context.getViewRoot().getViewId()); return (sb.toString()); }
From source file:org.kuali.ole.sys.web.struts.KualiBalanceInquiryReportMenuAction.java
/** * Takes care of storing the action form in the user session and forwarding to the balance inquiry lookup action. * //from w ww. ja v a 2 s. c o m * @param mapping * @param form * @param request * @param response * @return ActionForward * @throws Exception */ public ActionForward performBalanceInquiryLookup(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath(); // parse out the important strings from our methodToCall parameter String fullParameter = (String) request.getAttribute(OLEConstants.METHOD_TO_CALL_ATTRIBUTE); // parse out business object class name for lookup String boClassName = StringUtils.substringBetween(fullParameter, OLEConstants.METHOD_TO_CALL_BOPARM_LEFT_DEL, OLEConstants.METHOD_TO_CALL_BOPARM_RIGHT_DEL); if (StringUtils.isBlank(boClassName)) { throw new RuntimeException("Illegal call to perform lookup, no business object class name specified."); } // build the parameters for the lookup url Properties parameters = new Properties(); String conversionFields = StringUtils.substringBetween(fullParameter, OLEConstants.METHOD_TO_CALL_PARM1_LEFT_DEL, OLEConstants.METHOD_TO_CALL_PARM1_RIGHT_DEL); if (StringUtils.isNotBlank(conversionFields)) { parameters.put(OLEConstants.CONVERSION_FIELDS_PARAMETER, conversionFields); } // pass values from form that should be pre-populated on lookup search String parameterFields = StringUtils.substringBetween(fullParameter, OLEConstants.METHOD_TO_CALL_PARM2_LEFT_DEL, OLEConstants.METHOD_TO_CALL_PARM2_RIGHT_DEL); if (StringUtils.isNotBlank(parameterFields)) { String[] lookupParams = parameterFields.split(OLEConstants.FIELD_CONVERSIONS_SEPERATOR); for (int i = 0; i < lookupParams.length; i++) { String[] keyValue = lookupParams[i].split(OLEConstants.FIELD_CONVERSION_PAIR_SEPERATOR); // hard-coded passed value if (StringUtils.contains(keyValue[0], "'")) { parameters.put(keyValue[1], StringUtils.replace(keyValue[0], "'", "")); } // passed value should come from property else if (StringUtils.isNotBlank(request.getParameter(keyValue[0]))) { parameters.put(keyValue[1], request.getParameter(keyValue[0])); } } } // grab whether or not the "return value" link should be hidden or not String hideReturnLink = StringUtils.substringBetween(fullParameter, OLEConstants.METHOD_TO_CALL_PARM3_LEFT_DEL, OLEConstants.METHOD_TO_CALL_PARM3_RIGHT_DEL); if (StringUtils.isNotBlank(hideReturnLink)) { parameters.put(OLEConstants.HIDE_LOOKUP_RETURN_LINK, hideReturnLink); } // anchor, if it exists if (form instanceof KualiForm && StringUtils.isNotEmpty(((KualiForm) form).getAnchor())) { parameters.put(OLEConstants.LOOKUP_ANCHOR, ((KualiForm) form).getAnchor()); } // determine what the action path is String actionPath = StringUtils.substringBetween(fullParameter, OLEConstants.METHOD_TO_CALL_PARM4_LEFT_DEL, OLEConstants.METHOD_TO_CALL_PARM4_RIGHT_DEL); if (StringUtils.isBlank(actionPath)) { throw new IllegalStateException( "The \"actionPath\" attribute is an expected parameter for the <gl:balanceInquiryLookup> tag - it " + "should never be blank."); } // now add required parameters parameters.put(OLEConstants.DISPATCH_REQUEST_PARAMETER, "start"); parameters.put(OLEConstants.DOC_FORM_KEY, GlobalVariables.getUserSession().addObjectWithGeneratedKey(form)); parameters.put(OLEConstants.BUSINESS_OBJECT_CLASS_ATTRIBUTE, boClassName); parameters.put(OLEConstants.RETURN_LOCATION_PARAMETER, basePath + mapping.getPath() + ".do"); String lookupUrl = UrlFactory.parameterizeUrl(basePath + "/" + actionPath, parameters); return new ActionForward(lookupUrl, true); }