Search in sources :

Example 1 with HttpSocket

use of org.webpieces.httpclient11.api.HttpSocket in project webpieces by deanhiller.

the class BasicStartWithNoHttps method testNoHttps.

@Test
public void testNoHttps() throws InterruptedException, ExecutionException, TimeoutException {
    String[] arguments = new String[] { "-http.port=:0", "-https.port=" };
    PrivateWebserverForTest webserver = new PrivateWebserverForTest(getOverrides(false, new SimpleMeterRegistry()), null, null, arguments);
    webserver.start();
    // connecting http still works
    HttpSocket http11Socket = connectHttp(false, webserver.getUnderlyingHttpChannel().getLocalAddress());
    // https has no channel in webserver
    Assert.assertNull(webserver.getUnderlyingHttpsChannel());
}
Also used : HttpSocket(org.webpieces.httpclient11.api.HttpSocket) PrivateWebserverForTest(org.webpieces.webserver.PrivateWebserverForTest) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) PrivateWebserverForTest(org.webpieces.webserver.PrivateWebserverForTest) Test(org.junit.Test) AbstractWebpiecesTest(org.webpieces.webserver.test.AbstractWebpiecesTest)

Example 2 with HttpSocket

use of org.webpieces.httpclient11.api.HttpSocket in project webpieces by deanhiller.

the class Http2ClientProxy method createHttpsSocket.

@Override
public Http2Socket createHttpsSocket(SSLEngine engine, Http2SocketListener listener) {
    Http11CloseListener http11Listener = new Http11CloseListener(listener);
    HttpSocket socket11 = client11.createHttpsSocket(engine, http11Listener);
    Http2SocketImpl http2Socket = new Http2SocketImpl(socket11);
    http11Listener.setHttp2Socket(http2Socket);
    return http2Socket;
}
Also used : HttpSocket(org.webpieces.httpclient11.api.HttpSocket)

Example 3 with HttpSocket

use of org.webpieces.httpclient11.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(new SocketListener());
    else {
        ForTestSslClientEngineFactory sslFactory = new ForTestSslClientEngineFactory();
        socket = client.createHttpsSocket(sslFactory.createSslEngine(host, port), new SocketListener());
    }
    return socket;
}
Also used : HttpSocket(org.webpieces.httpclient11.api.HttpSocket) HttpClient(org.webpieces.httpclient11.api.HttpClient)

Example 4 with HttpSocket

use of org.webpieces.httpclient11.api.HttpSocket in project webpieces by deanhiller.

the class TestLesson7AdvancedCookiesCrud method setUp.

@Before
public void setUp() throws InterruptedException, ClassNotFoundException, ExecutionException, TimeoutException {
    log.info("Setting up test");
    Asserts.assertWasCompiledWithParamNames("test");
    // clear in-memory database
    jdbc.dropAllTablesFromDatabase();
    SimpleMeterRegistry metrics = new SimpleMeterRegistry();
    // you may want to create this server ONCE in a static method BUT if you do, also remember to clear out all your
    // mocks after every test AND you can no longer run single threaded(tradeoffs, tradeoffs)
    // This is however pretty fast to do in many systems...
    Server webserver = new Server(getOverrides(metrics), null, new ServerConfig(JavaCache.getCacheLocation()), args);
    webserver.start();
    HttpSocket https11Socket = connectHttps(null, webserver.getUnderlyingHttpChannel().getLocalAddress());
    webBrowser = new WebBrowserSimulator(https11Socket);
}
Also used : ServerConfig(org.webpieces.webserver.api.ServerConfig) HttpSocket(org.webpieces.httpclient11.api.HttpSocket) WebBrowserSimulator(org.webpieces.webserver.test.WebBrowserSimulator) SimpleMeterRegistry(io.micrometer.core.instrument.simple.SimpleMeterRegistry) Before(org.junit.Before)

Example 5 with HttpSocket

use of org.webpieces.httpclient11.api.HttpSocket in project webpieces by deanhiller.

the class AbstractWebpiecesTest method connectHttps.

public HttpSocket connectHttps(SSLEngine engine, InetSocketAddress addr, HttpSocketListener listener) {
    if (listener == null)
        listener = new NullHttp1CloseListener();
    HttpSocket socket = getClient().createHttpsSocket(engine, 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)

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