You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@abdera.apache.org by jm...@apache.org on 2006/09/08 04:00:07 UTC
svn commit: r441333 - in
/incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client:
CommonsClient.java util/AutoReleasingInputStream.java
Author: jmsnell
Date: Thu Sep 7 19:00:06 2006
New Revision: 441333
URL: http://svn.apache.org/viewvc?view=rev&rev=441333
Log:
Per http://jakarta.apache.org/commons/httpclient/threading.html
Use MultiThreadedHttpConnectionManager as recommended by the Commons HTTP Client docs.
Provide an implementation of an InputStream that will auto-release the HTTPMethod
object. This hasn't been plugged in anywhere yet as it has the nasty side effect of
making all of the headers in the response also disappear.
Added:
incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/util/AutoReleasingInputStream.java
Modified:
incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/CommonsClient.java
Modified: incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/CommonsClient.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/CommonsClient.java?view=diff&rev=441333&r1=441332&r2=441333
==============================================================================
--- incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/CommonsClient.java (original)
+++ incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/CommonsClient.java Thu Sep 7 19:00:06 2006
@@ -31,6 +31,7 @@
import org.apache.commons.httpclient.Credentials;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpMethod;
+import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
import org.apache.commons.httpclient.auth.AuthPolicy;
import org.apache.commons.httpclient.auth.AuthScope;
import org.apache.commons.httpclient.methods.RequestEntity;
@@ -57,7 +58,9 @@
public CommonsClient(String userAgent,Abdera abdera) {
super(abdera);
- client = new HttpClient();
+ MultiThreadedHttpConnectionManager connManager =
+ new MultiThreadedHttpConnectionManager();
+ client = new HttpClient(connManager);
client.getParams().setParameter(
HttpClientParams.USER_AGENT,
userAgent);
Added: incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/util/AutoReleasingInputStream.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/util/AutoReleasingInputStream.java?view=auto&rev=441333
==============================================================================
--- incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/util/AutoReleasingInputStream.java (added)
+++ incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/util/AutoReleasingInputStream.java Thu Sep 7 19:00:06 2006
@@ -0,0 +1,50 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. The ASF licenses this file to You
+* under the Apache License, Version 2.0 (the "License"); you may not
+* use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License. For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
+package org.apache.abdera.protocol.client.util;
+
+import java.io.FilterInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.apache.commons.httpclient.HttpMethod;
+
+public final class AutoReleasingInputStream
+ extends FilterInputStream {
+
+ private final HttpMethod method;
+
+ public AutoReleasingInputStream(HttpMethod method, InputStream in) {
+ super(in);
+ this.method = method;
+ }
+
+ @Override
+ public int read() throws IOException {
+ int r = super.read();
+ if (r == -1) method.releaseConnection();
+ return r;
+ }
+
+ @Override
+ public int read(byte[] b, int off, int len) throws IOException {
+ int r= super.read(b, off, len);
+ if (r == -1) method.releaseConnection();
+ return r;
+ }
+
+}