Repository: tomee Updated Branches: refs/heads/tomee-1.7.x 43c69b2cc -> 91472ad9b
slurp http inputstream in the connection factory to avoid to link the facade to an impl Project: http://git-wip-us.apache.org/repos/asf/tomee/repo Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/00f1176e Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/00f1176e Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/00f1176e Branch: refs/heads/tomee-1.7.x Commit: 00f1176e76171c6b1a4f7342ce8095a157e82a2c Parents: 43c69b2 Author: Romain manni-Bucau <rmannibu...@gmail.com> Authored: Mon Aug 29 08:50:39 2016 +0200 Committer: Jonathan Gallimore <j...@jrg.me.uk> Committed: Wed Aug 31 23:28:15 2016 +0100 ---------------------------------------------------------------------- .../java/org/apache/openejb/client/Client.java | 25 ----------- .../openejb/client/HttpConnectionFactory.java | 45 ++++++++++++++------ 2 files changed, 33 insertions(+), 37 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tomee/blob/00f1176e/server/openejb-client/src/main/java/org/apache/openejb/client/Client.java ---------------------------------------------------------------------- diff --git a/server/openejb-client/src/main/java/org/apache/openejb/client/Client.java b/server/openejb-client/src/main/java/org/apache/openejb/client/Client.java index 097dc4c..e88de73 100644 --- a/server/openejb-client/src/main/java/org/apache/openejb/client/Client.java +++ b/server/openejb-client/src/main/java/org/apache/openejb/client/Client.java @@ -404,31 +404,6 @@ public class Client { } } - if (null != in) { - - // consume anything left in the buffer if we're running in http(s) mode - if (HttpConnectionFactory.HttpConnection.class.isInstance(conn)) { - final HttpConnectionFactory.HttpConnection httpConnection = HttpConnectionFactory.HttpConnection.class.cast(conn); - if ("https".equalsIgnoreCase(httpConnection.getURI().getScheme())) { - - try { - int read = 0; - while (read > -1) { - read = in.read(); - } - } catch (Throwable e) { - // ignore - } - } - } - - try { - in.close(); - } catch (final Throwable e) { - //Ignore - } - } - if (null != conn) { try { conn.close(); http://git-wip-us.apache.org/repos/asf/tomee/blob/00f1176e/server/openejb-client/src/main/java/org/apache/openejb/client/HttpConnectionFactory.java ---------------------------------------------------------------------- diff --git a/server/openejb-client/src/main/java/org/apache/openejb/client/HttpConnectionFactory.java b/server/openejb-client/src/main/java/org/apache/openejb/client/HttpConnectionFactory.java index 35845e9..8088fb8 100644 --- a/server/openejb-client/src/main/java/org/apache/openejb/client/HttpConnectionFactory.java +++ b/server/openejb-client/src/main/java/org/apache/openejb/client/HttpConnectionFactory.java @@ -1,19 +1,18 @@ /** - * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * 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. + * <p> + * http://www.apache.org/licenses/LICENSE-2.0 + * <p> + * 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. */ package org.apache.openejb.client; @@ -29,7 +28,9 @@ import java.net.URL; import java.security.KeyManagementException; import java.security.NoSuchAlgorithmException; import java.util.Map; +import java.util.Queue; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.ConcurrentMap; /** @@ -37,21 +38,33 @@ import java.util.concurrent.ConcurrentMap; */ public class HttpConnectionFactory implements ConnectionFactory { // this map only ensures JVM keep alive socket caching works properly - private final ConcurrentMap<URI, SSLSocketFactory> socketFactoryMap = new ConcurrentHashMap<URI, SSLSocketFactory>(); + private final ConcurrentMap<URI, SSLSocketFactory> socketFactoryMap = new ConcurrentHashMap<>(); + private final Queue<byte[]> drainBuffers = new ConcurrentLinkedQueue<byte[]>(); @Override public Connection getConnection(final URI uri) throws IOException { - return new HttpConnection(uri, socketFactoryMap); + byte[] buffer = drainBuffers.poll(); + if (buffer == null) { + buffer = new byte[Integer.getInteger("openejb.client.http.drain-buffer.size", 64)]; + } + try { + return new HttpConnection(uri, socketFactoryMap, buffer); + } finally { // auto adjusting buffer caching, queue avoids leaks (!= ThreadLocal) + drainBuffers.add(buffer); + } } public static class HttpConnection implements Connection { + private final byte[] buffer; private HttpURLConnection httpURLConnection; private InputStream inputStream; private OutputStream outputStream; private final URI uri; - public HttpConnection(final URI uri, final ConcurrentMap<URI, SSLSocketFactory> socketFactoryMap) throws IOException { + public HttpConnection(final URI uri, final ConcurrentMap<URI, SSLSocketFactory> socketFactoryMap, + final byte[] buffer) throws IOException { this.uri = uri; + this.buffer = buffer; final URL url = uri.toURL(); final Map<String, String> params; @@ -118,6 +131,14 @@ public class HttpConnectionFactory implements ConnectionFactory { public void close() throws IOException { IOException exception = null; if (inputStream != null) { + // consume anything left in the buffer + try {// use a buffer cause it is faster, check HttpInputStreamImpl + while (inputStream.read(buffer) > -1) { + // no-op + } + } catch (final Throwable e) { + // ignore + } try { inputStream.close(); } catch (final IOException e) {