Skip to content

Commit abf97e9

Browse files
author
Stephane Landelle
committed
Minor clean up
1 parent 9cff47c commit abf97e9

File tree

4 files changed

+25
-49
lines changed

4 files changed

+25
-49
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public FilePart(String name, File file, String mimeType, String charSet) {
3737
/**
3838
* {@inheritDoc}
3939
*/
40-
/* @Override */
40+
@Override
4141
public String getName() {
4242
return name;
4343
}

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

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,9 @@
1717

1818
import static org.testng.Assert.*;
1919

20-
import java.io.File;
2120
import java.io.IOException;
2221
import java.io.InputStream;
2322
import java.net.ConnectException;
24-
import java.net.URL;
2523
import java.security.KeyStore;
2624
import java.security.SecureRandom;
2725
import java.security.cert.CertificateException;
@@ -38,6 +36,7 @@
3836
import javax.net.ssl.TrustManager;
3937
import javax.net.ssl.X509TrustManager;
4038
import javax.servlet.ServletException;
39+
import javax.servlet.http.Cookie;
4140
import javax.servlet.http.HttpServletRequest;
4241
import javax.servlet.http.HttpServletResponse;
4342

@@ -95,9 +94,9 @@ public void handle(String pathInContext, Request r, HttpServletRequest httpReque
9594

9695
httpResponse.addHeader("X-KEEP-ALIVE", httpRequest.getRemoteAddr() + ":" + httpRequest.getRemotePort());
9796

98-
javax.servlet.http.Cookie[] cs = httpRequest.getCookies();
97+
Cookie[] cs = httpRequest.getCookies();
9998
if (cs != null) {
100-
for (javax.servlet.http.Cookie c : cs) {
99+
for (Cookie c : cs) {
101100
httpResponse.addCookie(c);
102101
}
103102
}
@@ -141,10 +140,7 @@ public void zeroCopyPostTest() throws Throwable {
141140

142141
final AsyncHttpClient client = getAsyncHttpClient(new Builder().setSSLContext(createSSLContext(new AtomicBoolean(true))).build());
143142
try {
144-
URL url = getClass().getClassLoader().getResource("SimpleTextFile.txt");
145-
File file = new File(url.toURI());
146-
147-
Response resp = client.preparePost(getTargetUrl()).setBody(file).setHeader("Content-Type", "text/html").execute().get();
143+
Response resp = client.preparePost(getTargetUrl()).setBody(SIMPLE_TEXT_FILE).setHeader("Content-Type", "text/html").execute().get();
148144
assertNotNull(resp);
149145
assertEquals(resp.getStatusCode(), HttpServletResponse.SC_OK);
150146
assertEquals(resp.getResponseBody(), "This is a simple test file");
@@ -175,7 +171,7 @@ public void multipleSSLRequestsTest() throws Throwable {
175171

176172
@Test(groups = { "standalone", "default_provider" })
177173
public void multipleSSLWithoutCacheTest() throws Throwable {
178-
final AsyncHttpClient c = getAsyncHttpClient(new Builder().setSSLContext(createSSLContext(new AtomicBoolean(true))).setAllowSslConnectionPool(false).build());
174+
AsyncHttpClient c = getAsyncHttpClient(new Builder().setSSLContext(createSSLContext(new AtomicBoolean(true))).setAllowSslConnectionPool(false).build());
179175
try {
180176
String body = "hello there";
181177
c.preparePost(getTargetUrl()).setBody(body).setHeader("Content-Type", "text/html").execute();
@@ -193,9 +189,9 @@ public void multipleSSLWithoutCacheTest() throws Throwable {
193189
@Test(groups = { "standalone", "default_provider" })
194190
public void reconnectsAfterFailedCertificationPath() throws Throwable {
195191
AtomicBoolean trusted = new AtomicBoolean(false);
196-
final AsyncHttpClient c = getAsyncHttpClient(new Builder().setSSLContext(createSSLContext(trusted)).build());
192+
AsyncHttpClient c = getAsyncHttpClient(new Builder().setSSLContext(createSSLContext(trusted)).build());
197193
try {
198-
final String body = "hello there";
194+
String body = "hello there";
199195

200196
// first request fails because server certificate is rejected
201197
try {
@@ -213,7 +209,7 @@ public void reconnectsAfterFailedCertificationPath() throws Throwable {
213209
trusted.set(true);
214210

215211
// second request should succeed
216-
final Response response = c.preparePost(getTargetUrl()).setBody(body).setHeader("Content-Type", "text/html").execute().get(TIMEOUT, TimeUnit.SECONDS);
212+
Response response = c.preparePost(getTargetUrl()).setBody(body).setHeader("Content-Type", "text/html").execute().get(TIMEOUT, TimeUnit.SECONDS);
217213

218214
assertEquals(response.getResponseBody(), body);
219215
} finally {

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

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

15-
import static org.testng.Assert.assertNotNull;
1615
import static org.testng.AssertJUnit.*;
1716
import static org.testng.FileAssert.fail;
1817

@@ -21,7 +20,6 @@
2120

2221
import org.asynchttpclient.AsyncHttpClient;
2322
import org.asynchttpclient.AsyncHttpClientConfig;
24-
import org.asynchttpclient.ListenableFuture;
2523
import org.asynchttpclient.Request;
2624
import org.asynchttpclient.RequestBuilder;
2725
import org.asynchttpclient.Response;
@@ -60,27 +58,19 @@ public void testCustomChunking() throws Throwable {
6058
builder.setBody(new InputStreamBodyGenerator(new BufferedInputStream(new FileInputStream(LARGE_IMAGE_FILE), 400000)));
6159

6260
Request r = builder.build();
63-
Response res = null;
6461

65-
try {
66-
ListenableFuture<Response> response = c.executeRequest(r);
67-
res = response.get();
68-
assertNotNull(res.getResponseBodyAsStream());
69-
if (500 == res.getStatusCode()) {
70-
System.out.println("==============");
71-
System.out.println("500 response from call");
72-
System.out.println("Headers:" + res.getHeaders());
73-
System.out.println("==============");
74-
System.out.flush();
75-
assertEquals("Should have 500 status code", 500, res.getStatusCode());
76-
assertTrue("Should have failed due to chunking", res.getHeader("X-Exception").contains("invalid.chunk.length"));
77-
fail("HARD Failing the test due to provided InputStreamBodyGenerator, chunking incorrectly:" + res.getHeader("X-Exception"));
78-
} else {
79-
assertEquals(LARGE_IMAGE_BYTES, res.getResponseBodyAsBytes());
80-
}
81-
} catch (Exception e) {
82-
83-
fail("Exception Thrown:" + e.getMessage());
62+
Response response = c.executeRequest(r).get();
63+
if (500 == response.getStatusCode()) {
64+
System.out.println("==============");
65+
System.out.println("500 response from call");
66+
System.out.println("Headers:" + response.getHeaders());
67+
System.out.println("==============");
68+
System.out.flush();
69+
assertEquals("Should have 500 status code", 500, response.getStatusCode());
70+
assertTrue("Should have failed due to chunking", response.getHeader("X-Exception").contains("invalid.chunk.length"));
71+
fail("HARD Failing the test due to provided InputStreamBodyGenerator, chunking incorrectly:" + response.getHeader("X-Exception"));
72+
} else {
73+
assertEquals(LARGE_IMAGE_BYTES, response.getResponseBodyAsBytes());
8474
}
8575
} finally {
8676
c.close();

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

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import javax.servlet.http.HttpServletResponse;
2222

2323
import org.asynchttpclient.AsyncHttpClient;
24-
import org.asynchttpclient.AsyncHttpClient.BoundRequestBuilder;
2524
import org.asynchttpclient.AsyncHttpClientConfig;
2625
import org.asynchttpclient.FilePart;
2726
import org.asynchttpclient.Response;
@@ -34,14 +33,9 @@ public abstract class FilePartLargeFileTest extends AbstractBasicTest {
3433

3534
@Test(groups = { "standalone", "default_provider" }, enabled = true)
3635
public void testPutImageFile() throws Exception {
37-
AsyncHttpClientConfig config = new AsyncHttpClientConfig.Builder().setRequestTimeoutInMs(100 * 6000).build();
38-
AsyncHttpClient client = getAsyncHttpClient(config);
36+
AsyncHttpClient client = getAsyncHttpClient(new AsyncHttpClientConfig.Builder().setRequestTimeoutInMs(100 * 6000).build());
3937
try {
40-
BoundRequestBuilder rb = client.preparePut(getTargetUrl());
41-
42-
rb.addBodyPart(new FilePart("test", LARGE_IMAGE_FILE, "application/octet-stream", "UTF-8"));
43-
44-
Response response = rb.execute().get();
38+
Response response = client.preparePut(getTargetUrl()).addBodyPart(new FilePart("test", LARGE_IMAGE_FILE, "application/octet-stream", "UTF-8")).execute().get();
4539
Assert.assertEquals(200, response.getStatusCode());
4640
} finally {
4741
client.close();
@@ -51,15 +45,11 @@ public void testPutImageFile() throws Exception {
5145
@Test(groups = { "standalone", "default_provider" }, enabled = true)
5246
public void testPutLargeTextFile() throws Exception {
5347
long repeats = (1024 * 1024 / PATTERN_BYTES.length) + 1;
54-
File largeFile = createTempFile(PATTERN_BYTES, (int) repeats);
48+
File file = createTempFile(PATTERN_BYTES, (int) repeats);
5549

5650
AsyncHttpClient client = getAsyncHttpClient(null);
5751
try {
58-
BoundRequestBuilder rb = client.preparePut(getTargetUrl());
59-
60-
rb.addBodyPart(new FilePart("test", largeFile, "application/octet-stream", "UTF-8"));
61-
62-
Response response = rb.execute().get();
52+
Response response = client.preparePut(getTargetUrl()).addBodyPart(new FilePart("test", file, "application/octet-stream", "UTF-8")).execute().get();
6353
Assert.assertEquals(200, response.getStatusCode());
6454
} finally {
6555
client.close();

0 commit comments

Comments
 (0)