List of usage examples for javax.servlet.http HttpServletRequest getServletPath
public String getServletPath();
From source file:com.fuseim.webapp.ProxyServlet.java
/** * Copy cookie from the proxy to the servlet client. Replaces cookie path to local path and * renames cookie to avoid collisions./* ww w. ja v a 2 s . c om*/ */ protected void copyProxyCookie(HttpServletRequest servletRequest, HttpServletResponse servletResponse, String headerValue) { List<HttpCookie> cookies = HttpCookie.parse(headerValue); String path = servletRequest.getContextPath(); // path starts with / or is empty string path += servletRequest.getServletPath(); // servlet path starts with / or is empty string for (HttpCookie cookie : cookies) { //set cookie name prefixed w/ a proxy value so it won't collide w/ other cookies String proxyCookieName = doPreserveCookies ? cookie.getName() : getCookieNamePrefix(cookie.getName()) + cookie.getName(); Cookie servletCookie = new Cookie(proxyCookieName, cookie.getValue()); servletCookie.setComment(cookie.getComment()); servletCookie.setMaxAge((int) cookie.getMaxAge()); servletCookie.setPath(path); //set to the path of the proxy servlet // don't set cookie domain servletCookie.setSecure(cookie.getSecure()); servletCookie.setVersion(cookie.getVersion()); servletResponse.addCookie(servletCookie); } }
From source file:com.netspective.sparx.navigate.NavigationControllerServlet.java
protected void renderPage(NavigationContext nc) throws ServletException, IOException { final HttpServletResponse httpResponse = nc.getHttpResponse(); if (isSecure()) { HttpLoginManager loginManager = getLoginManager(); LoginDialogMode loginDialogMode = LoginDialogMode.ACCESS_ALLOWED; if (loginManager != null) { loginDialogMode = loginManager.getLoginDialogMode(nc); // if we're getting input or we're denying login it means that the presentation is complete (HTML is already on the screen) if (loginDialogMode == LoginDialogMode.GET_INPUT || loginDialogMode == LoginDialogMode.LOGIN_DENIED) return; }/* w ww.j av a 2 s . c o m*/ // if we get to here, it means that the login dialog mode is either LOGIN_ACCEPTED (user has just logged in) or ACCESS_ALLOWED // which means that access was previously granted and the user is still valid // check to see if the user has recently logged in and is using the wrong navigation tree if (loginDialogMode == LoginDialogMode.LOGIN_ACCEPTED) { AuthenticatedUser user = nc.getAuthenticatedUser(); if (user instanceof NavigationControllerAuthenticatedUser) { NavigationControllerAuthenticatedUser ncUser = (NavigationControllerAuthenticatedUser) user; if (ncUser.hasUserSpecificNavigationTree()) { NavigationTree userTree = ncUser.getUserSpecificNavigationTree(this, nc.getHttpRequest(), httpResponse); if (userTree != null && nc.getOwnerTree() != userTree) { // we want to redirect back to the home page of the navigation tree so that the proper tree // will be picked up by the createContext() method ncUser.redirectToUserTree(nc); return; } } } } } NavigationPage activePage = nc.getActivePage(); if (activePage != null) { nc.getResponse().setContentType("text/html"); if (nc.isActivePageValid()) { // make any necessary state changes (such as permissions, conditionals, etc). activePage.makeStateChanges(nc); // check to see if we have static content and we're in development mode (because in development presumably we don't want // anything to be static since 'static' is a performance attribute, not functionality if (!nc.getRuntimeEnvironmentFlags().isDevelopment() && activePage.getFlags().flagIsSet(NavigationPage.Flags.STATIC_CONTENT)) { final HttpServletRequest httpRequest = nc.getHttpRequest(); String staticPageKey = httpRequest.getServletPath() + httpRequest.getPathInfo(); Date lastModfTime = (Date) staticPagesRendered.get(staticPageKey); // If the client sent an If-Modified-Since header equal or after the // servlet's last modified time, send a short "Not Modified" status code // Round down to the nearest second since client headers are in seconds if (lastModfTime != null && httpRequest.getMethod().equals("GET") && ((lastModfTime.getTime() / 1000 * 1000) <= httpRequest .getDateHeader("If-Modified-Since"))) { httpResponse.setStatus(HttpServletResponse.SC_NOT_MODIFIED); return; } else { Date now = new Date(); httpResponse.setDateHeader("Last-Modified", now.getTime()); staticPagesRendered.put(staticPageKey, now); } } // if we get to there we're not static content or we're static but being rendered for the first // time in this instance of the servlet if (activePage.isRawHandler(nc)) activePage.handlePageRaw(nc); else activePage.handlePage(nc.getResponse().getWriter(), nc); } else activePage.handleInvalidPage(nc.getResponse().getWriter(), nc); } else { Writer writer = nc.getResponse().getWriter(); NavigationSkin skin = nc.getSkin(); NavigationTree tree = nc.getOwnerTree(); skin.renderPageMetaData(writer, nc); skin.renderPageHeader(writer, nc); writer.write("No page located for path '" + nc.getActivePathFindResults().getSearchedForPath() + "'."); if (nc.getRuntimeEnvironmentFlags().flagIsSet(RuntimeEnvironmentFlags.DEVELOPMENT)) { writer.write("<pre>\n"); writer.write(tree.toString()); writer.write("</pre>\n"); } skin.renderPageFooter(writer, nc); } }
From source file:com.sourcesense.confluence.servlets.CMISProxyServlet.java
/** * Retrieves all of the cookies from the servlet request and sets them on * the proxy request// w w w . j a v a 2 s . c o m * * @param httpServletRequest The request object representing the client's * request to the servlet engine * @param httpMethodProxyRequest The request that we are about to send to * the proxy host */ private void setProxyRequestCookies(HttpServletRequest httpServletRequest, HttpMethod httpMethodProxyRequest) { // Get an array of all of all the cookies sent by the client Cookie[] cookies = httpServletRequest.getCookies(); if (cookies == null) { return; } for (Cookie cookie : cookies) { cookie.setDomain(stringProxyHost); cookie.setPath(httpServletRequest.getServletPath()); httpMethodProxyRequest.setRequestHeader("Cookie", cookie.getName() + "=" + cookie.getValue() + "; Path=" + cookie.getPath()); } }
From source file:com.google.ratel.util.RatelUtils.java
/** * Return the page resource path from the request. For example: * <pre class="codeHtml">/* ww w . j av a2 s . com*/ * <span class="blue">http://www.mycorp.com/banking/secure/login.htm</span> -> <span class="red">/secure/login.htm</span> </pre> * * @param request the page servlet request * @return the page resource path from the request */ public static String getResourcePath(HttpServletRequest request) { // Adapted from VelocityViewServlet.handleRequest() method: // If we get here from RequestDispatcher.include(), getServletPath() // will return the original (wrong) URI requested. The following // special attribute holds the correct path. See section 8.3 of the // Servlet 2.3 specification. String path = (String) request.getAttribute("javax.servlet.include.servlet_path"); // Also take into account the PathInfo stated on // SRV.4.4 Request Path Elements. String info = (String) request.getAttribute("javax.servlet.include.path_info"); if (path == null) { path = request.getServletPath(); info = request.getPathInfo(); } if (info != null) { path += info; } return path; }
From source file:com.xmarts.ringingPayroll.rpf_process.Ring.java
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { if (log4j.isDebugEnabled()) log4j.debug("Posted: doPost"); VariablesSecureApp vars = new VariablesSecureApp(request); if (vars.commandIn("DEFAULT")) { String strKey = vars.getGlobalVariable("inprpfPayrollId", "Ring|RPF_Payroll_ID"); System.out.println("Clave Default:" + strKey); String strWindowId = vars.getGlobalVariable("inpwindowId", "Ring|windowId"); String strTabId = vars.getGlobalVariable("inpTabId", "Ring|tabId"); String strProcessId = vars.getGlobalVariable("inpProcessed", "Ring|processId", ""); String strPath = vars.getGlobalVariable("inpPath", "Ring|path", strDireccion + request.getServletPath()); String strPosted = null;// w w w. jav a2 s .c om String strRingd = "N"; String strDocNo = vars.getRequestGlobalVariable("inpdocumentno", "Ring|docNo"); String strWindowPath = Utility.getTabURL(this, strTabId, "E"); if (strWindowPath.equals("")) strWindowPath = strDefaultServlet; if (strRingd.equals("Y")) advisePopUp(request, response, Utility.messageBD(this, "ERROR", vars.getLanguage()), Utility.messageBD(this, "CFDI_Ring", vars.getLanguage())); printPage(response, vars, strKey, strWindowId, strTabId, strProcessId, strPath, strPosted, strWindowPath, strDocNo); } else if (vars.commandIn("SAVE")) { String strKey = vars.getGlobalVariable("inprpfPayrollId", "Ring|RPF_Payroll_ID"); String strWindowId = vars.getRequestGlobalVariable("inpwindowId", "Ring|windowId"); String strTabId = vars.getRequestGlobalVariable("inpTabId", "Ring|tabId"); String strProcessId = vars.getRequestGlobalVariable("inpProcessed", "Ring|processId"); String strPath = vars.getRequestGlobalVariable("inpPath", "Ring|path"); String strPosted = null; String strDocNo = vars.getRequestGlobalVariable("inpdocumentno", "Ring|docNo"); String strWindowPath = Utility.getTabURL(this, strTabId, "E"); String strFilePath = vars.getRequestGlobalVariable("inpFilePath", "Ring|FileName"); if (strWindowPath.equals("")) strWindowPath = strDefaultServlet; OBError myMessage = process(response, vars, strKey, strWindowId, strTabId, strProcessId, strPath, strPosted, strWindowPath, strDocNo); vars.setMessage(strTabId, myMessage); printPageClosePopUp(response, vars, strWindowPath); } else { advisePopUp(request, response, Utility.messageBD(this, "ERROR", vars.getLanguage()), Utility.messageBD(this, "ERROR", vars.getLanguage())); } }
From source file:com.acc.storefront.interceptors.beforeview.SeoRobotsFollowBeforeViewHandler.java
@Override public void beforeView(final HttpServletRequest request, final HttpServletResponse response, final ModelAndView modelAndView) { // Check to see if the controller has specified a Index/Follow directive for robots if (modelAndView != null && !modelAndView.getModel().containsKey("metaRobots")) { // Build a default directive String robotsValue = "no-index,no-follow"; if (RequestMethod.GET.name().equalsIgnoreCase(request.getMethod())) { if (request.isSecure()) { robotsValue = "no-index,follow"; }/*w w w. j av a2 s .c o m*/ //Since no model attribute metaRobots can be set for JSON response, then configure that servlet path in the xml. //If its a regular response and this setting has to be overriden then set model attribute metaRobots else if (CollectionUtils.contains(getRobotIndexForJSONMapping().keySet().iterator(), request.getServletPath())) { robotsValue = getRobotIndexForJSONMapping().get(request.getServletPath()); } else { robotsValue = "index,follow"; } } else if (RequestMethod.POST.name().equalsIgnoreCase(request.getMethod())) { robotsValue = "no-index,no-follow"; } modelAndView.addObject("metaRobots", robotsValue); } if (modelAndView != null && modelAndView.getModel().containsKey("metatags")) { final MetaElementData metaElement = new MetaElementData(); metaElement.setName("robots"); metaElement.setContent((String) modelAndView.getModel().get("metaRobots")); ((List<MetaElementData>) modelAndView.getModel().get("metatags")).add(metaElement); } }
From source file:com.exxonmobile.ace.hybris.storefront.interceptors.beforeview.SeoRobotsFollowBeforeViewHandler.java
@Override public void beforeView(final HttpServletRequest request, final HttpServletResponse response, final ModelAndView modelAndView) { // Check to see if the controller has specified a Index/Follow directive for robots if (modelAndView != null && !modelAndView.getModel().containsKey("metaRobots")) { // Build a default directive String robotsValue = "no-index,no-follow"; if (RequestMethod.GET.name().equalsIgnoreCase(request.getMethod())) { if (request.isSecure()) { robotsValue = "no-index,follow"; }//from w w w .ja v a2 s . c om //Since no model attribute metaRobots can be set for JSON response, then configure that servlet path in the xml. //If its a regular response and this setting has to be overriden then set model attribute metaRobots else if (CollectionUtils.contains(getRobotIndexForJSONMapping().keySet().iterator(), request.getServletPath())) { robotsValue = getRobotIndexForJSONMapping().get(request.getServletPath()); } else { robotsValue = "index,follow"; } } else if (RequestMethod.POST.name().equalsIgnoreCase(request.getMethod())) { robotsValue = "no-index,no-follow"; } modelAndView.addObject("metaRobots", robotsValue); } if (modelAndView != null && modelAndView.getModel().containsKey("metatags")) { final MetaElementData metaElement = new MetaElementData(); metaElement.setName("robots"); metaElement.setContent((String) modelAndView.getModel().get("metaRobots")); ((List<MetaElementData>) modelAndView.getModel().get("metatags")).add(metaElement); } }
From source file:org.xmlactions.web.conceal.HttpPager.java
public void processPage(ServletRequest request, ServletResponse response, String page) throws ServletException, IOException { IExecContext execContext = null;// w ww . j av a 2s. c om if (response instanceof HttpServletResponse && request instanceof HttpServletRequest) { try { HttpServletRequest httpServletRequest = (HttpServletRequest) request; HttpServletResponse httpServletResponse = (HttpServletResponse) response; execContext = setupExecContext(httpServletRequest, httpServletResponse); String pageName = httpServletRequest.getServletPath(); if (pageName.indexOf("axelconfig") > 0) { PrintWriter out = response.getWriter(); out.print(buildInfo(httpServletRequest, httpServletResponse)); out.close(); return; } if (!pageName.endsWith(".ajax")) { String alternatePage = processPrePages(execContext, httpServletRequest, httpServletResponse); if ("stop".equals(execContext.getString("pre.page.stop"))) { execContext.put("pre.page.stop", ""); response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); out.print(alternatePage); out.close(); } } log.debug("contextPath:" + httpServletRequest.getContextPath()); log.debug("URI:" + httpServletRequest.getRequestURI()); log.debug("root:" + realPath + " page:" + pageName + " wrapperPage:" + wrapperPage); log.debug(HttpSessionInfo.sysInfo(httpServletRequest)); Action action; if (pageName.endsWith(".ajax")) { page = processAjaxCall(httpServletRequest, httpServletResponse, pageName.substring(1, pageName.length() - ".ajax".length()), execContext); page = StrSubstitutor.replace(page, execContext); } else if (pageName.endsWith(".bin") || pageName.endsWith(".pdfbin")) { String pn = null; if (pageName.endsWith(".pdfbin")) { pn = pageName.substring(1, pageName.length() - ".pdfbin".length()); } else { pn = pageName.substring(1, pageName.length() - ".bin".length()); } page = processAjaxCall(httpServletRequest, httpServletResponse, pn, execContext); if (page.startsWith("EX:")) { PrintWriter out = response.getWriter(); out.print(page); out.close(); } else { byte[] image = (byte[]) execContext.get("image"); if (pageName.endsWith(".pdfbin")) { String outputPdfFileName = execContext.getString("outputFileName"); String ex = serviceJasperPdfRequest(httpServletResponse, image, outputPdfFileName); if (ex != null) { PrintWriter out = response.getWriter(); out.print(page); out.close(); } return; } else { String responseType = execContext.getString("response_type"); if (StringUtils.isEmpty(responseType)) { responseType = "image/png"; } response.setContentType(responseType); processPostPages(execContext, httpServletRequest, httpServletResponse); InputStream in = new ByteArrayInputStream(image); OutputStream out = response.getOutputStream(); // Copy the contents of the file to the output // stream byte[] buf = new byte[1024]; int count = 0; while ((count = in.read(buf)) >= 0) { out.write(buf, 0, count); } in.close(); out.close(); } return; } } else { if (pageName.startsWith("/:")) { String wrapperPageName = null; int secondColon = pageName.indexOf(':', 2); if (secondColon >= 0) { wrapperPageName = pageName.substring(2, secondColon); execContext.put("inner_page", "/" + pageName.substring(secondColon + 1)); } else { if (StringUtils.isEmpty(wrapperPage)) { throw new ServletException("No wrapper page set, why use :"); } wrapperPageName = wrapperPage; execContext.put("inner_page", "/" + pageName.substring(2)); } // insert the requested page into the wrapper page action = new Action(realPath, wrapperPageName, nameSpace); } else { if (StringUtils.isNotEmpty(wrapperPage)) { // we have a base wrapper page defined execContext.put("inner_page", "/" + pageName); action = new Action(realPath, wrapperPage, nameSpace); } else { if (pageName.indexOf("show_axel_config") >= 0) { page = AxelConfig.getAxelConfig(execContext); log.info(page); page = "Config Copied to Log"; action = null; } else { // if we don't have a wrapper page we show the requested page action = new Action(realPath, pageName, nameSpace); } } } if (action != null) { if (StringUtils.isNotEmpty(page)) { page = action.processPage(execContext, page); } else { page = action.processPage(execContext); } } } log.debug("URI:" + httpServletRequest.getRequestURI()); // log.debug("page:" + page); Object object = execContext.get(ActionConst.NO_STR_SUBST); // log.debug(ActionConst.NO_STR_SUBST + ":[" + object + "]"); execContext.put(ActionConst.NO_STR_SUBST, null); if (pageName.toLowerCase().endsWith("soap")) { response.setContentType(IExecContext.CONTENT_TYPE_XML); } else if (pageName.toLowerCase().endsWith("json")) { response.setContentType(IExecContext.CONTENT_TYPE_JSON); } else { response.setContentType(IExecContext.CONTENT_TYPE_HTML); } processPostPages(execContext, httpServletRequest, httpServletResponse); // = = = // check if there is a contentType value stored in the execContext. This could have been set by one of the actions such as an action that wants to return a JSON data. // = = = String contentType = execContext.getString(IExecContext.CONTENT_TYPE_KEY); if (StringUtils.isNotBlank(contentType)) { response.setContentType(contentType); // if (contentType.equals(IExecContext.CONTENT_TYPE_JSON) || contentType.equals(IExecContext.CONTENT_TYPE_XML)) { // if (response instanceof HttpServletResponse) { // ((HttpServletResponse)response).setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1 // ((HttpServletResponse)response).setHeader("Pragma", "no-cache"); // HTTP 1.0 // ((HttpServletResponse)response).setDateHeader("Expires", 0); // Proxies. // } // } } execContext.remove("content_type"); PrintWriter out = response.getWriter(); out.print(page); out.close(); } catch (Throwable t) { // TODO review this, use a better way for reporting the error. log.info(t.getMessage(), t); throw new ServletException(t); } finally { if (execContext != null) { execContext.saveToPersistence(); RequestExecContext.remove(); } } } else { String msg = "Not processing page. Must be HttpServletRequest not [" + request.getClass().getName() + "] and HttpServletResponse not [" + response.getClass().getName() + "]"; log.info(msg); throw new ServletException(msg); } }
From source file:eionet.util.SecurityUtil.java
/** * * @param request/*from w ww. j ava2 s .c o m*/ * @return */ public static String getLoginURL(HttpServletRequest request) { // Legacy login mechanism. Used if the application is configured to not use Central Authentication Service (CAS). //String result = "javascript:login('" + request.getContextPath() + "')"; String result = request.getContextPath() + "/" + LoginServlet.LOGIN_JSP; boolean rememberAfterLoginUrl = false; 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); } rememberAfterLoginUrl = true; try { result = casLoginUrl + "?service=" + URLEncoder.encode( request.getScheme() + "://" + casServerName + request.getContextPath() + "/login", "UTF-8"); } catch (UnsupportedEncodingException e) { throw new DDRuntimeException(e.toString(), e); } } } } else { String servletPath = request.getServletPath(); if (servletPath == null || !servletPath.endsWith(LoginServlet.LOGIN_JSP)) { rememberAfterLoginUrl = true; } } if (rememberAfterLoginUrl) { String requestURL = request.getRequestURL().toString(); if (requestURL != null && !AfterCASLoginServlet.isSkipUrl(requestURL)) { request.getSession().setAttribute(AfterCASLoginServlet.AFTER_LOGIN_ATTR_NAME, buildAfterLoginURL(request)); } } return result; }