Search in sources :

Example 1 with SocketCustomizationListener

use of org.eclipse.jetty.server.SocketCustomizationListener in project jetty.project by eclipse.

the class SslConnectionFactoryTest method testSocketCustomization.

@Test
public void testSocketCustomization() throws Exception {
    final Queue<String> history = new LinkedBlockingQueue<>();
    _connector.addBean(new SocketCustomizationListener() {

        @Override
        protected void customize(Socket socket, Class<? extends Connection> connection, boolean ssl) {
            history.add("customize connector " + connection + "," + ssl);
        }
    });
    _connector.getBean(SslConnectionFactory.class).addBean(new SocketCustomizationListener() {

        @Override
        protected void customize(Socket socket, Class<? extends Connection> connection, boolean ssl) {
            history.add("customize ssl " + connection + "," + ssl);
        }
    });
    _connector.getBean(HttpConnectionFactory.class).addBean(new SocketCustomizationListener() {

        @Override
        protected void customize(Socket socket, Class<? extends Connection> connection, boolean ssl) {
            history.add("customize http " + connection + "," + ssl);
        }
    });
    String response = getResponse("127.0.0.1", null);
    Assert.assertThat(response, Matchers.containsString("host=127.0.0.1"));
    Assert.assertEquals("customize connector class org.eclipse.jetty.io.ssl.SslConnection,false", history.poll());
    Assert.assertEquals("customize ssl class org.eclipse.jetty.io.ssl.SslConnection,false", history.poll());
    Assert.assertEquals("customize connector class org.eclipse.jetty.server.HttpConnection,true", history.poll());
    Assert.assertEquals("customize http class org.eclipse.jetty.server.HttpConnection,true", history.poll());
    Assert.assertEquals(0, history.size());
}
Also used : HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) SocketCustomizationListener(org.eclipse.jetty.server.SocketCustomizationListener) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) Socket(java.net.Socket) SSLSocket(javax.net.ssl.SSLSocket) Test(org.junit.Test)

Example 2 with SocketCustomizationListener

use of org.eclipse.jetty.server.SocketCustomizationListener in project jetty.project by eclipse.

the class SniSslConnectionFactoryTest method testSocketCustomization.

@Test
public void testSocketCustomization() throws Exception {
    final Queue<String> history = new LinkedBlockingQueue<>();
    _connector.addBean(new SocketCustomizationListener() {

        @Override
        protected void customize(Socket socket, Class<? extends Connection> connection, boolean ssl) {
            history.add("customize connector " + connection + "," + ssl);
        }
    });
    _connector.getBean(SslConnectionFactory.class).addBean(new SocketCustomizationListener() {

        @Override
        protected void customize(Socket socket, Class<? extends Connection> connection, boolean ssl) {
            history.add("customize ssl " + connection + "," + ssl);
        }
    });
    _connector.getBean(HttpConnectionFactory.class).addBean(new SocketCustomizationListener() {

        @Override
        protected void customize(Socket socket, Class<? extends Connection> connection, boolean ssl) {
            history.add("customize http " + connection + "," + ssl);
        }
    });
    String response = getResponse("127.0.0.1", null);
    Assert.assertThat(response, Matchers.containsString("X-HOST: 127.0.0.1"));
    Assert.assertEquals("customize connector class org.eclipse.jetty.io.ssl.SslConnection,false", history.poll());
    Assert.assertEquals("customize ssl class org.eclipse.jetty.io.ssl.SslConnection,false", history.poll());
    Assert.assertEquals("customize connector class org.eclipse.jetty.server.HttpConnection,true", history.poll());
    Assert.assertEquals("customize http class org.eclipse.jetty.server.HttpConnection,true", history.poll());
    Assert.assertEquals(0, history.size());
}
Also used : HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) SocketCustomizationListener(org.eclipse.jetty.server.SocketCustomizationListener) Matchers.containsString(org.hamcrest.Matchers.containsString) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) SslConnectionFactory(org.eclipse.jetty.server.SslConnectionFactory) Socket(java.net.Socket) SSLSocket(javax.net.ssl.SSLSocket) Test(org.junit.Test)

Aggregations

Socket (java.net.Socket)2 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)2 SSLSocket (javax.net.ssl.SSLSocket)2 HttpConnectionFactory (org.eclipse.jetty.server.HttpConnectionFactory)2 SocketCustomizationListener (org.eclipse.jetty.server.SocketCustomizationListener)2 SslConnectionFactory (org.eclipse.jetty.server.SslConnectionFactory)2 Test (org.junit.Test)2 Matchers.containsString (org.hamcrest.Matchers.containsString)1