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.sakaiproject.imagegallery.web.MultiFileUploaderController.java

public void multiFileUpload(HttpServletRequest request, HttpServletResponse response) throws Exception {
    if (log.isInfoEnabled())
        log.info("req contextPath=" + request.getContextPath() + ", pathInfo=" + request.getPathInfo()
                + ", query=" + request.getQueryString() + ", URI=" + request.getRequestURI() + ", URL="
                + request.getRequestURL() + ", servlet=" + request.getServletPath());
    if (request instanceof MultipartHttpServletRequest) {
        String newImageId = storeNewImage((MultipartHttpServletRequest) request);
        response.setContentType("text/plain");
        PrintWriter responseWriter = response.getWriter();
        responseWriter.print(newImageId);
        responseWriter.close();//from  www  .j a v  a2s .  c o  m
    }
}

From source file:com.xpn.xwiki.web.XWikiRequestProcessor.java

/**
 * {@inheritDoc}//from  w  ww  . j  ava  2s  . c  om
 * 
 * @see org.apache.struts.action.RequestProcessor#processPath(javax.servlet.http.HttpServletRequest,
 *      javax.servlet.http.HttpServletResponse)
 */
@Override
protected String processPath(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse)
        throws IOException {
    String result = super.processPath(httpServletRequest, httpServletResponse);

    if ("1".equals(XWikiConfigurationService.getProperty("xwiki.virtual.usepath", "0", getServletContext()))) {
        // Remove /wikiname part if the struts action is /wiki
        if (httpServletRequest.getServletPath().equals("/" + XWikiConfigurationService
                .getProperty("xwiki.virtual.usepath.servletpath", "wiki", getServletContext()))) {
            int wikiNameIndex = result.indexOf("/", 1);
            if (wikiNameIndex == -1) {
                result = "";
            } else {
                result = result.substring(wikiNameIndex);
            }
        }
    }

    if (StringUtils.countMatches(result, "/") <= 2) {
        if (result.startsWith("/xmlrpc/")) {
            return "/xmlrpc/";
        } else {
            return "/view/";
        }
    } else {
        return result.substring(0, result.indexOf("/", 1) + 1);
    }
}

From source file:com.sun.socialsite.web.filters.RedirectorFilter.java

private String getRedirectionUri(HttpServletRequest httpReq) {

    if (baseUri == null) {
        return null;
    }//from   w w  w.  j  av a  2s.  c o  m

    String serverName = httpReq.getServerName();
    String scheme = httpReq.getScheme();
    int port = httpReq.getServerPort();

    for (String exception : exceptions) {
        if (httpReq.getServletPath().startsWith(exception)) {
            return null;
        }
    }

    if (serverName.equalsIgnoreCase(baseUri.getHost()) && scheme.equalsIgnoreCase(baseUri.getScheme())
            && (port == basePort)) {
        return null;
    } else {
        log.debug(String.format("Redirecting Because ((%s != %s) || (%s != %s) || (%d != %d))", serverName,
                baseUri.getHost(), scheme, baseUri.getScheme(), port, basePort));
        StringBuilder sb = new StringBuilder(baseUri.toString());
        if (httpReq.getServletPath() != null)
            sb.append(httpReq.getServletPath());
        if (httpReq.getPathInfo() != null)
            sb.append(httpReq.getPathInfo());
        if (httpReq.getQueryString() != null)
            sb.append("?").append(httpReq.getQueryString());
        return sb.toString();
    }
}

From source file:grails.plugin.springsecurity.web.filter.DebugFilter.java

public void doFilter(ServletRequest req, ServletResponse res, FilterChain filterChain)
        throws ServletException, IOException {

    HttpServletRequest request = (HttpServletRequest) req;
    HttpServletResponse response = (HttpServletResponse) res;

    List<Filter> filters = getFilters(request);
    log(false, "Request received for '{}':\n\n{}\n\nservletPath:{}\npathInfo:{}\n\n{}",
            UrlUtils.buildRequestUrl(request), request, request.getServletPath(), request.getPathInfo(),
            formatFilters(filters));//from  ww  w .j  av  a  2s .  c  o m

    if (request.getAttribute(ALREADY_FILTERED_ATTR_NAME) == null) {
        invokeWithWrappedRequest(request, response, filterChain);
    } else {
        filterChainProxy.doFilter(request, response, filterChain);
    }
}

