Skip to content

Commit 0253d34

Browse files
author
Stephane Landelle
committed
Introduce Netty 4 support (disabled)
1 parent 57145c4 commit 0253d34

File tree

119 files changed

+3587
-3276
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

119 files changed

+3587
-3276
lines changed

api/src/main/java/org/asynchttpclient/AsyncHttpClientConfig.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -855,13 +855,8 @@ public Builder setSSLEngineFactory(SSLEngineFactory sslEngineFactory) {
855855
* @return a {@link Builder}
856856
*/
857857
public Builder setSSLContext(final SSLContext sslContext) {
858-
this.sslEngineFactory = new SSLEngineFactory() {
859-
public SSLEngine newSSLEngine() throws GeneralSecurityException {
860-
SSLEngine sslEngine = sslContext.createSSLEngine();
861-
sslEngine.setUseClientMode(true);
862-
return sslEngine;
863-
}
864-
};
858+
// reset previously set value so it will be lazily recreated
859+
this.sslEngineFactory = null;
865860
this.sslContext = sslContext;
866861
return this;
867862
}

api/src/main/java/org/asynchttpclient/RequestBuilder.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ public RequestBuilder setBody(EntityWriter dataWriter) {
109109
* @deprecated {@link #setBody(BodyGenerator)} setBody(new InputStreamBodyGenerator(inputStream))
110110
*/
111111
@Override
112+
// FIXME I'd do the exact opposite: deprecate InputStreamBodyGenerator
112113
@Deprecated
113114
public RequestBuilder setBody(InputStream stream) throws IllegalArgumentException {
114115
return super.setBody(stream);

api/src/main/java/org/asynchttpclient/generators/InputStreamBodyGenerator.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ public InputStreamBodyGenerator(InputStream inputStream) {
4747
}
4848
}
4949

50+
public InputStream getInputStream() {
51+
return inputStream;
52+
}
53+
5054
/**
5155
* {@inheritDoc}
5256
*/

api/src/main/java/org/asynchttpclient/ntlm/NTLMEngine.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ public class NTLMEngine {
108108
SIGNATURE[bytesWithoutNull.length] = (byte) 0x00;
109109
}
110110

111+
public static final NTLMEngine INSTANCE = new NTLMEngine();
112+
111113
/**
112114
* Returns the response for the given message.
113115
*

api/src/main/java/org/asynchttpclient/providers/ResponseBase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public final String getStatusText() {
4646
}
4747

4848
/* @Override */
49-
public final URI getUri() /*throws MalformedURLException*/ {
49+
public final URI getUri() {
5050
return status.getUrl();
5151
}
5252

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

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,11 @@ public void asyncStream301WithBody() throws Throwable {
340340
AsyncHttpClient c = getAsyncHttpClient(null);
341341
try {
342342
c.prepareGet("http://google.com/").execute(new AsyncHandlerAdapter() {
343-
private StringBuilder builder = new StringBuilder();
343+
344+
public STATE onStatusReceived(HttpResponseStatus status) throws Exception {
345+
Assert.assertEquals(301, status.getStatusCode());
346+
return STATE.CONTINUE;
347+
}
344348

345349
@Override
346350
public STATE onHeadersReceived(HttpResponseHeaders content) throws Exception {
@@ -352,16 +356,13 @@ public STATE onHeadersReceived(HttpResponseHeaders content) throws Exception {
352356

353357
@Override
354358
public STATE onBodyPartReceived(HttpResponseBodyPart content) throws Exception {
355-
builder.append(new String(content.getBodyPartBytes()));
356359
return STATE.CONTINUE;
357360
}
358361

359362
@Override
360363
public String onCompleted() throws Exception {
361-
String r = builder.toString();
362-
Assert.assertTrue(r.contains("301 Moved"));
363364
l.countDown();
364-
return r;
365+
return null;
365366
}
366367
});
367368

@@ -379,7 +380,11 @@ public void asyncStream301RedirectWithBody() throws Throwable {
379380
AsyncHttpClient c = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setFollowRedirects(true).build());
380381
try {
381382
c.prepareGet("http://google.com/").execute(new AsyncHandlerAdapter() {
382-
private StringBuilder builder = new StringBuilder();
383+
384+
public STATE onStatusReceived(HttpResponseStatus status) throws Exception {
385+
Assert.assertTrue(status.getStatusCode() != 301);
386+
return STATE.CONTINUE;
387+
}
383388

384389
@Override
385390
public STATE onHeadersReceived(HttpResponseHeaders content) throws Exception {
@@ -397,19 +402,10 @@ public STATE onHeadersReceived(HttpResponseHeaders content) throws Exception {
397402
return STATE.CONTINUE;
398403
}
399404

400-
@Override
401-
public STATE onBodyPartReceived(HttpResponseBodyPart content) throws Exception {
402-
builder.append(new String(content.getBodyPartBytes()));
403-
return STATE.CONTINUE;
404-
}
405-
406405
@Override
407406
public String onCompleted() throws Exception {
408-
String r = builder.toString();
409-
Assert.assertTrue(!r.contains("301 Moved"));
410407
l.countDown();
411-
412-
return r;
408+
return null;
413409
}
414410
});
415411

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,6 @@ public void onThrowable(Throwable t) {
119119
public STATE onBodyPartReceived(HttpResponseBodyPart e) throws Exception {
120120
String s = new String(e.getBodyPartBytes());
121121
log.info("got part: {}", s);
122-
if (s.equals("")) {
123-
// noinspection ThrowableInstanceNeverThrown
124-
log.warn("Sampling stacktrace.", new Throwable("trace that, we should not get called for empty body."));
125-
}
126122
queue.put(s);
127123
return STATE.CONTINUE;
128124
}

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

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,6 @@ abstract public class ChunkingTest extends AbstractBasicTest {
7373
*/
7474
@Test()
7575
public void testCustomChunking() throws Throwable {
76-
doTest(true);
77-
}
78-
79-
80-
private void doTest(boolean customChunkedInputStream) throws Exception {
8176
AsyncHttpClient c = null;
8277
try {
8378
AsyncHttpClientConfig.Builder bc =
@@ -95,13 +90,9 @@ private void doTest(boolean customChunkedInputStream) throws Exception {
9590

9691
RequestBuilder builder = new RequestBuilder("POST");
9792
builder.setUrl(getTargetUrl());
98-
if (customChunkedInputStream) {
99-
// made buff in stream big enough to mark.
100-
builder.setBody(new InputStreamBodyGenerator(new BufferedInputStream(new FileInputStream(getTestFile()), 400000)));
101-
} else {
102-
// made buff in stream big enough to mark.
103-
builder.setBody(new InputStreamBodyGenerator(new BufferedInputStream(new FileInputStream(getTestFile()), 400000)));
104-
}
93+
// made buff in stream big enough to mark.
94+
builder.setBody(new InputStreamBodyGenerator(new BufferedInputStream(new FileInputStream(getTestFile()), 400000)));
95+
10596
Request r = builder.build();
10697
Response res = null;
10798

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,6 @@ public void handle(String arg0, Request arg1, HttpServletRequest req, HttpServle
111111
b = new byte[8192];
112112
total += count;
113113
}
114-
System.err.println("consumed " + total + " bytes.");
115-
116114
resp.setStatus(200);
117115
resp.addHeader("X-TRANFERED", String.valueOf(total));
118116
resp.getOutputStream().flush();

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import javax.servlet.http.HttpServletResponse;
2828
import java.io.IOException;
2929
import java.io.InputStream;
30+
import java.io.ByteArrayOutputStream;
3031
import java.util.concurrent.ExecutionException;
3132
import java.util.concurrent.TimeoutException;
3233

@@ -38,11 +39,18 @@ public abstract class InputStreamTest extends AbstractBasicTest {
3839
private class InputStreamHandler extends AbstractHandler {
3940
public void handle(String s, Request r, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
4041
if ("POST".equalsIgnoreCase(request.getMethod())) {
41-
byte[] b = new byte[3];
42-
request.getInputStream().read(b, 0, 3);
42+
byte[] bytes = new byte[3];
43+
ByteArrayOutputStream bos = new ByteArrayOutputStream();
44+
int read = 0;
45+
while (read > -1) {
46+
read = request.getInputStream().read(bytes);
47+
if (read > 0) {
48+
bos.write(bytes, 0, read);
49+
}
50+
}
4351

4452
response.setStatus(HttpServletResponse.SC_OK);
45-
response.addHeader("X-Param", new String(b));
53+
response.addHeader("X-Param", new String(bos.toByteArray()));
4654
} else { // this handler is to handle POST request
4755
response.sendError(HttpServletResponse.SC_FORBIDDEN);
4856
}
@@ -80,7 +88,6 @@ public int read() throws IOException {
8088
} else {
8189
return -1;
8290
}
83-
8491
}
8592
};
8693

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,11 @@ public void handle(String arg0, Request arg1, HttpServletRequest req, HttpServle
9898
total += count;
9999
}
100100

101-
System.err.println("consumed " + total + " bytes.");
102-
103101
resp.setStatus(200);
104102
resp.getOutputStream().flush();
105103
resp.getOutputStream().close();
106104

107105
arg1.setHandled(true);
108-
109106
}
110107
};
111108
}

providers/netty-4/pom.xml

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)