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:com.thinkberg.moxo.dav.MkColHandler.java

public void service(HttpServletRequest request, HttpServletResponse response) throws IOException {
    if (request.getReader().readLine() != null) {
        response.sendError(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE);
        return;// w  w w.  j a  v a2  s .co  m
    }

    FileObject object = getResourceManager().getFileObject(request.getPathInfo());

    try {
        LockManager.getInstance().checkCondition(object, getIf(request));
    } catch (LockException e) {
        if (e.getLocks() != null) {
            response.sendError(SC_LOCKED);
        } else {
            response.sendError(HttpServletResponse.SC_PRECONDITION_FAILED);
        }
        return;
    }

    if (object.exists()) {
        response.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
        return;
    }

    if (!object.getParent().exists() || !FileType.FOLDER.equals(object.getParent().getType())) {
        response.sendError(HttpServletResponse.SC_CONFLICT);
        return;
    }

    try {
        object.createFolder();
        response.setStatus(HttpServletResponse.SC_CREATED);
    } catch (FileSystemException e) {
        response.sendError(HttpServletResponse.SC_FORBIDDEN);
    }
}

From source file:net.riezebos.thoth.servlets.ServletBase.java

protected String getRequestPath(HttpServletRequest request) {
    String servletPath = request.getServletPath();
    String pathInfo = request.getPathInfo();
    return StringUtils.isBlank(pathInfo) ? servletPath : pathInfo;
}

From source file:controllers.ChargesControllerServlet.java

/**
 * Handles the HTTP <code>POST</code> method.
 *
 * @param request servlet request/*from w w w  . jav a  2  s  .  co  m*/
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String product_id = request.getParameter("product_id");
    String token = request.getParameter("conektaTokenId");
    String path = request.getPathInfo();
    String url = path;
    Charge conektaCharge;
    if (url == null || url.equals("/")) {
        Conekta.apiKey = "key_eYvWV7gSDkNYXsmr";
        JSONObject card_payment_params;
        JSONObject valid_visa_card;
        try {
            Product product = Product.find(product_id);
            valid_visa_card = new JSONObject("{'card':'" + token + "'}");
            card_payment_params = new JSONObject("{'description':'" + product.description + "',"
                    + "'reference_id':'" + product.id + "'," + "'amount':"
                    + ((int) Float.parseFloat(product.price) * 100) + "," + "'currency':'MXN'" + "}");
            conektaCharge = Charge.create(card_payment_params.put("card", valid_visa_card.get("card")));
            url = request.getContextPath() + "/charges";
            models.Charge charge = new models.Charge();
            charge.build(conektaCharge.id, conektaCharge.livemode.toString(),
                    conektaCharge.created_at.toString(), conektaCharge.status, conektaCharge.currency,
                    conektaCharge.description, conektaCharge.reference_id, conektaCharge.failure_code,
                    conektaCharge.failure_message, conektaCharge.amount.toString(),
                    ((CardPayment) conektaCharge.payment_method).name,
                    ((CardPayment) conektaCharge.payment_method).exp_month,
                    ((CardPayment) conektaCharge.payment_method).exp_year,
                    ((CardPayment) conektaCharge.payment_method).auth_code,
                    ((CardPayment) conektaCharge.payment_method).last4,
                    ((CardPayment) conektaCharge.payment_method).brand);
            charge.save();

        } catch (Exception ex) {
            Logger.getLogger(ChargesControllerServlet.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    response.sendRedirect(url);
}

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

@Override
public void doPropFind(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException {
    StopWatch sw = new StopWatch();
    sw.start();//w  w w. ja  v  a  2s.c o m

    // Do the "sanitize url" trick
    String p = new String(req.getPathInfo().getBytes("ISO-8859-1"), "UTF-8");

    DavPath path = new DavPath(p);
    if (path.isRoot()) {
        DavMethod dm = new PropFindMethod(m_rootProvider);
        dm.execute(req, res, path);
    } else {
        String context = path.get(0);

        PropFindMethod m = new PropFindMethod(pickProvider(context));
        m.execute(req, res, path.subPath(1));
    }

    sw.stop();

    log.debug("Propfind done for path " + path + ", took " + sw);
}

From source file:mobi.jenkinsci.net.UrlPath.java

public UrlPath(final HttpServletRequest request) {
    this(request.getPathInfo());
}

From source file:com.github.restdriver.clientdriver.unit.ClientDriverHandlerTest.java

/**
 * with no expectations set, and a request made, the handler throws an error upon verification
 *//*from w  w w .  j a v a2s .c  o  m*/
@Test
public void testUnexpectedRequest() throws IOException, ServletException {

    Request mockRequest = mock(Request.class);
    HttpServletRequest mockHttpRequest = mock(HttpServletRequest.class);
    HttpServletResponse mockHttpResponse = mock(HttpServletResponse.class);

    when(mockHttpRequest.getMethod()).thenReturn("POST");
    when(mockHttpRequest.getPathInfo()).thenReturn("yarr");
    when(mockHttpRequest.getQueryString()).thenReturn("gooo=gredge");
    when(mockHttpRequest.getInputStream()).thenReturn(new DummyServletInputStream(IOUtils.toInputStream("")));

    try {
        sut.handle("", mockRequest, mockHttpRequest, mockHttpResponse);
        Assert.fail();
    } catch (ClientDriverFailedExpectationException e) {
        assertThat(e.getMessage(), containsString("1 unexpected request(s):"));
        assertThat(e.getMessage(), containsString("POST yarr; PARAMS: [gooo=[gredge]];"));
    }
}

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

@Override
protected void onHandleRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    if (SiteConfiguration.isDemandEdition()) {
        throw new MyCollabException("This servlet support file system setting only");
    }/*from ww w .j av  a 2  s. 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));
                    throw new ResourceNotFoundException("Invalid path " + path);
                }
            }

            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 {
            throw new ResourceNotFoundException("Invalid path " + path);
        }
    }
}

From source file:com.jaspersoft.jasperserver.rest.services.RESTPermission.java

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServiceException {
    String res = restUtils.extractRepositoryUri(req.getPathInfo());
    try {//www .  j  a  v a  2  s .c o  m
        List<ObjectPermission> permissions = permissionsService.getPermissions(res);
        restUtils.setStatusAndBody(HttpServletResponse.SC_OK, resp, generatePermissionUsingJaxb(permissions));
    } catch (RemoteException e) {
        throw new ServiceException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
                e.getClass().getName() + (e.getMessage() != null ? ": " + e.getMessage() : ""));
    }
}

From source file:org.ngrinder.infra.servlet.ResourceLocationConfigurableJnlpDownloadServlet.java

@Override
public void handleRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    try {/*  w w  w. j av  a 2  s . c o m*/
        // Forward the the request to existing JNLPDownloadServlet.
        LOGGER.debug("JNLP file is downloading : {}", request.getPathInfo());
        if ("GET".equals(request.getMethod())) {
            doGet(request, response);
        } else if ("HEAD".equals(request.getMethod())) {
            doHead(request, response);
        } else {
            doGet(request, response);
        }
    } catch (Exception e) {
        NoOp.noOp();
    }

}

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

/**
 * Really a mapping of /show/ and /change/
 *//*  w ww.ja va2 s  .  co  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);
    }
}