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:jp.aegif.nemaki.rest.AuthenticationFilter.java

private boolean checkResourceEnabled(HttpServletRequest request) {
    boolean enabled = true;

    String pathInfo = request.getPathInfo();
    if (pathInfo.startsWith("/user")) {
        String userResourceEnabled = propertyManager.readValue(PropertyKey.REST_USER_ENABLED);
        enabled = TOKEN_FALSE.equals(userResourceEnabled) ? false : true;
    } else if (pathInfo.startsWith("/group")) {
        String groupResourceEnabled = propertyManager.readValue(PropertyKey.REST_GROUP_ENABLED);
        enabled = TOKEN_FALSE.equals(groupResourceEnabled) ? false : true;
    } else if (pathInfo.startsWith("/type")) {
        String typeResourceEnabled = propertyManager.readValue(PropertyKey.REST_TYPE_ENABLED);
        enabled = TOKEN_FALSE.equals(typeResourceEnabled) ? false : true;
    } else if (pathInfo.startsWith("/archive")) {
        String archiveResourceEnabled = propertyManager.readValue(PropertyKey.REST_ARCHIVE_ENABLED);
        enabled = TOKEN_FALSE.equals(archiveResourceEnabled) ? false : true;
    } else if (pathInfo.startsWith("/search-engine")) {
        String solrResourceEnabled = propertyManager.readValue(PropertyKey.REST_SOLR_ENABLED);
        enabled = TOKEN_FALSE.equals(solrResourceEnabled) ? false : true;
    } else if (pathInfo.startsWith("/authtoken")) {
        String authtokenResourceEnabled = propertyManager.readValue(PropertyKey.REST_AUTHTOKEN_ENABLED);
        enabled = TOKEN_FALSE.equals(authtokenResourceEnabled) ? false : true;
    } else {//from w ww  . ja  va 2s  .c  o m
        enabled = false;
    }

    return enabled;
}

From source file:org.sakaiproject.imagegallery.integration.standalone.ImageStreamingController.java

/**
 * @see org.springframework.web.servlet.mvc.AbstractController#handleRequestInternal(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
 *///from w w w .  java2s . c o m
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
        throws Exception {
    if (log.isInfoEnabled())
        log.info("req contextPath=" + request.getContextPath() + ", pathInfo=" + request.getPathInfo()
                + ", query=" + request.getQueryString() + ", URI=" + request.getRequestURI() + ", URL="
                + request.getRequestURL() + ", servlet=" + request.getServletPath());
    String fileId = request.getPathInfo().substring(1);
    ImageFile imageFile = fileLibraryService.getImageFile(fileId);
    response.setContentType(imageFile.getContentType());
    FileStreamer fileStreamer = (FileStreamer) fileLibraryService;
    fileStreamer.streamImage(fileId, response.getOutputStream());
    return null;
}

From source file:io.hakbot.controller.servlet.ConsoleControllerServlet.java

