Does Apache or some other CLIENT JAVA implementation support HTTP/2? -


i'm looking java client can connect http/2 based server.. server supporting http/2 api. don't see popular apache http client https://hc.apache.org/ still supporting http/2.

does apache have implementation java client supports http/2?

if not, there java client supports connecting http/2 preferably on java 7?

jetty's provides 2 http/2 java client apis. both require java 8 , mandatory use of alpn, explained here.

low level apis

these apis based on http2client, it's based on http/2 concepts of session , streams , uses listeners notified of http/2 frames arrive server.

    // setup , start http2client.     http2client client = new http2client();     sslcontextfactory sslcontextfactory = new sslcontextfactory();     client.addbean(sslcontextfactory);     client.start();      // connect remote host obtains session.     futurepromise<session> sessionpromise = new futurepromise<>();     client.connect(sslcontextfactory, new inetsocketaddress(host, port), new serversessionlistener.adapter(), sessionpromise);     session session = sessionpromise.get(5, timeunit.seconds);      // use session make requests.     httpfields requestfields = new httpfields();     requestfields.put("user-agent", client.getclass().getname() + "/" + jetty.version);     metadata.request metadata = new metadata.request("get", new httpuri("https://webtide.com/"), httpversion.http_2, requestfields);     headersframe headersframe = new headersframe(metadata, null, true);     session.newstream(headersframe, new promise.adapter<>(), new stream.listener.adapter()     {         @override         public void onheaders(stream stream, headersframe frame)         {             // response headers.             system.err.println(frame);         }          @override         public void ondata(stream stream, dataframe frame, callback callback)         {             // response content.             system.err.println(frame);             callback.succeeded();         }     }); 

high level apis

jetty's httpclient provides way use different transports, 1 of http/2 transport. applications use higher level http apis, underneath jetty use http/2 transport http semantic.

in way, applications can use high level apis provided httpclient transparently, , factor out transport use in configuration or startup code.

    // setup , start httpclient http/2 transport.     http2client http2client = new http2client();     sslcontextfactory sslcontextfactory = new sslcontextfactory();     httpclient httpclient = new httpclient(new httpclienttransportoverhttp2(http2client), sslcontextfactory);     httpclient.start();      // make request.     contentresponse response = httpclient.get("https://webtide.com/"); 

Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

Cross-Compiling Linux Kernel for Raspberry Pi - ${CCPREFIX}gcc -v does not work -

java.lang.NoClassDefFoundError When Creating New Android Project -