Skip to content

Commit

Permalink
CXF-9062: Be able to create AsyncHTTPConduit based on URLConnectionHT…
Browse files Browse the repository at this point in the history
…TPConduit (add test suites to test forceURLConnection property activation)
  • Loading branch information
reta committed Oct 8, 2024
1 parent 818daec commit f4c0196
Show file tree
Hide file tree
Showing 11 changed files with 264 additions and 36 deletions.
25 changes: 25 additions & 0 deletions systests/transport-hc5/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,31 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<executions>
<execution>
<id>forceURLConnection-test</id>
<goals>
<goal>test</goal>
</goals>
<configuration>
<systemPropertyVariables>
<org.apache.cxf.transport.http.forceURLConnection>true</org.apache.cxf.transport.http.forceURLConnection>
</systemPropertyVariables>
</configuration>
</execution>
<execution>
<id>default-test</id>
<configuration>
<systemPropertyVariables>
<org.apache.cxf.transport.http.forceURLConnection>false</org.apache.cxf.transport.http.forceURLConnection>
</systemPropertyVariables>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* 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.
*/
package org.apache.cxf.systest.hc5;

import org.apache.cxf.transport.http.HTTPTransportFactory;
import org.apache.cxf.transport.http.asyncclient.hc5.AsyncHTTPConduit;
import org.apache.cxf.transport.http.asyncclient.hc5.URLConnectionAsyncHTTPConduit;
import org.hamcrest.Description;
import org.hamcrest.TypeSafeMatcher;

