Java Code Examples for org.apache.catalina.connector.Request#getContextPath()

The following examples show how to use org.apache.catalina.connector.Request#getContextPath() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
private boolean isContextSkipped(Request request) {
    Context context = request.getContext();
    String ctx = context == null ? null :context.getPath();
    if (ctx == null || "".equals(ctx)) {
        ctx = request.getContextPath();
        if (ctx == null || "".equals(ctx)) {
            String requestUri = request.getRequestURI();
            if ("/".equals(requestUri)) {
                return true;
            }
            StringTokenizer tokenizer = new StringTokenizer(request.getRequestURI(), "/");
            if (!tokenizer.hasMoreTokens()) {
                return false;
            }
            ctx = tokenizer.nextToken();
        }
    }
    return ("carbon".equalsIgnoreCase(ctx) || "services".equalsIgnoreCase(ctx));
}
 
Example 2
/**
 * Redirect to the configured landing page, if any.
 *
 * @param request The request.
 * @param response The response.
 *
 * @return {@code true} if successfully redirected, {@code false} if no
 * landing page is configured.
 *
 * @throws IOException If an I/O error happens communicating with the
 * client.
 */
protected boolean redirectToLandingPage(final Request request,
		final HttpServletResponse response)
	throws IOException {

	// do we have landing page configured?
	if (this.landingPage == null)
		return false;

	// construct landing page URI
	final String uri = request.getContextPath() + this.landingPage;

	// make it think the user originally requested the landing page
	final SavedRequest savedReq = new SavedRequest();
	savedReq.setMethod("GET");
	savedReq.setRequestURI(uri);
	savedReq.setDecodedRequestURI(uri);
	request.getSessionInternal(true).setNote(
			Constants.FORM_REQUEST_NOTE, savedReq);

	// send the redirect
	response.sendRedirect(response.encodeRedirectURL(uri));

	// done, success
	return true;
}
 
Example 3
private boolean isNonSecuredEndPoint(Request request) {
    if (request.getCoyoteRequest() != null && request.getCoyoteRequest().getMimeHeaders() !=
            null && request.getCoyoteRequest().getMimeHeaders().getValue(Constants
            .HTTPHeaders.HEADER_HTTP_AUTHORIZATION) != null) {
        //This is to handle the DEP behaviours of the same endpoint being non-secured in the
        // first call and then being secured in the second call which comes with the basic
        // auth header.
        return false;
    }
    String uri = request.getRequestURI();
    if (uri == null) {
        uri = "";
    }
    if (!uri.endsWith("/")) {
        uri = uri + "/";
    }
    String contextPath = request.getContextPath();
    //Check the contextPath in nonSecuredEndpoints. If so it means cache is not populated for this web-app.
    if (!nonSecuredEndpoints.containsKey(contextPath)) {
        String param = request.getContext().findParameter("nonSecuredEndPoints");
        String skippedEndPoint;
        if (param != null && !param.isEmpty()) {
            //Add the nonSecured end-points to cache
            StringTokenizer tokenizer = new StringTokenizer(param, ",");
            nonSecuredEndpoints.put(contextPath, "true");
            while (tokenizer.hasMoreTokens()) {
                skippedEndPoint = tokenizer.nextToken();
                skippedEndPoint = skippedEndPoint.replace("\n", "").replace("\r", "").trim();
                if (!skippedEndPoint.endsWith("/")) {
                    skippedEndPoint = skippedEndPoint + "/";
                }
                nonSecuredEndpoints.put(skippedEndPoint, "true");
            }
        }
    }
    return nonSecuredEndpoints.containsKey(uri);
}
 
Example 4
/**
 * Get web-application base URL (either from the {@code hostBaseURI}
 * authenticator property or auto-detected from the request).
 *
 * @param request The request.
 *
 * @return Base URL.
 */
protected String getBaseURL(final Request request) {

	if (this.hostBaseURI != null)
		return this.hostBaseURI + request.getContextPath();

	final StringBuilder baseURLBuf = new StringBuilder(64);
	baseURLBuf.append("https://").append(request.getServerName());
	final int port = request.getServerPort();
	if (port != 443)
		baseURLBuf.append(':').append(port);
	baseURLBuf.append(request.getContextPath());

	return baseURLBuf.toString();
}