List of usage examples for javax.servlet.http HttpServletRequest getScheme
public String getScheme();
From source file:net.cloudfree.apps.shop.internal.app.ListingServlet.java
private 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()); }// ww w . j a va2 s . c o m builder.append(req.getContextPath()); builder.append(req.getServletPath()); builder.append("/"); return builder; }
From source file:eionet.util.SecurityUtil.java
/** * * @param request/*from ww w. ja va2s .c om*/ * @return */ public static String getLogoutURL(HttpServletRequest request) { // The default result used when the application is configured to not use Central Authentication Service (CAS). String result = "index.jsp"; if (Props.isUseCentralAuthenticationService()) { CASFilterConfig casFilterConfig = CASFilterConfig.getInstance(); if (casFilterConfig != null) { String casLoginUrl = casFilterConfig.getInitParameter(CASFilter.LOGIN_INIT_PARAM); if (casLoginUrl != null) { String casServerName = casFilterConfig.getInitParameter(CASFilter.SERVERNAME_INIT_PARAM); if (casServerName == null) { throw new DDRuntimeException("If " + CASFilter.LOGIN_INIT_PARAM + " context parameter has been specified, so must be " + CASFilter.SERVERNAME_INIT_PARAM); } try { result = casLoginUrl.replaceFirst("/login", "/logout") + "?url=" + URLEncoder.encode( request.getScheme() + "://" + casServerName + request.getContextPath(), "UTF-8"); } catch (UnsupportedEncodingException e) { throw new DDRuntimeException(e.toString(), e); } } } } return result; }
From source file:org.energy_home.jemma.ah.webui.energyathome.ekitchen.EnergyAtHome.java
private boolean redirectToLoginPage(HttpServletRequest request, HttpServletResponse response) throws IOException { String redirect = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + applicationWebAlias + "/conf/login.html"; response.sendRedirect(redirect);/*from w w w.j av a 2 s.c om*/ return true; }
From source file:company.gonapps.loghut.controller.LoginController.java
@RequestMapping(value = "/login.do", method = RequestMethod.POST) public String login(HttpServletRequest request, String id, String password, String request_path) throws Exception { if (id.equals(getSettingDao().getSetting("admin.id")) && password.equals(getSettingDao().getSetting("admin.password"))) { request.getSession().setMaxInactiveInterval(new Integer(getSettingDao().getSetting("session.timeout"))); if (request_path != null) return "redirect:" + request.getScheme() + "://" + request.getServerName() + getSettingDao().getSetting("admin.url") + request_path; return "redirect:" + request.getScheme() + "://" + request.getServerName() + getSettingDao().getSetting("admin.url"); }/*www . ja v a 2 s. c o m*/ return "redirect:" + request.getScheme() + "://" + request.getServerName() + getSettingDao().getSetting("admin.url") + "/login_form.do"; }
From source file:org.kuali.rice.kew.rule.web.RuleQuickLinksAction.java
private void makeLookupPathParam(ActionMapping mapping, HttpServletRequest request) { String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath() + mapping.getModuleConfig().getPrefix(); request.setAttribute("basePath", basePath); }
From source file:org.chtijbug.drools.platform.web.filter.DynamicBaseFilter.java
@Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { logger.debug(">> doFilterInternal()"); try {//from ww w. j a v a 2s .c om PrintWriter out = response.getWriter(); CharResponseWrapper wrapper = new CharResponseWrapper(response); filterChain.doFilter(request, wrapper); String baseHref = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath() + "/"; logger.debug("About to replace the base href element with {}", baseHref); String modifiedHtml = baseElementPattern.matcher(wrapper.toString()) .replaceAll("<base href=\"" + baseHref + "\""); logger.debug("Modified HTML content : {}", modifiedHtml); // Write our modified text to the real response response.setContentLength(modifiedHtml.getBytes().length); out.write(modifiedHtml); out.close(); } catch (Throwable t) { logger.error(t.getMessage()); } finally { logger.debug("<< doFilterInternal()"); } }
From source file:com.cloudbees.demo.beesshop.web.ProductController.java
@RequestMapping(value = "/product/{id}/mail", method = RequestMethod.POST) public String sendEmail(@PathVariable long id, @RequestParam("recipientEmail") String recipientEmail, HttpServletRequest request, RedirectAttributes redirectAttributes) { Product product = productRepository.get(id); if (product == null) { throw new ProductNotFoundException(id); }/*from w ww . ja v a 2 s .c o m*/ try { String productPageUrl = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath() + "/product/" + id; mailService.sendProductEmail(product, recipientEmail, productPageUrl); redirectAttributes.addFlashAttribute("mailSuccessMessage", "Email sent!"); } catch (MessagingException e) { redirectAttributes.addFlashAttribute("mailFailureMessage", "Failure sending email: " + e.getMessage()); logger.warn("Failure sending message to " + recipientEmail, e); } return "redirect:/product/" + product.getId(); }
From source file:org.deegree.client.core.renderer.InputFileRenderer.java
private URL getUrl(HttpServletRequest request, String target, String fileName) throws MalformedURLException { if (target == null) { target = ""; }//from w w w. j a va 2 s .c om if (!target.startsWith("/")) { target = "/" + target; } if (!target.endsWith("/")) { target += "/"; } return new URL(request.getScheme(), request.getServerName(), request.getServerPort(), request.getContextPath() + target + fileName); }
From source file:org.apache.axis.transport.http.AxisServletBase.java
/** * extract the base of our webapp from an inbound request * * @param request request containing http://foobar/axis/services/something * @return some URL like http://foobar:8080/axis/ *///from ww w . j a v a2 s.co m protected String getWebappBase(HttpServletRequest request) { StringBuffer baseURL = new StringBuffer(128); baseURL.append(request.getScheme()); baseURL.append("://"); baseURL.append(request.getServerName()); if (request.getServerPort() != 80) { baseURL.append(":"); baseURL.append(request.getServerPort()); } baseURL.append(request.getContextPath()); return baseURL.toString(); }
From source file:com.cpjit.swagger4j.support.internal.DefaultApiViewWriter.java
@Deprecated @Override/* w w w . ja v a 2 s .co m*/ public void writeIndex(HttpServletRequest request, HttpServletResponse response, String lang, Properties props) throws IOException { Map<String, Object> root = new HashMap<String, Object>(); root.put("lang", lang); String path = request.getContextPath(); String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/"; root.put("basePath", basePath); String host = request.getServerName() + ":" + request.getServerPort() + path; String suffix = props.getProperty("suffix"); if (StringUtils.isBlank(suffix)) { suffix = ""; } root.put("getApisUrl", "http://" + host + "/api" + suffix); root.put("apiDescription", props.getProperty("apiDescription")); root.put("apiTitle", props.getProperty("apiTitle")); root.put("apiVersion", props.getProperty("apiVersion")); root.put("suffix", suffix); Template template = FreemarkerUtils.getTemplate(getTemplateName()); response.setContentType("text/html;charset=utf-8"); Writer out = response.getWriter(); try { template.process(root, out); } catch (TemplateException e) { throw new IOException(e); } out.flush(); out.close(); }