|
18 | 18 |
|
19 | 19 | importjava.io.File; |
20 | 20 | importjava.io.IOException; |
| 21 | +importjava.io.InputStream; |
21 | 22 |
|
22 | 23 | importjavax.servlet.ServletException; |
23 | 24 | importjavax.servlet.http.HttpServletRequest; |
|
30 | 31 | importorg.eclipse.jetty.server.handler.AbstractHandler; |
31 | 32 | importorg.testng.annotations.Test; |
32 | 33 |
|
33 | | -/** |
34 | | - * @author Benjamin Hanzelmann |
35 | | - */ |
36 | | -publicclassPutLargeFileTestextendsAbstractBasicTest { |
37 | | - |
38 | | -@Test(groups ="standalone") |
39 | | -publicvoidtestPutLargeFile()throwsException { |
40 | | - |
41 | | -Filefile =createTempFile(1024 *1024); |
| 34 | +publicclassPutFileTestextendsAbstractBasicTest { |
42 | 35 |
|
| 36 | +privatevoidput(intfileSize)throwsException { |
| 37 | +Filefile =createTempFile(fileSize); |
43 | 38 | inttimeout = (int)file.length() /1000; |
44 | | - |
45 | | -try (AsyncHttpClientclient =asyncHttpClient(config().setConnectTimeout(timeout))) { |
| 39 | +try (AsyncHttpClientclient =asyncHttpClient(config().setRequestTimeout(timeout))) { |
46 | 40 | Responseresponse =client.preparePut(getTargetUrl()).setBody(file).execute().get(); |
47 | 41 | assertEquals(response.getStatusCode(),200); |
48 | 42 | } |
49 | 43 | } |
50 | 44 |
|
51 | 45 | @Test(groups ="standalone") |
52 | | -publicvoidtestPutSmallFile()throwsException { |
53 | | - |
54 | | -Filefile =createTempFile(1024); |
| 46 | +publicvoidtestPutLargeFile()throwsException { |
| 47 | +put(1024 *1024); |
| 48 | +} |
55 | 49 |
|
56 | | -try (AsyncHttpClientclient =asyncHttpClient()) { |
57 | | -Responseresponse =client.preparePut(getTargetUrl()).setBody(file).execute().get(); |
58 | | -assertEquals(response.getStatusCode(),200); |
59 | | - } |
| 50 | +@Test(groups ="standalone") |
| 51 | +publicvoidtestPutSmallFile()throwsException { |
| 52 | +put(1024); |
60 | 53 | } |
61 | 54 |
|
62 | 55 | @Override |
63 | 56 | publicAbstractHandlerconfigureHandler()throwsException { |
64 | 57 | returnnewAbstractHandler() { |
65 | 58 |
|
66 | | -publicvoidhandle(Stringarg0,Requestarg1,HttpServletRequestreq,HttpServletResponseresp)throwsIOException,ServletException { |
| 59 | +publicvoidhandle(Stringtarget,RequestbaseRequest,HttpServletRequestrequest,HttpServletResponseresponse)throwsIOException,ServletException { |
67 | 60 |
|
68 | | -resp.setStatus(200); |
69 | | -resp.getOutputStream().flush(); |
70 | | -resp.getOutputStream().close(); |
| 61 | +InputStreamis =baseRequest.getInputStream(); |
| 62 | +intread =0; |
| 63 | +do { |
| 64 | +// drain upload |
| 65 | +read =is.read(); |
| 66 | + }while (read >=0); |
71 | 67 |
|
72 | | -arg1.setHandled(true); |
| 68 | +response.setStatus(200); |
| 69 | +response.getOutputStream().flush(); |
| 70 | +response.getOutputStream().close(); |
| 71 | +baseRequest.setHandled(true); |
73 | 72 | } |
74 | 73 | }; |
75 | 74 | } |
|