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:common.web.servlets.StaticFilesServlet.java

/** 
 * Handles the HTTP <code>GET</code> method.
 * @param request servlet request/*from w w  w . ja  v a2 s  . c  o m*/
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String name = getResourceName(request.getPathInfo());

    if (name == null) {
        response.sendError(HttpServletResponse.SC_NOT_FOUND, "Not Found");
        return;
    }

    File file = new File(realPath, name);

    if (!file.exists()) {
        response.sendError(HttpServletResponse.SC_NOT_FOUND, "Not Found");
        return;
    }

    //delete after testing
    //synchronized(semaphore){
    long time = System.nanoTime();
    if (logger.isDebugEnabled()) {
        logger.debug("get resource=" + name);
        logger.debug("get file=" + file.getAbsolutePath());
    }
    OutputStream os = response.getOutputStream();
    //if (useNew){
    //   FileUtils.loadFromFileNew(file, os);
    //} else {
    FileUtils.loadFromFileOld(file, os);
    //}
    os.flush();
    os.close();

    time = System.nanoTime() - time;
    //if (useNew){
    //logger.info("proceed time new = "+time+"; avg = "+(servTimeNew/servQuantityNew)+"; count="+servQuantityNew+"; size = "+servSizeNew);
    //   newStat.increaseCount();
    //   newStat.increaseSize(file.length());
    //   newStat.increaseTime(time);
    //   useNew = false;
    //} else {
    //logger.info("proceed time old = "+time+"; avg = "+(servTimeOld/servQuantityOld)+"; count="+servQuantityOld+"; size = "+servSizeOld);
    oldStat.increaseCount();
    oldStat.increaseSize(file.length());
    oldStat.increaseTime(time);
    //   useNew = true;
    //}
    //}
}

From source file:com.carolinarollergirls.scoreboard.jetty.XmlScoreBoardServlet.java

protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    super.doPost(request, response);

    try {//from   w ww.  j  a va  2 s.c o m
        if ("/set".equals(request.getPathInfo()))
            set(request, response);
        else if (!response.isCommitted())
            response.sendError(HttpServletResponse.SC_NOT_FOUND);
    } catch (JDOMException jE) {
        ScoreBoardManager.printMessage("XmlScoreBoardServlet ERROR: " + jE.getMessage());
        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    }
}

From source file:com.ibm.sbt.service.basic.ProxyEndpointService.java

@Override
protected void initProxy(HttpServletRequest request, HttpServletResponse response) throws ServletException {
    String pathInfo = request.getPathInfo();
    // Skip the URL_PATH of the proxy
    //     /[proxy root]/[URL_PATH]/[endpointname]/[full qualified url starting with http] 
    // or//www  .j av  a2 s.com
    //     /[proxy root]/[URL_PATH]/[endpointname]/[service url]
    int startEndPoint = getProxyUrlPath().length() + 2;
    if (startEndPoint < pathInfo.length()) {
        int startProxyUrl = pathInfo.indexOf('/', startEndPoint);
        if (startProxyUrl >= 0) {
            String endPointName = pathInfo.substring(startEndPoint, startProxyUrl);
            this.endpoint = EndpointFactory.getEndpoint(endPointName);
            if (!endpoint.isAllowClientAccess()) {
                throw new ServletException(StringUtil
                        .format("Client access forbidden for the specified endpoint {0}", endPointName));
            }

            String url = null;
            String endpointUrl = endpoint.getUrl();
            if (pathInfo.substring(startProxyUrl + 1).startsWith("http")) {
                url = pathInfo.substring(startProxyUrl + 1).replaceAll(" ", "%20").replaceFirst("\\/", "://");
                /*
                   if (!url.startsWith(endpointUrl)) {
                       throw new ServletException(StringUtil.format(
                       "The proxied url does not correspond to the endpoint {0}", endPointName));
                   }
                   */
            } else {
                pathInfo = pathInfo.substring(startProxyUrl).replaceAll(" ", "%20");
                url = endpointUrl + pathInfo;
            }
            requestURI = url;
            return;
        }
    }
    StringBuffer b = request.getRequestURL();
    String q = request.getQueryString();
    if (StringUtil.isNotEmpty(q)) {
        b.append('?');
        b.append(q);
    }
    throw new ServletException(StringUtil.format("Invalid url {0}", b.toString()));
}

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

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServiceException {
    WSRoleSearchCriteria criteria = restUtils.populateServiceObject(req.getPathInfo(), req.getParameterMap(),
            WSRoleSearchCriteria.class);

    WSRole[] roles = null;//  www .  jav a2  s .  c om

    try {
        // get the resources....
        roles = userAndRoleManagementService.findRoles(criteria);
    } catch (AxisFault axisFault) {
        throw new ServiceException(HttpServletResponse.SC_NOT_FOUND,
                "could not locate roles in uri: " + criteria.getRoleName() + axisFault.getLocalizedMessage());
    }

    if (log.isDebugEnabled()) {
        log.debug(roles.length + " roles were found");
    }

    String marshal = generateSummeryReport(roles);
    if (log.isDebugEnabled()) {
        log.debug("Marshaling OK");
    }
    restUtils.setStatusAndBody(HttpServletResponse.SC_OK, resp, marshal);
}

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

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServiceException {
    try {//from w w  w .  java2  s .c o  m
        // Get the uri of the resource
        long jobId = getJobId(restUtils.extractRepositoryUri(req.getPathInfo()));

        // get the resources....
        Job job = reportSchedulerService.getJob(jobId);

        StringWriter sw = new StringWriter();
        // create JAXB context and instantiate marshaller

        restUtils.getMarshaller(Job.class).marshal(job, sw);

        restUtils.setStatusAndBody(HttpServletResponse.SC_OK, resp, sw.toString());

    } catch (JAXBException e) {
        throw new ServiceException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());
    } catch (AxisFault axisFault) {
        throw new ServiceException(HttpServletResponse.SC_NOT_FOUND, axisFault.getMessage());
    }
}

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

