1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 package org.archive.httpclient;
26
27 import java.io.IOException;
28 import java.io.InputStream;
29
30 import org.apache.commons.httpclient.HostConfiguration;
31 import org.apache.commons.httpclient.HttpConnection;
32 import org.apache.commons.httpclient.SimpleHttpConnectionManager;
33
34 /***
35 * An HttpClient-compatible HttpConnection "manager" that actually
36 * just gives out a new connection each time -- skipping the overhead
37 * of connection management, since we already throttle our crawler
38 * with external mechanisms.
39 *
40 * @author gojomo
41 */
42 public class SingleHttpConnectionManager extends SimpleHttpConnectionManager {
43
44 public SingleHttpConnectionManager() {
45 super();
46 }
47
48 public HttpConnection getConnectionWithTimeout(
49 HostConfiguration hostConfiguration, long timeout) {
50
51 HttpConnection conn = new HttpConnection(hostConfiguration);
52 conn.setHttpConnectionManager(this);
53 conn.getParams().setDefaults(this.getParams());
54 return conn;
55 }
56
57 public void releaseConnection(HttpConnection conn) {
58
59 conn.close();
60 finishLast(conn);
61 }
62
63 static void finishLast(HttpConnection conn) {
64
65 InputStream lastResponse = conn.getLastResponseInputStream();
66 if (lastResponse != null) {
67 conn.setLastResponseInputStream(null);
68 try {
69 lastResponse.close();
70 } catch (IOException ioe) {
71
72 conn.close();
73 }
74 }
75 }
76 }