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.baidu.jprotobuf.rpc.server.HttpRequestHandlerServlet.java

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

    String context = request.getPathInfo();
    if (context == null) {
        LOGGER.warn("invalid request path.");
        response.setStatus(HttpServletResponse.SC_NOT_FOUND);
        return;//w  w w  .  ja  v a  2s .c o m
    } else {
        if (context.startsWith("/")) {
            context = context.substring(1);
        }

        if (!serviceMap.containsKey(context)) {
            LOGGER.warn("invalid request path service name[" + context + "] not found.");
            response.setStatus(HttpServletResponse.SC_NOT_FOUND);
            return;
        }
    }

    try {
        ServiceExporter idlServiceExporter = serviceMap.get(context);

        //to check if a get idl request 
        if (request.getParameter(ServiceExporter.INPUT_IDL_PARAMETER) != null) {

            String inputIDL = idlServiceExporter.getInputIDL();
            if (inputIDL != null) {
                response.setContentLength(inputIDL.length());
                response.getOutputStream().write(inputIDL.getBytes());

                return;
            }

        } else if (request.getParameter(ServiceExporter.OUTPUT_IDL_PARAMETER) != null) {
            String outputIDL = idlServiceExporter.getOutputIDL();
            if (outputIDL != null) {
                response.setContentLength(outputIDL.length());
                response.getOutputStream().write(outputIDL.getBytes());

                return;
            }
        }

        IDLProxyObject inputIDLProxyObject = idlServiceExporter.getInputProxyObject();
        IDLProxyObject input = null;
        if (inputIDLProxyObject != null && request.getContentLength() > 0) {
            byte[] bytes = readStream(request.getInputStream(), request.getContentLength());
            input = inputIDLProxyObject.decode(bytes);
        }

        IDLProxyObject result = idlServiceExporter.execute(input);
        if (result != null) {
            byte[] bytes = result.encode();
            response.setContentLength(bytes.length);
            response.getOutputStream().write(bytes);
        }
    } catch (Exception ex) {
        response.sendError(HttpServletResponse.SC_BAD_REQUEST, ex.getMessage());
    } finally {
        response.getOutputStream().flush();
        response.getOutputStream().close();
    }
}

From source file:com.scf.module.security.matcher.AntPathRequestMatcher.java

private String getRequestPath(HttpServletRequest request) {
    String url = request.getServletPath();

    if (request.getPathInfo() != null) {
        url += request.getPathInfo();//from  w w w  .j a va2  s. c  om
    }

    if (!caseSensitive) {
        url = url.toLowerCase();
    }

    return url;
}

From source file:org.usergrid.rest.SwaggerServlet.java

public boolean handleJsonOutput(HttpServletRequest request, HttpServletResponse response) throws IOException {
    String path = request.getServletPath();
    if (isEmpty(path)) {
        path = request.getPathInfo();
    }/*from  w  w  w  .  j  a  v  a2s.c o m*/
    if (isEmpty(path)) {
        return false;
    }
    path = path.toLowerCase();
    if (pathToJson.containsKey(path)) {
        String json = pathToJson.get(path);
        if (json != null) {
            allowAllOrigins(request, response);
            if ("get".equalsIgnoreCase(request.getMethod())) {
                response.setContentType("application/json");
                response.getWriter().print(json);
                return true;
            }
        }
    }
    return false;
}

From source file:edu.cornell.mannlib.vivo.orcid.controller.OrcidIntegrationController.java

/**
 * Get in before FreemarkerHttpServlet for special handling.
 *//*from  www . j a  v  a2 s.  c o  m*/
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
    if (!isOrcidConfigured()) {
        show404NotFound(resp);
    }
    if (PATHINFO_CALLBACK.equals(req.getPathInfo())) {
        new OrcidCallbackHandler(req, resp).exec();
    } else {
        super.doGet(req, resp);
    }
}

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

private URL[] getRequestResourceURLs(HttpServletRequest request) throws MalformedURLException {

    final String rawResourcePath = request.getServletPath() + request.getPathInfo();
    //The Spring ResourceServlet allowed for combined resource url delimited by ',' as you can see
    //below but we're not using it since we have one call to the server for each resource by default.
    //Still I left that code there in case in the future we want to use the feature.
    final String[] localResourcePaths = StringUtils.delimitedListToStringArray(rawResourcePath, ",");
    final URL[] resources = new URL[localResourcePaths.length];
    for (int i = 0; i < localResourcePaths.length; i++) {
        final URL resource = getServletContext().getResource(localResourcePaths[i]);
        if (resource == null) {
            return null;
        } else {//from  ww  w  .  j a v  a 2  s.c o m
            resources[i] = resource;
        }
    }
    return resources;
}

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   w  w  w  .  java 2 s  .  c  om
        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:com.jaspersoft.jasperserver.rest.services.RESTJob.java