public class IsAsyncHttpConduit extends TypeSafeMatcher<Object> {
public void describeTo(Description description) {
if (HTTPTransportFactory.isForceURLConnectionConduit()) {
description.appendText("instance of URLConnectionAsyncHTTPConduit async conduit ");
} else {
description.appendText("instance of AsyncHTTPConduit async conduit ");
}
}

@Override
protected boolean matchesSafely(Object item) {
return isAsyncConduit(item);
}

public static IsAsyncHttpConduit isInstanceOfAsyncHttpConduit() {
return new IsAsyncHttpConduit();
}

private static boolean isAsyncConduit(Object instance) {
if (HTTPTransportFactory.isForceURLConnectionConduit()) {
return instance instanceof URLConnectionAsyncHTTPConduit;
} else {
return instance instanceof AsyncHTTPConduit;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
import org.junit.BeforeClass;
import org.junit.Test;

import static org.apache.cxf.systest.hc5.IsAsyncHttpConduit.isInstanceOfAsyncHttpConduit;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
Expand Down Expand Up @@ -127,14 +129,11 @@ private Greeter setupClient(boolean async) throws Exception {
client.setReceiveTimeout(600000);
cond.setClient(client);
if (async) {
if (cond instanceof AsyncHTTPConduit) {
UsernamePasswordCredentials creds = new UsernamePasswordCredentials("foo", "bar".toCharArray());
bp.getRequestContext().put(Credentials.class.getName(), creds);
bp.getRequestContext().put(AsyncHTTPConduit.USE_ASYNC, Boolean.TRUE);
client.setAutoRedirect(true);
} else {
fail("Not an async conduit");
}
assertThat("Not an async conduit", cond, isInstanceOfAsyncHttpConduit());
UsernamePasswordCredentials creds = new UsernamePasswordCredentials("foo", "bar".toCharArray());
bp.getRequestContext().put(Credentials.class.getName(), creds);
bp.getRequestContext().put(AsyncHTTPConduit.USE_ASYNC, Boolean.TRUE);
client.setAutoRedirect(true);
} else {
bp.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "foo");
bp.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "bar");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@

import org.junit.Test;

import static org.apache.cxf.systest.hc5.IsAsyncHttpConduit.isInstanceOfAsyncHttpConduit;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;

abstract class AbstractApacheClientServerHttp2Test extends AbstractBusClientServerTestBase {
@Test
public void testBookNotFoundWithHttp2() throws Exception {
final WebClient client = createWebClient("/web/bookstore/notFound", true);
assertThat(WebClient.getConfig(client).getHttpConduit(), instanceOf(AsyncHTTPConduit.class));
assertThat(WebClient.getConfig(client).getHttpConduit(), isInstanceOfAsyncHttpConduit());

final Response response = client
.accept("text/plain")
.path(getContext() + "/web/bookstore/notFound")
Expand All @@ -51,7 +51,7 @@ public void testBookNotFoundWithHttp2() throws Exception {
@Test
public void testBookTraceWithHttp2() throws Exception {
final WebClient client = createWebClient("/web/bookstore/trace", true);
assertThat(WebClient.getConfig(client).getHttpConduit(), instanceOf(AsyncHTTPConduit.class));
assertThat(WebClient.getConfig(client).getHttpConduit(), isInstanceOfAsyncHttpConduit());

final Response response = client
.accept("text/plain")
Expand All @@ -66,7 +66,7 @@ public void testBookTraceWithHttp2() throws Exception {
@Test
public void testBookWithHttp2() throws Exception {
final WebClient client = createWebClient("/web/bookstore/booknames", true);
assertThat(WebClient.getConfig(client).getHttpConduit(), instanceOf(AsyncHTTPConduit.class));
assertThat(WebClient.getConfig(client).getHttpConduit(), isInstanceOfAsyncHttpConduit());

final Response response = client
.accept("text/plain")
Expand All @@ -81,7 +81,7 @@ public void testBookWithHttp2() throws Exception {
@Test
public void testBookEncodedWithHttp2() throws Exception {
final WebClient client = createWebClient("/web/bookstore/book%20names", true);
assertThat(WebClient.getConfig(client).getHttpConduit(), instanceOf(AsyncHTTPConduit.class));
assertThat(WebClient.getConfig(client).getHttpConduit(), isInstanceOfAsyncHttpConduit());

final Response response = client
.accept("text/plain")
Expand All @@ -96,7 +96,7 @@ public void testBookEncodedWithHttp2() throws Exception {
@Test
public void testGetBookStreamHttp2() throws Exception {
final WebClient client = createWebClient("/web/bookstore/bookstream", true);
assertThat(WebClient.getConfig(client).getHttpConduit(), instanceOf(AsyncHTTPConduit.class));
assertThat(WebClient.getConfig(client).getHttpConduit(), isInstanceOfAsyncHttpConduit());

final Response response = client
.accept("application/xml")
Expand Down
25 changes: 25 additions & 0 deletions systests/transport-undertow/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,31 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<executions>
<execution>
<id>forceURLConnection-test</id>
<goals>
<goal>test</goal>
</goals>
<configuration>
<systemPropertyVariables>
<org.apache.cxf.transport.http.forceURLConnection>true</org.apache.cxf.transport.http.forceURLConnection>
</systemPropertyVariables>
</configuration>
</execution>
<execution>
<id>default-test</id>
<configuration>
<systemPropertyVariables>
<org.apache.cxf.transport.http.forceURLConnection>false</org.apache.cxf.transport.http.forceURLConnection>
</systemPropertyVariables>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* 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.
*/
package org.apache.cxf.systest.http_undertow;

import org.apache.cxf.transport.http.HTTPTransportFactory;
import org.apache.cxf.transport.http.asyncclient.hc5.AsyncHTTPConduit;
import org.apache.cxf.transport.http.asyncclient.hc5.URLConnectionAsyncHTTPConduit;
import org.hamcrest.Description;
import org.hamcrest.TypeSafeMatcher;

public class IsAsyncHttpConduit extends TypeSafeMatcher<Object> {
public void describeTo(Description description) {
if (HTTPTransportFactory.isForceURLConnectionConduit()) {
description.appendText("instance of URLConnectionAsyncHTTPConduit async conduit ");
} else {
description.appendText("instance of AsyncHTTPConduit async conduit ");
}
}

@Override
protected boolean matchesSafely(Object item) {
return isAsyncConduit(item);
}

public static IsAsyncHttpConduit isInstanceOfAsyncHttpConduit() {
return new IsAsyncHttpConduit();
}

private static boolean isAsyncConduit(Object instance) {
if (HTTPTransportFactory.isForceURLConnectionConduit()) {
return instance instanceof URLConnectionAsyncHTTPConduit;
} else {
return instance instanceof AsyncHTTPConduit;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@
import org.junit.BeforeClass;
import org.junit.Test;

import static org.apache.cxf.systest.http_undertow.IsAsyncHttpConduit.isInstanceOfAsyncHttpConduit;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
Expand Down Expand Up @@ -118,14 +120,11 @@ private HTTPConduit setupClient(boolean async) throws Exception {
client.setReceiveTimeout(600000);
cond.setClient(client);
if (async) {
if (cond.getClass().getName().endsWith("AsyncHTTPConduit")) {
UsernamePasswordCredentials creds = new UsernamePasswordCredentials("ffang", "pswd".toCharArray());
bp.getRequestContext().put(Credentials.class.getName(), creds);
bp.getRequestContext().put(AsyncHTTPConduit.USE_ASYNC, Boolean.TRUE);
client.setAutoRedirect(true);
} else {
fail("Not an async conduit");
}
assertThat("Not an async conduit", cond, isInstanceOfAsyncHttpConduit());
UsernamePasswordCredentials creds = new UsernamePasswordCredentials("ffang", "pswd".toCharArray());
bp.getRequestContext().put(Credentials.class.getName(), creds);
bp.getRequestContext().put(AsyncHTTPConduit.USE_ASYNC, Boolean.TRUE);
client.setAutoRedirect(true);
} else {
bp.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "ffang");
bp.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "pswd");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@

import org.junit.Test;

import static org.apache.cxf.systest.http_undertow.IsAsyncHttpConduit.isInstanceOfAsyncHttpConduit;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

abstract class AbstractUndertowClientServerHttp2Test extends AbstractBusClientServerTestBase {
@Test
public void testBookNotFoundWithHttp2() throws Exception {
final WebClient client = createWebClient("/web/bookstore/notFound", true);
assertTrue(WebClient.getConfig(client).getHttpConduit().getClass().getName().endsWith("AsyncHTTPConduit"));
assertThat(WebClient.getConfig(client).getHttpConduit(), isInstanceOfAsyncHttpConduit());

final Response response = client
.accept("text/plain")
Expand All @@ -53,7 +53,7 @@ public void testBookNotFoundWithHttp2() throws Exception {
@Test
public void testBookWithHttp2() throws Exception {
final WebClient client = createWebClient("/web/bookstore/booknames", true);
assertTrue(WebClient.getConfig(client).getHttpConduit().getClass().getName().endsWith("AsyncHTTPConduit"));
assertThat(WebClient.getConfig(client).getHttpConduit(), isInstanceOfAsyncHttpConduit());

final Response response = client
.accept("text/plain")
Expand All @@ -68,8 +68,8 @@ public void testBookWithHttp2() throws Exception {
@Test
public void testGetBookStreamHttp2() throws Exception {
final WebClient client = createWebClient("/web/bookstore/bookstream", true);
assertTrue(WebClient.getConfig(client).getHttpConduit().getClass().getName().endsWith("AsyncHTTPConduit"));
assertThat(WebClient.getConfig(client).getHttpConduit(), isInstanceOfAsyncHttpConduit());

final Response response = client
.accept("application/json")
.get();
Expand Down
25 changes: 25 additions & 0 deletions systests/transports/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,31 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<executions>
<execution>
<id>forceURLConnection-test</id>
<goals>
<goal>test</goal>
</goals>
<configuration>
<systemPropertyVariables>
<org.apache.cxf.transport.http.forceURLConnection>true</org.apache.cxf.transport.http.forceURLConnection>
</systemPropertyVariables>
</configuration>
</execution>
<execution>
<id>default-test</id>
<configuration>
<systemPropertyVariables>
<org.apache.cxf.transport.http.forceURLConnection>false</org.apache.cxf.transport.http.forceURLConnection>
</systemPropertyVariables>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
Expand Down
Loading

0 comments on commit f4c0196

Please sign in to comment.