1

I am new to HTTP world, and I been reading an article about the development of the HTTP protocol until the most recent update at the end of 2015 for HTTP/2.

Until now when you wanted to create a simple HTTP server in java you could use:

 HttpServer.create(new InetSocketAddress(8000), 0)

Like it's described in this answer from 2010.

I want to know how can one build an HTTP/2 server today using only Java SE API?

Ilya Gazman
  • 31,250
  • 24
  • 137
  • 216

3 Answers3

0

As the previous posted stated, you cannot do this with only the Java SE API. You can however use Jetty (a 3rd party Java API).

https://webtide.com/introduction-to-http2-in-jetty/

Chris Maggiulli
  • 3,375
  • 26
  • 39
0

Jetty has support for HTTP/2:

https://www.eclipse.org/jetty/

Enable HTTP/2:

http://www.eclipse.org/jetty/documentation/current/http2.html

chocksaway
  • 870
  • 1
  • 10
  • 21
0

Basic HTTP2 server using Undertow Server API: https://undertow.io/

  Undertow server = Undertow.builder().setServerOption(UndertowOptions.ENABLE_HTTP2, true)
                .addHttpListener(port, host).setHandler(exchange -> {
                    System.out.println("Port: " + port + ", Client address is: " + exchange.getConnection().getPeerAddress().toString());
                    exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, "application/json");
//                  exchange.getResponseSender().send("Undertow Hi");
    
                }).build();
        server.start();  
Ankit
  • 99
  • 8