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:sample.ContextFilter.java

private String currentUrl(HttpServletRequest request) {
    StringBuilder url = new StringBuilder();
    url.append(request.getServletPath());

    String pathInfo = request.getPathInfo();
    if (pathInfo != null) {
        url.append(pathInfo);//from ww  w .j ava 2  s .com
    }
    return url.toString();
}

From source file:opentipbot.web.security.UserInterceptor.java

private void handleSignOut(HttpServletRequest request, HttpServletResponse response) {
    if (SecurityContext.userSignedIn() && request.getServletPath().startsWith("/signout")) {
        connectionRepository.createConnectionRepository(SecurityContext.getCurrentUser().getId().toString())
                .removeConnections("twitter");
        userCookieGenerator.removeCookie(response);
        SecurityContext.remove();/*ww  w .  j ava 2s.  c o m*/
    }
}

From source file:org.tonguetied.web.DirectoryViewController.java

@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) {
    final StringBuilder servletPath = new StringBuilder(request.getServletPath());
    if (logger.isDebugEnabled())
        logger.debug("servletPath = " + servletPath);
    if (servletPath.toString().endsWith(suffix))
        servletPath.delete(servletPath.length() - suffix.length(), servletPath.length());

    final String homePath = request.getSession().getServletContext().getRealPath(servletPath.toString());
    if (logger.isDebugEnabled())
        logger.debug("homePath = " + homePath);

    final FileBean baseDirectory = new FileBean(homePath);
    if (logger.isInfoEnabled())
        logger.info("displaying contents of basedir = " + baseDirectory);
    final int lastIndex = servletPath.lastIndexOf("/");
    final String[] parents;
    if (lastIndex > 0)
        parents = servletPath.substring(1, lastIndex).split("/");
    else//from   w ww .  j a  v  a2 s.  co m
        parents = new String[] {};

    Map<String, Object> model = new HashMap<String, Object>();
    model.put("baseDir", baseDirectory);
    model.put("suffix", suffix);
    model.put("parents", parents);

    return new ModelAndView("export/fileListing", model);
}

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

@RequestMapping("/handle/**")
public String processHandle(@RequestAttribute Context context, HttpServletRequest request) throws SQLException {
    String handle = null;/*from   w  ww.  j a  v  a  2  s. c o m*/
    String servletPath = request.getServletPath();

    if (servletPath != null) {
        if (servletPath.startsWith("/handle/")) {
            servletPath = servletPath.substring(8);
        }

        if (servletPath.startsWith(ConfigurationManager.getProperty("handle.prefix"))) {
            int handleEndPos = servletPath.indexOf("/",
                    ConfigurationManager.getProperty("handle.prefix").length() + 1);
            if (handleEndPos > 0) {
                if (handleEndPos + 1 < servletPath.length()) {
                    handle = servletPath.substring(0, handleEndPos);
                    servletPath = servletPath.substring(handleEndPos);
                } else {
                    handle = servletPath.substring(0, handleEndPos);
                    servletPath = null;
                }
            } else {
                handle = servletPath;
                servletPath = null;
            }
        }

        if (!StringUtils.isEmpty(handle)) {
            DSpaceObject dspaceObject = HandleManager.resolveToObject(context, handle);

            DSpaceRequestUtils.setScopeHandle(request, handle);
            DSpaceRequestUtils.setScopeObject(request, dspaceObject);

            if (!StringUtils.isEmpty(servletPath)) {
                return "forward:" + servletPath;
            } else {
                return "forward:/renderObject";
            }
        }
    }

    return "pages/invalidhandle";
}

From source file:com.thoughtworks.go.server.newsecurity.filters.DenyIfRefererIsNotFilesFilter.java

@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response,
        FilterChain filterChain) throws ServletException, IOException {
    if (request.getServletPath().startsWith("/files/")) {
        throw new UnsupportedOperationException("Filter should not be invoked for `/files/` urls.");
    }//from   w  w w . j  a v a2s . c  o  m

    if (isRequestFromArtifact(request)) {
        response.setStatus(HttpServletResponse.SC_BAD_REQUEST);

        ContentTypeAwareResponse contentTypeAwareResponse = CONTENT_TYPE_NEGOTIATION_MESSAGE_HANDLER
                .getResponse(request);
        response.setCharacterEncoding("utf-8");
        response.setContentType(contentTypeAwareResponse.getContentType().toString());
        response.getOutputStream().print(contentTypeAwareResponse
                .getFormattedMessage("Denied GoCD access for requests from artifacts."));
    } else {
        filterChain.doFilter(request, response);
    }
}

From source file:org.sakaiproject.metaobj.shared.control.CheckForTimeout.java

public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
        throws Exception {
    if (getIgnoreList().contains(request.getServletPath())) {
        return true;
    }/*w  w w .  ja  va2  s.  c om*/
    Agent agent = getAuthenticationManager().getAgent();
    boolean timeOut = (agent == null || agent.getId() == null || agent.getId().getValue().length() == 0);
    if (timeOut) {
        response.sendRedirect(getTimeoutUrl());
    }
    return !timeOut;
}

From source file:cc.aileron.wsgi.router.WsgiRouterImpl.java

/**
 * /*from  w  w  w.j  a  v  a2s  .c  om*/
 * @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.edm.app.interceptor.AuthInterceptor.java

@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
        throws Exception {
    String link = request.getServletPath();

    if (StringUtils.startsWith(link, "/403") || StringUtils.startsWith(link, "/404")) {
        return true;
    }/*from   ww w .  ja va  2  s  . c  om*/

    if (!Auth.isSetup()) {
        logger.info("(Auth:handle) error: auth is off");
        response.sendRedirect("/403");
        return false;
    }

    String robot = Auth.ROBOT;
    //      String code = Auth.MAP.get(UrlMap.CODE.getAction());
    //      String code = Auth.MAP.get("LICENSE_PASSWD");

    if (!Auth.size()) {
        logger.info("(Auth:handle) error: LICENSE is error");
        response.sendRedirect("/403");
        return false;
    }
    if (StringUtils.isBlank(robot)) {
        logger.info("(Auth:handle) error: ROBOT is error");
        response.sendRedirect("/403");
        return false;
    }
    if (!Auth.key(robot)) {
        logger.info("Auth is fail ");
        logger.info("(Auth:handle) error: KEY is error");
        response.sendRedirect("/403");
        return false;
    }
    //      if (!Auth.link(link, robot, code)) {
    //         logger.info("(Auth:handle) error: " + link + " is forbid");
    //         response.sendRedirect("/404");
    //         return false;
    //      }

    return true;
}

From source file:org.socialsignin.springsocial.security.signin.SpringSocialSecurityAccessDeniedHandler.java

public String getUri(HttpServletRequest request) {
    return request.getServletPath() + (request.getPathInfo() == null ? "" : request.getPathInfo());
}

From source file:com.squarecash4glass.servlet.OAuth2AuthorizationServlet.java

/**
 * @param req//from   w  ww. j  a v a 2  s  . c  om
 * @param provider
 * @return
 */
private String getProvider(HttpServletRequest req) {
    LOG.info("getServletPath: " + req.getServletPath());
    if ("/oauth2callbackdwolla".equals(req.getServletPath())) {
        return "dwolla";
    }
    if ("/oauth2callbacksquare".equals(req.getServletPath())) {
        return "square";
    }
    if ("/oauth2callbackvenmo".equals(req.getServletPath())) {
        return "venmo";
    }
    if ("/oauth2callback".equals(req.getServletPath())) {
        return "google";
    }
    return null;
}