protected long getLastModified(HttpServletRequest request) {
    if (log.isDebugEnabled()) {
        log.debug("Checking last modified of resource: " + request.getServletPath() + request.getPathInfo());
    }/*from  w w w  . j a va 2s  .  co m*/
    URL[] resources;
    try {
        resources = getRequestResourceURLs(request);
    } catch (MalformedURLException e) {
        return -1;
    }
    if (resources == null || resources.length == 0) {
        return -1;
    }
    long lastModified = -1;
    for (int i = 0; i < resources.length; i++) {
        URLConnection resourceConn;
        try {
            resourceConn = resources[i].openConnection();
        } catch (IOException e) {
            return -1;
        }
        if (resourceConn.getLastModified() > lastModified) {
            lastModified = resourceConn.getLastModified();
        }
    }
    return lastModified;
}

From source file:com.carolinarollergirls.scoreboard.jetty.XmlScoreBoardServlet.java

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

    try {/* w  w  w.  j  a  va 2 s. c o m*/
        if ("/get".equals(request.getPathInfo()))
            get(request, response);
        else if ("/debug".equals(request.getPathInfo()))
            setDebug(request, response);
        else if ("/config".equals(request.getPathInfo()))
            listenerConfig(request, response);
        else if (request.getPathInfo().endsWith(".xml"))
            getAll(request, response);
        else if (!response.isCommitted())
            response.sendError(HttpServletResponse.SC_NOT_FOUND);
    } catch (JDOMException jE) {
        ScoreBoardManager.printMessage("XmlScoreBoardServlet ERROR: " + jE.getMessage());
        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    }
}

From source file:com.qwazr.webapps.example.DocumentationServlet.java

@Override
public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {

    String path = request.getPathInfo().substring(remotePrefix.length());

    File file = new File(documentationPath, path);
    if (!file.exists()) {
        response.sendError(404, "File not found: " + file);
        return;//from   w ww . java2 s. c  o  m
    }
    if (file.isDirectory()) {
        if (!path.endsWith("/")) {
            response.sendRedirect(request.getPathInfo() + '/');
            return;
        }
        for (String indexFileName : indexFileNames) {
            File readMefile = new File(file, indexFileName);
            if (readMefile.exists()) {
                file = readMefile;
                break;
            }
        }
    }

    Pair<String, String[]> paths = getRemoteLink(path);
    request.setAttribute("original_link", paths.getLeft());
    request.setAttribute("breadcrumb_parts", paths.getRight());

    if (!file.exists()) {
        response.sendError(404, "File not found: " + file);
        return;
    }

    request.setAttribute("currentfile", file);
    final String extension = FilenameUtils.getExtension(file.getName());
    final List<File> fileList = getBuildList(file.getParentFile());
    if ("md".equals(extension)) {
        request.setAttribute("markdown", markdownTool.toHtml(file));
        request.setAttribute("filelist", fileList);
    } else if ("adoc".equals(extension)) {
        request.setAttribute("adoc", asciiDoctorTool.convertFile(file));
        request.setAttribute("filelist", fileList);
    } else if (file.isFile()) {
        String type = mimeTypeMap.getContentType(file);
        if (type != null)
            response.setContentType(type);
        response.setContentLengthLong(file.length());
        response.setDateHeader("Last-Modified", file.lastModified());
        response.setHeader("Cache-Control", "max-age=86400");
        response.setDateHeader("Expires", System.currentTimeMillis() + 86400 * 1000);
        InputStream inputStream = new FileInputStream(file);
        try {
            IOUtils.copy(inputStream, response.getOutputStream());
        } finally {
            IOUtils.closeQuietly(inputStream);
        }
        return;
    } else if (file.isDirectory()) {
        request.setAttribute("filelist", getBuildList(file));
    } else {
        response.sendRedirect(paths.getLeft());
    }
    try {
        freemarkerTool.template(templatePath, request, response);
    } catch (TemplateException e) {
        throw new ServletException(e);
    }
}

From source file:org.openqa.grid.selenium.proxy.DefaultRemoteProxy.java

public void afterCommand(TestSession session, HttpServletRequest request, HttpServletResponse response) {
    session.put("lastCommand", request.getMethod() + " - " + request.getPathInfo() + " executing ...");
}

From source file:org.openqa.grid.selenium.proxy.DefaultRemoteProxy.java

public void beforeCommand(TestSession session, HttpServletRequest request, HttpServletResponse response) {
    session.put("lastCommand", request.getMethod() + " - " + request.getPathInfo() + " executed.");
}