private void doRequest(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {

    final String pathInfo = request.getPathInfo();
    final String uuid;

    // Check to make sure path info was specified
    if (StringUtils.isEmpty(pathInfo)) {
        response.sendError(400);/* w ww.j a  v a 2s . c  o  m*/
        return;
    } else {
        // Path info was specified so strip off the leading / character
        uuid = StringUtils.stripStart(pathInfo, "/");
    }

    // Check to make sure the uuid is a valid format
    if (!UuidUtil.isValidUUID(uuid)) {
        response.sendError(400);
        return;
    }

    final QueryManager qm = new QueryManager();
    final Job job = qm.getJob(uuid, new SystemAccount());
    qm.close();
    if (job == null) {
        response.sendError(404);
        return;
    }

    final ExpectedClassResolver resolver = new ExpectedClassResolver();
    try {
        final Class pluginClass = resolver.resolveProvider(job);
        request.setAttribute("job", job);
        final String pluginPage = "/WEB-INF/plugins/" + pluginClass.getName() + "/index.jsp?uuid=" + uuid;
        response.setContentType("text/html;charset=UTF-8");
        request.getRequestDispatcher(pluginPage).include(request, response);
        return;
    } catch (ClassNotFoundException | ExpectedClassResolverException e) {
        LOGGER.error(e.getMessage());
    }

    response.sendError(404);
}

From source file:com.apress.progwt.server.web.controllers.ViewUserController.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);

    String path = req.getPathInfo();

    String[] pathParts = path.split("/");
    log.debug("!path parts " + Arrays.toString(pathParts));

    // "/user/jeff" splits to [,jeff]
    if (pathParts.length < 2) {
        return new ModelAndView(getNotFoundView());
    }// w w  w .  j a  v  a 2 s .c  om

    String nickname = pathParts[1];

    User fetchedUser = userService.getUserByNicknameFullFetch(nickname);

    if (log.isDebugEnabled()) {
        log.debug("user u: " + fetchedUser);
        log.debug("isinit user " + Hibernate.isInitialized(fetchedUser));
        log.debug("isinit schools " + Hibernate.isInitialized(fetchedUser.getSchoolRankings()));
        for (Application sap : fetchedUser.getSchoolRankings()) {
            if (!Hibernate.isInitialized(sap)) {
                log.debug("Not initialized");
            }
        }
    }

    if (fetchedUser == null) {
        return new ModelAndView(getNotFoundView(), "message", "Couldn't find user with nickname: " + nickname);
    }
    model.put("viewUser", fetchedUser);

    ModelAndView mav = getMav();
    mav.addAllObjects(model);
    return mav;
}

From source file:com.aipo.social.core.oauth2.AipoOAuth2Servlet.java

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String path = request.getPathInfo();
    if (path.endsWith(TOKEN)) {
        HttpUtil.setNoCache(response);//from www .  j  ava  2  s  .  c o m
        sendOAuth2Response(response, tokenHandler.handle(request, response));
    } else {
        // authorization endpoint must support GET method and may support POST as
        // well
        doGet(request, response);
    }
}

From source file:it.geosolutions.opensdi2.configurations.controller.OSDIModuleController.java

protected String getPathFragment(HttpServletRequest req, int index) {
    String path = req.getPathInfo();
    if (path == null) {
        throw new IllegalArgumentException(
                "The path found in the request is null... this should never happen...");
    }/*from w  ww  . java2  s  .c o m*/
    LOGGER.debug("Extracting part of the following path '" + path + "' in order to get the module name...");
    path = StringUtils.removeStart(path, "/");
    path = StringUtils.removeEnd(path, "/");

    String[] parts = path.split("/");
    if (parts == null || parts.length <= index || parts[index] == null) {
        throw new IllegalArgumentException("no fragment is found... this should never happen...");
    }
    if (StringUtils.isNotEmpty(parts[index])) {
        return parts[index];
    }
    for (int i = index; i < parts.length; i++) {
        if (StringUtils.isNotEmpty(parts[i])) {
            return parts[i];
        }
    }
    return null;
}

From source file:com.orangeandbronze.jblubble.sample.UploadServlet.java

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String pathInfo = request.getPathInfo();
    if (pathInfo == null) {
        pathInfo = "/";
    }/*  ww  w.j a v a2s.  c  om*/
    LOGGER.debug("POST {}{}", PATH, pathInfo);
    Part part = request.getPart("file");
    if (part != null) {
        BlobKey blobKey = blobstoreService.createBlob(part.getInputStream(), getFileName(part),
                part.getContentType());
        LOGGER.debug("Created blob, generated key [{}]", blobKey);
        blobKeys.add(blobKey);
    }
    response.sendRedirect(request.getServletContext().getContextPath() + "/uploads");
}

From source file:edu.northwestern.bioinformatics.studycalendar.web.template.ExportActivitiesController.java

