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.webdav.OptionsHandler.java

public void service(HttpServletRequest request, HttpServletResponse response) throws IOException {
    response.setHeader("DAV", "1, 2");

    String path = request.getPathInfo();
    StringBuffer options = new StringBuffer();
    FileObject object = VFSBackend.resolveFile(path);
    if (object.exists()) {
        options.append("OPTIONS, GET, HEAD, POST, DELETE, TRACE, COPY, MOVE, LOCK, UNLOCK, PROPFIND");
        if (FileType.FOLDER.equals(object.getType())) {
            options.append(", PUT");
        }/*from   w  w  w  . j a va 2  s  .  c o m*/
    } else {
        options.append("OPTIONS, MKCOL, PUT, LOCK");
    }
    response.setHeader("Allow", options.toString());

    // see: http://www-128.ibm.com/developerworks/rational/library/2089.html
    response.setHeader("MS-Author-Via", "DAV");
}

From source file:de.micromata.genome.gwiki.web.StaticFileServlet.java

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    String uri = req.getPathInfo();
    String servletp = req.getServletPath();
    String respath = servletp + uri;
    if (uri == null) {
        resp.sendError(HttpServletResponse.SC_NOT_FOUND);
        return;/*from w  ww  .  j  av a2  s  .c  om*/
    }

    InputStream is = getServletContext().getResourceAsStream(respath);
    if (is == null) {
        resp.sendError(HttpServletResponse.SC_NOT_FOUND);
        return;
    }
    long nt = new Date().getTime() + TimeInMillis.DAY;
    String mime = MimeUtils.getMimeTypeFromFile(respath);
    if (StringUtils.equals(mime, "application/x-shockwave-flash")) {
        resp.setHeader("Cache-Control", "cache, must-revalidate");
        resp.setHeader("Pragma", "public");
    }
    resp.setDateHeader("Expires", nt);
    resp.setHeader("Cache-Control", "max-age=86400, public");
    if (mime != null) {
        resp.setContentType(mime);
    }

    byte[] data = IOUtils.toByteArray(is);
    IOUtils.closeQuietly(is);
    resp.setContentLength(data.length);
    IOUtils.write(data, resp.getOutputStream());
}

From source file:graphql.servlet.GraphQLServletTest.java

@Test
@SneakyThrows/*w  ww. j  a  v a  2s .c  o m*/
public void schema() {
    GraphQLServlet servlet = new GraphQLServlet();

    HttpServletRequest req = mock(HttpServletRequest.class);
    when(req.getPathInfo()).thenReturn("/schema.json");
    HttpServletResponse resp = mock(HttpServletResponse.class);

    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    PrintWriter writer = new PrintWriter(outputStream, true);
    when(resp.getWriter()).thenReturn(writer);

    verify(resp, times(0)).setStatus(anyInt());

    servlet.bindQueryProvider(new TestQueryProvider());
    servlet.doGet(req, resp);

    writer.flush();

    Map<String, Object> response = new ObjectMapper().readValue(outputStream.toByteArray(),
            new TypeReference<Map<String, Object>>() {
            });
    assertTrue(response.containsKey("data"));
    assertFalse(response.containsKey("errors"));
}

From source file:it.cilea.osd.jdyna.web.controller.FileServiceController.java

@Override
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
    String idString = request.getPathInfo();
    String[] pathInfo = idString.split("/", 4);

    String folder = pathInfo[3];/*from  ww w  .j  a va  2  s. c om*/
    String fileName = request.getParameter("filename");

    File dir = new File(getPath() + File.separatorChar + folder);
    File file = new File(dir, fileName);

    if (file.getCanonicalPath().replace("\\", "/").startsWith(dir.getCanonicalPath().replace("\\", "/"))) {
        if (file.exists()) {
            InputStream is = null;
            try {
                is = new FileInputStream(file);

                response.setContentType(request.getSession().getServletContext().getMimeType(file.getName()));
                Long len = file.length();
                response.setContentLength(len.intValue());
                response.setHeader("Content-Disposition", "attachment; filename=" + file.getName());
                FileCopyUtils.copy(is, response.getOutputStream());
                response.getOutputStream().flush();
            } finally {
                if (is != null) {
                    is.close();
                }

            }
        } else {
            throw new RuntimeException("File doesn't exists!");
        }
    } else {
        throw new RuntimeException("No permission to download this file");
    }
    return null;
}

