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.rometools.propono.atom.server.impl.FileBasedAtomHandler.java

/**
 * Contruct handler for one request, using specified file storage directory.
 *
 * @param req Request to be handled.//from w  w  w.  j  av  a2s.  com
 * @param uploaddir File storage upload dir.
 */
public FileBasedAtomHandler(final HttpServletRequest req, final String uploaddir) {
    LOG.debug("ctor");

    userName = authenticateBASIC(req);

    atomProtocolURL = req.getScheme() + "://" + req.getServerName() + ":" + req.getServerPort()
            + req.getContextPath() + req.getServletPath();

    contextURI = req.getScheme() + "://" + req.getServerName() + ":" + req.getServerPort()
            + req.getContextPath();

    try {
        service = new FileBasedAtomService(userName, uploaddir, contextURI, req.getContextPath(),
                req.getServletPath());
    } catch (final Throwable t) {
        throw new RuntimeException("ERROR creating FileBasedAtomService", t);
    }
}

From source file:org.semispace.semimeter.controller.CounterController.java

/**
 * Really a mapping of /show/ and /change/
 *///from  w  ww. ja v  a 2 s.  c  o  m
@RequestMapping("/**")
public String entry(HttpServletRequest req, Model model, @RequestParam String resolution) {
    // PathInfo is the string behind "show", so "show/x" is "/x"
    String path = req.getPathInfo();
    if (path == null) {
        path = "";
    }

    if (!isSane(path)) {
        throw new RuntimeException("Disallowed character found in query.");
    }

    // It is slightly tricky to get spring to map separate general paths, so this must be done manually
    if ("/change".equals(req.getServletPath())) {
        return displayChange(path, model, resolution);
    } else {
        // Default to show
        return displayCurrent(path, model, resolution);
    }
}

From source file:com.octo.captcha.j2ee.servlet.ImageCaptchaFilter.java

/**
 * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest,
 *                                    javax.servlet.ServletResponse,
 *                                    javax.servlet.FilterChain)
 */// w w w  . j  a  va2  s.c o m
public void doFilter(final ServletRequest theRequest, final ServletResponse theResponse,
        final FilterChain theFilterChain) throws IOException, ServletException {
    HttpServletRequest request = (HttpServletRequest) theRequest;
    HttpServletResponse response = (HttpServletResponse) theResponse;

    // Get the URL the user asked for
    String servletPathInfo = request.getServletPath();

    if (servletPathInfo.equals(this.captchaRenderingURL)) {
        // This is the URL used to ask for captcha generation : do it !
        this.generateAndRenderCaptcha(request, response);
    } else if (this.verificationForwards.containsKey(servletPathInfo)) {
        // This is the URL used to ask for captcha challenge verification :
        // do it !
        this.verifyAnswerToACaptchaChallenge(request, response, servletPathInfo, theFilterChain);
    } else {
        // follow to the filter chain...
        theFilterChain.doFilter(theRequest, theResponse);
    }
}

From source file:be.dnsbelgium.rdap.servlet.LoggerFilter.java

@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain)
        throws IOException, ServletException {
    HttpServletRequest request = (HttpServletRequest) servletRequest;
    StatusExposingServletResponse response = new StatusExposingServletResponse(
            (HttpServletResponse) servletResponse);
    try {//  w  w w  .jav  a2s.c  o  m
        chain.doFilter(servletRequest, response);
    } finally {
        String currentUser = null;
        try {
            currentUser = SecurityContextHolder.getContext().getAuthentication().getName();
        } catch (NullPointerException npe) {
            LOGGER.debug("No SecurityContext", npe);
        }
        LOGGER.info("{} {} {} {}", request.getRemoteAddr(), currentUser, request.getServletPath(),
                response.getStatus());
    }
}

From source file:org.openqa.grid.internal.TestSession.java

private void processResponseHeaders(HttpServletRequest request, HttpServletResponse response, URL remoteURL,
        HttpResponse proxyResponse) throws MalformedURLException {
    String pathSpec = request.getServletPath() + request.getContextPath();
    for (Header header : proxyResponse.getAllHeaders()) {
        String name = header.getName();
        String value = header.getValue();

        // HttpEntity#getContent() chews up the chunk-size octet (i.e., the InputStream does not
        // actually map 1:1 to the underlying response body). This breaks any client expecting the
        // chunk size. We could
        // try to recreate it, but since the chunks are already read in and decoded, you'd end up with
        // a//from www .  j  a  v  a2 s.  c  o m
        // single chunk, which isn't all that useful. So, we return the response as a traditional
        // response with a
        // Content-Length header, obviating the need for the Transfer-Encoding header.
        if (name.equalsIgnoreCase("Transfer-Encoding") && value.equalsIgnoreCase("chunked")) {
            continue;
        }

        // the location needs to point to the hub that will proxy
        // everything.
        if (name.equalsIgnoreCase("Location")) {
            URL returnedLocation = new URL(value);
            String driverPath = remoteURL.getPath();
            String wrongPath = returnedLocation.getPath();
            String correctPath = wrongPath.replace(driverPath, "");
            Hub hub = slot.getProxy().getRegistry().getHub();
            String location = "http://" + hub.getHost() + ":" + hub.getPort() + pathSpec + correctPath;
            response.setHeader(name, location);
        } else {
            response.setHeader(name, value);
        }
    }
}

