List of usage examples for javax.servlet.http HttpServletRequest getServletPath
public String getServletPath();
From source file:it.smartcommunitylab.aac.controller.GlobalDefaultExceptionHandler.java
public ModelAndView resolveException(HttpServletRequest aReq, HttpServletResponse aRes, Object aHandler, Exception anExc) {/*from w w w .ja va 2 s.co m*/ // hack. should be done better in configuration if ("/oauth/token".equals(aReq.getServletPath())) { return null; } // Otherwise setup and send the user to a default error-view. ModelAndView mav = new ModelAndView(); mav.addObject("exception", anExc); mav.addObject("url", aReq.getRequestURL()); mav.setViewName(DEFAULT_ERROR_VIEW); logger.error("Global erro handler", anExc); return mav; }
From source file:com.apress.progwt.server.web.controllers.ViewUserController.java
@Override protected ModelAndView handleRequestInternal(HttpServletRequest req, HttpServletResponse arg1) throws Exception { log.debug("SERVLET PATH: " + req.getServletPath() + " " + req.getPathInfo() + " " + req.getQueryString()); Map<String, Object> model = getDefaultModel(req); String path = req.getPathInfo(); String[] pathParts = path.split("/"); log.debug("!path parts " + Arrays.toString(pathParts)); // "/user/jeff" splits to [,jeff] if (pathParts.length < 2) { return new ModelAndView(getNotFoundView()); }//from www .ja v a2 s . com String nickname = pathParts[1]; User fetchedUser = userService.getUserByNicknameFullFetch(nickname); if (log.isDebugEnabled()) { log.debug("user u: " + fetchedUser); log.debug("isinit user " + Hibernate.isInitialized(fetchedUser)); log.debug("isinit schools " + Hibernate.isInitialized(fetchedUser.getSchoolRankings())); for (Application sap : fetchedUser.getSchoolRankings()) { if (!Hibernate.isInitialized(sap)) { log.debug("Not initialized"); } } } if (fetchedUser == null) { return new ModelAndView(getNotFoundView(), "message", "Couldn't find user with nickname: " + nickname); } model.put("viewUser", fetchedUser); ModelAndView mav = getMav(); mav.addAllObjects(model); return mav; }
From source file:de.micromata.genome.gwiki.web.StaticFileServlet.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String uri = req.getPathInfo(); String servletp = req.getServletPath(); String respath = servletp + uri; if (uri == null) { resp.sendError(HttpServletResponse.SC_NOT_FOUND); return;/*from www. jav a 2 s .c o m*/ } InputStream is = getServletContext().getResourceAsStream(respath); if (is == null) { resp.sendError(HttpServletResponse.SC_NOT_FOUND); return; } long nt = new Date().getTime() + TimeInMillis.DAY; String mime = MimeUtils.getMimeTypeFromFile(respath); if (StringUtils.equals(mime, "application/x-shockwave-flash")) { resp.setHeader("Cache-Control", "cache, must-revalidate"); resp.setHeader("Pragma", "public"); } resp.setDateHeader("Expires", nt); resp.setHeader("Cache-Control", "max-age=86400, public"); if (mime != null) { resp.setContentType(mime); } byte[] data = IOUtils.toByteArray(is); IOUtils.closeQuietly(is); resp.setContentLength(data.length); IOUtils.write(data, resp.getOutputStream()); }
From source file:codes.thischwa.c5c.FilemanagerConfigFilter.java
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest req = (HttpServletRequest) request; HttpServletResponse resp = (HttpServletResponse) response; String path = req.getServletPath(); if (path.contains("filemanager.config.js")) { // set some default headers ConnectorServlet.initResponseHeader(resp); logger.debug("Filemanager config request: {}", path); FilemanagerConfig config = (path.endsWith(".default")) ? UserObjectProxy.getFilemanagerDefaultConfig() : UserObjectProxy.getFilemanagerUserConfig(req); ObjectMapper mapper = new ObjectMapper(); try {// ww w . j av a2 s. c o m mapper.writeValue(resp.getOutputStream(), config); } catch (Exception e) { logger.error(String.format("Handling of '%s' failed.", path), e); throw new RuntimeException(e); } finally { IOUtils.closeQuietly(resp.getOutputStream()); } } else { chain.doFilter(req, resp); } }
From source file:org.openmrs.web.controller.RedirectController.java
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // default to the current path if (redirectView == null) { redirectView = request.getServletPath(); }/* w w w. ja va 2 s . c o m*/ return new ModelAndView(redirectView); }
From source file:org.apache.lucene.replicator.http.ReplicationService.java
/** * Returns the path elements that were given in the servlet request, excluding * the servlet's action context./*from w w w . ja va 2 s.c om*/ */ private String[] getPathElements(HttpServletRequest req) { String path = req.getServletPath(); String pathInfo = req.getPathInfo(); if (pathInfo != null) { path += pathInfo; } int actionLen = REPLICATION_CONTEXT.length(); int startIdx = actionLen; if (path.length() > actionLen && path.charAt(actionLen) == '/') { ++startIdx; } // split the string on '/' and remove any empty elements. This is better // than using String.split() since the latter may return empty elements in // the array StringTokenizer stok = new StringTokenizer(path.substring(startIdx), "/"); ArrayList<String> elements = new ArrayList<>(); while (stok.hasMoreTokens()) { elements.add(stok.nextToken()); } return elements.toArray(new String[0]); }
From source file:com.acc.storefront.interceptors.beforecontroller.RequireHardLoginBeforeControllerHandler.java
protected String getRedirectUrl(final HttpServletRequest request) { if (request != null && request.getServletPath().contains("checkout")) { return getLoginAndCheckoutUrl(); } else {/*from w w w . j a v a2 s . c o m*/ return getLoginUrl(); } }
From source file:com.buaa.cfs.conf.ReconfigurationServlet.java
private Reconfigurable getReconfigurable(HttpServletRequest req) { LOG.info("servlet path: " + req.getServletPath()); LOG.info("getting attribute: " + CONF_SERVLET_RECONFIGURABLE_PREFIX + req.getServletPath()); return (Reconfigurable) this.getServletContext() .getAttribute(CONF_SERVLET_RECONFIGURABLE_PREFIX + req.getServletPath()); }
From source file:org.zht.framework.interceptors.LogInterceptor.java
@Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { init();/*w w w.j a v a 2s .c om*/ String requestUrl = request.getServletPath(); if (isIgnorUrl(requestUrl)) { return super.preHandle(request, response, handler); } OperationLog operationLog = LogUtil.genOperationLog(request); if (isPersistToDataBase) { if (operationLog != null) { try { operateLogService.$base_save(operationLog); } catch (Exception e) { } } } return super.preHandle(request, response, handler); }
From source file:de.micromata.genome.tpsb.httpmockup.MockFilterChain.java
@Override public void doFilter(final ServletRequest req, final ServletResponse resp) throws IOException, ServletException { HttpServletRequest hreq = (HttpServletRequest) req; String uri = hreq.getRequestURI(); String localUri = uri;/*from w w w . j a v a2s. c om*/ if (StringUtils.isNotBlank(hreq.getServletPath()) && StringUtils.isNotBlank(hreq.getPathInfo()) == true) { localUri = hreq.getServletPath() + hreq.getPathInfo(); } final MockFiltersConfig fc = this.mockupServletContext.getFiltersConfig(); this.filterIndex = fc.getNextFilterMapDef(localUri, this.filterIndex, this.dispatcherFlag); if (this.filterIndex == -1) { this.mockupServletContext.serveServlet((HttpServletRequest) req, (HttpServletResponse) resp); return; } final Filter f = fc.getFilterMapping().get(this.filterIndex).getFilterDef().getFilter(); ++this.filterIndex; if (log.isDebugEnabled() == true) { log.debug("Filter filter: " + f.getClass().getName()); } f.doFilter(req, resp, this); }