From source file:io.apicurio.studio.fe.servlet.filters.GitHubAuthenticationFilter.java

/**
 * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest,
 *      javax.servlet.ServletResponse, javax.servlet.FilterChain)
 *///from w ww .  j av  a2  s .co m
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    HttpServletRequest httpReq = (HttpServletRequest) request;
    HttpServletResponse httpResp = (HttpServletResponse) response;
    HttpSession session = httpReq.getSession();

    if (httpReq.getServletPath().endsWith("/callback")) {
        String code = httpReq.getParameter("code");
        String state = (String) session.getAttribute(STATE_KEY);

        AccessTokenRequest tokenReq = new AccessTokenRequest();
        tokenReq.setClient_id(clientId);
        tokenReq.setClient_secret(clientSecret);
        tokenReq.setCode(code);
        tokenReq.setState(state);

        try {
            HttpResponse<AccessTokenResponse> tokenResp = Unirest.post(ACCESS_TOKEN_URL)
                    .header("Content-Type", "application/json").header("Accept", "application/json")
                    .body(tokenReq).asObject(AccessTokenResponse.class);

            AccessTokenResponse token = tokenResp.getBody();
            session.setAttribute(RequestAttributeKeys.AUTH_KEY, token);
            User user = authenticateUser(token.getAccess_token());
            session.setAttribute(RequestAttributeKeys.USER_KEY, user);

            String redirectUrl = (String) session.getAttribute(REDIRECT_KEY);
            httpResp.sendRedirect(redirectUrl);
        } catch (UnirestException e) {
            throw new ServletException(e);
        }
    } else if (httpReq.getServletPath().endsWith("/logout")) {
        session.removeAttribute(RequestAttributeKeys.AUTH_KEY);
        session.removeAttribute(RequestAttributeKeys.USER_KEY);

        String logoutPageHtml = createLogoutPage();
        httpResp.setContentType("text/html");
        httpResp.setContentLength(logoutPageHtml.length());
        httpResp.getWriter().print(logoutPageHtml);
        httpResp.getWriter().flush();
    } else {
        AccessTokenResponse token = (AccessTokenResponse) session.getAttribute(RequestAttributeKeys.AUTH_KEY);
        if (token == null) {
            StringBuffer originalAppUrl = httpReq.getRequestURL();
            String qs = httpReq.getQueryString();
            if (qs != null && !qs.isEmpty()) {
                originalAppUrl.append("?").append(qs);
            }
            session.setAttribute(REDIRECT_KEY, originalAppUrl.toString());
            String state = String.valueOf(random.nextInt());
            session.setAttribute(STATE_KEY, state);
            String authUrl = AUTH_URL + clientId + "&state=" + state;

            String loginPageHtml = createLoginPage(authUrl);
            httpResp.setContentType("text/html");
            httpResp.setContentLength(loginPageHtml.length());
            httpResp.getWriter().print(loginPageHtml);
            httpResp.getWriter().flush();
        } else {
            chain.doFilter(request, response);
        }
    }
}

From source file:org.sakaiproject.imagegallery.web.MultiFileUploaderController.java

public ModelAndView singleFileUpload(HttpServletRequest request, HttpServletResponse response)
        throws Exception {
    if (log.isInfoEnabled())
        log.info("req contextPath=" + request.getContextPath() + ", pathInfo=" + request.getPathInfo()
                + ", query=" + request.getQueryString() + ", URI=" + request.getRequestURI() + ", URL="
                + request.getRequestURL() + ", servlet=" + request.getServletPath());
    if (request instanceof MultipartHttpServletRequest) {
        return new ModelAndView(new RedirectView(
                "/site/AddInformationToImages?imageIds=" + storeNewImage((MultipartHttpServletRequest) request),
                true));/*from  w w w.  j  av  a 2  s. c o m*/
    }

    return null;
}

From source file:com.codename1.corsproxy.CORSProxy.java