From source file:org.fusesource.restygwt.server.basic.EchoTestGwtServlet.java

@SuppressWarnings("unchecked")
private void doEchoRequest(HttpServletRequest request, HttpServletResponse response) throws IOException {
    Echo echo = new Echo();
    echo.path = request.getPathInfo();

    echo.params = new HashMap<String, String>();
    ObjectMapper mapper = new ObjectMapper();
    for (Map.Entry<String, String[]> entry : (Set<Map.Entry<String, String[]>>) request.getParameterMap()
            .entrySet()) {//from   ww w  . j  ava 2 s .  c om
        if (entry.getValue().length == 1) {
            echo.params.put(entry.getKey(), entry.getValue()[0]);
        } else {
            echo.params.put(entry.getKey(), mapper.writeValueAsString(entry.getValue()));
        }
    }
    response.setContentType("application/json");
    mapper.writeValue(response.getOutputStream(), echo);
}

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

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

    if (object.exists()) {
        if (FileType.FOLDER.equals(object.getType())) {
            response.sendError(HttpServletResponse.SC_FORBIDDEN);
            return;
        }/*  w w w.ja  v a  2s  . co m*/

        setHeader(response, object.getContent());

        InputStream is = object.getContent().getInputStream();
        OutputStream os = response.getOutputStream();
        Util.copyStream(is, os);
        is.close();
    } else {
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
    }
}

From source file:org.openmhealth.dsu.controller.GenericExceptionHandlingControllerAdvice.java

@ExceptionHandler(MissingServletRequestParameterException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)/*from   ww w .j  av  a2s.  c  o  m*/
public void handleMissingServletRequestParameterException(MissingServletRequestParameterException e,
        HttpServletRequest request) {

    log.debug("A {} request for '{}' failed because parameter '{}' is missing.", request.getMethod(),
            request.getPathInfo(), e.getParameterName(), e);
}

From source file:hudson.plugins.mercurial.MercurialStatusCrumbExclusion.java

@Override
public boolean process(HttpServletRequest req, HttpServletResponse resp, FilterChain chain)
        throws IOException, ServletException {
    String pathInfo = req.getPathInfo();
    if (StringUtils.isEmpty(pathInfo)) {
        return false;
    }//from w  w w.  j a  v  a2s.  com
    // in case the notifier cannot follow redirects
    pathInfo = pathInfo.endsWith("/") ? pathInfo : pathInfo + '/';
    if (!pathInfo.equals(getExclusionPath())) {
        return false;
    }
    chain.doFilter(req, resp);
    return true;
}

From source file:net.mindengine.oculus.frontend.web.controllers.report.SavedReportController.java

private SavedRun getSavedRun(HttpServletRequest request) throws Exception {
    String shortUrl = request.getPathInfo().substring(7).replace("." + type, "");
    String arr[] = shortUrl.split("-");
    if (arr == null || arr.length != 6)
        throw new Exception("Url is incorrect");
    Long id = Long.parseLong(arr[5]);
    SavedRun savedRun = testRunDAO.getSavedRunById(id);
    if (savedRun == null)
        throw new UnexistentResource("There is no saved run in DB with id '" + id + "'");
    return savedRun;
}

From source file:com.apress.progwt.server.web.controllers.IndexController.java

@Override
protected ModelAndView handleRequestInternal(HttpServletRequest req, HttpServletResponse arg1)
        throws Exception {

    log.debug("SERVLET PATH: " + req.getServletPath() + " " + req.getPathInfo() + " " + req.getQueryString());

    Map<String, Object> model = getDefaultModel(req);

    // parameter may be on param line if we're redirect:ed here
    // (createUserController)
    model.put("message", req.getParameter("message"));

    model.put("frontPage", new FrontPageData(userService, schoolService));

    ModelAndView mav = new ModelAndView();
    mav.addAllObjects(model);/*  ww  w  .jav a 2s  .  c  om*/
    return mav;
}