Skip to content

Commit bed6e1f

Browse files
slandelleslandelle
authored andcommitted
Minor clean up
1 parent c8795e5 commit bed6e1f

File tree

8 files changed

+29
-24
lines changed

8 files changed

+29
-24
lines changed

api/src/main/java/org/asynchttpclient/filter/FilterContext.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
* A {@link FilterContext} can be used to decorate {@link Request} and {@link AsyncHandler} from a list of {@link RequestFilter}.
2424
* {@link RequestFilter} gets executed before the HTTP request is made to the remote server. Once the response bytes are
2525
* received, a {@link FilterContext} is then passed to the list of {@link ResponseFilter}. {@link ResponseFilter}
26-
* gets invoked before the response gets processed, e.g. before authorization, redirection and invokation of {@link AsyncHandler}
26+
* gets invoked before the response gets processed, e.g. before authorization, redirection and invocation of {@link AsyncHandler}
2727
* gets processed.
2828
* <p/>
2929
* Invoking {@link FilterContext#getResponseStatus()} returns an instance of {@link HttpResponseStatus}

api/src/test/java/org/asynchttpclient/async/ProxyTest.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ public void testProxyProperties() throws IOException, ExecutionException, Timeou
150150
Properties props = new Properties();
151151
props.putAll(originalProps);
152152

153+
// FIXME most likely non threadsafe!
153154
System.setProperties(props);
154155

155156
System.setProperty("http.proxyHost", "127.0.0.1");
@@ -189,6 +190,7 @@ public void testIgnoreProxyPropertiesByDefault() throws IOException, ExecutionEx
189190
Properties props = new Properties();
190191
props.putAll(originalProps);
191192

193+
// FIXME most likely non threadsafe!
192194
System.setProperties(props);
193195

194196
System.setProperty("http.proxyHost", "127.0.0.1");
@@ -220,6 +222,7 @@ public void testProxyActivationProperty() throws IOException, ExecutionException
220222
Properties props = new Properties();
221223
props.putAll(originalProps);
222224

225+
// FIXME most likely non threadsafe!
223226
System.setProperties(props);
224227

225228
System.setProperty("http.proxyHost", "127.0.0.1");
@@ -259,6 +262,7 @@ public void testWildcardNonProxyHosts() throws IOException, ExecutionException,
259262
Properties props = new Properties();
260263
props.putAll(originalProps);
261264

265+
// FIXME most likely non threadsafe!
262266
System.setProperties(props);
263267

264268
System.setProperty("http.proxyHost", "127.0.0.1");
@@ -323,8 +327,8 @@ public void connectFailed(URI uri, SocketAddress sa, IOException ioe) {
323327
client.close();
324328
}
325329
} finally {
330+
// FIXME is this threadsafe???
326331
ProxySelector.setDefault(originalProxySelector);
327332
}
328333
}
329-
330334
}

extras/jdeferred/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
<relativePath>..</relativePath>
2323
</parent>
2424
<artifactId>async-http-client-extras-jdeferred</artifactId>
25+
<name>Async Http Client jDeffered Extras</name>
2526
<description>The Async Http Client jDeffered Extras.</description>
2627
<dependencies>
2728
<dependency>

providers/netty/src/test/java/org/asynchttpclient/providers/netty/NettyBasicAuthTest.java

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,10 @@
1212
*/
1313
package org.asynchttpclient.providers.netty;
1414

15-
import java.util.concurrent.ExecutionException;
16-
import java.util.concurrent.TimeoutException;
17-
18-
import org.testng.annotations.Test;
1915
import org.asynchttpclient.AsyncHttpClient;
2016
import org.asynchttpclient.AsyncHttpClientConfig;
2117
import org.asynchttpclient.async.BasicAuthTest;
18+
import org.testng.annotations.Test;
2219

