Example usage for javax.servlet.http HttpServletRequest getServletPath

List of usage examples for javax.servlet.http HttpServletRequest getServletPath

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletRequest getServletPath.

Prototype

public String getServletPath();

Source Link

Document

Returns the part of this request's URL that calls the servlet.

Usage

From source file:org.dspace.webmvc.controller.ResourceController.java

protected String getPath(HttpServletRequest req) {
    String servletPath = req.getServletPath();
    return servletPath + (StringUtils.isEmpty(req.getPathInfo()) ? "" : req.getPathInfo());
}

From source file:com.zyeeda.jofm.commands.HttpServletCommand.java

public HttpServletCommand(HttpServletRequest request, HttpServletResponse response)
        throws IllegalRequestException {
    this.request = request;
    this.response = response;

    String path = request.getServletPath();
    LoggerHelper.debug(logger, "servlet path = {}", path);
    String[] parts = StringUtils.split(path, '/');

    if (parts.length != 2) {
        throw new IllegalRequestException(request);
    }//ww  w  . j  a v  a2  s. com

    this.scope = parts[0];
    this.operation = parts[1];
}

From source file:com.googlecode.webutilities.servlets.WebProxyServlet.java

private void makeProxyRequest(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {
    String thisServletPath = req.getServletPath();
    String query = req.getQueryString();
    String url = req.getRequestURI();

    // Build the target URL
    String targetUrl = this.baseUri + (url.substring(url.indexOf(thisServletPath) + thisServletPath.length()));
    targetUrl += "?" + query;

    LOGGER.debug("Proxying {}:{}", req.getMethod(), targetUrl);

    HttpUriRequest request = getRequest(req.getMethod(), targetUrl);

    // Inject response headers
    this.requestHeadersToInject.forEach(request::setHeader);
    // Proxy/*from  w  w w .j  av  a  2  s . c o m*/
    this.copyResponse(HttpClients.createDefault().execute(request), resp);
    // Inject response headers
    this.responseHeadersToInject.forEach(resp::setHeader);

}

From source file:filters.ActionValidationFilter.java

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    HttpServletRequest httpServletRequest = (HttpServletRequest) request;
    String requPath = httpServletRequest.getServletPath();
    /*/*w  w  w.ja  v a2 s  . c  o  m*/
     * ignore resource files (CSS, JPEG/PNG, JavaScript) ... 
     */
    if (requPath.startsWith(STATIC_RESOURCES) || requPath.startsWith(API)) {
        chain.doFilter(request, response);
        return;
    }

    /*
     * This filter makes only sense, if user is logged in.
     */
    User user = AuthenticationUtils.getUser();
    if (user != null && user.getName() != null) {
        /*
         * get sessions credential storage variable
         */
        String storedCredential = (String) request.getAttribute(REQUEST_ATTRIB_CREDENTIAL);
        /*
         * if null, create new one
         */
        if (storedCredential == null) {
            storedCredential = getNewCredential(user, httpServletRequest.getSession());
            request.setAttribute(REQUEST_ATTRIB_CREDENTIAL, storedCredential);
        }
        log.debug("credential for " + user.getName() + " = " + storedCredential);

        /*
         * get credential from request parameter
         * 
         * FIXME: This does not work with multipart-requests! Thus, on such
         * requests we must otherwise send the ckey.
         */
        String requestCredential = request.getParameter(REQUEST_PARAM_CREDENTIAL);
        /*
         * check and propagate correctness 
         */
        request.setAttribute(REQUEST_ATTRIB_VALID_CREDENTIAL, storedCredential.equals(requestCredential));

    }

    // Pass control on to the next filter
    chain.doFilter(request, response);

}

From source file:org.jtalks.poulpe.web.AuthenticationCleaningAccessDeniedExceptionHandler.java

@Override
public void handle(HttpServletRequest request, HttpServletResponse response,
        AccessDeniedException accessDeniedException) throws IOException, ServletException {

    String errorPage;/*from www .j a v a 2s  .  co  m*/
    if (alternativeRoutes.containsKey(request.getServletPath())) {
        errorPage = alternativeRoutes.get(request.getServletPath());
    } else {
        SecurityContextHolder.getContext().setAuthentication(null);
        errorPage = defaultErrorPage;
    }
    response.sendRedirect(request.getContextPath() + errorPage);
}

