Skip to content

Commit 5b0e807

Browse files
committed
Fix deprecation warnings
1 parent a691620 commit 5b0e807

39 files changed

+181
-165
lines changed

client/src/main/java/org/asynchttpclient/RequestBuilderBase.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
*/
1616
package org.asynchttpclient;
1717

18+
import static io.netty.handler.codec.http.HttpHeaderNames.CONTENT_TYPE;
1819
import static org.asynchttpclient.util.HttpUtils.*;
1920
import static org.asynchttpclient.util.MiscUtils.isNonEmpty;
2021
import io.netty.handler.codec.http.DefaultHttpHeaders;
21-
import io.netty.handler.codec.http.HttpHeaderNames;
2222
import io.netty.handler.codec.http.HttpHeaders;
2323
import io.netty.resolver.DefaultNameResolver;
2424
import io.netty.resolver.NameResolver;
@@ -560,7 +560,7 @@ private RequestBuilderBase<?> executeSignatureCalculator() {
560560
private Charset computeCharset() {
561561
if (this.charset == null) {
562562
try {
563-
final String contentType = this.headers.get(HttpHeaderNames.CONTENT_TYPE);
563+
final String contentType = this.headers.get(CONTENT_TYPE);
564564
if (contentType != null) {
565565
final Charset charset = parseCharset(contentType);
566566
if (charset != null) {

client/src/main/java/org/asynchttpclient/channel/DefaultKeepAliveStrategy.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package org.asynchttpclient.channel;
22

3-
import io.netty.handler.codec.http.HttpHeaders;
3+
import static io.netty.handler.codec.http.HttpHeaderValues.CLOSE;
44
import io.netty.handler.codec.http.HttpRequest;
55
import io.netty.handler.codec.http.HttpResponse;
6+
import io.netty.handler.codec.http.HttpUtil;
67

78
import org.asynchttpclient.Request;
89

@@ -16,9 +17,9 @@ public class DefaultKeepAliveStrategy implements KeepAliveStrategy {
1617
*/
1718
@Override
1819
public boolean keepAlive(Request ahcRequest, HttpRequest request, HttpResponse response) {
19-
return HttpHeaders.isKeepAlive(response)//
20-
&& HttpHeaders.isKeepAlive(request)
20+
return HttpUtil.isKeepAlive(response)//
21+
&& HttpUtil.isKeepAlive(request)
2122
// support non standard Proxy-Connection
22-
&& !response.headers().contains("Proxy-Connection", HttpHeaders.Values.CLOSE, true);
23+
&& !response.headers().contains("Proxy-Connection", CLOSE, true);
2324
}
2425
}

client/src/main/java/org/asynchttpclient/handler/resumable/ResumableAsyncHandler.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@
1212
*/
1313
package org.asynchttpclient.handler.resumable;
1414

15+
import static io.netty.handler.codec.http.HttpHeaderNames.*;
16+
17+
import java.io.IOException;
18+
import java.nio.ByteBuffer;
19+
import java.util.HashMap;
20+
import java.util.Map;
21+
import java.util.concurrent.ConcurrentLinkedQueue;
22+
import java.util.concurrent.atomic.AtomicLong;
23+
1524
import org.asynchttpclient.AsyncHandler;
1625
import org.asynchttpclient.HttpResponseBodyPart;
1726
import org.asynchttpclient.HttpResponseHeaders;
@@ -24,15 +33,6 @@
2433
import org.slf4j.Logger;
2534
import org.slf4j.LoggerFactory;
2635

27-
import io.netty.handler.codec.http.HttpHeaders;
28-
29-
import java.io.IOException;
30-
import java.nio.ByteBuffer;
31-
import java.util.HashMap;
32-
import java.util.Map;
33-
import java.util.concurrent.ConcurrentLinkedQueue;
34-
import java.util.concurrent.atomic.AtomicLong;
35-
3636
/**
3737
* An {@link AsyncHandler} which support resumable download, e.g when used with an {@link ResumableIOExceptionFilter},
3838
* this handler can resume the download operation at the point it was before the interruption occurred. This prevent having to
@@ -179,7 +179,7 @@ public Response onCompleted() throws Exception {
179179
@Override
180180
public AsyncHandler.State onHeadersReceived(HttpResponseHeaders headers) throws Exception {
181181
responseBuilder.accumulate(headers);
182-
String contentLengthHeader = headers.getHeaders().get(HttpHeaders.Names.CONTENT_LENGTH);
182+
String contentLengthHeader = headers.getHeaders().get(CONTENT_LENGTH);
183183
if (contentLengthHeader != null) {
184184
if (Long.parseLong(contentLengthHeader) == -1L) {
185185
return AsyncHandler.State.ABORT;
@@ -212,8 +212,8 @@ public Request adjustRequestRange(Request request) {
212212
}
213213

214214
RequestBuilder builder = new RequestBuilder(request);
215-
if (request.getHeaders().get(HttpHeaders.Names.RANGE) == null && byteTransferred.get() != 0) {
216-
builder.setHeader(HttpHeaders.Names.RANGE, "bytes=" + byteTransferred.get() + "-");
215+
if (request.getHeaders().get(RANGE) == null && byteTransferred.get() != 0) {
216+
builder.setHeader(RANGE, "bytes=" + byteTransferred.get() + "-");
217217
}
218218
return builder.build();
219219
}

client/src/main/java/org/asynchttpclient/netty/NettyResponseStatus.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public NettyResponseStatus(Uri uri, AsyncHttpClientConfig config, HttpResponse r
4949
* @return the response status code
5050
*/
5151
public int getStatusCode() {
52-
return response.getStatus().code();
52+
return response.status().code();
5353
}
5454

5555
/**
@@ -58,27 +58,27 @@ public int getStatusCode() {
5858
* @return the response status text
5959
*/
6060
public String getStatusText() {
61-
return response.getStatus().reasonPhrase();
61+
return response.status().reasonPhrase();
6262
}
6363

6464
@Override
6565
public String getProtocolName() {
66-
return response.getProtocolVersion().protocolName();
66+
return response.protocolVersion().protocolName();
6767
}
6868

6969
@Override
7070
public int getProtocolMajorVersion() {
71-
return response.getProtocolVersion().majorVersion();
71+
return response.protocolVersion().majorVersion();
7272
}
7373

7474
@Override
7575
public int getProtocolMinorVersion() {
76-
return response.getProtocolVersion().minorVersion();
76+
return response.protocolVersion().minorVersion();
7777
}
7878

7979
@Override
8080
public String getProtocolText() {
81-
return response.getProtocolVersion().text();
81+
return response.protocolVersion().text();
8282
}
8383

8484
@Override

client/src/main/java/org/asynchttpclient/netty/channel/ChannelManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515

1616
import static org.asynchttpclient.util.MiscUtils.trimStackTrace;
1717
import io.netty.bootstrap.Bootstrap;
18-
import io.netty.bootstrap.ChannelFactory;
1918
import io.netty.buffer.ByteBufAllocator;
2019
import io.netty.channel.Channel;
20+
import io.netty.channel.ChannelFactory;
2121
import io.netty.channel.ChannelInitializer;
2222
import io.netty.channel.ChannelOption;
2323
import io.netty.channel.ChannelPipeline;

client/src/main/java/org/asynchttpclient/netty/channel/EpollSocketChannelFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*/
1414
package org.asynchttpclient.netty.channel;
1515

16-
import io.netty.bootstrap.ChannelFactory;
16+
import io.netty.channel.ChannelFactory;
1717
import io.netty.channel.epoll.EpollSocketChannel;
1818

1919
class EpollSocketChannelFactory implements ChannelFactory<EpollSocketChannel> {

client/src/main/java/org/asynchttpclient/netty/channel/NettyConnectListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ private void writeRequest(Channel channel) {
8383

8484
if (LOGGER.isDebugEnabled()) {
8585
HttpRequest httpRequest = future.getNettyRequest().getHttpRequest();
86-
LOGGER.debug("Using new Channel '{}' for '{}' to '{}'", channel, httpRequest.getMethod(), httpRequest.getUri());
86+
LOGGER.debug("Using new Channel '{}' for '{}' to '{}'", channel, httpRequest.method(), httpRequest.uri());
8787
}
8888

8989
Channels.setAttribute(channel, future);

client/src/main/java/org/asynchttpclient/netty/channel/NioSocketChannelFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*/
1414
package org.asynchttpclient.netty.channel;
1515

16-
import io.netty.bootstrap.ChannelFactory;
16+
import io.netty.channel.ChannelFactory;
1717
import io.netty.channel.socket.nio.NioSocketChannel;
1818

1919
enum NioSocketChannelFactory implements ChannelFactory<NioSocketChannel> {

client/src/main/java/org/asynchttpclient/netty/handler/HttpHandler.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import io.netty.handler.codec.http.HttpObject;
2222
import io.netty.handler.codec.http.HttpRequest;
2323
import io.netty.handler.codec.http.HttpResponse;
24+
import io.netty.handler.codec.http.HttpUtil;
2425
import io.netty.handler.codec.http.LastHttpContent;
2526

2627
import java.io.IOException;
@@ -77,7 +78,7 @@ private void notifyHandler(Channel channel, NettyResponseFuture<?> future, HttpR
7778
exitAfterHandlingReactiveStreams(channel, future, response, handler, httpRequest);
7879

7980
if (exit)
80-
finishUpdate(future, channel, HttpHeaders.isTransferEncodingChunked(httpRequest) || HttpHeaders.isTransferEncodingChunked(response));
81+
finishUpdate(future, channel, HttpUtil.isTransferEncodingChunked(httpRequest) || HttpUtil.isTransferEncodingChunked(response));
8182
}
8283

8384
private boolean exitAfterHandlingStatus(//
@@ -173,7 +174,7 @@ public void handleRead(final Channel channel, final NettyResponseFuture<?> futur
173174
try {
174175
if (e instanceof HttpObject) {
175176
HttpObject object = (HttpObject) e;
176-
Throwable t = object.getDecoderResult().cause();
177+
Throwable t = object.decoderResult().cause();
177178
if (t != null) {
178179
readFailed(channel, future, t);
179180
return;

client/src/main/java/org/asynchttpclient/netty/handler/WebSocketHandler.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@
1313
*/
1414
package org.asynchttpclient.netty.handler;
1515

16+
import static io.netty.handler.codec.http.HttpHeaderNames.*;
1617
import static io.netty.handler.codec.http.HttpResponseStatus.SWITCHING_PROTOCOLS;
1718
import static org.asynchttpclient.ws.WebSocketUtils.getAcceptKey;
1819
import io.netty.channel.Channel;
1920
import io.netty.channel.ChannelHandler.Sharable;
20-
import io.netty.handler.codec.http.HttpHeaders;
21+
import io.netty.handler.codec.http.HttpHeaderValues;
2122
import io.netty.handler.codec.http.HttpRequest;
2223
import io.netty.handler.codec.http.HttpResponse;
2324
import io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame;
@@ -28,15 +29,14 @@
2829
import io.netty.handler.codec.http.websocketx.WebSocketFrame;
2930

3031
import java.io.IOException;
31-
import java.util.Locale;
3232

3333
import org.asynchttpclient.AsyncHandler.State;
3434
import org.asynchttpclient.AsyncHttpClientConfig;
3535
import org.asynchttpclient.HttpResponseHeaders;
3636
import org.asynchttpclient.HttpResponseStatus;
37-
import org.asynchttpclient.netty.OnLastHttpContentCallback;
3837
import org.asynchttpclient.netty.NettyResponseFuture;
3938
import org.asynchttpclient.netty.NettyResponseStatus;
39+
import org.asynchttpclient.netty.OnLastHttpContentCallback;
4040
import org.asynchttpclient.netty.channel.ChannelManager;
4141
import org.asynchttpclient.netty.channel.Channels;
4242
import org.asynchttpclient.netty.request.NettyRequestSender;
@@ -85,12 +85,12 @@ private void invokeOnSucces(Channel channel, WebSocketUpgradeHandler h) {
8585
@Override
8686
public void call() throws Exception {
8787

88-
boolean validStatus = response.getStatus().equals(SWITCHING_PROTOCOLS);
89-
boolean validUpgrade = response.headers().get(HttpHeaders.Names.UPGRADE) != null;
90-
String connection = response.headers().get(HttpHeaders.Names.CONNECTION);
88+
boolean validStatus = response.status().equals(SWITCHING_PROTOCOLS);
89+
boolean validUpgrade = response.headers().get(UPGRADE) != null;
90+
String connection = response.headers().get(CONNECTION);
9191
if (connection == null)
92-
connection = response.headers().get(HttpHeaders.Names.CONNECTION.toLowerCase(Locale.ENGLISH));
93-
boolean validConnection = HttpHeaders.Values.UPGRADE.equalsIgnoreCase(connection);
92+
connection = response.headers().get(CONNECTION);
93+
boolean validConnection = HttpHeaderValues.UPGRADE.contentEqualsIgnoreCase(connection);
9494
boolean statusReceived = handler.onStatusReceived(status) == State.UPGRADE;
9595

9696
if (!statusReceived) {
@@ -108,8 +108,8 @@ public void call() throws Exception {
108108
return;
109109
}
110110

111-
String accept = response.headers().get(HttpHeaders.Names.SEC_WEBSOCKET_ACCEPT);
112-
String key = getAcceptKey(future.getNettyRequest().getHttpRequest().headers().get(HttpHeaders.Names.SEC_WEBSOCKET_KEY));
111+
String accept = response.headers().get(SEC_WEBSOCKET_ACCEPT);
112+
String key = getAcceptKey(future.getNettyRequest().getHttpRequest().headers().get(SEC_WEBSOCKET_KEY));
113113
if (accept == null || !accept.equals(key)) {
114114
requestSender.abort(channel, future, new IOException(String.format("Invalid challenge. Actual: %s. Expected: %s", accept, key)));
115115
}

client/src/main/java/org/asynchttpclient/netty/handler/intercept/Interceptors.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public boolean exitAfterIntercept(//
6565

6666
HttpRequest httpRequest = future.getNettyRequest().getHttpRequest();
6767
ProxyServer proxyServer = future.getProxyServer();
68-
int statusCode = response.getStatus().code();
68+
int statusCode = response.status().code();
6969
Request request = future.getCurrentRequest();
7070
Realm realm = request.getRealm() != null ? request.getRealm() : config.getRealm();
7171

@@ -85,7 +85,7 @@ public boolean exitAfterIntercept(//
8585
} else if (Redirect30xInterceptor.REDIRECT_STATUSES.contains(statusCode)) {
8686
return redirect30xInterceptor.exitAfterHandlingRedirect(channel, future, response, request, statusCode, realm);
8787

88-
} else if (httpRequest.getMethod() == HttpMethod.CONNECT && statusCode == OK_200) {
88+
} else if (httpRequest.method() == HttpMethod.CONNECT && statusCode == OK_200) {
8989
return connectSuccessInterceptor.exitAfterHandlingConnect(channel, future, request, proxyServer, statusCode, httpRequest);
9090

9191
}

client/src/main/java/org/asynchttpclient/netty/handler/intercept/ProxyUnauthorized407Interceptor.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
*/
1414
package org.asynchttpclient.netty.handler.intercept;
1515

16+
import static io.netty.handler.codec.http.HttpHeaderNames.*;
1617
import static org.asynchttpclient.Dsl.realm;
1718
import static org.asynchttpclient.util.AuthenticatorUtils.*;
1819
import static org.asynchttpclient.util.HttpConstants.Methods.CONNECT;
@@ -21,6 +22,7 @@
2122
import io.netty.handler.codec.http.HttpHeaders;
2223
import io.netty.handler.codec.http.HttpRequest;
2324
import io.netty.handler.codec.http.HttpResponse;
25+
import io.netty.handler.codec.http.HttpUtil;
2426

2527
import java.util.List;
2628

@@ -72,7 +74,7 @@ public boolean exitAfterHandling407(//
7274
return false;
7375
}
7476

75-
List<String> proxyAuthHeaders = response.headers().getAll(HttpHeaders.Names.PROXY_AUTHENTICATE);
77+
List<String> proxyAuthHeaders = response.headers().getAll(PROXY_AUTHENTICATE);
7678

7779
if (proxyAuthHeaders.isEmpty()) {
7880
LOGGER.info("Can't handle 407 as response doesn't contain Proxy-Authenticate headers");
@@ -173,8 +175,8 @@ public boolean exitAfterHandling407(//
173175

174176
LOGGER.debug("Sending proxy authentication to {}", request.getUri());
175177
if (future.isKeepAlive()//
176-
&& !HttpHeaders.isTransferEncodingChunked(httpRequest)//
177-
&& !HttpHeaders.isTransferEncodingChunked(response)) {
178+
&& !HttpUtil.isTransferEncodingChunked(httpRequest)//
179+
&& !HttpUtil.isTransferEncodingChunked(response)) {
178180
future.setConnectAllowed(true);
179181
future.setReuseChannel(true);
180182
requestSender.drainChannelAndExecuteNextRequest(channel, future, nextRequest);
@@ -195,7 +197,7 @@ private void kerberosProxyChallenge(Channel channel,//
195197
NettyResponseFuture<?> future) throws SpnegoEngineException {
196198

197199
String challengeHeader = SpnegoEngine.instance().generateToken(proxyServer.getHost());
198-
headers.set(HttpHeaders.Names.PROXY_AUTHORIZATION, NEGOTIATE + " " + challengeHeader);
200+
headers.set(PROXY_AUTHORIZATION, NEGOTIATE + " " + challengeHeader);
199201
}
200202

201203
private void ntlmProxyChallenge(String authenticateHeader,//
@@ -209,7 +211,7 @@ private void ntlmProxyChallenge(String authenticateHeader,//
209211
String challengeHeader = NtlmEngine.INSTANCE.generateType1Msg();
210212
// FIXME we might want to filter current NTLM and add (leave other
211213
// Authorization headers untouched)
212-
requestHeaders.set(HttpHeaders.Names.PROXY_AUTHORIZATION, "NTLM " + challengeHeader);
214+
requestHeaders.set(PROXY_AUTHORIZATION, "NTLM " + challengeHeader);
213215
future.setInProxyAuth(false);
214216

215217
} else {
@@ -218,7 +220,7 @@ private void ntlmProxyChallenge(String authenticateHeader,//
218220
proxyRealm.getNtlmHost(), serverChallenge);
219221
// FIXME we might want to filter current NTLM and add (leave other
220222
// Authorization headers untouched)
221-
requestHeaders.set(HttpHeaders.Names.PROXY_AUTHORIZATION, "NTLM " + challengeHeader);
223+
requestHeaders.set(PROXY_AUTHORIZATION, "NTLM " + challengeHeader);
222224
}
223225
}
224226
}

0 commit comments

Comments
 (0)