package test.codec.http2;

import java.nio.ByteBuffer;
import java.util.concurrent.ExecutionException;

import com.firefly.client.http2.ClientHTTPHandler;
import com.firefly.client.http2.HTTP2Client;
import com.firefly.client.http2.HTTPClientConnection;
import com.firefly.client.http2.HTTPClientRequest;
import com.firefly.codec.http2.model.MetaData.Request;
import com.firefly.codec.http2.model.MetaData.Response;
import com.firefly.codec.http2.stream.HTTP2Configuration;
import com.firefly.codec.http2.stream.HTTPConnection;
import com.firefly.codec.http2.stream.HTTPOutputStream;
import com.firefly.net.tcp.ssl.FileSSLContextFactory;
import com.firefly.utils.concurrent.FuturePromise;
import com.firefly.utils.io.BufferUtils;

public class HTTPClientTLSDemo {

	public static void main(String[] args) throws InterruptedException, ExecutionException {
		// System.setProperty("javax.net.debug", "all");

		final HTTP2Configuration http2Configuration = new HTTP2Configuration();
		FileSSLContextFactory sslContextFactory = new FileSSLContextFactory("/Users/bjhl/Develop/CA_SSL/cacerts",
				"123456", null, "PKIX", "PKIX", null);
		// SSLContextFactory sslContextFactory = new DefaultSSLContextFactory();
		http2Configuration.setSslContextFactory(sslContextFactory);
		http2Configuration.setSecureConnectionEnabled(true);
		http2Configuration.getTcpConfiguration().setTimeout(60 * 1000);
		HTTP2Client client = new HTTP2Client(http2Configuration);
		FuturePromise<HTTPClientConnection> promise = new FuturePromise<>();
		client.connect("ehr.baijiahulian.com", 443, promise);

		final HTTPClientConnection httpConnection = promise.get();
		HTTPClientRequest request = new HTTPClientRequest("GET", "/");
		httpConnection.send(request, new ClientHTTPHandler.Adapter() {

			@Override
			public boolean content(ByteBuffer item, Request request, Response response, HTTPOutputStream output,
					HTTPConnection connection) {
				System.out.println(BufferUtils.toUTF8String(item));
				return false;
			}

			@Override
			public boolean messageComplete(Request request, Response response, HTTPOutputStream output,
					HTTPConnection connection) {
				System.out.println(response.getStatus() + "|" + response.getReason() + "|" + response.getFields());
				return true;
			}
		});

	}

}

@@ -604,20 +604,65 @@
 net.
-tcp.ssl.File
+SSLContextFactory;%0Aimport com.firefly.net.tcp.ssl.Default
 SSLC
@@ -1021,16 +1021,19 @@
 on();%0A%09%09
+// 
 FileSSLC
@@ -1069,16 +1069,21 @@
 ry = new
+%0A%09%09//
  FileSSL
@@ -1137,18 +1137,19 @@
 rts%22,%0A%09%09
-%09%09
+// 
 %22123456%22
@@ -1181,19 +1181,16 @@
 ull);%0A%09%09
-// 
 SSLConte
@@ -1587,24 +1587,17 @@
 ct(%22
-ehr
+www
 .bai
-jiahulian
+du
 .com

modify testcase