01: /* SingleHttpConnectionManager
02: *
03: * $Id: SingleHttpConnectionManager.java 3882 2005-10-10 09:31:18Z gojomo $
04: *
05: * Created on Mar 8, 2004
06: *
07: * Copyright (C) 2004 Internet Archive.
08: *
09: * This file is part of the Heritrix web crawler (crawler.archive.org).
10: *
11: * Heritrix is free software; you can redistribute it and/or modify
12: * it under the terms of the GNU Lesser Public License as published by
13: * the Free Software Foundation; either version 2.1 of the License, or
14: * any later version.
15: *
16: * Heritrix is distributed in the hope that it will be useful,
17: * but WITHOUT ANY WARRANTY; without even the implied warranty of
18: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19: * GNU Lesser Public License for more details.
20: *
21: * You should have received a copy of the GNU Lesser Public License
22: * along with Heritrix; if not, write to the Free Software
23: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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
43: SimpleHttpConnectionManager {
44:
45: public SingleHttpConnectionManager() {
46: super ();
47: }
48:
49: public HttpConnection getConnectionWithTimeout(
50: HostConfiguration hostConfiguration, long timeout) {
51:
52: HttpConnection conn = new HttpConnection(hostConfiguration);
53: conn.setHttpConnectionManager(this );
54: conn.getParams().setDefaults(this .getParams());
55: return conn;
56: }
57:
58: public void releaseConnection(HttpConnection conn) {
59: // ensure connection is closed
60: conn.close();
61: finishLast(conn);
62: }
63:
64: static void finishLast(HttpConnection conn) {
65: // copied from superclass because it wasn't made available to subclasses
66: InputStream lastResponse = conn.getLastResponseInputStream();
67: if (lastResponse != null) {
68: conn.setLastResponseInputStream(null);
69: try {
70: lastResponse.close();
71: } catch (IOException ioe) {
72: //FIXME: badness - close to force reconnect.
73: conn.close();
74: }
75: }
76: }
77: }
|