Example usage for javax.servlet.http HttpServletRequest getServletPath

List of usage examples for javax.servlet.http HttpServletRequest getServletPath

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletRequest getServletPath.

Prototype

public String getServletPath();

Source Link

Document

Returns the part of this request's URL that calls the servlet.

Usage

From source file:com.justcloud.osgifier.servlet.OsgifierServlet.java

public String buildUrl(HttpServletRequest req) {
    return req.getRequestURI().replace(req.getContextPath(), "").replace(req.getServletPath(), "");
}

From source file:net.maritimecloud.identityregistry.controllers.BaseControllerWithCertificate.java

protected void revokeCertificate(Long certId, CertificateRevocation input, HttpServletRequest request)
        throws McBasicRestException {
    Certificate cert = this.certificateService.getCertificateById(certId);
    if (!input.validateReason()) {
        throw new McBasicRestException(HttpStatus.BAD_REQUEST, MCIdRegConstants.INVALID_REVOCATION_REASON,
                request.getServletPath());
    }//  w  w  w.  ja  v a2 s  .  c  o m
    if (input.getRevokedAt() == null) {
        throw new McBasicRestException(HttpStatus.BAD_REQUEST, MCIdRegConstants.INVALID_REVOCATION_DATE,
                request.getServletPath());
    }
    cert.setRevokedAt(input.getRevokedAt());
    cert.setRevokeReason(input.getRevokationReason());
    cert.setRevoked(true);
    this.certificateService.saveCertificate(cert);
}

From source file:dk.itst.oiosaml.sp.develmode.DevelModeImpl.java

public void doFilter(HttpServletRequest req, HttpServletResponse res, FilterChain fc, Configuration conf)
        throws IOException, ServletException {

    // Inserted to avoid loginpage when a samlhandler is requested in develmode
    if (req.getServletPath().equals(conf.getProperty(Constants.PROP_SAML_SERVLET))) {
        log.debug("Develmode: Request to SAML servlet, access granted");
        fc.doFilter(req, res);/*from www .ja  v  a  2 s.c o m*/
        return;
    }

    UserAssertionHolder.set(null);
    UserAssertion ua = (UserAssertion) req.getSession().getAttribute(Constants.SESSION_USER_ASSERTION);
    if (ua == null) {
        String[] users = conf.getStringArray("oiosaml-sp.develmode.users");
        if (users == null || users.length == 0) {
            log.error("No users defined in properties. Set oiosaml-sp.develmode.users");
            res.setStatus(500);
            HTTPUtils.sendCacheHeaders(res);
            render("nousers.vm", res, new HashMap<String, Object>());
            return;
        }

        if (users.length == 1) {
            ua = selectUser(users[0], conf);
        } else {
            String selected = req.getParameter("__oiosaml_devel");
            if (selected == null || !Arrays.asList(users).contains(selected)) {
                HTTPUtils.sendCacheHeaders(res);

                Map<String, Object> params = new HashMap<String, Object>();
                params.put("users", users);
                params.put("params", buildParameterString(req.getParameterMap()));
                render("users.vm", res, params);
                return;
            } else {
                HTTPUtils.sendCacheHeaders(res);
                ua = selectUser(selected, conf);
                req.getSession().setAttribute(Constants.SESSION_USER_ASSERTION, ua);
                res.sendRedirect(req.getRequestURI() + "?" + buildParameterString(req.getParameterMap()));
                return;
            }
        }
    }

    if (ua != null) {
        req.getSession().setAttribute(Constants.SESSION_USER_ASSERTION, ua);
        UserAssertionHolder.set(ua);

        HttpServletRequestWrapper requestWrap = new SAMLHttpServletRequest(req, ua, "");
        fc.doFilter(requestWrap, res);
        return;
    } else {
        log.error("No assertion found");
        res.sendError(500);
        return;
    }
}

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)
 *//*  ww  w  . j  a va2s.  co 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:no.dusken.common.spring.ExceptionHandler.java

