5353import org .apache .hc .core5 .http .HttpHeaders ;
5454import org .apache .hc .core5 .http .HttpRequest ;
5555import org .apache .hc .core5 .http .HttpRequestInterceptor ;
56- import org .apache .hc .core5 .http .HttpRequestMapper ;
57- import org .apache .hc .core5 .http .HttpResponse ;
5856import org .apache .hc .core5 .http .HttpStatus ;
5957import org .apache .hc .core5 .http .impl .bootstrap .HttpServer ;
60- import org .apache .hc .core5 .http .impl .io . HttpService ;
58+ import org .apache .hc .core5 .http .impl .bootstrap . ServerBootstrap ;
6159import org .apache .hc .core5 .http .io .HttpRequestHandler ;
6260import org .apache .hc .core5 .http .io .entity .ByteArrayEntity ;
63- import org .apache .hc .core5 .http .io .support .BasicHttpServerRequestHandler ;
6461import org .apache .hc .core5 .http .protocol .HttpContext ;
65- import org .apache .hc .core5 .http .protocol .HttpProcessor ;
6662
6763import org .junit .After ;
6864import org .junit .AfterClass ;
@@ -120,7 +116,6 @@ public void handle(
120116 ClassicHttpRequest request , ClassicHttpResponse response , HttpContext context )
121117 throws HttpException , IOException {
122118 response .setCode (HttpStatus .SC_OK );
123- response .setHeader (HttpHeaders .CONTENT_LENGTH , "0" );
124119 }
125120 };
126121 try (FakeServer server = new FakeServer (handler )) {
@@ -141,7 +136,6 @@ public void handle(
141136 String responseJson = "{\" data\" :\" {\\ \" foo\\ \" :\\ \" bar\\ \" }\" }" ;
142137 byte [] responseData = responseJson .getBytes (StandardCharsets .UTF_8 );
143138 response .setCode (HttpStatus .SC_OK );
144- response .setHeader (HttpHeaders .CONTENT_LENGTH , String .valueOf (responseData .length ));
145139 response .setHeader (HttpHeaders .CONTENT_TYPE , "application/json" );
146140 response .setEntity (new ByteArrayEntity (responseData , ContentType .APPLICATION_JSON ));
147141 }
@@ -309,38 +303,10 @@ private static class FakeServer implements AutoCloseable {
309303 private final HttpServer server ;
310304
311305 FakeServer (final HttpRequestHandler httpHandler ) throws IOException {
312- HttpRequestMapper <HttpRequestHandler > mapper = new HttpRequestMapper <HttpRequestHandler >() {
313- @ Override
314- public HttpRequestHandler resolve (HttpRequest request , HttpContext context )
315- throws HttpException {
316- return httpHandler ;
317- }
318- };
319- server = new HttpServer (
320- 0 ,
321- HttpService .builder ()
322- .withHttpProcessor (
323- new HttpProcessor () {
324- @ Override
325- public void process (
326- HttpRequest request , EntityDetails entity , HttpContext context )
327- throws HttpException , IOException {
328- }
329-
330- @ Override
331- public void process (
332- HttpResponse response , EntityDetails entity , HttpContext context )
333- throws HttpException , IOException {
334- }
335- })
336- .withHttpServerRequestHandler (new BasicHttpServerRequestHandler (mapper ))
337- .build (),
338- null ,
339- null ,
340- null ,
341- null ,
342- null ,
343- null );
306+ server = ServerBootstrap .bootstrap ()
307+ .setListenerPort (0 )
308+ .register ("*" , httpHandler )
309+ .create ();
344310 server .start ();
345311 }
346312
0 commit comments