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.apress.progwt.server.web.controllers.ErrorController.java

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

    log.error("\nErrorController reqServ " + req.getServletPath() + " PathInfo:" + req.getPathInfo()
            + " Param: " + req.getParameterNames().toString() + " Q: " + req.getQueryString() + "</>");

    //        if(log.isDebugEnabled()){
    //            for(Object s :req.getParameterMap().keySet()){
    //                log.debug("param "+s);
    //            }
    //            Enumeration attrs = req.getAttributeNames();
    //            while(attrs.hasMoreElements()){
    //                String attr = (String) attrs.nextElement();
    //                log.debug("attr: "+attr+" "+req.getAttribute(attr));
    //            }
    //        }//from  www .  j  a  va 2  s  .  co  m

    ModelAndView m = super.handleRequestInternal(req, arg1);
    String code = req.getParameter("code");
    if (code != null) {
        Object uri = req.getAttribute("javax.servlet.error.request_ uri");
        m.addObject("message", code + " error for page " + uri);
    }
    return m;
}

From source file:com.googlesource.gerrit.plugins.github.velocity.VelocityStaticServlet.java

private Resource local(final HttpServletRequest req) {
    final String name = req.getPathInfo();
    if (name.length() < 2 || !name.startsWith("/") || isUnreasonableName(name)) {
        // Too short to be a valid file name, or doesn't start with
        // the path info separator like we expected.
        ////from  w w w .  j av a2  s .c o  m
        return null;
    }

    String resourceName = name.substring(1);
    try {
        return velocity.getContent(resourceName);
    } catch (Exception e) {
        log.error("Cannot resolve resource " + resourceName, e);
        return null;
    }
}

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

public void service(HttpServletRequest request, HttpServletResponse response) throws IOException {
    FileObject object = getResourceManager().getFileObject(request.getPathInfo());
    if (request instanceof Request) {
        String fragment = ((Request) request).getUri().getFragment();
        if (fragment != null) {
            response.sendError(HttpServletResponse.SC_FORBIDDEN);
            return;
        }//from   ww w.ja va2  s. c  o  m
    }

    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()) {
        if (object.delete(ALL_FILES_SELECTOR) > 0) {
            response.setStatus(HttpServletResponse.SC_OK);
        } else {
            response.sendError(HttpServletResponse.SC_FORBIDDEN);
        }
    } else {
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
    }
}

From source file:net.myrrix.web.servlets.EstimateForAnonymousServlet.java

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

    CharSequence pathInfo = request.getPathInfo();
    if (pathInfo == null) {
        response.sendError(HttpServletResponse.SC_BAD_REQUEST, "No path");
        return;//from   w w  w  .  jav  a2  s  .c o m
    }
    Iterator<String> pathComponents = SLASH.split(pathInfo).iterator();
    long toItemID;
    Pair<long[], float[]> itemIDsAndValue;
    try {
        toItemID = Long.parseLong(pathComponents.next());
        itemIDsAndValue = RecommendToAnonymousServlet.parseItemValuePairs(pathComponents);
    } catch (NoSuchElementException nsee) {
        response.sendError(HttpServletResponse.SC_BAD_REQUEST, nsee.toString());
        return;
    } catch (NumberFormatException nfe) {
        response.sendError(HttpServletResponse.SC_BAD_REQUEST, nfe.toString());
        return;
    }

    if (itemIDsAndValue.getFirst().length == 0) {
        response.sendError(HttpServletResponse.SC_BAD_REQUEST, "No items");
        return;
    }

    long[] itemIDs = itemIDsAndValue.getFirst();
    float[] values = itemIDsAndValue.getSecond();

    MyrrixRecommender recommender = getRecommender();
    try {
        float estimate = recommender.estimateForAnonymous(toItemID, itemIDs, values);
        Writer out = response.getWriter();
        out.write(Float.toString(estimate));
        out.write('\n');
    } catch (NotReadyException nre) {
        response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, nre.toString());
    } catch (NoSuchItemException nsie) {
        response.sendError(HttpServletResponse.SC_NOT_FOUND, nsie.toString());
    } catch (TasteException te) {
        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, te.toString());
        getServletContext().log("Unexpected error in " + getClass().getSimpleName(), te);
    }
}

From source file:com.graphhopper.http.I18NServlet.java

