Search in sources :

Example 1 with HttpSocket

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));
}
Also used : HttpRequest(org.webpieces.httpparser.api.dto.HttpRequest) Header(org.webpieces.httpparser.api.common.Header) Logger(org.slf4j.Logger) LoggerFactory(org.slf4j.LoggerFactory) KnownHeaderName(org.webpieces.httpparser.api.common.KnownHeaderName) HttpUri(org.webpieces.httpparser.api.dto.HttpUri) InetSocketAddress(java.net.InetSocketAddress) HttpResponseListener(org.webpieces.httpclient.api.HttpResponseListener) HttpSocket(org.webpieces.httpclient.api.HttpSocket) HttpResponse(org.webpieces.httpparser.api.dto.HttpResponse) HttpRequest(org.webpieces.httpparser.api.dto.HttpRequest) HttpRequestLine(org.webpieces.httpparser.api.dto.HttpRequestLine) HttpData(org.webpieces.httpparser.api.dto.HttpData) KnownHttpMethod(org.webpieces.httpparser.api.dto.KnownHttpMethod) HttpSocket(org.webpieces.httpclient.api.HttpSocket) InetSocketAddress(java.net.InetSocketAddress)

Example 2 with HttpSocket

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;
}
Also used : HttpSocket(org.webpieces.httpclient.api.HttpSocket) HttpClient(org.webpieces.httpclient.api.HttpClient)

Example 3 with HttpSocket

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);
}
Also used : HttpRequest(org.webpieces.httpparser.api.dto.HttpRequest) BufferPool(org.webpieces.data.api.BufferPool) LoggerFactory(org.slf4j.LoggerFactory) ChannelManager(org.webpieces.nio.api.ChannelManager) HttpResponseListener(org.webpieces.httpclient.api.HttpResponseListener) ChannelManagerFactory(org.webpieces.nio.api.ChannelManagerFactory) HttpResponse(org.webpieces.httpparser.api.dto.HttpResponse) HttpRequest(org.webpieces.httpparser.api.dto.HttpRequest) DataWrapper(org.webpieces.data.api.DataWrapper) HttpData(org.webpieces.httpparser.api.dto.HttpData) HttpParserFactory(org.webpieces.httpparser.api.HttpParserFactory) Header(org.webpieces.httpparser.api.common.Header) Logger(org.slf4j.Logger) Executor(java.util.concurrent.Executor) HttpClient(org.webpieces.httpclient.api.HttpClient) 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) HttpClientFactory(org.webpieces.httpclient.api.HttpClientFactory) HttpSocket(org.webpieces.httpclient.api.HttpSocket) BufferCreationPool(org.webpieces.data.api.BufferCreationPool) HttpRequestLine(org.webpieces.httpparser.api.dto.HttpRequestLine) KnownHttpMethod(org.webpieces.httpparser.api.dto.KnownHttpMethod) HttpSocket(org.webpieces.httpclient.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.httpclient.api.HttpSocket)3 InetSocketAddress (java.net.InetSocketAddress)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 HttpClient (org.webpieces.httpclient.api.HttpClient)2 HttpResponseListener (org.webpieces.httpclient.api.HttpResponseListener)2 Header (org.webpieces.httpparser.api.common.Header)2 KnownHeaderName (org.webpieces.httpparser.api.common.KnownHeaderName)2 HttpData (org.webpieces.httpparser.api.dto.HttpData)2 HttpRequest (org.webpieces.httpparser.api.dto.HttpRequest)2 HttpRequestLine (org.webpieces.httpparser.api.dto.HttpRequestLine)2 HttpResponse (org.webpieces.httpparser.api.dto.HttpResponse)2 HttpUri (org.webpieces.httpparser.api.dto.HttpUri)2 KnownHttpMethod (org.webpieces.httpparser.api.dto.KnownHttpMethod)2 Executor (java.util.concurrent.Executor)1 Executors (java.util.concurrent.Executors)1 BufferCreationPool (org.webpieces.data.api.BufferCreationPool)1 BufferPool (org.webpieces.data.api.BufferPool)1 DataWrapper (org.webpieces.data.api.DataWrapper)1 HttpClientFactory (org.webpieces.httpclient.api.HttpClientFactory)1