HttpURLConnection throws SunCertPathBuilderException in jdk11

2018-06-12 Thread Андрей Турбанов
Hello.
I tried to use early jdk11 build (http://jdk.java.net/11/) - Oracle JDK
build for Windows.
I got exception when my program tries to connect (via HttpURLConnection) to
https://api.vk.com/

sun.security.provider.certpath.SunCertPathBuilderException: unable to find
valid certification path to requested target
at
sun.security.provider.certpath.SunCertPathBuilder.build(SunCertPathBuilder.java:141)
~[?:?]
at
sun.security.provider.certpath.SunCertPathBuilder.engineBuild(SunCertPathBuilder.java:126)
~[?:?]
at java.security.cert.CertPathBuilder.build(CertPathBuilder.java:297)
~[?:?]
at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:380)
~[?:?]
at
sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:290)
~[?:?]
at sun.security.validator.Validator.validate(Validator.java:264) ~[?:?]
at
sun.security.ssl.X509TrustManagerImpl.validate(X509TrustManagerImpl.java:343)
~[?:?]

Same code works well with JDK 10.
Does JDK11 have different set of SSL certificates? Is there any way to
allow connection to vk.com?

Andrey Turbanov


NullPointerException in jdk.incubator.http.internal.hpack.HeaderTable.Table

2018-05-28 Thread Андрей Турбанов
Hello
I'm trying to new use new shiny httpclient from JDK10. Code is pretty
simple. I use synchronous HTTP call form multiple threads:

private final HttpClient httpClient = HttpClient.newBuilder()
.executor(Utils.newFixedThreadPoolExecutor(1, "HttpClient"))
.build();
private JsonObject useHttpClient(URL url, String params) throws Exception {
HttpRequest req = HttpRequest.newBuilder()
.uri(url.toURI())
.setHeader("Connection", "keep-alive")
.setHeader("Accept-Encoding", "gzip")
.timeout(timeout)
.POST(HttpRequest.BodyPublisher.fromString(params))
.build();
HttpResponse response = httpClient.send(req,
HttpResponse.BodyHandler.asInputStream());
if (response.statusCode() != 200) {
throw new IOException("Server returned " + response.statusCode());
}
String encoding =
response.headers().firstValue("content-encoding").orElse("");
return parseResponseStream(encoding, response.body());}



Sometimes I get NPEs:

java.lang.NullPointerException: null
at 
jdk.incubator.http.internal.hpack.HeaderTable$Table.remove(HeaderTable.java:455)
~[jdk.incubator.httpclient:?]
at 
jdk.incubator.http.internal.hpack.HeaderTable.evictEntry(HeaderTable.java:264)
~[jdk.incubator.httpclient:?]
at jdk.incubator.http.internal.hpack.HeaderTable.put(HeaderTable.java:233)
~[jdk.incubator.httpclient:?]
at jdk.incubator.http.internal.hpack.HeaderTable.put(HeaderTable.java:215)
~[jdk.incubator.httpclient:?]
at 
jdk.incubator.http.internal.hpack.Decoder.resumeLiteralWithIndexing(Decoder.java:464)
~[jdk.incubator.httpclient:?]
at jdk.incubator.http.internal.hpack.Decoder.proceed(Decoder.java:268)
~[jdk.incubator.httpclient:?]
at jdk.incubator.http.internal.hpack.Decoder.decode(Decoder.java:246)
~[jdk.incubator.httpclient:?]
at jdk.incubator.http.Http2Connection.decodeHeaders(Http2Connection.java:471)
~[jdk.incubator.httpclient:?]
at jdk.incubator.http.Http2Connection.processFrame(Http2Connection.java:635)
~[jdk.incubator.httpclient:?]
at 
jdk.incubator.http.internal.frame.FramesDecoder.decode(FramesDecoder.java:156)
~[jdk.incubator.httpclient:?]
at 
jdk.incubator.http.Http2Connection$FramesController.processReceivedData(Http2Connection.java:195)
~[jdk.incubator.httpclient:?]
at jdk.incubator.http.Http2Connection.asyncReceive(Http2Connection.java:528)
~[jdk.incubator.httpclient:?]
at 
jdk.incubator.http.Http2Connection$Http2TubeSubscriber.processQueue(Http2Connection.java:1054)
~[jdk.incubator.httpclient:?]
at 
jdk.incubator.http.internal.common.SequentialScheduler$SynchronizedRestartableTask.run(SequentialScheduler.java:175)
~[jdk.incubator.httpclient:?]
at 
jdk.incubator.http.internal.common.SequentialScheduler$CompleteRestartableTask.run(SequentialScheduler.java:147)
~[jdk.incubator.httpclient:?]
at 
jdk.incubator.http.internal.common.SequentialScheduler$SchedulableTask.run(SequentialScheduler.java:198)
~[jdk.incubator.httpclient:?]
at 
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1135)
[?:?]

Are there any problem in my code? What can be reason for this exception?

C:\Program Files\Java\jdk-10\bin>java -version
java version "10" 2018-03-20Java(TM) SE Runtime Environment 18.3
(build 10+46)Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10+46,
mixed mode)



Andrey Turbanov