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:com.sap.cloudlabs.connectivity.proxy.ProxyServlet.java

/**
 * Returns the URL to the proxy servlet and used destination. 
 *//*from   www  . jav a2  s. c  om*/
private String getProxyUrl(HttpServletRequest request) throws MalformedURLException {
    URL url = new URL(request.getRequestURL().toString());
    String proxyUrl = request.getScheme() + "://" + url.getAuthority() + request.getContextPath()
            + request.getServletPath();
    return proxyUrl;
}

From source file:com.sfwl.framework.web.casclient.AuthenticationFilter.java

public final void doFilter(final ServletRequest servletRequest, final ServletResponse servletResponse,
        final FilterChain filterChain) throws IOException, ServletException {

    final HttpServletRequest request = (HttpServletRequest) servletRequest;
    final HttpServletResponse response = (HttpServletResponse) servletResponse;

    if (isRequestUrlExcluded(request)) {
        logger.debug("Request is ignored.");
        filterChain.doFilter(request, response);
        return;/*from   w  w w  . ja  v a 2s .  c  om*/
    }

    // URL(js+css+img)
    if (excepUrlPattern != null && excepUrlPattern.matcher(request.getServletPath()).matches()) {
        filterChain.doFilter(request, response);
        return;
    }

    final HttpSession session = request.getSession(false);
    final Assertion assertion = session != null ? (Assertion) session.getAttribute(CONST_CAS_ASSERTION) : null;

    if (assertion != null) {
        filterChain.doFilter(request, response);
        return;
    }

    final String serviceUrl = constructServiceUrl(request, response);
    final String ticket = retrieveTicketFromRequest(request);
    final boolean wasGatewayed = this.gateway && this.gatewayStorage.hasGatewayedAlready(request, serviceUrl);

    if (CommonUtils.isNotBlank(ticket) || wasGatewayed) {
        filterChain.doFilter(request, response);
        return;
    }

    final String modifiedServiceUrl;

    logger.debug("no ticket and no assertion found");
    if (this.gateway) {
        logger.debug("setting gateway attribute in session");
        modifiedServiceUrl = this.gatewayStorage.storeGatewayInformation(request, serviceUrl);
    } else {
        modifiedServiceUrl = serviceUrl;
    }

    logger.debug("Constructed service url: {}", modifiedServiceUrl);

    final String urlToRedirectTo = CommonUtils.constructRedirectUrl(this.casServerLoginUrl,
            getServiceParameterName(), modifiedServiceUrl, this.renew, this.gateway);

    logger.debug("redirecting to \"{}\"", urlToRedirectTo);
    this.authenticationRedirectStrategy.redirect(request, response, urlToRedirectTo);
}

From source file:net.sourceforge.vulcan.web.ProjectFileServlet.java

private String getFallbackParentPath(HttpServletRequest request, String workDir) {
    final StringBuilder pathInfo = new StringBuilder(request.getPathInfo());

    while (!getFile(workDir, pathInfo.toString(), true).exists()) {
        pathInfo.delete(pathInfo.lastIndexOf("/"), pathInfo.length());
    }/*from   w w  w  . j  a  va 2s.c om*/

    final StringBuilder buf = new StringBuilder(request.getContextPath());
    buf.append(request.getServletPath());
    buf.append(pathInfo);
    buf.append("/");

    return buf.toString();
}

From source file:org.cloudfoundry.identity.uaa.login.RemoteUaaController.java

@RequestMapping(value = { "/oauth/error", "oauth/token" })
@ResponseBody//from   ww w . j a  v a 2 s  .c o m
public ResponseEntity<byte[]> sundry(HttpServletRequest request, HttpEntity<byte[]> entity,
        Map<String, Object> model) throws Exception {
    logger.info("Pass through request for " + request.getServletPath());
    return passthru(request, entity, model, false);
}

From source file:com.ucap.uccc.cmis.impl.webservices.CmisWebServicesServlet.java