From source file:com.cloud.servlet.StaticResourceServletTest.java

@Test
public void testNoSuchFile() throws ServletException, IOException {
    final StaticResourceServlet servlet = Mockito.mock(StaticResourceServlet.class);
    Mockito.doCallRealMethod().when(servlet).doGet(Matchers.any(HttpServletRequest.class),
            Matchers.any(HttpServletResponse.class));
    final ServletContext servletContext = Mockito.mock(ServletContext.class);
    Mockito.when(servletContext.getRealPath("notexisting.css"))
            .thenReturn(new File(rootDirectory, "notexisting.css").getAbsolutePath());
    Mockito.when(servlet.getServletContext()).thenReturn(servletContext);

    final HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
    Mockito.when(request.getServletPath()).thenReturn("notexisting.css");
    final HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
    servlet.doGet(request, response);//w  ww  .ja  v a2 s .  com
    Mockito.verify(response).setStatus(HttpServletResponse.SC_NOT_FOUND);
}

From source file:com.razorfish.controllers.misc.StoreSessionController.java

protected String getReturnRedirectUrlWithoutReferer(final HttpServletRequest request) {
    final String referer = StringUtils.remove(request.getRequestURL().toString(), request.getServletPath());
    if (referer != null && !referer.isEmpty()) {
        return REDIRECT_PREFIX + referer;
    }/*from   w  w  w.  ja  va 2  s .c o  m*/
    return REDIRECT_PREFIX + '/';
}

From source file:com.scf.module.security.matcher.AntPathRequestMatcher.java

private String getRequestPath(HttpServletRequest request) {
    String url = request.getServletPath();

    if (request.getPathInfo() != null) {
        url += request.getPathInfo();//from   w  w  w.  j  a  va 2  s. co  m
    }

    if (!caseSensitive) {
        url = url.toLowerCase();
    }

    return url;
}

From source file:de.hybris.platform.b2bdocumentsfilter.B2BDocumentsSecureMediaFilter.java

protected String getResourcePath(final HttpServletRequest httpRequest) {
    String resourcePath = httpRequest.getServletPath();
    if ((resourcePath == null) || (resourcePath.trim().isEmpty()))

    {// w w w.  jav  a 2s .  c  o  m
        final String reqURI = httpRequest.getRequestURI();
        final String ctxPath = httpRequest.getContextPath();
        resourcePath = reqURI.replace(ctxPath, "");
    }

    return resourcePath;
}

From source file:com.clican.pluto.cms.ui.servlet.VelocityResourceServlet.java

@SuppressWarnings("unchecked")
@Override/*from  w  w  w .  ja  va  2  s.  co m*/
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String prefix = request.getContextPath() + request.getServletPath();
    if (request.getRequestURI().startsWith(prefix)) {
        String path = request.getRequestURI().replaceFirst(prefix, "");
        if (path.startsWith("/")) {
            path = path.substring(1, path.indexOf(";"));
        }
        // request.getSession().setAttribute("propertyDescriptionList", new
        // ArrayList<PropertyDescription>());
        Writer w = new OutputStreamWriter(response.getOutputStream(), "utf-8");
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        InputStream is = null;
        try {
            is = Thread.currentThread().getContextClassLoader().getResourceAsStream(path);
            byte[] data = new byte[is.available()];
            is.read(data);
            String content = new String(data, "utf-8");
            Template t = null;
            VelocityContext velocityContext = new VelocityContext();
            HttpSession session = request.getSession();
            Enumeration<String> en = session.getAttributeNames();
            while (en.hasMoreElements()) {
                String name = en.nextElement();
                velocityContext.put(name, session.getAttribute(name));
            }
            SimpleNode node = RuntimeSingleton.getRuntimeServices().parse(content, path);
            t = new Template();
            t.setName(path);
            t.setRuntimeServices(RuntimeSingleton.getRuntimeServices());
            t.setData(node);
            t.initDocument();
            Writer wr = new OutputStreamWriter(os);
            t.merge(velocityContext, wr);
            wr.flush();
            byte[] datas = os.toByteArray();
            String s = new String(datas);
            log.info(s);
        } catch (Exception e) {
            log.error("", e);
            response.sendError(HttpServletResponse.SC_NOT_FOUND);
        } finally {
            if (w != null) {
                w.close();
            }
            if (is != null) {
                is.close();
            }
        }
    } else {
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
    }

}