List of usage examples for javax.servlet.http HttpServletRequest getPathInfo
public String getPathInfo();
From source file:it.geosolutions.opensdi2.servlet.RestFacade.java
/** * Perform the request based on this.urlFacade * //from w ww . j a v a2 s. c o m * @param httpServletRequest The {@link HttpServletRequest} object passed in by the servlet engine representing the client request to be proxied * @param httpServletResponse The {@link HttpServletResponse} object by which we can send a proxied response to the client * @throws IOException if an error occur handling the request */ public void handleRequest(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws IOException { String pathInfo = httpServletRequest.getPathInfo(), urlWrapped = null, path = ""; for (String relPath : pathInfo.split(PATH_SEPARATOR)) { if (urlWrapped == null) { urlWrapped = StringUtils.isEmpty(relPath) ? null : relPath; } else { path += relPath + PATH_SEPARATOR; } } urlFacade.handleRequest(httpServletRequest, httpServletResponse, urlWrapped, path); }
From source file:com.kixeye.chassis.transport.swagger.SwaggerServlet.java
@Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { // figure out the real path String pathInfo = StringUtils.trimToEmpty(req.getPathInfo()); while (pathInfo.endsWith("/")) { pathInfo = StringUtils.removeEnd(pathInfo, "/"); }/* w ww .j ava 2 s . c o m*/ while (pathInfo.startsWith("/")) { pathInfo = StringUtils.removeStart(pathInfo, "/"); } if (StringUtils.isBlank(pathInfo)) { resp.sendRedirect(rootContextPath + "/" + WELCOME_PAGE); } else { // get the resource AbstractFileResolvingResource resource = (AbstractFileResolvingResource) resourceLoader .getResource(SWAGGER_DIRECTORY + "/" + pathInfo); // send it to the response if (resource.exists()) { StreamUtils.copy(resource.getInputStream(), resp.getOutputStream()); resp.setStatus(HttpServletResponse.SC_OK); resp.flushBuffer(); } else { resp.sendError(HttpServletResponse.SC_NOT_FOUND); } } }
From source file:com.googlesource.gerrit.plugins.github.velocity.VelocityViewServlet.java
@Override public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException { HttpServletRequest req = (HttpServletRequest) request; HttpServletResponse resp = (HttpServletResponse) response; String servletPath = req.getPathInfo(); NextPage nextPage = (NextPage) req.getAttribute("destUrl"); String destUrl = null;/* w ww . ja va 2 s.com*/ if (nextPage != null && !nextPage.uri.startsWith("/")) { destUrl = servletPath.substring(0, servletPath.lastIndexOf("/")) + "/" + nextPage.uri; } String pathInfo = Objects.firstNonNull(destUrl, servletPath); if (!pathInfo.startsWith(STATIC_PREFIX)) { resp.sendError(HttpStatus.SC_NOT_FOUND); } try { Template template = velocityRuntime.getTemplate(pathInfo, "UTF-8"); VelocityContext context = initVelocityModel(req).getContext(); context.put("request", req); resp.setHeader("content-type", "text/html"); resp.setCharacterEncoding(StandardCharsets.UTF_8.name()); template.merge(context, resp.getWriter()); } catch (ResourceNotFoundException e) { log.error("Cannot load velocity template " + pathInfo, e); resp.sendError(HttpStatus.SC_NOT_FOUND); } catch (Exception e) { log.error("Error executing velocity template " + pathInfo, e); resp.sendError(HttpStatus.SC_INTERNAL_SERVER_ERROR, e.getLocalizedMessage()); } }
From source file:com.googlesource.gerrit.plugins.github.wizard.VelocityControllerServlet.java
private String getControllerClassName(HttpServletRequest req) { String reqServletName;//from ww w . j a va2s. c o m StringBuilder controllerName = new StringBuilder(); reqServletName = req.getPathInfo(); reqServletName = trimFromChar(reqServletName, '/'); reqServletName = trimUpToChar(reqServletName, '.'); String[] controllerNameParts = reqServletName.split("-"); for (String namePart : controllerNameParts) { controllerName.append(Character.toUpperCase(namePart.charAt(0)) + namePart.substring(1)); } return controllerName.toString(); }
From source file:cc.aileron.wsgi.router.WsgiRouterImpl.java
/** * // www . j a v a 2 s . c o m * @return * @throws FileUploadException */ private WorkflowFindCondition getFindCondition(final HttpServletRequest request) throws FileUploadException { final String servletPath = request.getServletPath(); final String pathInfo = request.getPathInfo() != null ? request.getPathInfo() : ""; final WorkflowFindCondition condition = new WorkflowFindCondition(); // condition.uri = // EncodeConvertorUtils.getConvertor(environment.getEncode()) // .convert(servletPath + pathInfo); condition.uri = servletPath + pathInfo; condition.method = WorkflowMethod.valueOf(request.getMethod()); condition.parameter = requestParameterFactory.create(request); return condition; }
From source file:com.ikon.servlet.CssServlet.java
/** * //from w w w . j a v a 2s .c om */ public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { String path = request.getPathInfo(); OutputStream os = null; try { if (path.length() > 1) { String[] foo = path.substring(1).split("/"); if (foo.length > 1) { String context = foo[0]; String name = foo[1]; Css css = CssDAO.getInstance().findByContextAndName(context, name); if (css == null) { InputStream is = null; try { if (Css.CONTEXT_FRONTEND.equals(context)) { } else if (Css.CONTEXT_EXTENSION.equals(context)) { } /* if (is != null) { css = new Css(); css.setContent(IOUtils.toString(is)); css.setContext(context); css.setName(name); css.setActive(true); } */ } finally { IOUtils.closeQuietly(is); } } if (css != null) { // Prepare file headers WebUtils.prepareSendFile(request, response, css.getName() + ".css", MimeTypeConfig.MIME_CSS, false); PrintWriter out = new PrintWriter( new OutputStreamWriter(response.getOutputStream(), "UTF8"), true); out.append(css.getContent()); out.flush(); } } } } catch (DatabaseException e) { log.error(e.getMessage(), e); } finally { IOUtils.closeQuietly(os); } }
From source file:com.sketchy.server.JsonServlet.java
@Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); String pathInfo = request.getPathInfo(); if (pathInfo.startsWith("/")) pathInfo = StringUtils.substringAfter(pathInfo, "/"); String action = ACTION_PACKAGE + pathInfo; JSONServletResult jsonServletResult = null; try {/* ww w .ja va 2s . c o m*/ ServletAction servletAction = ServletAction.getInstance(action); jsonServletResult = servletAction.execute(request); } catch (ClassNotFoundException e) { jsonServletResult = new JSONServletResult(Status.ERROR, "ServletAction '" + pathInfo + "' not found! " + e.getMessage()); } catch (Exception e) { jsonServletResult = new JSONServletResult(Status.ERROR, "Unexpected Exception from ServletAction '" + pathInfo + "'! " + e.getMessage()); } response.setStatus(HttpServletResponse.SC_OK); response.getWriter().println(jsonServletResult.toJSONString()); }
From source file:net.bafeimao.umbrella.web.interceptor.SecurityCheckingHandlerInterceptor.java
@Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { if (request.getSession().getAttribute("user") == null) { response.sendRedirect(request.getContextPath() + "/login?returl=" + request.getPathInfo()); return false; }/*www.j a v a2 s.co m*/ return super.preHandle(request, response, handler); }
From source file:com.evolveum.midpoint.web.boot.StaticWebServlet.java
protected void serveResource(HttpServletRequest request, HttpServletResponse response, boolean content) throws IOException, ServletException { String relativePath = request.getPathInfo(); LOGGER.trace("Serving relative path {}", relativePath); String requestUri = request.getRequestURI(); if (relativePath == null || relativePath.length() == 0 || "/".equals(relativePath)) { response.sendError(HttpServletResponse.SC_NOT_FOUND, requestUri); return;//from w w w. j ava 2 s . com } File file = new File(base, relativePath); if (!file.exists() || !file.isFile()) { response.sendError(HttpServletResponse.SC_NOT_FOUND, requestUri); return; } String contentType = getServletContext().getMimeType(file.getName()); if (contentType == null) { contentType = "application/octet-stream"; } response.setContentType(contentType); response.setHeader("Content-Length", String.valueOf(file.length())); LOGGER.trace("Serving file {}", file.getPath()); ServletOutputStream outputStream = response.getOutputStream(); FileInputStream fileInputStream = new FileInputStream(file); try { IOUtils.copy(fileInputStream, outputStream); } catch (IOException e) { throw e; } finally { fileInputStream.close(); outputStream.close(); } }
From source file:javax.faces.webapp.FacesServlet.java
public void service(ServletRequest request, ServletResponse response) throws IOException, ServletException { HttpServletRequest httpRequest = ((HttpServletRequest) request); String pathInfo = httpRequest.getPathInfo(); // if it is a prefix mapping ... if (pathInfo != null && (pathInfo.startsWith("/WEB-INF") || pathInfo.startsWith("/META-INF"))) { StringBuffer buffer = new StringBuffer(); buffer.append(" Someone is trying to access a secure resource : ").append(pathInfo); buffer.append("\n remote address is ").append(httpRequest.getRemoteAddr()); buffer.append("\n remote host is ").append(httpRequest.getRemoteHost()); buffer.append("\n remote user is ").append(httpRequest.getRemoteUser()); buffer.append("\n request URI is ").append(httpRequest.getRequestURI()); log.warn(buffer.toString());/* w w w . j av a 2 s . c o m*/ // Why does RI return a 404 and not a 403, SC_FORBIDDEN ? ((HttpServletResponse) response).sendError(HttpServletResponse.SC_NOT_FOUND); return; } if (log.isTraceEnabled()) log.trace("service begin"); FacesContext facesContext = _facesContextFactory.getFacesContext(_servletConfig.getServletContext(), request, response, _lifecycle); try { _lifecycle.execute(facesContext); _lifecycle.render(facesContext); } catch (Throwable e) { if (e instanceof IOException) { throw (IOException) e; } else if (e instanceof ServletException) { throw (ServletException) e; } else if (e.getMessage() != null) { throw new ServletException(e.getMessage(), e); } else { throw new ServletException(e); } } finally { facesContext.release(); } if (log.isTraceEnabled()) log.trace("service end"); }