private UrlBuilder compileBaseUrl(HttpServletRequest request, HttpServletResponse response) {
    UrlBuilder result;//from  w ww. j  av  a2  s. c o  m

    String baseUrl = (String) request.getAttribute(Dispatcher.BASE_URL_ATTRIBUTE);
    if (baseUrl != null) {
        result = new UrlBuilder(baseUrl);
    } else {
        result = new UrlBuilder(request.getScheme(), request.getServerName(), request.getServerPort(), null);
        result.addPath(request.getContextPath());
        result.addPath(request.getServletPath());
    }

    return result;
}

From source file:com.portfolio.security.LTIv2Servlet.java

private String getServiceURL(HttpServletRequest request) {
    String scheme = request.getScheme(); // http
    String serverName = request.getServerName(); // localhost
    int serverPort = request.getServerPort(); // 80
    String contextPath = request.getContextPath(); // /imsblis
    String servletPath = request.getServletPath(); // /ltitest
    String url = scheme + "://" + serverName + ":" + serverPort + contextPath + servletPath + "/";
    return url;/*from  www.  ja  v a 2s  . c  o  m*/
}

From source file:info.magnolia.cms.filters.ServletDispatchingFilterTest.java

private void doTestBypassAndPathInfo(final boolean shouldBypass, final String expectedPathInfo,
        final String expectedServletPath, final String requestPath, String mapping,
        boolean shouldCheckPathInfoAndServletPath) throws Exception {
    ComponentsTestUtil.setInstance(Voting.class, new DefaultVoting());
    WebContext ctx = createStrictMock(WebContext.class);
    MgnlContext.setInstance(ctx);//from  w w  w . ja va 2s.  c  o  m
    final AggregationState state = new MockAggregationState();
    expect(ctx.getContextPath()).andReturn("/magnoliaAuthor").anyTimes();

    final FilterChain chain = createNiceMock(FilterChain.class);
    final HttpServletResponse res = createNiceMock(HttpServletResponse.class);
    final HttpServletRequest req = createMock(HttpServletRequest.class);
    expect(req.getAttribute(EasyMock.<String>anyObject())).andReturn(null).anyTimes();
    expect(ctx.getAggregationState()).andReturn(state).anyTimes();
    expect(req.getRequestURI()).andReturn("/magnoliaAuthor" + requestPath).anyTimes();
    expect(req.getContextPath()).andReturn("/magnoliaAuthor").anyTimes();
    expect(req.getServletPath()).andReturn("/magnoliaAuthor" + requestPath).anyTimes();
    expect(req.getPathInfo()).andReturn(null).anyTimes();
    expect(req.getQueryString()).andReturn(null).anyTimes();

    final Servlet servlet = createStrictMock(Servlet.class);
    if (!shouldBypass) {
        servlet.service(isA(HttpServletRequestWrapper.class), same(res));
        expectLastCall().andAnswer(new IAnswer<Object>() {
            @Override
            public Object answer() throws Throwable {
                final HttpServletRequestWrapper requestWrapper = (HttpServletRequestWrapper) getCurrentArguments()[0];
                final String pathInfo = requestWrapper.getPathInfo();
                final String servletPath = requestWrapper.getServletPath();
                assertEquals("pathInfo does not match", expectedPathInfo, pathInfo);
                assertEquals("servletPath does not match", expectedServletPath, servletPath);
                return null;
            }
        });
    }

    replay(chain, res, req, servlet, ctx);

    state.setCurrentURI(requestPath);
    final AbstractMgnlFilter filter = new ServletDispatchingFilter();
    final Field servletField = ServletDispatchingFilter.class.getDeclaredField("servlet");
    servletField.setAccessible(true);
    servletField.set(filter, servlet);

    filter.addMapping(mapping);

    assertEquals("Should " + (shouldBypass ? "" : "not ") + "have bypassed", shouldBypass,
            !filter.matches(req));
    if (!shouldBypass) {
        filter.doFilter(req, res, chain);
    }

    verify(chain, res, req, servlet, ctx);
}

From source file:com.miserablemind.butter.security.MyAccessDeniedHandler.java

/**
 * Handle Exception Method/*from  w  ww  .  jav  a2s .  com*/
 *
 * @param request               {@link HttpServletRequest} provides session and {@link SecurityContext}
 * @param response              used for redirecting to 500 page
 * @param accessDeniedException exception used for logging the stack trace
 * @throws IOException
 * @throws ServletException
 */
