Search in sources :

Example 11 with HttpSocket

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);
    }
}
Also used : HttpSocket(org.webpieces.httpclient11.api.HttpSocket) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException)

Example 12 with HttpSocket

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);
}
Also used : HttpRequest(org.webpieces.httpparser.api.dto.HttpRequest) BufferPool(org.webpieces.data.api.BufferPool) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) LoggerFactory(org.slf4j.LoggerFactory) HttpResponseListener(org.webpieces.httpclient11.api.HttpResponseListener) BackpressureConfig(org.webpieces.nio.api.BackpressureConfig) ChannelManager(org.webpieces.nio.api.ChannelManager) Metrics(io.micrometer.core.instrument.Metrics) ChannelManagerFactory(org.webpieces.nio.api.ChannelManagerFactory) HttpResponse(org.webpieces.httpparser.api.dto.HttpResponse) HttpRequest(org.webpieces.httpparser.api.dto.HttpRequest) TwoPools(org.webpieces.data.api.TwoPools) DataWrapper(org.webpieces.data.api.DataWrapper) HttpData(org.webpieces.httpparser.api.dto.HttpData) HttpClient(org.webpieces.httpclient11.api.HttpClient) HttpParserFactory(org.webpieces.httpparser.api.HttpParserFactory) Header(org.webpieces.httpparser.api.common.Header) Logger(org.slf4j.Logger) HttpDataWriter(org.webpieces.httpclient11.api.HttpDataWriter) Executor(java.util.concurrent.Executor) NamedThreadFactory(org.webpieces.util.threading.NamedThreadFactory) HttpParser(org.webpieces.httpparser.api.HttpParser) KnownHeaderName(org.webpieces.httpparser.api.common.KnownHeaderName) HttpUri(org.webpieces.httpparser.api.dto.HttpUri) InetSocketAddress(java.net.InetSocketAddress) Executors(java.util.concurrent.Executors) XFuture(org.webpieces.util.futures.XFuture) HttpRequestLine(org.webpieces.httpparser.api.dto.HttpRequestLine) HttpClientFactory(org.webpieces.httpclient11.api.HttpClientFactory) KnownHttpMethod(org.webpieces.httpparser.api.dto.KnownHttpMethod) HttpSocket(org.webpieces.httpclient11.api.HttpSocket) HttpSocket(org.webpieces.httpclient11.api.HttpSocket) HttpRequestLine(org.webpieces.httpparser.api.dto.HttpRequestLine) Header(org.webpieces.httpparser.api.common.Header) InetSocketAddress(java.net.InetSocketAddress) HttpUri(org.webpieces.httpparser.api.dto.HttpUri)

Aggregations

HttpSocket (org.webpieces.httpclient11.api.HttpSocket)10 SimpleMeterRegistry (io.micrometer.core.instrument.simple.SimpleMeterRegistry)3 ExecutionException (java.util.concurrent.ExecutionException)2 TimeoutException (java.util.concurrent.TimeoutException)2 HttpClient (org.webpieces.httpclient11.api.HttpClient)2 HttpSocketImpl (org.webpieces.httpclient11.impl.HttpSocketImpl)2 ConnectionListener (org.webpieces.nio.api.handlers.ConnectionListener)2 MockTcpChannel (org.webpieces.webserver.test.MockTcpChannel)2 Metrics (io.micrometer.core.instrument.Metrics)1 InetSocketAddress (java.net.InetSocketAddress)1 Executor (java.util.concurrent.Executor)1 Executors (java.util.concurrent.Executors)1 Before (org.junit.Before)1 Test (org.junit.Test)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1 BufferPool (org.webpieces.data.api.BufferPool)1 DataWrapper (org.webpieces.data.api.DataWrapper)1 TwoPools (org.webpieces.data.api.TwoPools)1 HttpClientFactory (org.webpieces.httpclient11.api.HttpClientFactory)1