use of org.webpieces.httpclient.api.HttpSocket in project webpieces by deanhiller.
the class IntegColoradoEdu method main.
public static void main(String[] args) {
boolean isHttp = false;
String host = "www.colorado.edu";
int port = 443;
if (isHttp)
port = 80;
HttpRequest req = createRequest(host);
log.info("starting socket");
ChunkedResponseListener listener = new ChunkedResponseListener();
HttpSocket socket = IntegGoogleHttps.createSocket(isHttp, host, port);
socket.connect(new InetSocketAddress(host, port)).thenAccept(p -> socket.send(req, listener)).exceptionally(e -> reportException(socket, e));
}
use of org.webpieces.httpclient.api.HttpSocket in project webpieces by deanhiller.
the class IntegGoogleHttps method createSocket.
public static HttpSocket createSocket(boolean isHttp, String host, int port) {
HttpClient client = createHttpClient();
HttpSocket socket;
if (isHttp)
socket = client.createHttpSocket("oneTimer");
else {
ForTestSslClientEngineFactory sslFactory = new ForTestSslClientEngineFactory();
socket = client.createHttpsSocket("oneTimer", sslFactory.createSslEngine(host, port));
}
return socket;
}
use of org.webpieces.httpclient.api.HttpSocket in project webpieces by deanhiller.
the class IntegGoogleHttps method start.
public void start() throws InterruptedException {
log.info("starting test to download / page from google");
boolean isHttp = false;
String host = "www.google.com";
int port = 443;
if (isHttp)
port = 80;
HttpRequestLine requestLine = new HttpRequestLine();
requestLine.setMethod(KnownHttpMethod.GET);
requestLine.setUri(new HttpUri("/"));
HttpRequest req = new HttpRequest();
req.setRequestLine(requestLine);
req.addHeader(new Header(KnownHeaderName.HOST, host));
req.addHeader(new Header(KnownHeaderName.ACCEPT, "*/*"));
req.addHeader(new Header(KnownHeaderName.USER_AGENT, "webpieces/0.9"));
HttpSocket socket = createSocket(isHttp, host, port);
socket.connect(new InetSocketAddress(host, port)).thenAccept(p -> sendRequest(socket, req)).exceptionally(e -> reportException(socket, e));
Thread.sleep(100000);
}
Aggregations