Skip to content

Commit 10e8a7a

Browse files
committed
Replaced deprecated functionality
1 parent 0b4e653 commit 10e8a7a

9 files changed

Lines changed: 87 additions & 41 deletions

File tree

httpclient5-testing/src/test/java/org/apache/hc/client5/testing/extension/async/TestAsyncClient.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ protected <T> Future<T> doExecute(final HttpHost target,
9797
return client.execute(target, requestProducer, responseConsumer, pushHandlerFactory, context, callback);
9898
}
9999

100+
/**
101+
* @deprecated Do not use.
102+
*/
103+
@Deprecated
100104
@Override
101105
public void register(final String hostname,
102106
final String uriPattern,

httpclient5-testing/src/test/java/org/apache/hc/client5/testing/extension/sync/TestServerBootstrap.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,9 @@ public TestServer build() throws Exception {
108108
.build());
109109
for (final HandlerEntry<HttpRequestHandler> entry: handlerList) {
110110
if (entry.hostname != null) {
111-
server.registerHandlerVirtual(entry.hostname, entry.uriPattern, entry.handler);
111+
server.register(entry.hostname, entry.uriPattern, entry.handler);
112112
} else {
113-
server.registerHandler(entry.uriPattern, entry.handler);
113+
server.register(entry.uriPattern, entry.handler);
114114
}
115115
}
116116
return new TestServer(

httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/AbstractHttpAsyncClientBase.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ public final void start() {
7070
}
7171
}
7272

73+
/**
74+
* @deprecated Use {@link org.apache.hc.core5.http.impl.routing.RequestRouter}
75+
* at the construction time
76+
*/
77+
@Deprecated
7378
@Override
7479
public void register(final String hostname, final String uriPattern, final Supplier<AsyncPushConsumer> supplier) {
7580
pushConsumerRegistry.register(hostname, uriPattern, supplier);

httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/AsyncPushConsumerRegistry.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,25 +34,25 @@
3434
import org.apache.hc.core5.function.Supplier;
3535
import org.apache.hc.core5.http.HttpRequest;
3636
import org.apache.hc.core5.http.nio.AsyncPushConsumer;
37-
import org.apache.hc.core5.http.protocol.UriPatternMatcher;
3837
import org.apache.hc.core5.net.URIAuthority;
3938
import org.apache.hc.core5.util.Args;
4039

40+
@SuppressWarnings("deprecation")
4141
class AsyncPushConsumerRegistry {
4242

43-
private final UriPatternMatcher<Supplier<AsyncPushConsumer>> primary;
44-
private final ConcurrentMap<String, UriPatternMatcher<Supplier<AsyncPushConsumer>>> hostMap;
43+
private final org.apache.hc.core5.http.protocol.UriPatternMatcher<Supplier<AsyncPushConsumer>> primary;
44+
private final ConcurrentMap<String, org.apache.hc.core5.http.protocol.UriPatternMatcher<Supplier<AsyncPushConsumer>>> hostMap;
4545

4646
public AsyncPushConsumerRegistry() {
47-
this.primary = new UriPatternMatcher<>();
47+
this.primary = new org.apache.hc.core5.http.protocol.UriPatternMatcher<>();
4848
this.hostMap = new ConcurrentHashMap<>();
4949
}
5050

51-
private UriPatternMatcher<Supplier<AsyncPushConsumer>> getPatternMatcher(final String hostname) {
51+
private org.apache.hc.core5.http.protocol.UriPatternMatcher<Supplier<AsyncPushConsumer>> getPatternMatcher(final String hostname) {
5252
if (hostname == null) {
5353
return primary;
5454
}
55-
final UriPatternMatcher<Supplier<AsyncPushConsumer>> hostMatcher = hostMap.get(hostname);
55+
final org.apache.hc.core5.http.protocol.UriPatternMatcher<Supplier<AsyncPushConsumer>> hostMatcher = hostMap.get(hostname);
5656
if (hostMatcher != null) {
5757
return hostMatcher;
5858
}
@@ -63,7 +63,7 @@ public AsyncPushConsumer get(final HttpRequest request) {
6363
Args.notNull(request, "Request");
6464
final URIAuthority authority = request.getAuthority();
6565
final String key = authority != null ? authority.getHostName().toLowerCase(Locale.ROOT) : null;
66-
final UriPatternMatcher<Supplier<AsyncPushConsumer>> patternMatcher = getPatternMatcher(key);
66+
final org.apache.hc.core5.http.protocol.UriPatternMatcher<Supplier<AsyncPushConsumer>> patternMatcher = getPatternMatcher(key);
6767
if (patternMatcher == null) {
6868
return null;
6969
}
@@ -83,9 +83,9 @@ public void register(final String hostname, final String uriPattern, final Suppl
8383
primary.register(uriPattern, supplier);
8484
} else {
8585
final String key = hostname.toLowerCase(Locale.ROOT);
86-
UriPatternMatcher<Supplier<AsyncPushConsumer>> matcher = hostMap.get(key);
86+
org.apache.hc.core5.http.protocol.UriPatternMatcher<Supplier<AsyncPushConsumer>> matcher = hostMap.get(key);
8787
if (matcher == null) {
88-
final UriPatternMatcher<Supplier<AsyncPushConsumer>> newMatcher = new UriPatternMatcher<>();
88+
final org.apache.hc.core5.http.protocol.UriPatternMatcher<Supplier<AsyncPushConsumer>> newMatcher = new org.apache.hc.core5.http.protocol.UriPatternMatcher<>();
8989
matcher = hostMap.putIfAbsent(key, newMatcher);
9090
if (matcher == null) {
9191
matcher = newMatcher;

httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/CloseableHttpAsyncClient.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,18 @@ public final Future<SimpleHttpResponse> execute(
129129
return execute(request, null, callback);
130130
}
131131

132+
/**
133+
* @deprecated Use {@link org.apache.hc.core5.http.impl.routing.RequestRouter}
134+
* at the construction time
135+
*/
136+
@Deprecated
132137
public abstract void register(String hostname, String uriPattern, Supplier<AsyncPushConsumer> supplier);
133138

139+
/**
140+
* @deprecated Use {@link org.apache.hc.core5.http.impl.routing.RequestRouter}
141+
* at the construction time
142+
*/
143+
@Deprecated
134144
public final void register(final String uriPattern, final Supplier<AsyncPushConsumer> supplier) {
135145
register(null, uriPattern, supplier);
136146
}

httpclient5/src/main/java/org/apache/hc/client5/http/impl/async/HttpAsyncClients.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,12 @@
3737
import org.apache.hc.client5.http.nio.AsyncClientConnectionManager;
3838
import org.apache.hc.client5.http.ssl.DefaultClientTlsStrategy;
3939
import org.apache.hc.core5.concurrent.DefaultThreadFactory;
40+
import org.apache.hc.core5.function.Supplier;
4041
import org.apache.hc.core5.http.config.CharCodingConfig;
4142
import org.apache.hc.core5.http.config.Http1Config;
43+
import org.apache.hc.core5.http.impl.routing.RequestRouter;
44+
import org.apache.hc.core5.http.nio.AsyncPushConsumer;
45+
import org.apache.hc.core5.http.nio.HandlerFactory;
4246
import org.apache.hc.core5.http.nio.ssl.TlsStrategy;
4347
import org.apache.hc.core5.http.protocol.DefaultHttpProcessor;
4448
import org.apache.hc.core5.http.protocol.HttpProcessor;
@@ -333,4 +337,16 @@ public static MinimalH2AsyncClient createHttp2Minimal() {
333337
return createHttp2Minimal(H2Config.DEFAULT);
334338
}
335339

340+
/**
341+
* Creates {@link HandlerFactory} backed by a push {@link RequestRouter}.
342+
*
343+
* @since 5.4
344+
*/
345+
public static HandlerFactory<AsyncPushConsumer> pushRouter(final RequestRouter<Supplier<AsyncPushConsumer>> requestRouter) {
346+
return (request, context) -> {
347+
final Supplier<AsyncPushConsumer> supplier = requestRouter.resolve(request, context);
348+
return supplier != null ? supplier.get() : null;
349+
};
350+
}
351+
336352
}

httpclient5/src/main/java/org/apache/hc/client5/http/impl/cookie/BasicDomainHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public void validate(final Cookie cookie, final CookieOrigin origin)
101101
}
102102

103103
static boolean domainMatch(final String domain, final String host) {
104-
if (InetAddressUtils.isIPv4Address(host) || InetAddressUtils.isIPv6Address(host)) {
104+
if (InetAddressUtils.isIPv4(host) || InetAddressUtils.isIPv6(host)) {
105105
return false;
106106
}
107107
final String normalizedDomain = domain.startsWith(".") ? domain.substring(1) : domain;

httpclient5/src/main/java/org/apache/hc/client5/http/ssl/DefaultHostnameVerifier.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,14 +273,14 @@ static String extractCN(final String subjectPrincipal) throws SSLException {
273273
}
274274

275275
static HostNameType determineHostFormat(final String host) {
276-
if (InetAddressUtils.isIPv4Address(host)) {
276+
if (InetAddressUtils.isIPv4(host)) {
277277
return HostNameType.IPv4;
278278
}
279279
String s = host;
280280
if (s.startsWith("[") && s.endsWith("]")) {
281281
s = host.substring(1, host.length() - 1);
282282
}
283-
if (InetAddressUtils.isIPv6Address(s)) {
283+
if (InetAddressUtils.isIPv6(s)) {
284284
return HostNameType.IPv6;
285285
}
286286
return HostNameType.DNS;

httpclient5/src/test/java/org/apache/hc/client5/http/examples/AsyncClientH2ServerPush.java

Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,15 @@
3737
import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient;
3838
import org.apache.hc.client5.http.impl.async.HttpAsyncClients;
3939
import org.apache.hc.client5.http.impl.nio.PoolingAsyncClientConnectionManagerBuilder;
40+
import org.apache.hc.core5.function.Supplier;
4041
import org.apache.hc.core5.http.ContentType;
4142
import org.apache.hc.core5.http.HttpException;
4243
import org.apache.hc.core5.http.HttpRequest;
4344
import org.apache.hc.core5.http.HttpResponse;
45+
import org.apache.hc.core5.http.impl.routing.RequestRouter;
4446
import org.apache.hc.core5.http.message.BasicHttpRequest;
4547
import org.apache.hc.core5.http.message.StatusLine;
48+
import org.apache.hc.core5.http.nio.AsyncPushConsumer;
4649
import org.apache.hc.core5.http.nio.support.BasicRequestProducer;
4750
import org.apache.hc.core5.http.support.BasicRequestBuilder;
4851
import org.apache.hc.core5.http2.HttpVersionPolicy;
@@ -69,39 +72,44 @@ public static void main(final String[] args) throws Exception {
6972

7073
client.start();
7174

72-
client.register("*", () -> new AbstractBinPushConsumer() {
75+
final RequestRouter<Supplier<AsyncPushConsumer>> pushRequestRouter = RequestRouter.<Supplier<AsyncPushConsumer>>builder()
76+
// Route all requests to the local authority
77+
.resolveAuthority(RequestRouter.LOCAL_AUTHORITY_RESOLVER)
78+
// Use the same route for all requests
79+
.addRoute(RequestRouter.LOCAL_AUTHORITY, "*", () -> new AbstractBinPushConsumer() {
7380

74-
@Override
75-
protected void start(
76-
final HttpRequest promise,
77-
final HttpResponse response,
78-
final ContentType contentType) throws HttpException, IOException {
79-
System.out.println(promise.getPath() + " (push)->" + new StatusLine(response));
80-
}
81+
@Override
82+
protected void start(
83+
final HttpRequest promise,
84+
final HttpResponse response,
85+
final ContentType contentType) throws HttpException, IOException {
86+
System.out.println(promise.getPath() + " (push)->" + new StatusLine(response));
87+
}
8188

82-
@Override
83-
protected int capacityIncrement() {
84-
return Integer.MAX_VALUE;
85-
}
89+
@Override
90+
protected int capacityIncrement() {
91+
return Integer.MAX_VALUE;
92+
}
8693

87-
@Override
88-
protected void data(final ByteBuffer data, final boolean endOfStream) throws IOException {
89-
}
94+
@Override
95+
protected void data(final ByteBuffer data, final boolean endOfStream) throws IOException {
96+
}
9097

91-
@Override
92-
protected void completed() {
93-
}
98+
@Override
99+
protected void completed() {
100+
}
94101

95-
@Override
96-
public void failed(final Exception cause) {
97-
System.out.println("(push)->" + cause);
98-
}
102+
@Override
103+
public void failed(final Exception cause) {
104+
System.out.println("(push)->" + cause);
105+
}
99106

100-
@Override
101-
public void releaseResources() {
102-
}
107+
@Override
108+
public void releaseResources() {
109+
}
103110

104-
});
111+
})
112+
.build();
105113

106114
final BasicHttpRequest request = BasicRequestBuilder.get("https://nghttp2.org/httpbin/").build();
107115

@@ -140,7 +148,10 @@ public void failed(final Exception cause) {
140148
public void releaseResources() {
141149
}
142150

143-
}, null);
151+
},
152+
HttpAsyncClients.pushRouter(pushRequestRouter),
153+
null,
154+
null);
144155
future.get();
145156

146157
System.out.println("Shutting down");

0 commit comments

Comments
 (0)