@Override
protected void copyProxyCookie(HttpServletRequest servletRequest, HttpServletResponse servletResponse,
        Header header) {/*from  ww w  . java2  s .c o  m*/
    List<HttpCookie> cookies = HttpCookie.parse(header.getValue());
    String path = servletRequest.getContextPath(); // path starts with / or is empty string
    path += servletRequest.getServletPath(); // servlet path starts with / or is empty string

    for (HttpCookie cookie : cookies) {
        //set cookie name prefixed w/ a proxy value so it won't collide w/ other cookies
        String proxyCookieName = getCookieNamePrefix() + cookie.getName();
        Cookie servletCookie = new Cookie(proxyCookieName, cookie.getValue());
        servletCookie.setComment(cookie.getComment());
        servletCookie.setMaxAge((int) cookie.getMaxAge());
        servletCookie.setPath(path); //set to the path of the proxy servlet
        // don't set cookie domain
        //servletCookie.setSecure(cookie.getSecure());
        servletCookie.setSecure(false);
        servletCookie.setVersion(cookie.getVersion());
        servletResponse.addCookie(servletCookie);
    }
}

From source file:org.xmatthew.spy2servers.component.web.ComponentsViewServlet.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    String path = request.getServletPath();

    String parameter = request.getParameter("type");
    if (StringUtils.isBlank(parameter)) {
        parameter = "spy";
    }//w  w  w  .ja  v  a 2s . c o  m

    StringBuffer sbuff = new StringBuffer(1000);
    sbuff.append("<a href='").append(path).append("?type=spy'>").append("SpyComponents").append("</a>&nbsp;");
    sbuff.append("<a href='").append(path).append("?type=alert'>").append("AlertComponents")
            .append("</a>&nbsp;");
    sbuff.append("<a href='").append(path).append("?type=channel'>").append("ChannelAwareComponents")
            .append("</a>&nbsp;");
    sbuff.append("<a href='").append(path).append("?type=rule'>").append("AlertRule").append("</a><br>");

    if (componentContext == null) {
        componentContext = getComponentContext();
    }

    response.setContentType("text/html");
    response.setStatus(HttpServletResponse.SC_OK);

    List<Component> components = componentContext.getComponents();
    int size = components.size();

    List<SpyComponent> spyComponents = new ArrayList<SpyComponent>(size);
    List<AlertComponent> alertComponents = new ArrayList<AlertComponent>(size);
    List<MessageAlertChannelActiveAwareComponent> channelAwareComponents;
    channelAwareComponents = new ArrayList<MessageAlertChannelActiveAwareComponent>(size);

    CoreComponent coreComponent = null;
    for (Component component : components) {
        if (component instanceof SpyComponent) {
            spyComponents.add((SpyComponent) component);
        } else if (component instanceof AlertComponent) {
            alertComponents.add((AlertComponent) component);
        } else if (component instanceof MessageAlertChannelActiveAwareComponent) {
            channelAwareComponents.add((MessageAlertChannelActiveAwareComponent) component);
        } else if (component instanceof CoreComponent) {
            coreComponent = (CoreComponent) component;
        }
    }

    sbuff.append("<b>Components list:</b><br><br><br>");

    if ("spy".equals(parameter)) {
        getSpyHtmlView(spyComponents, sbuff);
    } else if ("alert".equals(parameter)) {
        getAlertHtmlView(alertComponents, sbuff);
    } else if ("channel".equals(parameter)) {
        getChannelHtmlView(channelAwareComponents, sbuff);
    } else if ("rule".equals(parameter)) {
        if (coreComponent != null) {
            getAlertRuleHtmlView(coreComponent.getAlertRule(), sbuff);
        }

    }
    response.getWriter().println(sbuff);
}

From source file:com.jnj.b2b.storefront.controllers.misc.StoreSessionController.java

protected String getReturnRedirectUrlWithoutReferer(final HttpServletRequest request) {
    final String originalReferer = (String) request.getSession()
            .getAttribute(StorefrontFilter.ORIGINAL_REFERER);
    if (StringUtils.isNotBlank(originalReferer)) {
        return REDIRECT_PREFIX + originalReferer;
    }// w  ww .  j av  a 2  s .  co  m

    final String referer = StringUtils.remove(request.getRequestURL().toString(), request.getServletPath());
    if (referer != null && !referer.isEmpty()) {
        return REDIRECT_PREFIX + referer;
    }
    return REDIRECT_PREFIX + '/';
}

From source file:com.jsmartframework.web.manager.ServletControl.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String path = request.getServletPath();

    // If path is secure, check if user was logged case @AuthBean annotation was provided
    if (checkAuthentication(path, request, response)) {
        return;//from w ww. ja v a  2 s .  c o m
    }
    // Return if request is for async bean handling
    if (doAsync(path, request, response)) {
        return;
    }
    // If got here the request is for web bean handling
    sendForward(path, request, response);
}