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:edu.harvard.hul.ois.fits.service.servlets.FitsServlet.java

/**
 * Handles the HTTP <code>GET</code> method. There are currently two end point for GET:
 * <ol>/*from w ww .j a v a  2  s  . c om*/
 * <li>/examine -- to have FITS examine a file and return "text/xml" FITS output. Use this when uploading
 * a file locally.</li>
 * <li>/version -- to receive "text/plain" output of the version of FITS being used to process files.</li>
 * </ol>
 * "/examine" requires the path to the file to be analyzed
 * with the request parameter "file" set to location of the file.
 * E.g.: http://<host>[:port]/fits/examine?file=<path/to/file/filename
 * Note: "fits" in the above URL needs to be adjusted to the final name of the WAR file.
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    String servletPath = request.getServletPath(); // gives servlet mapping
    logger.debug("Entering doGet(): " + servletPath);

    // See if path is just requesting version number. If so, just return it.
    if (FITS_RESOURCE_PATH_VERSION.equals(servletPath)) {
        sendFitsVersionResponse(request, response); // outputs version of FITS, not the version of web application
        return;
    }

    // Send it to the FITS processor...
    String filePath = request.getParameter(FITS_FILE_PARAM);

    boolean includeStdOutput = true; // include standard output by default
    String includeStandardMetadata = request.getParameter(INCLUDE_STANDARD_OUTPUT_PARAM);
    if (FALSE.equalsIgnoreCase(includeStandardMetadata)) {
        includeStdOutput = false;
    }

    try {
        sendFitsExamineResponse(filePath, includeStdOutput, request, response);
    } catch (Exception e) {
        logger.error("Unexpected exception: " + e.getMessage(), e);
        ErrorMessage errorMessage = new ErrorMessage(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
                e.getMessage(), request.getRequestURL().toString());
        sendErrorMessageResponse(errorMessage, response);
    }
}

From source file:com.logiclander.jaasmine.authentication.http.SPNegoFilter.java

/**
 * This implementation will filter requests for credentials and determine if
 * processing of the FilterChain can proceed.  Filtering occurs as follows:
 * <OL>/* w  w  w  .j a  v a 2 s. com*/
 *  <LI>If the request is not an HttpServletRequest and the response is not
 * an HttpServletResponse, continue processing the filter chain (this almost
 * never happens)</LI>
 *  <LI>The HttpServletRequest is checked for a {@code WWW-Authenticate}
 * request header.  If found, it is checked for the scheme used, which must
 * be set to {@code Negotiate}.</LI>
 *  <LI>If found, the SPNego token is decoded and validated.  If it is
 * valid, processing is allowed to continue.  If not, processing will stop
 * and an HTTP 401 is returned with a {@code WWW-Authenticate} request
 * header set to {@code Negotiate}.</LI>
 *  <LI>If the request header is not found, an HTTP 401 is returned with a
 * {@code WWW-Authenticate} request header set to {@code Negotiate}.</LI>
 * </OL>
 *
 * @param request the ServletRequest
 * @param response the ServletResponse
 * @param chain the FilterChain
 * @throws IOException if an I/O error occurs in the FilterChain
 * @throws ServletException if a processing error occurs in the FilterChain
 */
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {

    if (logger.isDebugEnabled()) {
        logger.debug(String.format("%s: entering doFilter", filterName));
    }

    if (!(request instanceof HttpServletRequest) && !(response instanceof HttpServletResponse)) {

        chain.doFilter(request, response);

    } else {

        HttpServletRequest httpReq = (HttpServletRequest) request;
        HttpServletResponse httpResp = (HttpServletResponse) response;

        if (logger.isDebugEnabled()) {
            logger.debug(String.format("Filtering request: %s%s", httpReq.getContextPath(),
                    httpReq.getServletPath()));
        }

        String sPNegoToken = getSPNegoToken(httpReq);
        boolean canExecute = false;
        SPNegoServer server = null;

        try {

            server = new SPNegoServer(sPNegoToken);
            canExecute = server.isValidToken();

            // Wrap the HttpServletRequest with the requester's GSSName
            // so that additional processing can take place w/out having
            // to re-examine the SPNego token.
            httpReq = new JaasmineHttpServletRequest(httpReq, server.getRequesterName());

        } catch (GSSException ex) {

            if (logger.isDebugEnabled()) {

                logger.debug("Problem with SPNego token", ex);

            } else {

                logger.info(String.format("Problem with SPNego token: %s", ex.getMessage()));

            }

            canExecute = false;

        } catch (Exception ex) {

            if (logger.isFatalEnabled()) {
                logger.fatal(ex.getMessage(), ex);
            }

            canExecute = false;

        }

        if (canExecute) {

            chain.doFilter(httpReq, httpResp);

        } else {

            if (!httpResp.isCommitted()) {
                httpResp.setHeader("WWW-Authenticate", "Negotiate");
                httpResp.sendError(HttpServletResponse.SC_UNAUTHORIZED);
                return;
            }

        }
    }
}

From source file:com.spring.tutorial.controllers.DefaultController.java

