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:net.mindengine.oculus.frontend.web.controllers.customization.ProjectCustomizationController.java

@Override
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
    String path = request.getPathInfo().substring(9);
    Project project = projectDAO.getProjectByPath(path);
    Map<String, Object> map = new HashMap<String, Object>();
    map.put("project", project);

    verifyPermissions(request);/*  w  w w.j  a  va 2 s.co m*/
    String unit = request.getParameter("unit");
    map.put("unit", unit);
    map.put("title", getTitle());
    if (unit == null) {
        return new ModelAndView(viewChooseUnit, map);
    }
    /*
     * Fetching customizations with theirs possible values
     */
    List<Customization> customizations = customizationDAO.getCustomizations(project.getId(), unit);
    List<Map<String, Object>> customizationsMap = new LinkedList<Map<String, Object>>();
    for (Customization customization : customizations) {
        Map<String, Object> c = new HashMap<String, Object>();
        c.put("customization", customization);
        if (customization.getType().equals(Customization.TYPE_LIST)
                || customization.getType().equals(Customization.TYPE_CHECKLIST)) {
            c.put("possibleValues", customizationDAO.getCustomizationPossibleValues(customization.getId()));
        }
        customizationsMap.add(c);
    }
    map.put("customizations", customizationsMap);

    return new ModelAndView(getView(), map);
}

From source file:ch.entwine.weblounge.kernel.http.WelcomeFileFilterServlet.java

/**
 * {@inheritDoc}/*from   w ww .  j  av a 2 s.com*/
 *
 * @see javax.servlet.http.HttpServlet#service(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
 */
public void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {

    if (req.getPathInfo() != null && "/".equals(req.getPathInfo())) {
        if (!welcomeFileList.isEmpty()) {
            // use the first one for now:
            for (String welcomeFile : welcomeFileList) {
                String file = welcomeFile;
                if (welcomeFile.startsWith("/"))
                    file = welcomeFile.substring(1);
                RequestDispatcher dispatcher = req.getRequestDispatcher(file);
                // TODO: check if resource exists before forwarding
                dispatcher.forward(req, res);
                return;
            }
        } else {
            req.getRequestDispatcher(req.getServletPath() + "/resources/index.html").forward(req, res);
            // Tomcat also defaults to index.jsp
            return;
        }
    } else {
        // no welcome file, trying to forward to remapped resource:
        // /resources"+req.getPathInfo()
        req.getRequestDispatcher(req.getServletPath() + "/resources" + req.getPathInfo()).forward(req, res);
    }
}

From source file:com.ikon.servlet.FlagIconServlet.java

/**
 * //from ww w.ja v  a  2 s. c  o m
 */
public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {
    String lgId = request.getPathInfo();
    OutputStream os = null;

    try {
        if (lgId.length() > 1) {
            Language language = LanguageDAO.findByPk(lgId.substring(1)); // The first character / must be removed

            if (language != null) {
                byte[] img = SecureStore.b64Decode(new String(language.getImageContent()));
                response.setContentType(language.getImageMime());
                response.setContentLength(img.length);
                os = response.getOutputStream();
                os.write(img);
                os.flush();
            }
        }
    } catch (DatabaseException e) {
        log.error(e.getMessage(), e);
    } finally {
        IOUtils.closeQuietly(os);
    }
}

From source file:com.ikon.servlet.MimeIconServlet.java

/**
 * //from www  . j  ava2  s . c o  m
 */
public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {
    String mime = request.getPathInfo();
    OutputStream os = null;

    try {
        if (mime.length() > 1) {
            MimeType mt = MimeTypeDAO.findByName(mime.substring(1));

            if (mt != null) {
                byte[] img = SecureStore.b64Decode(new String(mt.getImageContent()));
                response.setContentType(mt.getImageMime());
                response.setContentLength(img.length);
                os = response.getOutputStream();
                os.write(img);
                os.flush();
            }
        }
    } catch (DatabaseException e) {
        log.error(e.getMessage(), e);
    } finally {
        IOUtils.closeQuietly(os);
    }
}

From source file:com.googlesource.gerrit.plugins.lfs.locks.LfsLocksContext.java