2320
@Test
2421
public class NettyBasicAuthTest extends BasicAuthTest {
@@ -32,10 +29,4 @@ public AsyncHttpClient getAsyncHttpClient(AsyncHttpClientConfig config) {
3229
public String getProviderClass() {
3330
return NettyAsyncHttpProvider.class.getName();
3431
}
35-
36-
@Override
37-
@Test
38-
public void redirectAndBasicAuthTest() throws Exception, ExecutionException, TimeoutException, InterruptedException {
39-
super.redirectAndBasicAuthTest(); // To change body of overridden methods use File | Settings | File Templates.
40-
}
4132
}

providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/Channels.java

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import io.netty.handler.codec.http.websocketx.WebSocket08FrameEncoder;
2626
import io.netty.handler.ssl.SslHandler;
2727
import io.netty.handler.stream.ChunkedWriteHandler;
28+
import io.netty.util.Attribute;
2829
import io.netty.util.AttributeKey;
2930

3031
import java.io.IOException;
@@ -66,7 +67,7 @@ public class Channels {
6667
private final AsyncHttpClientConfig config;
6768
private final NettyAsyncHttpProviderConfig asyncHttpProviderConfig;
6869

69-
private EventLoopGroup eventLoop;
70+
private EventLoopGroup eventLoopGroup;
7071
private final Class<? extends SocketChannel> socketChannelFactory;
7172
private final boolean allowReleaseSocketChannelFactory;
7273

@@ -109,12 +110,12 @@ public Channels(final AsyncHttpClientConfig config, NettyAsyncHttpProviderConfig
109110
this.allowReleaseSocketChannelFactory = false;
110111
} else {
111112
socketChannelFactory = NioSocketChannel.class;
112-
eventLoop = asyncHttpProviderConfig.getEventLoopGroup();
113-
if (eventLoop == null) {
113+
eventLoopGroup = asyncHttpProviderConfig.getEventLoopGroup();
114+
if (eventLoopGroup == null) {
114115
if (socketChannelFactory == OioSocketChannel.class) {
115-
eventLoop = new OioEventLoopGroup();
116+
eventLoopGroup = new OioEventLoopGroup();
116117
} else if (socketChannelFactory == NioSocketChannel.class) {
117-
eventLoop = new NioEventLoopGroup();
118+
eventLoopGroup = new NioEventLoopGroup();
118119
} else {
119120
throw new IllegalArgumentException("No set event loop compatbile with socket channel " + scf);
120121
}
@@ -125,10 +126,10 @@ public Channels(final AsyncHttpClientConfig config, NettyAsyncHttpProviderConfig
125126
}
126127
}
127128

128-
plainBootstrap = new Bootstrap().channel(socketChannelFactory).group(eventLoop);
129-
secureBootstrap = new Bootstrap().channel(socketChannelFactory).group(eventLoop);
130-
webSocketBootstrap = new Bootstrap().channel(socketChannelFactory).group(eventLoop);
131-
secureWebSocketBootstrap = new Bootstrap().channel(socketChannelFactory).group(eventLoop);
129+
plainBootstrap = new Bootstrap().channel(socketChannelFactory).group(eventLoopGroup);
130+
secureBootstrap = new Bootstrap().channel(socketChannelFactory).group(eventLoopGroup);
131+
webSocketBootstrap = new Bootstrap().channel(socketChannelFactory).group(eventLoopGroup);
132+
secureWebSocketBootstrap = new Bootstrap().channel(socketChannelFactory).group(eventLoopGroup);
132133

133134
// This is dangerous as we can't catch a wrong typed ConnectionsPool
134135
ConnectionsPool<String, Channel> cp = (ConnectionsPool<String, Channel>) config.getConnectionsPool();
@@ -247,7 +248,7 @@ public void close() {
247248
}
248249
openChannels.close();
249250
if (this.allowReleaseSocketChannelFactory) {
250-
eventLoop.shutdownGracefully();
251+
eventLoopGroup.shutdownGracefully();
251252
}
252253
}
253254

@@ -494,7 +495,12 @@ public static Object getDefaultAttribute(Channel channel) {
494495
}
495496

496497
public static Object getDefaultAttribute(ChannelHandlerContext ctx) {
497-
return ctx.attr(DEFAULT_ATTRIBUTE).get();
498+
if (ctx == null) {
499+
// ctx might be null if the channel never reached the handler
500+
return null;
501+
}
502+
Attribute<Object> attr = ctx.attr(DEFAULT_ATTRIBUTE);
503+
return attr != null ? attr.get() : null;
498504
}
499505

500506
public static void setDefaultAttribute(Channel channel, Object o) {

providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyChannelHandler.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -835,6 +835,8 @@ public void handle(ChannelHandlerContext ctx, NettyResponseFuture future, Object
835835
LOGGER.debug("UpgradeHandler returned a null NettyWebSocket ");
836836
}
837837
}
838+
} else if (e instanceof LastHttpContent) {
839+
// FIXME what to do with this kind of messages?
838840
} else {
839841
LOGGER.error("Invalid message {}", e);
840842
}

providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/NettyRequestSender.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,7 @@ protected final <T> void writeRequest(final Channel channel, final AsyncHttpClie
340340
if (Channels.getSslHandler(channel) != null) {
341341
writeFuture = channel.write(new ChunkedFile(raf, 0, fileLength, Constants.MAX_BUFFERED_BYTES), channel.newProgressivePromise());
342342
} else {
343+
// FIXME why not use io.netty.channel.DefaultFileRegion?
343344
FileRegion region = new OptimizedFileRegion(raf, 0, fileLength);
344345
writeFuture = channel.write(region, channel.newProgressivePromise());
345346
}

providers/netty4/src/main/java/org/asynchttpclient/providers/netty4/Protocol.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
public interface Protocol{
1818

19-
void handle(ChannelHandlerContext ctx, NettyResponseFuture future, Object message) throws Exception;
19+
void handle(ChannelHandlerContext ctx, NettyResponseFuture<?> future, Object message) throws Exception;
2020

2121
void onError(ChannelHandlerContext ctx, Throwable error);
2222

0 commit comments

Comments
 (0)