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.sfwl.framework.web.casclient.AbstractTicketValidationFilter.java

public final void doFilter(final ServletRequest servletRequest, final ServletResponse servletResponse,
        final FilterChain filterChain) throws IOException, ServletException {

    if (!preFilter(servletRequest, servletResponse, filterChain)) {
        return;//from w ww .  jav a 2s .  c  om
    }

    final HttpServletRequest request = (HttpServletRequest) servletRequest;
    final HttpServletResponse response = (HttpServletResponse) servletResponse;
    final String ticket = retrieveTicketFromRequest(request);

    // URL(js+css+img)
    if (excepUrlPattern != null && excepUrlPattern.matcher(request.getServletPath()).matches()) {
        filterChain.doFilter(servletRequest, servletResponse);
        return;
    }

    if (CommonUtils.isNotBlank(ticket)) {
        logger.debug("Attempting to validate ticket: {}", ticket);

        try {
            final Assertion assertion = this.ticketValidator.validate(ticket,
                    constructServiceUrl(request, response));

            logger.debug("Successfully authenticated user: {}", assertion.getPrincipal().getName());

            request.setAttribute(CONST_CAS_ASSERTION, assertion);

            if (this.useSession) {
                request.getSession().setAttribute(CONST_CAS_ASSERTION, assertion);
            }
            onSuccessfulValidation(request, response, assertion);

            if (this.redirectAfterValidation) {
                logger.debug("Redirecting after successful ticket validation.");
                response.sendRedirect(constructServiceUrl(request, response));
                return;
            }
        } catch (final TicketValidationException e) {
            logger.debug(e.getMessage(), e);

            onFailedValidation(request, response);

            if (this.exceptionOnValidationFailure) {
                throw new ServletException(e);
            }

            response.sendError(HttpServletResponse.SC_FORBIDDEN, e.getMessage());

            return;
        }
    }

    filterChain.doFilter(request, response);

}

From source file:com.sun.syndication.propono.atom.server.impl.FileBasedAtomHandler.java

/**
 * Contruct handler for one request, using specified file storage directory.
 * @param req       Request to be handled.
 * @param uploaddir File storage upload dir.
 *//* www.  j  ava 2  s .  c  o m*/
public FileBasedAtomHandler(HttpServletRequest req, String uploaddir) {
    log.debug("ctor");

    userName = authenticateBASIC(req);

    atomProtocolURL = req.getScheme() + "://" + req.getServerName() + ":" + req.getServerPort()
            + req.getContextPath() + req.getServletPath();

    contextURI = req.getScheme() + "://" + req.getServerName() + ":" + req.getServerPort()
            + req.getContextPath();

    try {
        service = new FileBasedAtomService(userName, uploaddir, contextURI, req.getContextPath(),
                req.getServletPath());
    } catch (Throwable t) {
        throw new RuntimeException("ERROR creating FileBasedAtomService", t);
    }
}

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

/**
 * Returns a list of entities owned by the organization identified by the given ID
 *
 * @return a reply...//from w w w.j  a va  2 s.  c  om
 * @throws McBasicRestException
 */
protected Page<T> getOrganizationEntities(HttpServletRequest request, String orgMrn, Pageable pageable)
        throws McBasicRestException {
    Organization org = this.organizationService.getOrganizationByMrn(orgMrn);
    if (org != null) {
        return this.entityService.listPageFromOrg(org.getId(), pageable);
    } else {
        throw new McBasicRestException(HttpStatus.NOT_FOUND, MCIdRegConstants.ORG_NOT_FOUND,
                request.getServletPath());
    }
}

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

/**
 * Approves the organization identified by the given ID
 * /*from  ww w.  j a v a2s.co m*/
 * @return a reply...
 * @throws McBasicRestException 
 */
