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

The following examples show how to use javax.servlet.http.HttpServletRequest#getPathTranslated() . 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 check out the related API usage on the sidebar.
Example 1
Source File: OneTimeETagGenerationFilter.java    From mirrorgate with Apache License 2.0 5 votes vote down vote up
@Override
public void doFilter(
    final ServletRequest request,
    final ServletResponse response,
    final FilterChain chain
) throws IOException, ServletException {

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

    int cacheTime = 0;

    for (final Map.Entry<Pattern, Integer> entry : TIME_FOR_URL.entrySet()) {
        if (entry.getKey().matcher(httpRequest.getRequestURI()).matches()) {
            cacheTime = TIME_FOR_URL.get(entry.getKey());
        }
    }
    httpResponse.setHeader(HttpHeaders.CACHE_CONTROL, "max-age=" + cacheTime + ", must-revalidate");

    httpRequest.getRequestURI();

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

    filter.doFilter(request, response, chain);
    cache.put(key, httpResponse.getHeader(HttpHeaders.ETAG));
}
 
Example 2
Source File: PathDisplay.java    From portals-pluto with Apache License 2.0 5 votes vote down vote up
public PathDisplay(HttpServletRequest req, String caller) {
      this.caller = caller;
      title = (String) req.getAttribute("title");
      async_request_uri = (String) req.getAttribute("javax.servlet.async.request_uri");
      async_context_path = (String) req.getAttribute("javax.servlet.async.context_path");
      async_servlet_path = (String) req.getAttribute("javax.servlet.async.servlet_path");
      async_path_info = (String) req.getAttribute("javax.servlet.async.path_info");
      async_query_string = (String) req.getAttribute("javax.servlet.async.query_string");

      forward_request_uri = (String) req.getAttribute("javax.servlet.forward.request_uri");
      forward_context_path = (String) req.getAttribute("javax.servlet.forward.context_path");
      forward_servlet_path = (String) req.getAttribute("javax.servlet.forward.servlet_path");
      forward_path_info = (String) req.getAttribute("javax.servlet.forward.path_info");
      forward_query_string = (String) req.getAttribute("javax.servlet.forward.query_string");

      include_request_uri = (String) req.getAttribute("javax.servlet.include.request_uri");
      include_context_path = (String) req.getAttribute("javax.servlet.include.context_path");
      include_servlet_path = (String) req.getAttribute("javax.servlet.include.servlet_path");
      include_path_info = (String) req.getAttribute("javax.servlet.include.path_info");
      include_query_string = (String) req.getAttribute("javax.servlet.include.query_string");

      method_request_uri = req.getRequestURI();
      method_context_path = req.getContextPath();
      method_servlet_path = req.getServletPath();
      method_path_info = req.getPathInfo();
      method_path_xlated = req.getPathTranslated();
      method_query_string = req.getQueryString();
      
      type = req.getDispatcherType().name();
      isAsyncSupported = req.isAsyncSupported();
      
      Map<String, String[]> pmap = req.getParameterMap();
      for (String key : pmap.keySet()) {
         params.put(key, Arrays.asList(pmap.get(key)));
      }
}
 
Example 3
Source File: HttpServletRequestSnapshot.java    From cxf with Apache License 2.0 5 votes vote down vote up
public HttpServletRequestSnapshot(HttpServletRequest request) {
    super(request);
    authType = request.getAuthType();
    characterEncoding = request.getCharacterEncoding();
    contentLength = request.getContentLength();
    contentType = request.getContentType();
    contextPath = request.getContextPath();
    cookies = request.getCookies();
    requestHeaderNames = request.getHeaderNames();
    Enumeration<String> tmp = request.getHeaderNames();
    while (tmp.hasMoreElements()) {
        String key = tmp.nextElement();
        headersMap.put(key, request.getHeaders(key));
    }
    localAddr = request.getLocalAddr();
    local = request.getLocale();
    localName = request.getLocalName();
    localPort = request.getLocalPort();
    method = request.getMethod();
    pathInfo = request.getPathInfo();
    pathTranslated = request.getPathTranslated();
    protocol = request.getProtocol();
    queryString = request.getQueryString();
    remoteAddr = request.getRemoteAddr();
    remoteHost = request.getRemoteHost();
    remotePort = request.getRemotePort();
    remoteUser = request.getRemoteUser();
    requestURI = request.getRequestURI();
    requestURL = request.getRequestURL();
    requestedSessionId = request.getRequestedSessionId();
    schema = request.getScheme();
    serverName = request.getServerName();
    serverPort = request.getServerPort();
    servletPath = request.getServletPath();
    if (request.isRequestedSessionIdValid()) {
        session = request.getSession();
    }
    principal = request.getUserPrincipal();
}
 
