Java Code Examples for javax.servlet.http.HttpServletRequest.getPathTranslated()

The following are Jave code examples for showing how to use getPathTranslated() of the javax.servlet.http.HttpServletRequest class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: mirrorgate   File: OneTimeETagGenerationFilter.java   View Source Code Vote up 5 votes
@Override
public void doFilter(ServletRequest request, ServletResponse response,
        FilterChain chain) throws IOException, ServletException {

    if (!(request instanceof HttpServletRequest) || !(response instanceof HttpServletResponse)) {
        throw new ServletException("Just supports HTTP requests");
    }
    HttpServletRequest httpRequest = (HttpServletRequest) request;
    HttpServletResponse httpResponse = (HttpServletResponse) response;

    int cacheTime = 0;

    for(Pattern pattern : TIME_FOR_URL.keySet()) {
        if(pattern.matcher(httpRequest.getRequestURI()).matches()) {
            cacheTime = TIME_FOR_URL.get(pattern);
        }
    }
    httpResponse.setHeader(HttpHeaders.CACHE_CONTROL, "max-age="+cacheTime+", must-revalidate");

    httpRequest.getRequestURI();

    String key = httpRequest.getPathTranslated();
    if(cache.containsKey(key)) {
        String expectedEtag = httpRequest.getHeader(HttpHeaders.IF_NONE_MATCH);
        String currentEtag = cache.get(key);
        if(expectedEtag != null && expectedEtag.equals(currentEtag)) {
            httpResponse.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
            return;
        }
    }

    filter.doFilter(request, response, chain);
    String etag = httpResponse.getHeader(HttpHeaders.ETAG);
    cache.put(key, etag);
}
 
Example 2
Project: lams   File: InvokerHttpRequest.java   View Source Code Vote up 5 votes
/**
 * Construct a new wrapped request around the specified servlet request.
 *
 * @param request The servlet request being wrapped
 */
public InvokerHttpRequest(HttpServletRequest request) {

    super(request);
    this.pathInfo = request.getPathInfo();
    this.pathTranslated = request.getPathTranslated();
    this.requestURI = request.getRequestURI();
    this.servletPath = request.getServletPath();

}
 
Example 3
Project: jerrydog   File: InvokerHttpRequest.java   View Source Code Vote up 5 votes
/**
 * Construct a new wrapped request around the specified servlet request.
 *
 * @param request The servlet request being wrapped
 */
public InvokerHttpRequest(HttpServletRequest request) {

    super(request);
    this.pathInfo = request.getPathInfo();
    this.pathTranslated = request.getPathTranslated();
    this.requestURI = request.getRequestURI();
    this.servletPath = request.getServletPath();

}
 
Example 4
Project: gitplex-mit   File: ServletRequestCopy.java   View Source Code Vote up 4 votes
public ServletRequestCopy(HttpServletRequest request) {
	this.servletPath = request.getServletPath();
	this.contextPath = request.getContextPath();
	this.pathInfo = request.getPathInfo();
	this.requestUri = request.getRequestURI();
	this.requestURL = request.getRequestURL();
	this.method = request.getMethod();
	this.serverName = request.getServerName();
	this.serverPort = request.getServerPort();
	this.protocol = request.getProtocol();
	this.scheme = request.getScheme();
	
	
	/*
	 * have to comment out below two lines as otherwise web socket will
	 * report UnSupportedOperationException upon connection
	 */
	//this.characterEncoding = request.getCharacterEncoding();
	//this.contentType = request.getContentType();
	//this.requestedSessionId = request.getRequestedSessionId();
	this.characterEncoding = null;
	this.contentType = null;
	this.requestedSessionId = null;
	
	this.locale = request.getLocale();
	this.locales = request.getLocales();
	this.isSecure = request.isSecure();
	this.remoteUser = request.getRemoteUser();
	this.remoteAddr = request.getRemoteAddr();
	this.remoteHost = request.getRemoteHost();
	this.remotePort = request.getRemotePort();
	this.localAddr = request.getLocalAddr();
	this.localName = request.getLocalName();
	this.localPort = request.getLocalPort();
	this.pathTranslated = request.getPathTranslated();
	this.principal = request.getUserPrincipal();

	HttpSession session = request.getSession(true);
	httpSession = new HttpSessionCopy(session);

	String s;
	Enumeration<String> e = request.getHeaderNames();
	while (e != null && e.hasMoreElements()) {
		s = e.nextElement();
		Enumeration<String> headerValues = request.getHeaders(s);
		this.headers.put(s, headerValues);
	}

	e = request.getAttributeNames();
	while (e != null && e.hasMoreElements()) {
		s = e.nextElement();
		attributes.put(s, request.getAttribute(s));
	}

	e = request.getParameterNames();
	while (e != null && e.hasMoreElements()) {
		s = e.nextElement();
		parameters.put(s, request.getParameterValues(s));
	}
}