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:org.trpr.platform.batch.impl.spring.web.JobConfigController.java

/**
 * Finds the jobname from the request URL
 *//*from w w  w . j  av  a 2  s  . c  om*/
@ModelAttribute("jobName")
public String getJobName(HttpServletRequest request) {
    String path = request.getPathInfo();
    int index = path.lastIndexOf("jobs/") + 5;
    if (index >= 0) {
        path = path.substring(index);
    }
    return path;
}

From source file:org.eclipse.jgit.lfs.server.fs.FileLfsServlet.java

/**
 * Retrieve object id from request/*  w  w  w  .java 2 s  .  c o m*/
 *
 * @param req
 *            servlet request
 * @param rsp
 *            servlet response
 * @return object id, or <code>null</code> if the object id could not be
 *         retrieved
 * @throws IOException
 *             if an I/O error occurs
 * @since 4.6
 */
protected AnyLongObjectId getObjectToTransfer(HttpServletRequest req, HttpServletResponse rsp)
        throws IOException {
    String info = req.getPathInfo();
    int length = 1 + Constants.LONG_OBJECT_ID_STRING_LENGTH;
    if (info.length() != length) {
        sendError(rsp, HttpStatus.SC_UNPROCESSABLE_ENTITY,
                MessageFormat.format(LfsServerText.get().invalidPathInfo, info));
        return null;
    }
    try {
        return LongObjectId.fromString(info.substring(1, length));
    } catch (InvalidLongObjectIdException e) {
        sendError(rsp, HttpStatus.SC_UNPROCESSABLE_ENTITY, e.getMessage());
        return null;
    }
}

From source file:org.pentaho.plugin.j2ee.EnunciateJerseyPluginServlet.java

@Override
public void service(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    logger.debug("servicing request for resource " + request.getPathInfo()); //$NON-NLS-1$
    //Strip out the content generator id from the URL here so Jersey can match the @Path of the resource
    HttpServletRequestWrapper wrapper = new HttpServletRequestWrapper(request) {

        @Override// www .  j  av a  2  s  . c om
        public String getRequestURI() {
            String uri = super.getRequestURI().replace("content/", "");
            return uri;
        }

        @Override
        public StringBuffer getRequestURL() {
            String url = super.getRequestURL().toString();
            return new StringBuffer(url.replace("content/", ""));
        }

    };
    super.service(wrapper, response);
}

From source file:de.xwic.appkit.webbase.modules.ModuleProviderServlet.java

/**
 * user name from request path/*from  w  w w . ja  va 2 s .  co  m*/
 *
 * @param req
 * @param resp
 * @return
 * @throws IOException
 */
private String getUserNameFromPath(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    final String pathInfo = req.getPathInfo();
    if (pathInfo == null || pathInfo.isEmpty()) {
        notFound(USER_NOT_FOUND_ERROR_MESSAGE, resp);
        return null;
    }
    return pathInfo.replaceFirst("/", "");
}

From source file:com.thinkberg.moxo.dav.PropPatchHandler.java

