73
73
import org .eclipse .jetty .http3 .client .HTTP3Client ;
74
74
import org .eclipse .jetty .http3 .client .transport .HttpClientTransportOverHTTP3 ;
75
75
import org .eclipse .jetty .util .ssl .SslContextFactory ;
76
+ import org .slf4j .Logger ;
77
+ import org .slf4j .LoggerFactory ;
76
78
77
79
/**
78
80
* A transporter for HTTP/HTTPS.
79
81
*/
80
82
final class HttpTransporter extends AbstractTransporter {
81
83
84
+ static final Logger LOGGER = LoggerFactory .getLogger ("http3.plugin" );
85
+
82
86
private final static Set <String > CENTRAL = Set .of (
83
87
"repo.maven.apache.org" ,
84
88
"oss.sonatype.org" ,
@@ -114,7 +118,7 @@ final class HttpTransporter extends AbstractTransporter {
114
118
}
115
119
this .checksumExtractors = requireNonNull (checksumExtractors , "checksum extractors must not be null" );
116
120
try {
117
- System . err . println ( " \t Custom HttpTransporter repo: " + repository . toString () );
121
+ LOGGER . debug ( "Custom HttpTransporter repo: {}" , repository );
118
122
this .baseUri = new URI (repository .getUrl () + "/" ).normalize ().parseServerAuthority ();
119
123
if (baseUri .isOpaque ()) {
120
124
throw new URISyntaxException (repository .getUrl (), "URL must not be opaque" );
@@ -293,24 +297,23 @@ private Pair<InputStream, HttpFields> makeRequest(
293
297
}).body (bodyContent ).send (listener );
294
298
final Response response = listener .get (this .connectTimeout , TimeUnit .MILLISECONDS );
295
299
if (response .getStatus () >= 300 ) {
296
- System . err . printf (
297
- "Request over %s error status %s , method=%s , url=%s%n " ,
300
+ LOGGER . debug (
301
+ "{} request error status {} , method={} , url={} " ,
298
302
version , response .getStatus (), method , url
299
303
);
300
304
throw new HttpResponseException (Integer .toString (response .getStatus ()), response );
301
305
}
302
- System .err .printf (
303
- "Request over %s done, method=%s, resp status=%s, url=%s%n" ,
304
- version , method , response .getStatus (), url
306
+ LOGGER .debug (
307
+ "{} request done, method={}, resp status={}, url={}" , version , method , response .getStatus (), url
305
308
);
306
309
return new ImmutablePair <>(listener .getInputStream (), response .getHeaders ());
307
310
} catch (Exception ex ) {
308
- System . err . printf (
309
- "Request over %s error=%s: %s , method=%s , url=%s%n " , version ,
311
+ LOGGER . debug (
312
+ "{} request error={}: {} , method={} , url={} " , version ,
310
313
ex .getClass (), ex .getMessage (), method , url
311
314
);
312
315
if (version == HttpVersion .HTTP_3 && ex instanceof TimeoutException ) {
313
- System . err . printf ("Repeat request over HTTP/1.1 method=%s , url=%s%n " , method , url );
316
+ LOGGER . debug ("Repeat via HTTP/1.1 method={} , url={} " , method , url );
314
317
return this .makeRequest (method , task , bodyContent , this .initOrGetHttpClient ());
315
318
}
316
319
throw new HttpRequestException (ex .getMessage (), request );
@@ -354,7 +357,7 @@ private HttpVersion httpVersion(final HttpClient client) {
354
357
* @throws IllegalAccessException
355
358
*/
356
359
private void forceLoadHttp3Support () throws NoSuchFieldException , IllegalAccessException {
357
- System . err . println ("Custom HttpTransporter.forceLoadHttp3Support() called!" );
360
+ LOGGER . debug ("Custom HttpTransporter.forceLoadHttp3Support() called!" );
358
361
// Checking http3 support is available (loaded)
359
362
PreEncodedHttpField f = new PreEncodedHttpField ("Host" , "localhost" );
360
363
for (final HttpVersion v : HttpVersion .values ()) {
@@ -369,47 +372,20 @@ private void forceLoadHttp3Support() throws NoSuchFieldException, IllegalAccessE
369
372
370
373
// TODO: Force http3 initialization (HACK!)
371
374
final ServiceLoader <HttpFieldPreEncoder > load = ServiceLoader .load (HttpFieldPreEncoder .class ,PreEncodedHttpField .class .getClassLoader ());
372
- /*ServiceLoader<HttpFieldPreEncoder> load = null;
373
- ClassLoader saveCl = Thread.currentThread().getContextClassLoader();
374
- try {
375
- Thread.currentThread().setContextClassLoader(PreEncodedHttpField.class.getClassLoader());
376
- load = ServiceLoader.load(HttpFieldPreEncoder.class);
377
- }finally {
378
- Thread.currentThread().setContextClassLoader(saveCl);
379
- }*/
380
-
381
- /*System.err.println("\tCustom HttpTransporter ServiceLoader=" + load);
382
- Stream<ServiceLoader.Provider<HttpFieldPreEncoder>> providerStream = TypeUtil.serviceProviderStream(load);
383
- System.err.println("\tCustom HttpTransporter Stream<ServiceLoader.Provider<HttpFieldPreEncoder>> = " + providerStream);
384
- ArrayList<Integer> calls = new ArrayList<>();
385
- providerStream.forEach((provider) -> {
386
- try {
387
- calls.add(calls.size());
388
- HttpFieldPreEncoder encoder = (HttpFieldPreEncoder)provider.get();
389
- HttpVersion v = encoder.getHttpVersion();
390
- System.err.println("\tCustom HttpTransporter HttpFieldPreEncoder: encoder=" + encoder + "; ver=" + v);
391
- } catch (RuntimeException | Error var3) {
392
- System.err.println("\tCustom HttpTransporter Error processing encoder: " + provider.get());
393
- }
394
- });
395
- System.err.println("\tCustom HttpTransporter providerStream calls=" + calls.size());*/
396
-
397
375
HashMap <HttpVersion , HttpFieldPreEncoder > encoders = new HashMap <>();
398
376
for (HttpFieldPreEncoder val : load ) {
399
- //System.err.println("\tCustom HttpTransporter HttpFieldPreEncoder val=" + val);
377
+ LOGGER . debug ( "Custom HttpTransporter HttpFieldPreEncoder val={}" , val );
400
378
encoders .put (val .getHttpVersion (), val );
401
379
}
402
380
403
381
Field ff = PreEncodedHttpField .class .getDeclaredField ("__encoders" );
404
382
ff .setAccessible (true );
405
- String fldDescr = ff .get (null ).toString ();
406
- //System.err.println("\tCustom HttpTransporter __encoders BEFORE: " + fldDescr + "; this=" + this);
407
383
@ SuppressWarnings ("unchecked" ) EnumMap <HttpVersion , HttpFieldPreEncoder > obj = (EnumMap <HttpVersion , HttpFieldPreEncoder >)ff .get (null );
408
384
if (encoders .containsKey (HttpVersion .HTTP_3 ) && !obj .containsKey (HttpVersion .HTTP_3 )) {
409
- //System.err.println("\tCustom HttpTransporter adding to __encoders: " + obj + "; this=" + this);
385
+ LOGGER . debug ( "Custom HttpTransporter adding to __encoders: {}, this = {}" , obj , this );
410
386
obj .put (HttpVersion .HTTP_3 , encoders .get (HttpVersion .HTTP_3 ));
411
387
}
412
- //System.err.println("\tCustom HttpTransporter __encoders AFTER: " + obj + " ; this=" + this);
388
+ LOGGER . debug ( "Custom HttpTransporter __encoders AFTER: {} ; this={}" , obj , this );
413
389
414
390
// Rechecking http3 support is available (loaded)
415
391
f = new PreEncodedHttpField ("Host" , "localhost" );
@@ -420,7 +396,7 @@ private void forceLoadHttp3Support() throws NoSuchFieldException, IllegalAccessE
420
396
} catch (Exception ex ) {
421
397
len = -1 ;
422
398
}
423
- //System.err.println("\tCustom HttpTransporter PreEncodedHttpField v=" + v + " ; len=" + len);
399
+ LOGGER . debug ( "Custom HttpTransporter PreEncodedHttpField v={} ; len={}" , v , len );
424
400
}
425
401
}
426
402
}
0 commit comments