@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServiceException {
    try {/*from   w w  w  . ja v a 2  s . c o m*/
        long jobId = getJobId(restUtils.extractRepositoryUri(req.getPathInfo()));

        Job job = restUtils.unmarshal(Job.class, req.getInputStream());

        if (job.getId() != jobId) {
            if (log.isDebugEnabled()) {
                log.debug("job descriptor id " + job.getId() + " and request id " + jobId
                        + "do not match. assigning the request id to as the job id");
            }
            job.setId(jobId);
        }

        if (job.getVersion() == DISREGARD_VERSION && reportSchedulerService.getJob(jobId) != null) {
            Job oldJob = reportSchedulerService.getJob(jobId);
            job.setVersion(oldJob.getVersion());

        }
        reportSchedulerService.updateJob(job);
    } catch (AxisFault axisFault) {
        throw new ServiceException(HttpServletResponse.SC_NOT_FOUND, axisFault.getMessage());
    } catch (IOException e) {
        throw new ServiceException(ServiceException.INTERNAL_SERVER_ERROR, e.getMessage());
    } catch (JAXBException e) {
        throw new ServiceException(HttpServletResponse.SC_BAD_REQUEST,
                "please check the request job descriptor");
    }

}

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

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

    try {/* w w  w  . ja v  a2  s .c o m*/
        final LockManager manager = LockManager.getInstance();
        final LockManager.EvaluationResult evaluation = manager.evaluateCondition(object, getIf(request));
        if (!evaluation.result) {
            response.sendError(HttpServletResponse.SC_PRECONDITION_FAILED);
            return;
        } else {
            if (!evaluation.locks.isEmpty()) {
                LOG.debug(String.format("discovered locks: %s", evaluation.locks));
                sendLockAcquiredResponse(response, evaluation.locks.get(0));
                return;
            }
        }
    } catch (LockConflictException e) {
        List<Lock> locks = e.getLocks();
        for (Lock lock : locks) {
            if (Lock.EXCLUSIVE.equals(lock.getType())) {
                response.sendError(SC_LOCKED);
                return;
            }
        }
    } catch (ParseException e) {
        response.sendError(HttpServletResponse.SC_PRECONDITION_FAILED);
        return;
    }

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

        Element rootEl = lockInfo.getRootElement();
        String lockScope = null, lockType = null;
        Object owner = null;
        Iterator elIt = rootEl.elementIterator();
        while (elIt.hasNext()) {
            Element el = (Element) elIt.next();
            if (TAG_LOCKSCOPE.equals(el.getName())) {
                lockScope = el.selectSingleNode("*").getName();
            } else if (TAG_LOCKTYPE.equals(el.getName())) {
                lockType = el.selectSingleNode("*").getName();
            } else if (TAG_OWNER.equals(el.getName())) {
                // TODO correctly handle owner
                Node subEl = el.selectSingleNode("*");
                if (subEl != null && TAG_HREF.equals(subEl.getName())) {
                    owner = new URL(el.selectSingleNode("*").getText());
                } else {
                    owner = el.getText();
                }
            }
        }

        LOG.debug("LOCK(" + lockType + ", " + lockScope + ", " + owner + ")");

        Lock requestedLock = new Lock(object, lockType, lockScope, owner, getDepth(request),
                getTimeout(request));
        try {
            LockManager.getInstance().acquireLock(requestedLock);
            sendLockAcquiredResponse(response, requestedLock);
        } catch (LockConflictException e) {
            response.sendError(SC_LOCKED);
        } catch (IllegalArgumentException e) {
            response.sendError(HttpServletResponse.SC_BAD_REQUEST);
        }
    } catch (DocumentException e) {
        e.printStackTrace();
        response.sendError(HttpServletResponse.SC_BAD_REQUEST);
    }
}

From source file:com.boundlessgeo.geoserver.AppAuthFilter.java

@Override
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
        throws IOException, ServletException {
    HttpServletRequest req = (HttpServletRequest) servletRequest;
    HttpServletResponse res = (HttpServletResponse) servletResponse;
    String path = req.getPathInfo();

    if (req.getServletPath().startsWith("/app") && path.startsWith("/api")) {

        if ("POST".equalsIgnoreCase(req.getMethod()) && LOGIN_RE.matcher(path).matches()) {
            // hack: we have to jump through a few hoops to piggy back on the geoserver web auth:
            // 1. we fake the request path to fool the security filter
            // 2. we ignore redirects
            boolean success = runSecurityFilters(new HttpServletRequestWrapper(req) {
                @Override/*  w w w . j  av a2  s .  c o  m*/
                public String getServletPath() {
                    return "";
                }

                @Override
                public String getPathInfo() {
                    return "/j_spring_security_check";
                }
            }, new HttpServletResponseWrapper(res) {
                @Override
                public void sendRedirect(String location) throws IOException {
                }
            }, WEB_LOGIN_CHAIN_NAME);

            if (success) {
                filterChain.doFilter(servletRequest, servletResponse);
            } else {
                res.setStatus(401);
            }

        } else if (LOGOUT_RE.matcher(path).matches()) {
            // invalidate the session if it exists
            HttpSession session = req.getSession(false);
            if (session != null) {
                session.invalidate();
            }
        } else {
            // two modes of authentication, basic vs form.
            String chainName = req.getHeader("Authorization") != null ? DEFAULT_CHAIN_NAME : WEB_CHAIN_NAME;
            if (runSecurityFilters(req, res, chainName)) {
                filterChain.doFilter(servletRequest, servletResponse);
            } else {
                res.setStatus(401);
            }
        }
    } else {
        filterChain.doFilter(servletRequest, servletResponse);
    }
}

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

@Override
protected void doDelete(HttpServletRequest req, HttpServletResponse resp) throws ServiceException {
    // Get the uri of the resource
    long jobId = getJobId(restUtils.extractRepositoryUri(req.getPathInfo()));

    // get the resources....
    try {/*from   w  ww . j  a v  a 2  s . c  o  m*/
        reportSchedulerService.deleteJob(jobId);
    } catch (AxisFault axisFault) {
        throw new ServiceException(HttpServletResponse.SC_NOT_FOUND, axisFault.getMessage());
    }

    String xml = null; //m.writeResourceDescriptor(job);
    // send the xml...
    restUtils.setStatusAndBody(HttpServletResponse.SC_OK, resp, "");

}