@Override
public void handle(HttpServletRequest request, HttpServletResponse response,
        AccessDeniedException accessDeniedException) throws IOException, ServletException {

    long userId = 0;

    SecurityContext securityContext = (SecurityContext) request.getSession()
            .getAttribute("SPRING_SECURITY_CONTEXT");
    if (securityContext != null) {
        Object principal = securityContext.getAuthentication().getPrincipal();
        if (principal != null && principal != "anonymousUser") {
            AppUser user = (AppUser) principal;
            userId = user.getId();
        }
    }

    logger.error("Accessing Denied. User ID: " + userId + " URL: " + request.getServletPath(),
            accessDeniedException);
    response.sendRedirect("/error/500");

}

From source file:it.delli.mwebc.servlet.MWebCRenderer.java

public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    Application application = (Application) request.getSession().getAttribute("application");
    if (application == null) {
        log.info("Application not present in context. Creating new Application");
        application = MWebCConfig.init(request.getSession());
    }/*from  www . j  a  v a  2  s.c  o m*/
    String pageName = request.getServletPath().substring(1, request.getServletPath().indexOf(".mwc"));
    String debugWidget = request.getParameter("debugWidget");
    Page page = application.createPage(pageName);
    application.addPage(page);
    try {
        Document pageDocument = DocumentBuilderFactory.newInstance().newDocumentBuilder()
                .parse(new File(getServletContext().getRealPath("/" + pageName + ".mwc")));
        buildLayout(pageDocument.getDocumentElement(), null, page);
    } catch (Exception e) {
        log.error("Exception in building widget tree", e);
    }

    ReflectionUtils.registerAnnotatedEventListenerMethods(page.getEventListener(), page);

    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    out.println("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
    out.println(
            "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//`EN\" \"http://www.w3.org/TR/html4/strict.dtd\">");
    out.println("<html xmlns:v=\"urn:schemas-microsoft-com:vml\">");
    out.println("<head>");
    out.println("<title>" + page.getTitle() + "</title>");
    out.println("<!-- mwebc by Francesco Delli Paoli -->");
    for (Iterator<String> iterator = application.getResources().getJavascriptUrl().iterator(); iterator
            .hasNext();) {
        out.println("<script type=\"text/javascript\" src=\"" + iterator.next() + "\"></script>");
    }
    for (Iterator<String> iterator = application.getResources().getCssUrl().iterator(); iterator.hasNext();) {
        out.println("<link rel=\"stylesheet\" type=\"text/css\" href=\"" + iterator.next() + "\" />");
    }
    for (Iterator<String> iterator = application.getResources().getJavascript().iterator(); iterator
            .hasNext();) {
        out.println("<script type=\"text/javascript\">" + iterator.next() + "</script>");
    }
    for (Iterator<String> iterator = application.getResources().getCss().iterator(); iterator.hasNext();) {
        out.println("<style type=\"text/css\">" + iterator.next() + "</style>");
    }
    if (debugWidget != null) {
        out.println("<script src=\"resources/" + debugWidget.replace(".", "/") + ".js\"></script>");
        out.println("<script>mwebc.debugWidget = \"" + debugWidget + "\";</script>");
    }
    out.println("</head>");
    out.println("<body class=\"claro\" >");
    out.println("</body>");
    out.println("<script type=\"text/javascript\">");
    out.println("mwebc.ready(function() {");
    out.println("   mwebc.delegate('event', {sessionId: '" + request.getSession().getId()
            + "', event: 'onInitPage', eventType: 'HtmlEvent', pageName: '" + page.getName()
            + "', forward: 'onInit', data: {} }, false);");
    out.println("   mwebc.delegate('event', {sessionId: '" + request.getSession().getId()
            + "', event: 'onLoadPage', eventType: 'HtmlEvent', pageName: '" + page.getName()
            + "', forward: 'onLoad', data: {} });");
    out.println("});");
    out.println("</script>");
    out.println("</html>");

}