List of usage examples for javax.servlet.http HttpServletRequest getServerName
public String getServerName();
From source file:demo.rest.RestApi.java
private String getKmlUrl(HttpServletRequest request) { final String scheme = request.getScheme(); final String serverName = request.getServerName(); final int serverPort = request.getServerPort(); final String contextPath = request.getContextPath(); StringBuilder url = new StringBuilder(); url.append(scheme).append("://").append(serverName); if ((serverPort != 80) && (serverPort != 443)) { url.append(":").append(serverPort); }//from ww w . j a va 2 s. c om url.append(contextPath).append("/api/kml/"); return url.toString(); }
From source file:org.coursera.cmbrehm.kewlvideo.server.VideoController.java
private String getUrlBaseForLocalServer() { HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()) .getRequest();// www .j a v a 2s . c om String base = "http://" + request.getServerName() + ((request.getServerPort() != 80) ? ":" + request.getServerPort() : ""); return base; }
From source file:com.sun.socialsite.web.filters.RedirectorFilter.java
private String getRedirectionUri(HttpServletRequest httpReq) { if (baseUri == null) { return null; }//from w w w . ja va 2s.co m String serverName = httpReq.getServerName(); String scheme = httpReq.getScheme(); int port = httpReq.getServerPort(); for (String exception : exceptions) { if (httpReq.getServletPath().startsWith(exception)) { return null; } } if (serverName.equalsIgnoreCase(baseUri.getHost()) && scheme.equalsIgnoreCase(baseUri.getScheme()) && (port == basePort)) { return null; } else { log.debug(String.format("Redirecting Because ((%s != %s) || (%s != %s) || (%d != %d))", serverName, baseUri.getHost(), scheme, baseUri.getScheme(), port, basePort)); StringBuilder sb = new StringBuilder(baseUri.toString()); if (httpReq.getServletPath() != null) sb.append(httpReq.getServletPath()); if (httpReq.getPathInfo() != null) sb.append(httpReq.getPathInfo()); if (httpReq.getQueryString() != null) sb.append("?").append(httpReq.getQueryString()); return sb.toString(); } }
From source file:cec.easyshop.storefront.controllers.pages.LoginPageController.java
protected void storeReferer(final String referer, final HttpServletRequest request, final HttpServletResponse response) { if (StringUtils.isNotBlank(referer) && !StringUtils.endsWith(referer, "/login") && StringUtils.contains(referer, request.getServerName())) { httpSessionRequestCache.saveRequest(request, response); }//w w w . j a v a 2s .co m }
From source file:com.greenline.guahao.web.module.common.interceptor.VipDomainInterceptor.java
@Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { String domain = request.getServerName(); // ?? String errorMessage;/* w ww. j av a 2 s . co m*/ if (!domain.matches(REGEX_DOMAIN)) { errorMessage = "??"; } else if (!domain.endsWith(level1And2Domain)) { errorMessage = "??"; } else { String level3AddDomain = domain.substring(0, domain.length() - level1And2Domain.length() - 1); // ??? if (!level3AddDomains.contains(level3AddDomain)) { errorMessage = "??"; } else { Domaininfo domaininfo = InterceptorUtil.getInstance().getDomaininfo(level3AddDomain); if (null == domaininfo) { errorMessage = "??"; } else { // ?????:taikang.vip ?:vip.taikang // ?:[vip,taikang] // String[] level3AddDomainArr = // StringUtils.reverseDelimited(level3AddDomain, // '.').split("[.]"); // String uri = request.getRequestURI(); // // ???????? // if (null == request.getAttribute(REQUEST_KEY_REAL_URI) // && uri.startsWith("/" + level3AddDomainArr[0])) { // for (String d : level3AddDomainArr) { // uri = uri.replaceFirst("^/" + d, ""); // } // String urlPre = request.getScheme() + "://" + domain; // response.sendRedirect(urlPre + uri); // ?? // return true; // } else { request.setAttribute("domainTypeId", domaininfo.getTypeid()); request.setAttribute("domainObjId", domaininfo.getObjid()); request.setAttribute("doamintype_id", domaininfo.getObjid()); request.setAttribute("domaininfoid", domaininfo.getId()); request.setAttribute("showprocince", domaininfo.getShowprocince()); request.setAttribute("header_ftl", domaininfo.getHeaderftl()); request.setAttribute("footer_ftl", domaininfo.getFooterftl()); request.setAttribute("domain_showurl", domaininfo.getShowurl()); request.setAttribute("domain_sysname", domaininfo.getSysdomain()); request.setAttribute("servername", domain); request.setAttribute("preDomain", level3AddDomain); request.setAttribute("guahaoServer", CommonUtils.getServerNameAndPort(request)); return true; // } } } } if (null != request.getAttribute("error_message")) { return true; } else { logger.error(errorMessage); request.setAttribute("error_message", errorMessage); request.getRequestDispatcher("/error").forward(request, response); return false; } }
From source file:org.magnum.dataup.controller.VideoSvc.java
/** * Get base URL for local server/* w w w . j a v a 2 s . com*/ * * @return Base URL for local server */ private String getUrlBaseForLocalServer() { HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()) .getRequest(); String base = "http://" + request.getServerName() + ((request.getServerPort() != 80) ? ":" + request.getServerPort() : ""); return base; }
From source file:org.jnap.core.mvc.i18n.CompositeLocaleResolver.java
/** * TODO doc/*from ww w.j a v a2s . c o m*/ * @param localeResolver * @param request */ private void configCookieScope(LocaleResolver localeResolver, HttpServletRequest request) { if (localeResolver instanceof CookieGenerator) { CookieGenerator cookieGenerator = CookieGenerator.class.cast(localeResolver); cookieGenerator.setCookieDomain(request.getServerName()); cookieGenerator.setCookiePath(request.getContextPath()); } }
From source file:be.fedict.eid.idp.protocol.openid.AbstractOpenIDIdentityHttpServlet.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { LOG.debug("doGet"); String location = "https://" + request.getServerName(); if (request.getServerPort() != 443) { location += ":" + request.getServerPort(); }// w w w .j ava 2s.c om location += "/eid-idp"; LOG.debug("location: " + location); PrintWriter printWriter = response.getWriter(); if (request.getRequestURI().endsWith("/xrds")) { LOG.debug("returning the YADIS XRDS document"); response.setContentType("application/xrds+xml"); printWriter.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); printWriter.println("<xrds:XRDS xmlns:xrds=\"xri://$xrds\" xmlns=\"xri://$xrd*($v*2.0)\">"); printWriter.println("<XRD>"); printWriter.println("<Service>"); printWriter.println("<Type>http://specs.openid.net/auth/2.0/server</Type>"); printWriter.println("<Type>http://specs.openid.net/extensions/ui/1.0/lang-pref</Type>"); for (String additionalServiceType : getAdditionalServiceTypes()) { printWriter.println("<Type>" + additionalServiceType + "</Type>"); } printWriter.println("<URI>" + location + "/protocol/" + getPath() + "</URI>"); printWriter.println("</Service>"); printWriter.println("<Service>"); printWriter.println("<Type>http://specs.openid.net/auth/2.0/signon</Type>"); printWriter.println("<Type>http://specs.openid.net/extensions/pape/1.0</Type>"); printWriter.println("<URI>" + location + "/protocol/" + getPath() + "</URI>"); printWriter.println("</Service>"); printWriter.println("</XRD>"); printWriter.println("</xrds:XRDS>"); return; } LOG.debug("returning the HTML identity document"); String xrdsLocation = location + "/endpoints/" + getPath() + "/xrds"; response.setContentType("text/html"); response.addHeader("X-XRDS-Location", xrdsLocation); printWriter.println("<html>"); printWriter.println("<head>"); printWriter.println("<meta http-equiv=\"X-XRDS-Location\" content=\"" + xrdsLocation + "\"/>"); printWriter.println("<title>OpenID Identity URL</title>"); printWriter.println("</head>"); printWriter.println("<body><p>OpenID Identity URL</p></body>"); printWriter.println("</html>"); }
From source file:com.pontecultural.flashcards.CardController.java
@RequestMapping(method = RequestMethod.GET) public String getUploadForm(HttpServletRequest req, Locale locale, Model model, @RequestParam("id") Integer aId) { logger.info("get cards for deck"); // compute base URL to allow client to call us back. String callbackURL = req.getScheme() + "://" + req.getServerName() + ":" + req.getServerPort() + req.getContextPath() + "/deckId/" + aId.toString() + "/cards.json"; model.addAttribute("callbackURL", callbackURL); model.addAttribute("deckname", jdbcFlashcardsDao.fetchDeckname(aId)); model.addAttribute("deckId", aId.toString()); return "viewCards"; }
From source file:gal.udc.fic.muei.tfm.dap.flipper.web.rest.AccountResource.java
@RequestMapping(value = "/account/reset_password/init", method = RequestMethod.POST, produces = MediaType.TEXT_PLAIN_VALUE) @Timed/*from w ww .j a v a 2 s . co m*/ public ResponseEntity<?> requestPasswordReset(@RequestBody String mail, HttpServletRequest request) { return userService.requestPasswordReset(mail).map(user -> { String baseUrl = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort(); mailService.sendPasswordResetMail(user, baseUrl); return new ResponseEntity<>("e-mail was sent", HttpStatus.OK); }).orElse(new ResponseEntity<>("e-mail address not registered", HttpStatus.BAD_REQUEST)); }