You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2023/08/30 22:58:54 UTC
[cxf] 01/02: Add system properly to force use of older URLConnection
This is an automated email from the ASF dual-hosted git repository.
dkulp pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cxf.git
commit 3d70de80fb60b74040c0214fc6a28774362556e4
Author: Daniel Kulp <da...@kulp.com>
AuthorDate: Wed Aug 30 12:28:20 2023 -0400
Add system properly to force use of older URLConnection
---
.../cxf/transport/http/HTTPTransportFactory.java | 11 ++-
.../cxf/transport/http/HttpClientHTTPConduit.java | 81 ++++++++++++----------
.../transport/http/URLConnectionHTTPConduit.java | 7 --
3 files changed, 53 insertions(+), 46 deletions(-)
diff --git a/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPTransportFactory.java b/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPTransportFactory.java
index f13e236425..40d42c8e31 100644
--- a/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPTransportFactory.java
+++ b/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HTTPTransportFactory.java
@@ -37,6 +37,7 @@ import java.util.logging.Logger;
import org.apache.cxf.Bus;
import org.apache.cxf.common.injection.NoJSR250Annotations;
import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.common.util.SystemPropertyAction;
import org.apache.cxf.configuration.Configurer;
import org.apache.cxf.service.Service;
import org.apache.cxf.service.model.BindingInfo;
@@ -84,6 +85,9 @@ public class HTTPTransportFactory
private final ReadWriteLock lock = new ReentrantReadWriteLock();
private final Lock r = lock.readLock();
private final Lock w = lock.writeLock();
+
+ private boolean forceURLConnectionConduit
+ = Boolean.valueOf(SystemPropertyAction.getProperty("org.apache.cxf.transport.http.forceURLConnection"));
public HTTPTransportFactory() {
this(new DestinationRegistryImpl());
@@ -233,8 +237,11 @@ public class HTTPTransportFactory
conduit = factory.createConduit(this, bus, endpointInfo, target);
}
if (conduit == null) {
- //conduit = new URLConnectionHTTPConduit(bus, endpointInfo, target);
- conduit = new HttpClientHTTPConduit(bus, endpointInfo, target);
+ if (forceURLConnectionConduit) {
+ conduit = new URLConnectionHTTPConduit(bus, endpointInfo, target);
+ } else {
+ conduit = new HttpClientHTTPConduit(bus, endpointInfo, target);
+ }
}
// Spring configure the conduit.
diff --git a/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HttpClientHTTPConduit.java b/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HttpClientHTTPConduit.java
index e16f9d3b48..b40b6904dc 100644
--- a/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HttpClientHTTPConduit.java
+++ b/rt/transports/http/src/main/java/org/apache/cxf/transport/http/HttpClientHTTPConduit.java
@@ -90,10 +90,6 @@ public class HttpClientHTTPConduit extends URLConnectionHTTPConduit {
volatile HttpClient client;
volatile int lastTlsHash = -1;
volatile URI sslURL;
-
- public HttpClientHTTPConduit(Bus b, EndpointInfo ei) throws IOException {
- super(b, ei);
- }
public HttpClientHTTPConduit(Bus b, EndpointInfo ei, EndpointReferenceType t) throws IOException {
super(b, ei, t);
@@ -115,7 +111,13 @@ public class HttpClientHTTPConduit extends URLConnectionHTTPConduit {
* Close the conduit
*/
public void close() {
- if (client != null) {
+ if (client instanceof AutoCloseable) {
+ try {
+ ((AutoCloseable)client).close();
+ } catch (Exception e) {
+ //ignore
+ }
+ } else if (client != null) {
String name = client.toString();
client = null;
tryToShutdownSelector(name);
@@ -398,6 +400,41 @@ public class HttpClientHTTPConduit extends URLConnectionHTTPConduit {
}
}
+ private boolean isConnectionAttemptCompleted(HTTPClientPolicy csPolicy, PipedOutputStream out)
+ throws IOException {
+ if (!connectionComplete) {
+ // if we haven't connected yet, we'll see if an exception is the reason
+ // why we haven't connected. Otherwise, wait for the connection
+ // to complete.
+ if (future.isDone()) {
+ try {
+ future.get();
+ } catch (InterruptedException | ExecutionException e) {
+ if (e.getCause() instanceof IOException) {
+ throw new Fault("Could not send Message.", LOG, (IOException)e.getCause());
+ }
+ }
+ return false;
+ }
+ try {
+ out.wait(csPolicy.getConnectionTimeout());
+ } catch (InterruptedException e) {
+ //ignore
+ }
+ if (future.isDone()) {
+ try {
+ future.get();
+ } catch (InterruptedException | ExecutionException e) {
+ if (e.getCause() instanceof IOException) {
+ throw new Fault("Could not send Message.", LOG, (IOException)e.getCause());
+ }
+ }
+ return false;
+ }
+ }
+ return true;
+ }
+
@Override
protected void setProtocolHeaders() throws IOException {
HttpClient cl = outMessage.get(HttpClient.class);
@@ -410,37 +447,7 @@ public class HttpClientHTTPConduit extends URLConnectionHTTPConduit {
? 4096 : csPolicy.getChunkLength());
pout = new PipedOutputStream(pin) {
synchronized boolean canWrite() throws IOException {
- if (!connectionComplete) {
- // if we haven't connected yet, we'll see if an exception is the reason
- // why we haven't connected. Otherwise, wait for the connection
- // to complete.
- if (future.isDone()) {
- try {
- future.get();
- } catch (InterruptedException | ExecutionException e) {
- if (e.getCause() instanceof IOException) {
- throw new Fault("Could not send Message.", LOG, (IOException)e.getCause());
- }
- }
- return false;
- }
- try {
- wait(csPolicy.getConnectionTimeout());
- } catch (InterruptedException e) {
- //ignore
- }
- if (future.isDone()) {
- try {
- future.get();
- } catch (InterruptedException | ExecutionException e) {
- if (e.getCause() instanceof IOException) {
- throw new Fault("Could not send Message.", LOG, (IOException)e.getCause());
- }
- }
- return false;
- }
- }
- return true;
+ return isConnectionAttemptCompleted(csPolicy, this);
}
@Override
public void write(int b) throws IOException {
@@ -466,7 +473,7 @@ public class HttpClientHTTPConduit extends URLConnectionHTTPConduit {
@Override
public void subscribe(Subscriber<? super ByteBuffer> subscriber) {
connectionComplete = true;
- synchronized(pout) {
+ synchronized (pout) {
pout.notifyAll();
}
BodyPublishers.ofInputStream(new Supplier<InputStream>() {
diff --git a/rt/transports/http/src/main/java/org/apache/cxf/transport/http/URLConnectionHTTPConduit.java b/rt/transports/http/src/main/java/org/apache/cxf/transport/http/URLConnectionHTTPConduit.java
index e31b2c5782..028eaf950f 100644
--- a/rt/transports/http/src/main/java/org/apache/cxf/transport/http/URLConnectionHTTPConduit.java
+++ b/rt/transports/http/src/main/java/org/apache/cxf/transport/http/URLConnectionHTTPConduit.java
@@ -76,13 +76,6 @@ public class URLConnectionHTTPConduit extends HTTPConduit {
*/
protected HttpsURLConnectionFactory connectionFactory;
-
- public URLConnectionHTTPConduit(Bus b, EndpointInfo ei) throws IOException {
- super(b, ei);
- connectionFactory = new HttpsURLConnectionFactory();
- CXFAuthenticator.addAuthenticator();
- }
-
public URLConnectionHTTPConduit(Bus b, EndpointInfo ei, EndpointReferenceType t) throws IOException {
super(b, ei, t);
connectionFactory = new HttpsURLConnectionFactory();