private String getBody(HttpServletRequest request, Exception ex) {
    StringBuilder builder = new StringBuilder();
    builder.append("Method: ");
    builder.append(request.getMethod());
    builder.append('\n');
    builder.append("Servletpath: ");
    builder.append(request.getServletPath());
    builder.append('\n');
    builder.append("URI: ");
    builder.append(request.getRequestURI());
    builder.append('\n');
    builder.append("Query: ");
    builder.append(request.getQueryString());
    builder.append('\n');
    builder.append("User-Agent: ");
    builder.append(request.getHeader("User-Agent"));
    builder.append('\n');
    builder.append("Accept: ");
    builder.append(request.getHeader("Accept"));
    builder.append('\n');
    builder.append("Accept-Encoding: ");
    builder.append(request.getHeader("Accept-Encoding"));
    builder.append('\n');

    builder.append("Stacktrace:");
    builder.append('\n');

    String stacktrace = getStackTraceAsString(ex.getStackTrace())
            + (ex.getMessage() == null ? "" : "| Message: " + ex.getMessage());
    builder.append(stacktrace);/*from   w  w  w. j  av  a2 s.  co m*/
    return builder.toString();
}

From source file:com.glaf.core.util.RequestUtils.java

/**
 * ?//from w  ww . jav a 2s. c o  m
 * 
 * @param request
 * @param url
 * @return
 */
public static String getRelativeUrl(HttpServletRequest request, String url) {
    if (!url.startsWith(getLocalHostAddress(request, true) + "/")) {
        return url;
    }
    url = url.replace((getLocalHostAddress(request, true) + "/"), "");
    String actualServlet = request.getContextPath() + request.getServletPath();
    if (actualServlet.startsWith("/")) {
        actualServlet = actualServlet.substring(1);
    }
    int i = actualServlet.indexOf("/");
    while (i != -1) {
        if (url.startsWith(actualServlet.substring(0, i))) {
            url = url.replace(actualServlet.substring(0, i + 1), "");
        } else {
            url = "../" + url;
        }
        actualServlet = actualServlet.substring(i + 1);
        i = actualServlet.indexOf("/");
    }
    return url;
}

From source file:com.krawler.esp.servlets.ProfileImageServlet.java

public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    // Get the absolute path of the image
    ServletContext sc = getServletContext();
    String uri = req.getRequestURI();
    String servletBase = req.getServletPath();
    if (!StringUtil.isNullOrEmpty(req.getParameter("flag"))) {
        try {/*w w w  .  j a v  a  2s.  co m*/
            // TODO: Fix hardcoded url
            if (!StringUtil.isNullOrEmpty(req.getParameter("trackid"))) {
                String url = "/remoteapi.jsp?action=100&data={\"iscommit\":true}&trackid="
                        + req.getParameter("trackid");
                RequestDispatcher rd = req.getRequestDispatcher(url);
                rd.include(req, resp);
            }
            String fileName = StorageHandler.GetProfileImgStorePath() + "blankImage.png";
            File file = new File(fileName);
            if (file.exists()) {
                FileInputStream in = new FileInputStream(file);
                OutputStream out = resp.getOutputStream();

                // Copy the contents of the file to the output stream
                byte[] buf = new byte[4096];
                int count = 0;
                while ((count = in.read(buf)) >= 0) {
                    out.write(buf, 0, count);
                }
                in.close();
                out.close();
            }
        } catch (Exception e) {
            logger.warn(e.getMessage(), e);
        }
    } else {
        boolean Companyflag = (req.getParameter("company") != null) ? true : false;
        String imagePath = defaultImgPath;
        String requestedFileName = "";
        if (Companyflag) {
            imagePath = defaultCompanyImgPath;
            String companyId = null;
            try {
                companyId = sessionHandlerImpl.getCompanyid(req);
            } catch (Exception ee) {
                logger.warn(ee.getMessage(), ee);
            }
            if (StringUtil.isNullOrEmpty(companyId)) {
                String domain = URLUtil.getDomainName(req);
                if (!StringUtil.isNullOrEmpty(domain)) {
                    //@@@
                    //                        companyId = sessionHandlerImpl.getCompanyid(domain);
                    requestedFileName = "/original_" + companyId + ".png";
                } else {
                    requestedFileName = "logo.gif";
                }
            } else {
                requestedFileName = "/" + companyId + ".png";
            }
        } else {
            requestedFileName = uri.substring(uri.lastIndexOf(servletBase) + servletBase.length());
        }
        String fileName = null;

        fileName = StorageHandler.GetProfileImgStorePath() + requestedFileName;
        // Get the MIME type of the image
        String mimeType = sc.getMimeType(fileName);
        if (mimeType == null) {
            sc.log("Could not get MIME type of " + fileName);
            resp.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            return;
        }

        // Set content type
        resp.setContentType(mimeType);

        // Set content size
        File file = new File(fileName);
        if (!file.exists()) {
            if (fileName.contains("_100.")) {
                file = new File(fileName.replaceAll("_100.", "."));
            }
            if (!file.exists()) {
                file = new File(sc.getRealPath(imagePath));
            }
        }

        resp.setContentLength((int) file.length());

        // Open the file and output streams
        FileInputStream in = new FileInputStream(file);
        OutputStream out = resp.getOutputStream();

        // Copy the contents of the file to the output stream
        byte[] buf = new byte[4096];
        int count = 0;
        while ((count = in.read(buf)) >= 0) {
            out.write(buf, 0, count);
        }
        in.close();
        out.close();
    }
}

