Example usage for javax.servlet.http HttpServletRequest getPathInfo

List of usage examples for javax.servlet.http HttpServletRequest getPathInfo

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletRequest getPathInfo.

Prototype

public String getPathInfo();

Source Link

Document

Returns any extra path information associated with the URL the client sent when it made this request.

Usage

From source file:ch.entwine.weblounge.kernel.security.UserContextFilter.java

/**
 * {@inheritDoc}/*  w w  w .  ja va  2  s  . c  o  m*/
 * 
 * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest,
 *      javax.servlet.ServletResponse, javax.servlet.FilterChain)
 */
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {

    // Make sure we have a site
    Site site = securityService.getSite();
    if (site == null)
        throw new IllegalStateException("Site context is not available at user lookup");

    User user = null;

    // Extract the user from the request
    if (request instanceof HttpServletRequest) {
        HttpServletRequest httpRequest = (HttpServletRequest) request;
        user = getUser(site);
        if (user != null)
            logger.debug("Processing {} as user '{}'", httpRequest.getPathInfo(), site.getIdentifier());
        else
            logger.debug("No user found for request to {}", httpRequest.getPathInfo());
    }

    // Set the site and the user on the request
    securityService.setUser(user);

    chain.doFilter(request, response);

    // Make sure the thread is not associated with the site or the user anymore
    securityService.setUser(null);
}

From source file:ch.entwine.weblounge.kernel.fop.FopEndpoint.java

/**
 * Returns the endpoint documentation./* w  ww.j a v  a  2  s  .  c o m*/
 * 
 * @return the endpoint documentation
 */
@GET
@Path("/docs")
@Produces(MediaType.TEXT_HTML)
public String getDocumentation(@Context HttpServletRequest request) {
    if (docs == null) {
        String docsPath = request.getRequestURI();
        String docsPathExtension = request.getPathInfo();
        String servicePath = request.getRequestURI().substring(0,
                docsPath.length() - docsPathExtension.length());
        docs = FopEndpointDocs.createDocumentation(servicePath);
    }
    return docs;
}

From source file:com.ecyrd.jspwiki.dav.WikiDavServlet.java

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
    // Do the "sanitize url" trick
    // String p = new String(req.getPathInfo().getBytes("ISO-8859-1"), "UTF-8");

    String p = req.getPathInfo();

    DavPath path = new DavPath(p);

    if (path.isRoot()) {
        DavMethod dm = new GetMethod(m_rootProvider);
        dm.execute(req, res, path);//from   w ww  . j  ava2  s  . c o m
    } else {
        DavMethod dm = new GetMethod(pickProvider(path.get(0)));

        dm.execute(req, res, path.subPath(1));
    }
}

From source file:com.example.cloud.bigtable.helloworld.JsonServlet.java

/**
 * doDelete - Delete REST verb -- deletes the entire ROW -- All Versions.
 **//*w ww  .  j ava 2  s  . c o m*/
@Override
protected void doDelete(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    String path = req.getPathInfo();
    log("doDelete-" + path);
    if (path.length() < 5) {
        resp.sendError(HttpServletResponse.SC_BAD_REQUEST);
        log("doDelete-bad length-" + path + "(" + path.length() + ")");
        return;
    }

    // IMPORTANT - This try() is a java7 try w/ resources which will close() the table at the end.
    try (Table t = BigtableHelper.getConnection().getTable(TABLE)) {
        resp.setContentType("application/json");
        JSONObject json = new JSONObject();
        Delete d = new Delete(Bytes.toBytes(path.substring(1))); // Delete the ROW
        t.delete(d);
    } catch (Exception e) {
        log("doDelete", e);
        resp.sendError(HttpServletResponse.SC_BAD_REQUEST);
        return;
    }
    resp.addHeader("Access-Control-Allow-Origin", "*");
    resp.setStatus(HttpServletResponse.SC_OK);
}

From source file:gov.nih.nci.ncicb.tcga.dcc.common.web.StaticContentServlet.java

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

    final String rawResourcePath = request.getServletPath() + request.getPathInfo();

    if (log.isDebugEnabled()) {
        log.debug("Attempting to GET resource: " + rawResourcePath);
    }/*from w  w  w.  j  a  v  a2  s.com*/
    final URL[] resources = getRequestResourceURLs(request);
    if (resources == null || resources.length == 0) {
        if (log.isDebugEnabled()) {
            log.debug("Resource not found: " + rawResourcePath);
        }
        response.sendError(HttpServletResponse.SC_NOT_FOUND); //Error 404
        return;
    }
    //Render the resource as-is with a stream
    prepareResponse(response, resources, rawResourcePath);
    final OutputStream out = response.getOutputStream();
    try {
        for (int i = 0; i < resources.length; i++) {
            final URLConnection resourceConn = resources[i].openConnection();
            final InputStream in = resourceConn.getInputStream();
            try {
                byte[] buffer = new byte[1024];
                int bytesRead = -1;
                while ((bytesRead = in.read(buffer)) != -1) {
                    out.write(buffer, 0, bytesRead);
                }
            } finally {
                in.close();
            }
        }
    } finally {
        out.close();
    }
}

From source file:com.esofthead.mycollab.module.file.servlet.UserAvatarHttpServletRequestHandler.java