public void service(HttpServletRequest request, HttpServletResponse response) throws IOException {
    FileObject object = getResourceManager().getFileObject(request.getPathInfo());

    try {//w w  w  .  j a  v  a2s .co  m
        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;
    }

    SAXReader saxReader = new SAXReader();
    try {
        Document propDoc = saxReader.read(request.getInputStream());
        //      log(propDoc);

        response.setContentType("text/xml");
        response.setCharacterEncoding("UTF-8");
        response.setStatus(SC_MULTI_STATUS);

        if (object.exists()) {
            Document resultDoc = DocumentHelper.createDocument();
            Element multiStatusResponse = resultDoc.addElement("multistatus", "DAV:");
            Element responseEl = multiStatusResponse.addElement("response");
            try {
                URL url = new URL(getBaseUrl(request), URLEncoder.encode(object.getName().getPath(), "UTF-8"));
                log("!! " + url);
                responseEl.addElement("href").addText(url.toExternalForm());
            } catch (Exception e) {
                e.printStackTrace();
            }

            Element propstatEl = responseEl.addElement("propstat");
            Element propEl = propstatEl.addElement("prop");

            Element propertyUpdateEl = propDoc.getRootElement();
            for (Object elObject : propertyUpdateEl.elements()) {
                Element el = (Element) elObject;
                if ("set".equals(el.getName())) {
                    for (Object propObject : el.elements()) {
                        setProperty(propEl, object, (Element) propObject);
                    }
                } else if ("remove".equals(el.getName())) {
                    for (Object propObject : el.elements()) {
                        removeProperty(propEl, object, (Element) propObject);
                    }
                }
            }
            propstatEl.addElement("status").addText(DavResource.STATUS_403);

            //        log(resultDoc);

            // write the actual response
            XMLWriter writer = new XMLWriter(response.getWriter(), OutputFormat.createCompactFormat());
            writer.write(resultDoc);
            writer.flush();
            writer.close();
        } else {
            log("!! " + object.getName().getPath() + " NOT FOUND");
            response.sendError(HttpServletResponse.SC_NOT_FOUND);
        }
    } catch (DocumentException e) {
        log("!! inavlid request: " + e.getMessage());
        response.sendError(HttpServletResponse.SC_BAD_REQUEST);
    }
}

From source file:com.jaspersoft.jasperserver.rest.RESTAbstractService.java

protected void doDelete(HttpServletRequest req, HttpServletResponse resp) throws ServiceException {
    log.error(//from www  .j av a2  s .  co m
            "Method DELETE is not supported for this object type - request params: Path: " + req.getPathInfo());
    restUtils.setStatusAndBody(HttpServletResponse.SC_METHOD_NOT_ALLOWED, resp,
            "Method not supported for this object type");
}

From source file:edu.mayo.cts2.framework.plugin.web.editor.StaticHttpService.java

/**
 * Service the request. The only path recognized by this servlet is
 * \/editor/console - all others will be delegated to OSGi resource handling.
 *
 * @param request the request//from   www .ja  va2 s .c om
 * @param response the response
 * @throws ServletException the servlet exception
 * @throws IOException Signals that an I/O exception has occurred.
 */
private void service(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    // check whether we are not at .../{webManagerRoot}
    final String pathInfo = request.getPathInfo();

    if (pathInfo.equals("/console")) {
        InputStream in = this.getClass().getResourceAsStream("/index.html");

        response.setContentType("text/html");

        IOUtils.copy(in, response.getWriter());
    }
}

From source file:com.novartis.pcs.ontology.rest.servlet.GraphServlet.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String pathInfo = StringUtils.trimToNull(request.getPathInfo());
    String orientation = StringUtils.trimToNull(request.getParameter("orientation"));
    String callback = StringUtils.trimToNull(request.getParameter("callback"));
    String mediaType = getExpectedMediaType(request);

    if (pathInfo != null && pathInfo.length() > 1) {
        String termRefId = pathInfo.substring(1);
        graph(termRefId, mediaType, orientation, callback, response);
    } else {//from   w  ww  .  java 2s.  c o  m
        response.setStatus(HttpServletResponse.SC_NOT_FOUND);
        response.setContentLength(0);
    }
}

From source file:com.thinkberg.webdav.PropPatchHandler.java

/**
 * Handle a PROPPATCH request./*w  w w .ja v  a 2  s.  c  om*/
 *
 * @param request  the servlet request
 * @param response the servlet response
 * @throws IOException if there is an error that cannot be handled normally
 */