From source file:com.mirth.connect.server.servlets.WebStartServlet.java

@Override
public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    // MIRTH-1745
    response.setCharacterEncoding("UTF-8");

    try {//  w w  w .j a  va 2  s  . c  o  m
        response.setContentType("application/x-java-jnlp-file");
        response.setHeader("Pragma", "no-cache");
        PrintWriter out = response.getWriter();
        Document jnlpDocument = null;

        if (request.getServletPath().equals("/webstart.jnlp") || request.getServletPath().equals("/webstart")) {
            jnlpDocument = getAdministratorJnlp(request);
        } else if (request.getServletPath().equals("/webstart/extensions")) {
            String extensionPath = StringUtils.removeEnd(StringUtils.removeStart(request.getPathInfo(), "/"),
                    ".jnlp");
            jnlpDocument = getExtensionJnlp(extensionPath);
        }

        DocumentSerializer docSerializer = new DocumentSerializer(true);
        docSerializer.toXML(jnlpDocument, out);
    } catch (RuntimeIOException rio) {
        logger.debug(rio);
    } catch (Throwable t) {
        logger.error(ExceptionUtils.getStackTrace(t));
        throw new ServletException(t);
    }
}

From source file:com.googlesource.gerrit.plugins.github.wizard.VelocityControllerServlet.java

@SuppressWarnings("unchecked")
@Override/*from   w  w w.j  a v a  2 s. co  m*/
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    String controllerName;
    VelocityController controller;
    controllerName = getControllerClassName(req);

    try {
        Class<? extends VelocityController> controllerClass = (Class<? extends VelocityController>) Class
                .forName(CONTROLLER_PACKAGE + "." + controllerName + "Controller");
        controller = injector.getInstance(controllerClass);
    } catch (ClassNotFoundException e) {
        log.debug("Cannot find any controller for servlet " + req.getServletPath());
        redirectToNextStep(req, resp);
        return;
    }

    GitHubLogin hubLogin = loginProvider.get(req);
    IdentifiedUser user = userProvider.get();
    WrappedResponse wrappedResp = new WrappedResponse(resp);
    controller.doAction(user, hubLogin, req, wrappedResp, errorsProvider.get());

    if (wrappedResp.getStatus() == 0 || wrappedResp.getStatus() == HttpStatus.SC_OK) {
        redirectToNextStep(req, resp);
    }
}

From source file:edu.stanford.muse.webapp.JSPHelper.java

public static void logRequestComplete(HttpServletRequest request) {
    log.info("COMPLETED " + getRequestDescription(request, true));
    String page = request.getServletPath();
    Thread.currentThread().setName("done-" + page);
}

From source file:de.micromata.genome.tpsb.httpmockup.MockServletContext.java

public void serveServlet(final HttpServletRequest req, final HttpServletResponse resp)
        throws IOException, ServletException {
    String uri = req.getRequestURI();
    String localUri = uri;//from w w w . j  av  a  2  s  .  co m
    if (StringUtils.isNotBlank(req.getServletPath()) == true) {
        if (StringUtils.isNotBlank(req.getPathInfo()) == true) {
            localUri = req.getServletPath() + req.getPathInfo();
        } else {
            localUri = req.getServletPath();
        }
    }
    MockServletMapDef map = this.servletsConfig.getServletMappingByPath(localUri);
    if (map == null) {
        map = this.servletsConfig.getServletMappingByPath(uri);
    }
    if (map != null) {
        log.debug("Serve Servlet: " + map.getServletDef().getServlet().getClass().getName());
        map.getServletDef().getServlet().service(req, resp);
    } else {
        log.warn("No servlet found for request: " + req.getRequestURL().toString());
    }
}

From source file:net.lightbody.bmp.proxy.jetty.servlet.AdminServlet.java

private Element lifeCycle(HttpServletRequest request, String id, LifeCycle lc, String name) {
    Composite comp = new Composite();
    comp.add(new Target(id));
    Font font = new Font();
    comp.add(font);/*from   w ww .ja  v  a 2s .co m*/
    font.color(lc.isStarted() ? "green" : "red");
    font.add(name);

    String action = lc.isStarted() ? "Stop" : "Start";

    comp.add("&nbsp;[");
    comp.add(new Link(URI.addPaths(request.getContextPath(), request.getServletPath()) + "?T="
            + Long.toString(System.currentTimeMillis(), 36) + "&A=" + action + "&ID="
            + UrlEncoded.encodeString(id), action));
    comp.add("]");
    return comp;
}