Example 4
Source File: RequestData.java    From sample.ferret with Apache License 2.0 5 votes vote down vote up
public RequestData(final HttpServletRequest request) {
    method = request.getMethod();
    uri = request.getRequestURI();
    protocol = request.getProtocol();
    servletPath = request.getServletPath();
    pathInfo = request.getPathInfo();
    pathTranslated = request.getPathTranslated();
    characterEncoding = request.getCharacterEncoding();
    queryString = request.getQueryString();
    contentLength = request.getContentLength();
    contentType = request.getContentType();
    serverName = request.getServerName();
    serverPort = request.getServerPort();
    remoteUser = request.getRemoteUser();
    remoteAddress = request.getRemoteAddr();
    remoteHost = request.getRemoteHost();
    remotePort = request.getRemotePort();
    localAddress = request.getLocalAddr();
    localHost = request.getLocalName();
    localPort = request.getLocalPort();
    authorizationScheme = request.getAuthType();
    preferredClientLocale = request.getLocale();
    allClientLocales = Collections.list(request.getLocales());
    contextPath = request.getContextPath();
    userPrincipal = request.getUserPrincipal();
    requestHeaders = getRequestHeaders(request);
    cookies = getCookies(request.getCookies());
    requestAttributes = getRequestAttributes(request);
}
 
Example 5
Source File: ServletRequestCopy.java    From onedev with MIT License 4 votes vote down vote up
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));
	}
}
 
Example 6
Source File: RequestServlet.java    From java-tutorial with Creative Commons Attribution Share Alike 4.0 International 4 votes vote down vote up
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	logger.info("访问 doGet");

	request.setCharacterEncoding("UTF-8");
	response.setCharacterEncoding("UTF-8");

	response.setContentType("text/html");

	String authType = request.getAuthType();
	String localAddr = request.getLocalAddr();
	Locale locale = request.getLocale();
	String localName = request.getLocalName();
	String contextPath = request.getContextPath();
	int localPort = request.getLocalPort();
	String method = request.getMethod();
	String pathInfo = request.getPathInfo();
	String pathTranslated = request.getPathTranslated();
	String protocol = request.getProtocol();
	String queryString = request.getQueryString();
	String remoteAddr = request.getRemoteAddr();
	int port = request.getRemotePort();
	String remoteUser = request.getRemoteUser();
	String requestedSessionId = request.getRequestedSessionId();
	String requestURI = request.getRequestURI();
	StringBuffer requestURL = request.getRequestURL();
	String scheme = request.getScheme();
	String serverName = request.getServerName();
	int serverPort = request.getServerPort();
	String servletPath = request.getServletPath();
	Principal userPrincipal = request.getUserPrincipal();

	String accept = request.getHeader("accept");
	String referer = request.getHeader("referer");
	String userAgent = request.getHeader("user-agent");

	String serverInfo = this.getServletContext().getServerInfo();

	PrintWriter out = response.getWriter();
	out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
	out.println("<HTML>");

	// 这里<title></title>之间的信息在浏览器中显示为标题
	out.println("  <HEAD><TITLE>Request Servlet</TITLE></HEAD>");
	out.println("  <style>body, font, td, div {font-size:12px; line-height:18px; }</style>");
	out.println("  <BODY>");

	out.println("<b>您的IP为</b> " + remoteAddr + "<b>;您使用</b> " + getOS(userAgent) + " <b>操作系统</b>,"
		+ getNavigator(userAgent) + " <b>。您使用</b> " + getLocale(locale) + "。<br/>");
	out.println("<b>服务器IP为</b> " + localAddr + localAddr + "<b>;服务器使用</b> " + serverPort + " <b>端口,您的浏览器使用了</b> "
		+ port + " <b>端口访问本网页。</b><br/>");
	out.println("<b>服务器软件为</b>:" + serverInfo + "。<b>服务器名称为</b> " + localName + "。<br/>");
	out.println("<b>您的浏览器接受</b> " + getAccept(accept) + "。<br/>");
	out.println("<b>您从</b> " + referer + " <b>访问到该页面。</b><br/>");
	out.println("<b>使用的协议为</b> " + protocol + "。<b>URL协议头</b> " + scheme + ",<b>服务器名称</b> " + serverName
		+ ",<b>您访问的URI为</b> " + requestURI + "。<br/>");
	out.println("<b>该 Servlet 路径为</b> " + servletPath + ",<b>该 Servlet 类名为</b> " + this.getClass().getName()
		+ "。<br/>");
	out.println("<b>本应用程序在硬盘的根目录为</b> " + this.getServletContext().getRealPath("") + ",<b>网络相对路径为</b> "
		+ contextPath + "。 <br/>");

	out.println("<br/>");

	out.println("<br/><br/><a href=" + requestURI + "> 点击刷新本页面 </a>");

	out.println("  </BODY>");
	out.println("</HTML>");
	out.flush();
	out.close();
}