@Override
protected void onHandleRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    if (!StorageFactory.getInstance().isFileStorage()) {
        throw new MyCollabException("This servlet support file system setting only");
    }//  w  w  w  .j a va2s . c  o m

    String path = request.getPathInfo();

    if (path != null) {
        path = FilenameUtils.getBaseName(path);
        int lastIndex = path.lastIndexOf("_");
        if (lastIndex > 0) {
            String username = path.substring(0, lastIndex);
            int size = Integer.valueOf(path.substring(lastIndex + 1, path.length()));
            FileStorage fileStorage = (FileStorage) StorageFactory.getInstance();
            File avatarFile = fileStorage.getAvatarFile(username, size);
            InputStream avatarInputStream;
            if (avatarFile != null) {
                avatarInputStream = new FileInputStream(avatarFile);
            } else {
                String userAvatarPath = String.format("assets/icons/default_user_avatar_%d.png", size);
                avatarInputStream = UserAvatarHttpServletRequestHandler.class.getClassLoader()
                        .getResourceAsStream(userAvatarPath);
                if (avatarInputStream == null) {
                    LOG.error("Error to get avatar",
                            new MyCollabException("Invalid request for avatar " + path));
                    return;
                }
            }

            response.setHeader("Content-Type", "image/png");
            response.setHeader("Content-Length", String.valueOf(avatarInputStream.available()));

            try (BufferedInputStream input = new BufferedInputStream(avatarInputStream);
                    BufferedOutputStream output = new BufferedOutputStream(response.getOutputStream())) {
                byte[] buffer = new byte[8192];
                int length;
                while ((length = input.read(buffer)) > 0) {
                    output.write(buffer, 0, length);
                }
            }
        } else {
            LOG.error("Invalid path " + path);
        }
    }
}

From source file:com.mothsoft.alexis.web.ChartServlet.java

/**
 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
 *      response)//from w  w  w .jav a2  s  . com
 */
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    final String[] pathComponents = request.getPathInfo().split("/");
    final String graphType = pathComponents[1];

    if ("line".equals(graphType)) {

        final String[] dataSets = request.getParameterValues("ds");

        final String w = request.getParameter("w");
        final Integer width = w == null ? 405 : Integer.valueOf(w);

        final String h = request.getParameter("h");
        final Integer height = h == null ? 325 : Integer.valueOf(h);

        final String n = request.getParameter("n");
        final Integer numberOfSamples = n == null ? 12 : Integer.valueOf(n);

        final String title = request.getParameter("title");

        final long start = System.currentTimeMillis();
        doLineGraph(request, response, title, dataSets, width, height, numberOfSamples);
        logger.debug("Graph took: " + (System.currentTimeMillis() - start) + " milliseconds");
    }
}

From source file:edu.cornell.mannlib.oce.servlets.MainController.java

public MainControllerCore(HttpServletRequest req, HttpServletResponse resp) {
    this.req = req;
    this.resp = resp;
    this.loginId = req.getHeader(HEADER_NAME);
    this.pathInfo = req.getPathInfo();
    log.debug("NetID=" + loginId + ", pathInfo=" + pathInfo);

    this.occ = OrcidClientContext.getInstance();
    this.authManager = this.occ.getAuthorizationManager(req);
    this.authStatus = authManager.getAuthorizationStatus(AUTHENTICATE);
    log.debug("AuthStatus: " + authStatus);
}

From source file:edu.cornell.mannlib.vitro.webapp.controller.datatools.dumprestore.DumpRestoreController.java

@Override
public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
    if (!PolicyHelper.isAuthorizedForActions(req, REQUIRED_ACTION)) {
        resp.sendError(HttpServletResponse.SC_FORBIDDEN);
    }//from   w ww  .  ja v a 2s .c om

    try {
        if (ACTION_RESTORE.equals(req.getPathInfo())) {
            long tripleCount = new RestoreModelsAction(req, resp).restoreModels();
            req.setAttribute(ATTRIBUTE_TRIPLE_COUNT, tripleCount);
            super.doGet(req, resp);
        } else {
            resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
        }
    } catch (BadRequestException | RDFServiceException e) {
        throw new RuntimeException(e);
    }
}

From source file:org.n52.iceland.service.Service.java

/**
 * Get the implementation of {@link Binding} that is registered for the
 * given <code>request</code>.
 *
 * @param request//from  ww  w  . j  a  v a 2 s .c o  m
 *            URL pattern from request URL
 *
 * @return The implementation of {@link Binding} that is registered for the
 *         given <code>urlPattern</code>.
 *
 *
 * @throws HTTPException If the URL pattern or ContentType is not supported
 *                       by this service.
 */
private Binding getBinding(HttpServletRequest request) throws HTTPException {
    final String requestURI = request.getPathInfo();
    if (requestURI == null || requestURI.isEmpty() || requestURI.equals("/")) {
        MediaType contentType = getContentType(request);
        // strip of the parameters to get rid of things like encoding
        Binding binding = this.bindingRepository.getBinding(contentType.withoutParameters());
        if (binding == null) {
            if (contentType.equals(MediaTypes.APPLICATION_KVP)) {
                throw new HTTPException(HTTPStatus.METHOD_NOT_ALLOWED);
            } else {
                throw new HTTPException(HTTPStatus.UNSUPPORTED_MEDIA_TYPE);
            }
        } else {
            return binding;
        }
    }

    for (String prefix : this.bindingRepository.getAllBindingsByPath().keySet()) {
        if (requestURI.startsWith(prefix)) {
            return this.bindingRepository.getBinding(prefix);
        }
    }
    throw new HTTPException(HTTPStatus.NOT_FOUND);
}