From source file:ca.uhn.fhir.rest.server.IncomingRequestAddressStrategy.java

@Override
public String determineServerBase(ServletContext theServletContext, HttpServletRequest theRequest) {
    String requestFullPath = StringUtils.defaultString(theRequest.getRequestURI());

    String servletPath;//from w w w .  j  av a2 s . co  m
    if (myServletPath != null) {
        servletPath = myServletPath;
    } else {
        servletPath = StringUtils.defaultString(theRequest.getServletPath());
    }

    StringBuffer requestUrl = theRequest.getRequestURL();
    String servletContextPath = StringUtils.defaultString(theRequest.getContextPath());

    String requestPath = requestFullPath.substring(servletContextPath.length() + servletPath.length());
    if (requestPath.length() > 0 && requestPath.charAt(0) == '/') {
        requestPath = requestPath.substring(1);
    }

    int startOfPath = requestUrl.indexOf("//");
    int requestUrlLength = requestUrl.length();

    if (startOfPath != -1 && (startOfPath + 2) < requestUrlLength) {
        startOfPath = requestUrl.indexOf("/", startOfPath + 2);
    }
    if (startOfPath == -1) {
        startOfPath = 0;
    }

    int contextIndex;
    if (servletPath.length() == 0 || servletPath.equals("/")) {
        if (requestPath.length() == 0) {
            contextIndex = requestUrlLength;
        } else {
            contextIndex = requestUrl.indexOf(requestPath, startOfPath);
        }
    } else {
        //servletContextPath can start with servletPath 
        contextIndex = requestUrl.indexOf(servletPath + "/", startOfPath);
        if (contextIndex == -1) {
            contextIndex = requestUrl.indexOf(servletPath, startOfPath);
        }
    }

    String fhirServerBase;
    int length = contextIndex + servletPath.length();
    if (length > requestUrlLength) {
        length = requestUrlLength;
    }
    fhirServerBase = requestUrl.substring(0, length);
    return fhirServerBase;
}

From source file:ar.com.zauber.commons.spring.web.handlers.UrlBasedHandlerAdapter.java

