use of org.webpieces.httpclient11.api.HttpSocket in project webpieces by deanhiller.
the class AbstractWebpiecesTest method connectHttp.
public HttpSocket connectHttp(InetSocketAddress addr, HttpSocketListener listener) {
if (listener == null)
listener = new NullHttp1CloseListener();
HttpSocket socket = getClient().createHttpSocket(listener);
XFuture<Void> connect = socket.connect(addr);
try {
connect.get(2, TimeUnit.SECONDS);
return socket;
} catch (InterruptedException | ExecutionException | TimeoutException e) {
throw SneakyThrow.sneak(e);
}
}
use of org.webpieces.httpclient11.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