@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
        throws Exception {
    String identifier = extractIdentifier(request.getPathInfo(), ID_PATTERN);
    String fullPath = request.getPathInfo();
    String extension = fullPath.substring(fullPath.lastIndexOf(".") + 1).toLowerCase();

    if (identifier == null) {
        response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Could not extract study identifier");
        return null;
    }//from www  .  j  a  v a2 s  .  c o  m
    Source source = sourceDao.getByName(identifier);
    if (source == null) {
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
        return null;
    }
    if (!(extension.equals("csv") || extension.equals("xls") || extension.equals("xml"))) {
        response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Wrong extension type");
        return null;
    }
    String elt;

    if (extension.equals("xml")) {
        response.setContentType("text/xml");
        elt = activitySourceXmlSerializer.createDocumentString(source);
    } else {
        if (extension.equals("csv")) {
            response.setContentType("text/plain");
            elt = sourceSerializer.createDocumentString(source, ',');
        } else {
            response.setContentType("text");
            elt = sourceSerializer.createDocumentString(source, '\t');
        }
    }

    byte[] content = elt.getBytes();
    response.setContentLength(content.length);
    response.setHeader("Content-Disposition", "attachment");
    FileCopyUtils.copy(content, response.getOutputStream());
    return null;
}

From source file:org.mocksy.rules.http.HttpProxyRule.java

protected HttpRequestBase getProxyMethod(HttpServletRequest request) {
    String proxyUrl = this.proxyUrl;
    proxyUrl += request.getPathInfo();
    if (request.getQueryString() != null) {
        proxyUrl += "?" + request.getQueryString();
    }//w w w. j  a va  2  s  .c  om
    HttpRequestBase method = null;
    if ("GET".equals(request.getMethod())) {
        method = new HttpGet(proxyUrl);
        method.addHeader("Cache-Control", "no-cache");
        method.addHeader("Pragma", "no-cache");
    } else if ("POST".equals(request.getMethod())) {
        method = new HttpPost(proxyUrl);

        Map<String, String[]> paramMap = request.getParameterMap();
        List<NameValuePair> params = new ArrayList<NameValuePair>();
        for (String paramName : paramMap.keySet()) {
            String[] values = paramMap.get(paramName);
            for (String value : values) {
                NameValuePair param = new BasicNameValuePair(paramName, value);
                params.add(param);
            }
        }

        try {
            ((HttpPost) method).setEntity(new UrlEncodedFormEntity(params));
        } catch (UnsupportedEncodingException e) {
            // don't worry, this won't happen
        }
    }

    Enumeration headers = request.getHeaderNames();
    while (headers.hasMoreElements()) {
        String header = (String) headers.nextElement();
        if ("If-Modified-Since".equals(header) || "Content-Length".equals(header)
                || "Transfer-Encoding".equals(header))
            continue;
        Enumeration values = request.getHeaders(header);
        while (values.hasMoreElements()) {
            String value = (String) values.nextElement();
            method.addHeader(header, value);
        }
    }

    return method;
}

From source file:net.myrrix.web.servlets.RecommendToAnonymousServlet.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.j  ava  2s  .  c  o m*/
    }
    Iterator<String> pathComponents = SLASH.split(pathInfo).iterator();
    Pair<long[], float[]> itemIDsAndValue;
    try {
        itemIDsAndValue = 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();
    RescorerProvider rescorerProvider = getRescorerProvider();
    try {
        IDRescorer rescorer = rescorerProvider == null ? null
                : rescorerProvider.getRecommendToAnonymousRescorer(itemIDs, recommender,
                        getRescorerParams(request));
        Iterable<RecommendedItem> recommended = recommender.recommendToAnonymous(itemIDs, values,
                getHowMany(request), rescorer);
        output(request, response, recommended);
    } 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);
    } catch (IllegalArgumentException iae) {
        response.sendError(HttpServletResponse.SC_BAD_REQUEST, iae.toString());
    }
}