public void service(HttpServletRequest request, HttpServletResponse response) throws IOException {
    FileObject object = VFSBackend.resolveFile(request.getPathInfo());

    try {
        if (!LockManager.getInstance().evaluateCondition(object, getIf(request)).result) {
            response.sendError(HttpServletResponse.SC_PRECONDITION_FAILED);
            return;
        }
    } catch (LockException e) {
        response.sendError(SC_LOCKED);
        return;
    } catch (ParseException e) {
        response.sendError(HttpServletResponse.SC_PRECONDITION_FAILED);
        return;
    }

    if (object.exists()) {
        SAXReader saxReader = new SAXReader();
        try {
            Document propDoc = saxReader.read(request.getInputStream());
            logXml(propDoc);

            Element propUpdateEl = propDoc.getRootElement();
            List<Element> requestedProperties = new ArrayList<Element>();
            for (Object elObject : propUpdateEl.elements()) {
                Element el = (Element) elObject;
                String command = el.getName();
                if (AbstractDavResource.TAG_PROP_SET.equals(command)
                        || AbstractDavResource.TAG_PROP_REMOVE.equals(command)) {
                    for (Object propElObject : el.elements()) {
                        for (Object propNameElObject : ((Element) propElObject).elements()) {
                            Element propNameEl = (Element) propNameElObject;
                            requestedProperties.add(propNameEl);
                        }
                    }
                }
            }

            // respond as XML encoded multi status
            response.setContentType("text/xml");
            response.setCharacterEncoding("UTF-8");
            response.setStatus(SC_MULTI_STATUS);

            Document multiStatusResponse = getMultiStatusResponse(object, requestedProperties,
                    getBaseUrl(request));

            logXml(multiStatusResponse);

            // write the actual response
            XMLWriter writer = new XMLWriter(response.getWriter(), OutputFormat.createCompactFormat());
            writer.write(multiStatusResponse);
            writer.flush();
            writer.close();

        } catch (DocumentException e) {
            LOG.error("invalid request: " + e.getMessage());
            response.sendError(HttpServletResponse.SC_BAD_REQUEST);
        }
    } else {
        LOG.error(object.getName().getPath() + " NOT FOUND");
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
    }
}

From source file:com.thinkberg.webdav.CopyMoveBase.java

/**
 * Handle a COPY or MOVE request.//from   w  ww .  j a v  a  2 s.c  o  m
 *
 * @param request  the servlet request
 * @param response the servlet response
 * @throws IOException if there is an error executing this request
 */
public void service(HttpServletRequest request, HttpServletResponse response) throws IOException {
    boolean overwrite = getOverwrite(request);
    FileObject object = VFSBackend.resolveFile(request.getPathInfo());
    FileObject targetObject = getDestination(request);

    try {
        final LockManager lockManager = LockManager.getInstance();
        LockManager.EvaluationResult evaluation = lockManager.evaluateCondition(targetObject, getIf(request));
        if (!evaluation.result) {
            response.sendError(HttpServletResponse.SC_PRECONDITION_FAILED);
            return;
        }
        if ("MOVE".equals(request.getMethod())) {
            evaluation = lockManager.evaluateCondition(object, getIf(request));
            if (!evaluation.result) {
                response.sendError(HttpServletResponse.SC_PRECONDITION_FAILED);
                return;
            }
        }
    } catch (LockException e) {
        response.sendError(SC_LOCKED);
        return;
    } catch (ParseException e) {
        response.sendError(HttpServletResponse.SC_PRECONDITION_FAILED);
        return;
    }

    if (null == targetObject) {
        response.sendError(HttpServletResponse.SC_BAD_REQUEST);
        return;
    }

    if (object.equals(targetObject)) {
        response.sendError(HttpServletResponse.SC_FORBIDDEN);
        return;
    }

    if (targetObject.exists()) {
        if (!overwrite) {
            response.sendError(HttpServletResponse.SC_PRECONDITION_FAILED);
            return;
        }
        response.setStatus(HttpServletResponse.SC_NO_CONTENT);
    } else {
        FileObject targetParent = targetObject.getParent();
        if (!targetParent.exists() || !FileType.FOLDER.equals(targetParent.getType())) {
            response.sendError(HttpServletResponse.SC_CONFLICT);
        }
        response.setStatus(HttpServletResponse.SC_CREATED);
    }

    // delegate the actual execution to a sub class
    copyOrMove(object, targetObject, getDepth(request));
}