/** @see HandlerAdapter#handle(HttpServletRequest,HttpServletResponse, Object) */
@Override/*from w  w w .j a  va 2s.  c o m*/
public final ModelAndView handle(final HttpServletRequest request, final HttpServletResponse response,
        final Object handler) throws Exception {
    final Long start = System.currentTimeMillis();
    try {
        final ModelAndView mv = getHandler(request).handle(request, response, handler);
        logActivity(request.getServletPath(), (System.currentTimeMillis() - start));
        return mv;
    } catch (Exception e) {
        logger.error("Error with request:" + request.getServletPath(), e);
        logActivity(request.getServletPath(), (System.currentTimeMillis() - start), e);
        throw e;
    }
}

From source file:org.abstracthorizon.proximity.webapp.controllers.ArtifactsController.java

/**
 * Artifacts list.//from w  ww  . j ava 2s  .co  m
 * 
 * @param request the request
 * @param response the response
 * 
 * @return the model and view
 * 
 * @throws Exception the exception
 */
public ModelAndView artifactsList(HttpServletRequest request, HttpServletResponse response) throws Exception {
    String requestURI = request.getRequestURI()
            .substring(request.getContextPath().length() + request.getServletPath().length());
    if (requestURI.length() == 0) {
        requestURI = "/";
    }
    logger.debug("Got artifact request on URI " + requestURI);
    String orderBy = request.getParameter("orderBy") == null ? "name" : request.getParameter("orderBy");
    String targetRepository = request.getParameter("repositoryId");
    String targetGroup = request.getParameter("repositoryGroupId");
    List requestPathList = explodeUriToList(requestURI);

    String gid = null;
    String aid = null;
    String version = null;

    if (requestPathList.size() > 0) {
        gid = (String) requestPathList.get(0);
    }
    if (requestPathList.size() > 1) {
        aid = (String) requestPathList.get(1);
    }
    if (requestPathList.size() > 2) {
        version = (String) requestPathList.get(2);
    }

    // this view relies on search only, thats the trick:
    // level 1: search for "kind:pom", extract the "pom.gid" properties,
    // make them unique, show
    // level 2: search for "kind:pom AND pom.gid:SELECTION", extract the
    // "pom.aid" properties, make them unqie, show
    // level 3: search for "kind:pom AND pom.gid:SELECTION AND
    // pom.aid:SELECTION", extract the "pom.version" ...
    // level 4: search for "kind:pom AND pom.gid:SELECTION AND
    // pom.aid:SELECTION AND pom.version:SELECTION" and offer pom.pck
    // download?

    // URI: /pom.gid/pom.aid/pom.version

    logger.debug("Got request for artifactList on URI=" + requestURI);

    String searchExpr = "m2kind:pom";
    if (targetRepository != null) {
        searchExpr += " AND repository.id:" + targetRepository;
    }
    if (targetGroup != null) {
        searchExpr += " AND repository.groupId:" + targetGroup;
    }
    if (gid != null) {
        searchExpr += " AND pom.gid:" + gid;
    }
    if (aid != null) {
        searchExpr += " AND pom.aid:" + aid;
    }
    if (version != null) {
        searchExpr += " AND pom.version:" + version;
    }

    // make list unique and ordered on smthn
    List artifactList = null;
    if (version != null) {
        artifactList = sortAndMakeUnique(indexer.searchByQuery(searchExpr), "pom.version");
    } else if (aid != null) {
        artifactList = sortAndMakeUnique(indexer.searchByQuery(searchExpr), "pom.version");
    } else if (gid != null) {
        artifactList = sortAndMakeUnique(indexer.searchByQuery(searchExpr), "pom.aid");
    } else {
        artifactList = sortAndMakeUnique(indexer.searchByQuery(searchExpr), "pom.gid");
    }

    Map result = new HashMap();
    result.put("gid", gid);
    result.put("aid", aid);
    result.put("version", version);
    result.put("items", artifactList);
    result.put("orderBy", orderBy);
    result.put("requestUri", requestURI);
    result.put("requestPathList", requestPathList);

    return new ModelAndView("repository/artifactList", result);

}