@RequestMapping(value = "/api/org/{orgMrn}/approve", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
@PreAuthorize("hasRole('ROLE_APPROVE_ORG')")
public ResponseEntity<Organization> approveOrganization(HttpServletRequest request, @PathVariable String orgMrn)
        throws McBasicRestException {
    Organization org = this.organizationService.getOrganizationByMrnDisregardApproved(orgMrn);
    if (org == null) {
        throw new McBasicRestException(HttpStatus.NOT_FOUND, MCIdRegConstants.ORG_NOT_FOUND,
                request.getServletPath());
    }
    if (org.isApproved()) {
        throw new McBasicRestException(HttpStatus.BAD_REQUEST, MCIdRegConstants.ORG_ALREADY_APPROVED,
                request.getServletPath());
    }
    // Create the Identity Provider for the org
    if ("own-idp".equals(org.getFederationType()) && org.getIdentityProviderAttributes() != null
            && !org.getIdentityProviderAttributes().isEmpty()) {
        keycloakAU.init(KeycloakAdminUtil.BROKER_INSTANCE);
        try {
            keycloakAU.createIdentityProvider(org.getMrn().toLowerCase(), org.getIdentityProviderAttributes());
        } catch (MalformedURLException e) {
            throw new McBasicRestException(HttpStatus.BAD_REQUEST, MCIdRegConstants.INVALID_IDP_URL,
                    request.getServletPath());
        } catch (IOException e) {
            throw new McBasicRestException(HttpStatus.BAD_REQUEST, MCIdRegConstants.COULD_NOT_GET_DATA_FROM_IDP,
                    request.getServletPath());
        }
    }
    // Enabled the organization and save it
    org.setApproved(true);
    Organization approvedOrg = this.organizationService.save(org);
    return new ResponseEntity<>(approvedOrg, HttpStatus.OK);
}

From source file:de.micromata.genome.gwiki.web.dav.WebDavServlet.java

public synchronized HttpManager getHttpManager(HttpServletRequest req) {
    if (httpManager != null) {
        return httpManager;
    }/*ww  w . j  ava 2 s.co  m*/

    GWikiStorage wkStorage = GWikiServlet.INSTANCE.getDAOContext().getStorage();
    FileSystem storage = null;
    if (wkStorage instanceof GWikiFileStorage) {
        storage = ((GWikiFileStorage) wkStorage).getStorage();
    } else {
        throw new RuntimeException("GWiki not found or has no compatible storage");
    }
    String cpath = req.getContextPath();
    String servPath = req.getServletPath();
    // String pi = req.getPathInfo();
    String prefix = cpath + servPath;
    ResponseHandler responseHandler = new CompressingResponseHandler(new DefaultResponseHandler());
    FsDavResourceFactory fsfac = new FsDavResourceFactory(storage, prefix);
    fsfac.setInternalUserName(internalUserName);
    fsfac.setInternalPass(internalPass);
    fsfac.setWordHtmlEdit(wordHtmlEdit);
    if (wordHtmlEdit == true) {
        httpManager = new HttpManager(new FsDavOfficeResourceFactory(GWikiServlet.INSTANCE.getWikiWeb(), fsfac),
                responseHandler);
    } else {
        httpManager = new HttpManager(fsfac, responseHandler);
    }
    return httpManager;
}

From source file:org.cloudfoundry.identity.uaa.login.RemoteUaaController.java

@RequestMapping(value = "/oauth/**")
@ResponseBody//from  w w w. j  a va 2  s  . c om
public void invalid(HttpServletRequest request) throws Exception {
    throw new OAuth2Exception("no matching handler for request: " + request.getServletPath());
}

From source file:com.meltmedia.cadmium.servlets.jersey.StatusService.java

@GET
@Path("/health")
@Produces("text/plain")
public String health(@Context HttpServletRequest request) {
    StringBuilder builder = new StringBuilder();
    builder.append("Server: " + request.getServerName() + "\n");
    builder.append("Scheme: " + request.getScheme() + "\n");
    builder.append("Port: " + request.getServerPort() + "\n");
    builder.append("ContextPath:  " + request.getContextPath() + "\n");
    builder.append("ServletPath: " + request.getServletPath() + "\n");
    builder.append("Uri: " + request.getRequestURI() + "\n");
    builder.append("Query: " + request.getQueryString() + "\n");
    Enumeration<?> headerNames = request.getHeaderNames();
    builder.append("Headers:\n");
    while (headerNames.hasMoreElements()) {
        String name = (String) headerNames.nextElement();
        Enumeration<?> headers = request.getHeaders(name);
        builder.append("  '" + name + "':\n");
        while (headers.hasMoreElements()) {
            String headerValue = (String) headers.nextElement();
            builder.append("    -" + headerValue + "\n");
        }/*w w  w  .ja  v a  2  s.  co  m*/
    }
    if (request.getCookies() != null) {
        builder.append("Cookies:\n");
        for (Cookie cookie : request.getCookies()) {
            builder.append("  '" + cookie.getName() + "':\n");
            builder.append("    value: " + cookie.getValue() + "\n");
            builder.append("    domain: " + cookie.getDomain() + "\n");
            builder.append("    path: " + cookie.getPath() + "\n");
            builder.append("    maxAge: " + cookie.getMaxAge() + "\n");
            builder.append("    version: " + cookie.getVersion() + "\n");
            builder.append("    comment: " + cookie.getComment() + "\n");
            builder.append("    secure: " + cookie.getSecure() + "\n");
        }
    }
    return builder.toString();
}

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

/**
 * Deletes a Logo//ww w . jav a 2s .  c  om
 *
 * @return a reply...
 * @throws McBasicRestException
 */
@RequestMapping(value = "/api/org/{orgMrn}/logo", method = RequestMethod.DELETE)
@ResponseBody
@PreAuthorize("hasRole('ORG_ADMIN') and @accessControlUtil.hasAccessToOrg(#orgMrn)")
public ResponseEntity<?> deleteLogo(HttpServletRequest request, @PathVariable String orgMrn)
        throws McBasicRestException {
    Organization org = this.organizationService.getOrganizationByMrn(orgMrn);
    if (org != null) {
        if (org.getLogo() != null) {
            org.setLogo(null);
            organizationService.save(org);
        }
        return new ResponseEntity<>(HttpStatus.OK);
    } else {
        throw new McBasicRestException(HttpStatus.NOT_FOUND, MCIdRegConstants.ORG_NOT_FOUND,
                request.getServletPath());
    }
}

From source file:com.codeabovelab.dm.gateway.proxy.common.HttpProxy.java

/**
 * Copy cookie from the proxy to the servlet client.
 * Replaces cookie path to local path and renames cookie to avoid collisions.
 *//*from  w ww. ja v a  2  s.com*/
private void copyProxyCookie(HttpServletRequest servletRequest, HttpServletResponse servletResponse,
        Header header) {
    List<HttpCookie> cookies = HttpCookie.parse(header.getValue());
    String path = servletRequest.getContextPath(); // path starts with / or is empty string
    path += servletRequest.getServletPath(); // servlet path starts with / or is empty string
    for (int i = 0, l = cookies.size(); i < l; i++) {
        HttpCookie cookie = cookies.get(i);
        //set cookie name prefixed w/ a proxy value so it won't collide w/ other cookies
        String proxyCookieName = getCookieNamePrefix() + cookie.getName();
        Cookie servletCookie = new Cookie(proxyCookieName, cookie.getValue());
        servletCookie.setComment(cookie.getComment());
        servletCookie.setMaxAge((int) cookie.getMaxAge());
        servletCookie.setPath(path); //set to the path of the proxy servlet
        // don't set cookie domain
        servletCookie.setSecure(cookie.getSecure());
        servletCookie.setVersion(cookie.getVersion());
        servletResponse.addCookie(servletCookie);
    }
}

From source file:org.mashupmedia.controller.remote.RemoteLibraryController.java

@RequestMapping(value = "/stream/{uniqueName}/{mediaItemId}", method = { RequestMethod.GET,
        RequestMethod.HEAD })// w  w w  . ja v  a 2 s.co m
public ModelAndView handleStreamMediaItem(HttpServletRequest request, @PathVariable String uniqueName,
        @PathVariable Long mediaItemId, Model model) throws IOException {
    Library remoteLibrary = getRemoteLibrary(uniqueName, request, true);
    if (remoteLibrary == null) {
        logger.info("Unable to stream remote media, unknown host: " + request.getRemoteHost());
        return null;
    }

    logInAsSystemuser(request);

    StringBuilder servletPathBuilder = new StringBuilder(request.getServletPath());
    servletPathBuilder.append("/streaming/media");
    servletPathBuilder.append("/" + mediaItemId);
    return new ModelAndView("forward:" + servletPathBuilder.toString());
}