dukescript commented on pull request #2337:
URL: https://github.com/apache/netbeans/pull/2337#issuecomment-692671641


   It is actually very easy to use 
   
   > http client libraries
   
   with the here-in introduced system. Here is a demo: Start by creating a [new 
module](https://github.com/dukescript/netbeans/commit/d439aee5d5992fd8e6b35bfc57bcc8c013fd6a50)
 which is using the JDK11 specific 
[HttpClient](https://docs.oracle.com/en/java/javase/11/docs/api/java.net.http/java/net/http/HttpClient.html)
 API:
   ```java
       public void demo() throws Exception {
           HttpClient client = HttpClient.newBuilder()
                .version(Version.HTTP_1_1)
                .followRedirects(Redirect.NORMAL)
                .connectTimeout(Duration.ofSeconds(20))
                .proxy(ProxySelector.of(new 
InetSocketAddress("proxy.example.com", 80)))
                .authenticator(Authenticator.getDefault())
                .build();
           HttpRequest request = HttpRequest.newBuilder()
               .uri(URI.create("https://foo.com/";))
               .timeout(Duration.ofMinutes(2))
               .header("Content-Type", "application/json")
               .build();
           HttpResponse<String> response = client.send(request, 
HttpResponse.BodyHandlers.ofString());
           System.out.println(response.statusCode());
           System.out.println(response.body());  
       }
   ```
   of course, you can't compile this on JDK8. What do you do? You enable the 
[future API aware 
compiler](https://github.com/dukescript/netbeans/commit/72e067467dac6f4f651a048a5cc31ba237d37875)
 and tell it to use JDK11's API (by setting `javac.target=11`). Then everything 
compiles even on JDK8. The last step is to [use the 
module](https://github.com/dukescript/netbeans/commit/b325d3c0297def205c23c781a510f848c4dff1ef)
 when available - of course it is only available when running on JDK11+, 
otherwise it is disabled.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to