@Override
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
    try {/*from  w  w  w. j a  v a 2s.  com*/
        String locale = "";
        String path = req.getPathInfo();
        if (!Helper.isEmpty(path) && path.startsWith("/"))
            locale = path.substring(1);

        if (Helper.isEmpty(locale)) {
            // fall back to language specified in header e.g. via browser settings
            String acceptLang = req.getHeader("Accept-Language");
            if (!Helper.isEmpty(acceptLang))
                locale = acceptLang.split(",")[0];
        }

        Translation tr = map.get(locale);
        JSONObject json = new JSONObject();
        if (tr != null && !Locale.US.equals(tr.getLocale()))
            json.put("default", tr.asMap());

        json.put("locale", locale.toString());
        json.put("en", map.get("en").asMap());
        writeJson(req, res, json);
    } catch (Exception ex) {
        logger.error("Error while executing request: " + req.getQueryString(), ex);
        writeError(res, SC_INTERNAL_SERVER_ERROR, "Problem occured:" + ex.getMessage());
    }
}

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

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

    try {//from  w w w . j av  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;
    }

    // it is forbidden to write data on a folder
    if (object.exists() && FileType.FOLDER.equals(object.getType())) {
        response.sendError(HttpServletResponse.SC_FORBIDDEN);
        return;
    }

    FileObject parent = object.getParent();
    if (!parent.exists()) {
        response.sendError(HttpServletResponse.SC_FORBIDDEN);
        return;
    }

    if (!FileType.FOLDER.equals(parent.getType())) {
        response.sendError(HttpServletResponse.SC_CONFLICT);
        return;
    }

    InputStream is = request.getInputStream();
    OutputStream os = object.getContent().getOutputStream();
    log("PUT sends " + request.getHeader("Content-length") + " bytes");
    log("PUT copied " + Util.copyStream(is, os) + " bytes");
    os.flush();
    object.close();

    response.setStatus(HttpServletResponse.SC_CREATED);
}

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

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

    try {/*  w  ww.j  a  v  a2  s  .  c o  m*/
        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;
    }
    // it is forbidden to write data on a folder
    if (object.exists() && FileType.FOLDER.equals(object.getType())) {
        response.sendError(HttpServletResponse.SC_FORBIDDEN);
        return;
    }

    FileObject parent = object.getParent();
    if (!parent.exists()) {
        response.sendError(HttpServletResponse.SC_FORBIDDEN);
        return;
    }

    if (!FileType.FOLDER.equals(parent.getType())) {
        response.sendError(HttpServletResponse.SC_CONFLICT);
        return;
    }

    InputStream is = request.getInputStream();
    OutputStream os = object.getContent().getOutputStream();
    long bytesCopied = Util.copyStream(is, os);
    String contentLengthHeader = request.getHeader("Content-length");
    LOG.debug(String.format("sent %d/%s bytes", bytesCopied,
            contentLengthHeader == null ? "unknown" : contentLengthHeader));
    os.flush();
    object.close();

    response.setStatus(HttpServletResponse.SC_CREATED);
}

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

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

    try {//from  ww  w.  j  ava 2  s .co m
        String fragment = new URI(request.getRequestURI()).getFragment();
        if (fragment != null) {
            response.sendError(HttpServletResponse.SC_FORBIDDEN);
            return;
        }
    } catch (URISyntaxException e) {
        throw new IOException(e.getMessage());
    }

    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()) {
        int deletedObjects = object.delete(ALL_FILES_SELECTOR);
        LOG.debug("deleted " + deletedObjects + " objects");
        if (deletedObjects > 0) {
            response.setStatus(HttpServletResponse.SC_OK);
        } else {
            response.sendError(HttpServletResponse.SC_FORBIDDEN);
        }
    } else {
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
    }
}

From source file:org.dspace.app.webui.cris.controller.DynamicObjectDetailsController.java

private String extractTabName(HttpServletRequest request) {
    String path = request.getPathInfo().substring(1); // remove first /
    String[] splitted = path.split("/");
    if (splitted.length > 2) {
        return splitted[2].replaceAll("\\.html", "");
    } else/*from  ww  w . ja v a2  s . c  o m*/
        return null;
}

From source file:me.chester.myretweetedtweets.RetrieveTweetsServlet.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String path = request.getPathInfo();
    String callback = request.getParameter("callback");
    PrintWriter out = response.getWriter();
    if (path != null && path.length() > 1) {
        try {// w ww.j  a  v  a2  s.  c  om
            long id = Long.parseLong(path.substring(1));
            String json = getJsonWithCache(id, callback);
            response.setContentType("application/json");
            out.write(json);
            return;
        } catch (NumberFormatException e) {
            // Invalid id, will be treated as 404-not-found below
        } catch (EntityNotFoundException e) {
            // Invalid id, will be treated as 404-not-found below
        } catch (TwitterException e) {
            response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            out.write("Error retrieving tweets. Maybe you should re-authorize?");
        } catch (CacheException e) {
            response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            out.write("Error with Memcache. We are all doomed.");
        }
    }
    response.setStatus(HttpServletResponse.SC_NOT_FOUND);
    out.write("Invalid URL. Try authorizing again to get a valid one");
}