@RequestMapping(value = "/my-drive/dropbox/**", method = RequestMethod.GET)
public String dropbox(HttpServletRequest request, ModelMap map) throws DbxException, IOException, Exception {
    String path = request.getServletPath()
            .substring(request.getServletPath().indexOf("/my-drive/dropbox/") + 17);

    map.addAttribute("title", "dropbox");

    HttpSession session = request.getSession();

    if (request.getSession().getAttribute("dropbox_token") != null) {
        config = new DbxRequestConfig("JavaTutorial/1.0", Locale.getDefault().toString());
        DropboxEntityFactory dbxFactory = new DropboxEntityFactory();

        if (path.equals("/home")) {
            map.addAttribute("dropbox_entities",
                    dbxFactory.getFilesAndFolders((String) session.getAttribute("id"), "/"));
        } else {/*from w  w  w  .  jav a2s.com*/
            map.addAttribute("dropbox_entities", dbxFactory.getFilesAndFolders(
                    (String) session.getAttribute("id"), URLDecoder.decode(path, "UTF-8") + "/"));
        }
        if (path.equals("/home")) {
            map.addAttribute("url_path", "home");
        } else {
            map.addAttribute("url_path", ("home" + URLDecoder.decode(path, "UTF-8")).split("/"));
        }
    }
    return "mydrive/dropbox";
}

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

protected String getReturnRedirectUrlForUrlEncoding(final HttpServletRequest request, final String old,
        final String current) {
    final String originalReferer = (String) request.getSession()
            .getAttribute(StorefrontFilter.ORIGINAL_REFERER);
    if (StringUtils.isNotBlank(originalReferer)) {
        return REDIRECT_PREFIX + StringUtils.replace(originalReferer, "/" + old + "/", "/" + current + "/");
    }//from w w w  . j  av a  2s . co  m

    String referer = StringUtils.remove(request.getRequestURL().toString(), request.getServletPath());
    if (!StringUtils.endsWith(referer, "/")) {
        referer = referer + "/";
    }
    if (referer != null && !referer.isEmpty() && StringUtils.contains(referer, "/" + old)) {
        return REDIRECT_PREFIX + StringUtils.replace(referer, "/" + old, "/" + current);
    }
    return REDIRECT_PREFIX + referer;
}

From source file:edu.cornell.mannlib.vitro.webapp.controller.freemarker.FreemarkerHttpServlet.java

private String getCurrentPageUrl(HttpServletRequest request) {
    String path = request.getServletPath().replaceFirst("/", "");
    String pathInfo = request.getPathInfo();
    if (pathInfo != null) {
        path += pathInfo;/*from   w ww . ja va 2 s.  c  om*/
    }
    path = normalizeServletName(path);
    return UrlBuilder.getUrl(path);
}

From source file:net.riezebos.thoth.testutil.ThothTestBase.java

protected HttpServletRequest createHttpRequest(String contextName, String path) throws IOException {
    String fullPath = ThothUtil.prefix(contextName, "/") + path;
    HttpServletRequest request = mock(HttpServletRequest.class);
    when(request.getRequestURI()).thenReturn(path);
    when(request.getContextPath()).thenReturn(ThothUtil.prefix(contextName, "/"));
    when(request.getServletPath()).thenReturn(path);
    when(request.getPathInfo()).thenReturn(fullPath);
    when(request.getParameterNames()).thenReturn(getParameterNames());
    recordGetParameter(request);// www .  j  a  va  2 s .  co m
    return request;
}

From source file:ca.flop.jpublish.dwr.DWRUrlProcessor.java

public void handle(JPublishContext context) throws IOException {
    HttpServletRequest request = context.getRequest();
    HttpServletResponse response = context.getResponse();
    try {/*from  ww  w  . j a  va  2s.  com*/
        String pathInfo = LocalUtil.replace(request.getPathInfo(), (String) context.get("dwrPathPrefix"), "");
        //String pathInfo = request.getPathInfo();

        if (pathInfo == null || pathInfo.length() == 0 || pathInfo.equals("/")) {
            response.sendRedirect(request.getContextPath() + request.getServletPath() + indexHandlerUrl);
        } else {
            // Loop through all the known URLs
            for (Iterator it = urlMapping.entrySet().iterator(); it.hasNext();) {
                Map.Entry entry = (Map.Entry) it.next();
                String url = (String) entry.getKey();

                // If this URL matches, call the handler
                if (pathInfo.startsWith(url)) {
                    Handler handler = (Handler) entry.getValue();
                    handler.handle(request, response);
                    context.setStopProcessing();
                    return;
                }
            }

            notFoundHandler.handle(request, response);
        }
    } catch (Exception ex) {
        exceptionHandler.setException(ex);
        exceptionHandler.handle(request, response);
    }
}

From source file:de.fau.amos4.web.LoginFormController.java

@RequestMapping("/client/submit")
public String ClientSubmit(HttpServletRequest request, @ModelAttribute(value = "client") Client client)
        throws MessagingException {
    // Generate new confirmation string for the client
    client.generateConfirmationString();
    // Set client to inactive
    client.setActivated(false);//from  w  ww  .  ja  v  a2 s .c o m
    // Save new, in-activate client
    clientRepository.save(client);

    // Prepare and send email
    String contextPath = "http://" + request.getServerName() + ":" + request.getServerPort()
            + request.getServletPath().replace("/client/submit", "/client/confirm");
    String ConfirmationCode = client.getConfirmationString();
    // TODO: Replace this with Thymeleaf based tample generated content
    String Content = "<a href='" + contextPath + "?id=" + client.getId() + "&confirmation=" + ConfirmationCode
            + "'>Confirm my email address.</a>";
    EmailSender sender = new EmailSender();
    sender.SendEmail(client.getEmail(), "Personalragebogen 2.0 - Confirmation", Content, null, null);

    // Display login screen after
    return "redirect:/?m=registered";
}