List of usage examples for javax.servlet.http HttpServletRequest getContextPath
public String getContextPath();
From source file:edu.usu.sdl.openstorefront.web.init.ShiroAdjustedFilter.java
@Override protected void doFilterInternal(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain) throws ServletException, IOException { if (servletRequest instanceof HttpServletRequest) { HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest; String url = httpServletRequest.getRequestURL().toString(); if (url.contains("Login.action") && url.contains(";")) { HttpServletResponse response = (HttpServletResponse) servletResponse; response.sendRedirect(httpServletRequest.getContextPath()); return; }/*from w w w . j a v a 2s . c o m*/ if (url.endsWith("Login.action") == false && url.contains("/api/") == false && url.contains("/apidoc/") == false) { String queryString = httpServletRequest.getQueryString(); if (StringUtils.isNotBlank(queryString)) { url = url + "?" + queryString; } httpServletRequest.getSession().setAttribute(REFERENCED_FILTER_URL_ATTRIBUTE, url); } } super.doFilterInternal(servletRequest, servletResponse, chain); }
From source file:net.osxx.controller.shop.LoginController.java
/** * ?/*from ww w. j a v a 2 s . co m*/ */ @RequestMapping(value = "/index", method = RequestMethod.GET) public String index(String redirectUrl, HttpServletRequest request, ModelMap model) { Setting setting = SettingUtils.get(); if (redirectUrl != null && !redirectUrl.equalsIgnoreCase(setting.getSiteUrl()) && !redirectUrl.startsWith(request.getContextPath() + "/") && !redirectUrl.startsWith(setting.getSiteUrl() + "/")) { redirectUrl = null; } model.addAttribute("redirectUrl", redirectUrl); model.addAttribute("captchaId", UUID.randomUUID().toString()); return "/shop/login/index"; }
From source file:pivotal.au.se.gemfirexdweb.controller.CreateTypeController.java
@RequestMapping(value = "/createtype", method = RequestMethod.GET) public String createType(Model model, HttpServletResponse response, HttpServletRequest request, HttpSession session) throws Exception { if (session.getAttribute("user_key") == null) { logger.debug("user_key is null new Login required"); response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login"); return null; } else {//from w w w. j ava2 s.c o m Connection conn = AdminUtil.getConnection((String) session.getAttribute("user_key")); if (conn == null) { response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login"); return null; } else { if (conn.isClosed()) { response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login"); return null; } } } logger.debug("Received request to create a new UDT (Type)"); model.addAttribute("typeAttribute", new Type()); // This will resolve to /WEB-INF/jsp/create-type.jsp return "create-type"; }
From source file:info.magnolia.cms.servlets.EntryServlet.java
/** * @return URI mapping as in ServerInfo/*from w w w . j ava 2s .c o m*/ * @param request HttpServletRequest */ private String getURIMap(HttpServletRequest request) { return VirtualURIManager.getInstance() .getURIMapping(StringUtils.substringAfter(request.getRequestURI(), request.getContextPath())); }
From source file:net.paoding.rose.web.RequestPath.java
public RequestPath(HttpServletRequest request) { // method/*from ww w.j av a 2 s. c o m*/ setMethod(parseMethod(request)); // ctxpath setCtxpath(request.getContextPath()); String invocationCtxpath = null; // includeinvocationCtxPathincludectxpath // dispather, uri, ctxpath String uri; if (WebUtils.isIncludeRequest(request)) { setDispatcher(Dispatcher.INCLUDE); uri = (String) request.getAttribute(WebUtils.INCLUDE_REQUEST_URI_ATTRIBUTE); invocationCtxpath = ((String) request.getAttribute(WebUtils.INCLUDE_CONTEXT_PATH_ATTRIBUTE)); setRosePath((String) request.getAttribute(WebUtils.INCLUDE_SERVLET_PATH_ATTRIBUTE)); } else { uri = request.getRequestURI(); this.setRosePath(request.getServletPath()); if (request.getAttribute(WebUtils.FORWARD_REQUEST_URI_ATTRIBUTE) == null) { this.setDispatcher(Dispatcher.REQUEST); } else { this.setDispatcher(Dispatcher.FORWARD); } } if (uri.startsWith("http://") || uri.startsWith("https://")) { int start = uri.indexOf('/', 9); if (start == -1) { uri = ""; } else { uri = uri.substring(start); } } if (uri.indexOf('%') != -1) { try { String encoding = request.getCharacterEncoding(); if (encoding == null || encoding.length() == 0) { encoding = "UTF-8"; } uri = URLDecoder.decode(uri, encoding); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } this.setUri(uri); // requestPathctxpathincludeinvocationCtxpath if (getCtxpath().length() <= 1) { setRosePath(getUri()); } else { setRosePath( getUri().substring((invocationCtxpath == null ? getCtxpath() : invocationCtxpath).length())); } }
From source file:eionet.webq.web.controller.RemoteWebFormTestRun.java
/** * Test run for remote web forms.//from w ww .j av a 2 s . c o m * * @param webFormId web form id * @param instance form instance URL * @param additionalParameters additional request parameters * @param request request * @return redirect to web form * @throws FileNotAvailableException if web form's default instance is not available. */ @RequestMapping("/test/run") public String webFormTestRun(@RequestParam int webFormId, @RequestParam(required = false) String instance, @RequestParam(required = false) String additionalParameters, HttpServletRequest request) throws FileNotAvailableException { int fileId = userFileService.saveBasedOnWebForm(new UserFile(), webFormService.findActiveWebFormById(webFormId)); String redirect = "redirect:/xform/?formId=" + webFormId + "&fileId=" + fileId + "&base_uri=" + request.getContextPath(); if (StringUtils.isNotEmpty(instance)) { redirect += "&instance=" + instance; } if (StringUtils.isNotEmpty(additionalParameters)) { redirect += "&" + additionalParameters; } return redirect; }
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);/* w w w . ja v a 2 s . c om*/ model.addAttribute("formSigner", formSigner); model.addAttribute("templateName", "video_upload"); return "base"; }
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 www . ja v a2 s. com*/ url.append(contextPath).append("/api/kml/"); return url.toString(); }
From source file:pivotal.au.se.gemfirexdweb.controller.CreateSchemaController.java
@RequestMapping(value = "/createschema", method = RequestMethod.GET) public String createSchema(Model model, HttpServletResponse response, HttpServletRequest request, HttpSession session) throws Exception { if (session.getAttribute("user_key") == null) { logger.debug("user_key is null new Login required"); response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login"); return null; } else {/*ww w . j ava 2s . co m*/ Connection conn = AdminUtil.getConnection((String) session.getAttribute("user_key")); if (conn == null) { response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login"); return null; } else { if (conn.isClosed()) { response.sendRedirect(request.getContextPath() + "/GemFireXD-Web/login"); return null; } } } logger.debug("Received request to create a new Schema"); model.addAttribute("schemaAttribute", new NewSchema()); model.addAttribute("schemas", GemFireXDWebDAOUtil.getAllSchemas((String) session.getAttribute("user_key"))); // This will resolve to /WEB-INF/jsp/create-schema.jsp return "create-schema"; }
From source file:net.sf.sripathi.ws.mock.servlet.MockServlet.java
/** * The service operation generated the mocked response for the input SOAP request message. *///from ww w . j a va 2 s. c o m @Override public void service(HttpServletRequest req, HttpServletResponse resp) { long startTime = System.currentTimeMillis(); try { String tmp = req.getRequestURI().substring((req.getContextPath() + "/mock/").length()); String[] tmps = tmp.split("/"); String domainName = tmps[0]; Domain domain = DomainFactory.getInstance().getDomain(domainName); String soapResp = null; String soapReq = ""; if (tmps.length != 3) { soapResp = SoapUtil.getSoapFault("NOT_A_VALID_URL", "URL " + req.getRequestURI() + " is not valid"); } else if (domain == null) { soapResp = SoapUtil.getSoapFault("NOT_A_VALID_PROFILE", "Domain " + domainName + " is not valid"); LOGGER.error(soapResp); } else { String serviceName = tmps[2]; Service service = domain.getService(serviceName); if (service == null) { soapResp = SoapUtil.getSoapFault("NOT_A_VALID_SERVICE", "Service " + serviceName + " is not valid"); LOGGER.error(soapResp); } else { LOGGER.info("Request received for service - " + serviceName + " on domain - " + domainName); InputStream is = req.getInputStream(); soapReq = new String(IOUtils.toByteArray(is)); this.getLogger(domainName, serviceName).info("Request - " + soapReq); try { Scenario scenario = service.getMockResponse(soapReq); soapResp = scenario.getResponse(); if (scenario.getDelayInMilliSec() > 0) { long curTime = System.currentTimeMillis(); long diff = curTime - startTime; if (diff < scenario.getDelayInMilliSec()) { Thread.sleep(scenario.getDelayInMilliSec() - diff); } } } catch (MockException me) { soapResp = SoapUtil.getSoapFault("UNABLE_TO_PROCESS_REQ", me.getMessage()); } this.getLogger(domainName, serviceName).info("Mock Response - " + soapResp); } } if (soapReq.contains(javax.xml.soap.SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE)) { resp.setContentType(javax.xml.soap.SOAPConstants.SOAP_1_2_CONTENT_TYPE); } else { resp.setContentType(javax.xml.soap.SOAPConstants.SOAP_1_1_CONTENT_TYPE); } if (soapResp != null && soapResp.indexOf("Fault>") != -1 && soapResp.indexOf("faultcode>") != -1 && soapResp.indexOf("faultstring>") != -1) { resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } resp.getOutputStream().write(soapResp.getBytes()); } catch (Exception e) { e.printStackTrace(); } }