ASF Bugzilla – Attachment 26566 Details for
Bug 50642
keepAliveProtection doesn't work
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
Alternative implementation of the servlet
HttpClientServlet.java (text/plain), 2.56 KB, created by
Konstantin Kolinko
on 2011-01-27 13:22:23 UTC
(
hide
)
Description:
Alternative implementation of the servlet
Filename:
MIME Type:
Creator:
Konstantin Kolinko
Created:
2011-01-27 13:22:23 UTC
Size:
2.56 KB
patch
obsolete
>package issue50642; > >import java.io.IOException; >import java.io.InputStream; >import java.io.PrintWriter; >import java.io.OutputStreamWriter; > >import javax.servlet.ServletException; >import javax.servlet.http.HttpServlet; >import javax.servlet.http.HttpServletRequest; >import javax.servlet.http.HttpServletResponse; > >import java.lang.reflect.Field; >import java.net.URL; >import java.net.URLClassLoader; >import sun.net.www.http.HttpClient; >import sun.net.www.http.KeepAliveCache; > >public class HttpClientServlet extends HttpServlet { > public void init() throws ServletException { > log("HttpClientServlet.init: CCL=" > + Thread.currentThread().getContextClassLoader()); > } > > public void service(HttpServletRequest request, HttpServletResponse response) > throws ServletException, IOException { > log("HttpClientServlet.service: CCL=" > + Thread.currentThread().getContextClassLoader()); > > try { > PrintWriter out = response.getWriter(); > printThreadStatus(out); > > startKeepAliveThread(); > > printThreadStatus(out); > } catch (Exception e) { > throw new ServletException("Could not toy with HttpClient", e); > } > } > > public static void printThreadStatus(PrintWriter out) throws Exception { > final Field kac = HttpClient.class.getDeclaredField("kac"); > kac.setAccessible(true); > final Field keepAliveTimer = KeepAliveCache.class > .getDeclaredField("keepAliveTimer"); > keepAliveTimer.setAccessible(true); > > final Thread t = (Thread) keepAliveTimer.get(kac.get(null)); > > out.println("KeepAliveThread: " + t + ", cl=" > + (null == t ? "null" : t.getContextClassLoader().toString())); > } > > public static void startKeepAliveThread() throws Exception { > URL url = new URL("http://www.google.com/"); > InputStream is = url.openStream(); > byte buf[] = new byte[2048]; > while (is.read(buf, 0, buf.length) > 0) { > // > } > is.close(); > } > > public static void main(String[] args) throws Exception { > ClassLoader cl = new URLClassLoader(new URL[0], Thread.currentThread() > .getContextClassLoader()); > Thread.currentThread().setContextClassLoader(cl); > > PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out)); > > printThreadStatus(out); > > startKeepAliveThread(); > > printThreadStatus(out); > > out.flush(); > } >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 50642
:
26541
|
26564
| 26566