LfsLocksContext(LfsGson gson, final HttpServletRequest req, final HttpServletResponse res) {
    this.path = req.getPathInfo().startsWith("/") ? req.getPathInfo() : "/" + req.getPathInfo();
    this.req = req;
    this.res = res;
    this.writer = Suppliers.memoize(new Supplier<Writer>() {
        @Override/*  w ww.  j a  v a  2s .  c o m*/
        public Writer get() {
            try {
                return new BufferedWriter(new OutputStreamWriter(res.getOutputStream(), UTF_8));
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    });
    this.reader = Suppliers.memoize(new Supplier<Reader>() {
        @Override
        public Reader get() {
            try {
                return new BufferedReader(new InputStreamReader(req.getInputStream(), UTF_8));
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    });
    this.gson = gson;
    setLfsResponseType();
}

From source file:com.rabbitstewdio.build.maven.tomcat.AbstractContentServlet.java

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

    String filename = request.getPathInfo();

    InputStream in = findResource(filename);
    if (in == null) {
        log.warn("Unable to find [" + filename + "] on " + getServletName());
        response.setStatus(404);//w  ww  .  j a va2  s  . co m
        return;
    }

    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    IOUtils.copy(in, bout);

    response.setCharacterEncoding("UTF-8");

    String mimeType = getServletContext().getMimeType(filename);
    if (mimeType != null) {
        response.setContentType(mimeType);
    }

    response.addDateHeader("Expires", 0L);
    response.setDateHeader(LAST_MODIFIED, new Date().getTime());
    response.setContentLength(bout.size());
    response.getOutputStream().write(bout.toByteArray());
    response.flushBuffer();
}

From source file:org.alfresco.repo.lotus.server.QuickrServlet.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException {
    if (request.getMethod().equals("GET") && (request.getPathInfo().endsWith("/services/LibraryService")
            || request.getPathInfo().endsWith("/services/ContentService"))) {
        response.setStatus(HttpServletResponse.SC_OK);
        return;//from w  w  w  . ja v  a 2  s .  c  om
    }

    super.doGet(request, response);
}

From source file:com.silverpeas.peasUtil.GoTo.java

public String getObjectId(HttpServletRequest request) {
    String pathInfo = request.getPathInfo();
    if (pathInfo != null) {
        return pathInfo.substring(1);
    }/*from w w  w.j  a  v a 2  s .  c  o  m*/
    return null;
}

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

@Override
public ModelAndView handleRequest(HttpServletRequest req, HttpServletResponse response) throws Exception {

    String idString = req.getPathInfo();
    String[] pathInfo = idString.split("/", 3);
    String tabId = pathInfo[2];/*  ww  w. j av a 2 s.  co m*/

    String contentType = "";
    String ext = "";

    Tab tab = applicationService.get(Tab.class, Integer.parseInt(tabId));
    ext = tab.getExt();
    contentType = tab.getMime();
    if (ext != null && !ext.isEmpty() && contentType != null && !contentType.isEmpty()) {
        File image = new File(
                tab.getFileSystemPath() + File.separatorChar + AFormTabController.DIRECTORY_TAB_ICON
                        + File.separatorChar + AFormTabController.PREFIX_TAB_ICON + tabId + "." + ext);

        InputStream is = null;
        try {
            is = new FileInputStream(image);

            response.setContentType(contentType);

            // Response length
            response.setHeader("Content-Length", String.valueOf(image.length()));

            Utils.bufferedCopy(is, response.getOutputStream());
            is.close();
            response.getOutputStream().flush();
        } catch (FileNotFoundException not) {
            log.error(not.getMessage());
            response.sendError(HttpServletResponse.SC_NOT_FOUND);
        } finally {
            if (is != null) {
                is.close();
            }
        }
    }

    return null;
}

From source file:org.dspace.app.webui.cris.json.RelationPreferenceJSONController.java

private String getRelationType(HttpServletRequest request) {
    String pathInfo = request.getPathInfo();
    // example /uuid/XXXXXXXXX/relMgmt/publications.json
    String path = pathInfo.substring("/uuid/".length());
    String[] splitted = path.split("/");
    String type = splitted[2].split("\\.json")[0];
    return type;/*from w w  w.ja va2  s .c  om*/
}