Search in sources :

Example 6 with LeakTrackingByteBufferPool

use of org.eclipse.jetty.io.LeakTrackingByteBufferPool in project jetty.project by eclipse.

the class DebugHandlerTest method startServer.

@SuppressWarnings("deprecation")
@Before
public void startServer() throws Exception {
    server = new Server();
    ServerConnector httpConnector = new ServerConnector(server);
    httpConnector.setPort(0);
    server.addConnector(httpConnector);
    File keystorePath = MavenTestingUtils.getTestResourceFile("keystore");
    SslContextFactory sslContextFactory = new SslContextFactory();
    sslContextFactory.setKeyStorePath(keystorePath.getAbsolutePath());
    sslContextFactory.setKeyStorePassword("storepwd");
    sslContextFactory.setKeyManagerPassword("keypwd");
    sslContextFactory.setTrustStorePath(keystorePath.getAbsolutePath());
    sslContextFactory.setTrustStorePassword("storepwd");
    ByteBufferPool pool = new LeakTrackingByteBufferPool(new MappedByteBufferPool.Tagged());
    ServerConnector sslConnector = new ServerConnector(server, (Executor) null, (Scheduler) null, pool, 1, 1, AbstractConnectionFactory.getFactories(sslContextFactory, new HttpConnectionFactory()));
    server.addConnector(sslConnector);
    debugHandler = new DebugHandler();
    capturedLog = new ByteArrayOutputStream();
    debugHandler.setOutputStream(capturedLog);
    debugHandler.setHandler(new AbstractHandler() {

        @Override
        public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
            baseRequest.setHandled(true);
            response.setStatus(HttpStatus.OK_200);
        }
    });
    server.setHandler(debugHandler);
    server.start();
    String host = httpConnector.getHost();
    if (host == null)
        host = "localhost";
    serverURI = URI.create(String.format("http://%s:%d/", host, httpConnector.getLocalPort()));
    secureServerURI = URI.create(String.format("https://%s:%d/", host, sslConnector.getLocalPort()));
    KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
    try (InputStream stream = sslContextFactory.getKeyStoreResource().getInputStream()) {
        keystore.load(stream, "storepwd".toCharArray());
    }
    TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
    trustManagerFactory.init(keystore);
    sslContext = SSLContext.getInstance("TLS");
    sslContext.init(null, trustManagerFactory.getTrustManagers(), null);
    try {
        HttpsURLConnection.setDefaultHostnameVerifier(__hostnameverifier);
        SSLContext sc = SSLContext.getInstance("TLS");
        sc.init(null, SslContextFactory.TRUST_ALL_CERTS, new java.security.SecureRandom());
        HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
    } catch (Exception e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
}
Also used : LeakTrackingByteBufferPool(org.eclipse.jetty.io.LeakTrackingByteBufferPool) ByteBufferPool(org.eclipse.jetty.io.ByteBufferPool) MappedByteBufferPool(org.eclipse.jetty.io.MappedByteBufferPool) Server(org.eclipse.jetty.server.Server) ServerConnector(org.eclipse.jetty.server.ServerConnector) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletException(javax.servlet.ServletException) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) InputStream(java.io.InputStream) LeakTrackingByteBufferPool(org.eclipse.jetty.io.LeakTrackingByteBufferPool) Request(org.eclipse.jetty.server.Request) HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) SSLContext(javax.net.ssl.SSLContext) KeyStore(java.security.KeyStore) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) MappedByteBufferPool(org.eclipse.jetty.io.MappedByteBufferPool) TrustManagerFactory(javax.net.ssl.TrustManagerFactory) File(java.io.File) Before(org.junit.Before)

Example 7 with LeakTrackingByteBufferPool

use of org.eclipse.jetty.io.LeakTrackingByteBufferPool in project jetty.project by eclipse.

the class HttpClientLoadTest method newServerConnector.

@Override
protected ServerConnector newServerConnector(Server server) {
    int cores = Runtime.getRuntime().availableProcessors();
    ByteBufferPool byteBufferPool = new ArrayByteBufferPool();
    byteBufferPool = new LeakTrackingByteBufferPool(byteBufferPool);
    return new ServerConnector(server, null, null, byteBufferPool, 1, Math.min(1, cores / 2), provideServerConnectionFactory(transport));
}
Also used : LeakTrackingByteBufferPool(org.eclipse.jetty.io.LeakTrackingByteBufferPool) ArrayByteBufferPool(org.eclipse.jetty.io.ArrayByteBufferPool) ByteBufferPool(org.eclipse.jetty.io.ByteBufferPool) MappedByteBufferPool(org.eclipse.jetty.io.MappedByteBufferPool) ArrayByteBufferPool(org.eclipse.jetty.io.ArrayByteBufferPool) ServerConnector(org.eclipse.jetty.server.ServerConnector) LeakTrackingByteBufferPool(org.eclipse.jetty.io.LeakTrackingByteBufferPool)

Example 8 with LeakTrackingByteBufferPool

use of org.eclipse.jetty.io.LeakTrackingByteBufferPool in project jetty.project by eclipse.

the class TooFastClientTest method testUpgradeWithLargeFrame.

/**
     * Test where were a client sends a HTTP Upgrade to websocket AND enough websocket frame(s)
     * to completely overfill the {@link org.eclipse.jetty.io.AbstractConnection#getInputBufferSize()}
     * to test a situation where the WebSocket connection opens with prefill that exceeds 
     * the normal input buffer sizes.
     * @throws Exception on test failure
     */
@Test
@Ignore("RELEASE")
public void testUpgradeWithLargeFrame() throws Exception {
    BlockheadClient client = new BlockheadClient(server.getServerUri());
    try {
        client.connect();
        // Create ByteBuffer representing the initial opening network packet from the client
        ByteBuffer initialPacket = ByteBuffer.allocate(100 * 1024);
        BufferUtil.clearToFill(initialPacket);
        // Add upgrade request to packet
        StringBuilder upgradeRequest = client.generateUpgradeRequest();
        ByteBuffer upgradeBuffer = BufferUtil.toBuffer(upgradeRequest.toString(), StandardCharsets.UTF_8);
        initialPacket.put(upgradeBuffer);
        // Add text frames
        Generator generator = new Generator(WebSocketPolicy.newClientPolicy(), new LeakTrackingByteBufferPool(new MappedByteBufferPool.Tagged()));
        byte[] bigMsgBytes = new byte[64 * 1024];
        Arrays.fill(bigMsgBytes, (byte) 'x');
        String bigMsg = new String(bigMsgBytes, StandardCharsets.UTF_8);
        // Need to set frame mask (as these are client frames)
        byte[] mask = new byte[] { 0x11, 0x22, 0x33, 0x44 };
        TextFrame frame = new TextFrame().setPayload(bigMsg);
        frame.setMask(mask);
        generator.generateWholeFrame(frame, initialPacket);
        // Write packet to network
        BufferUtil.flipToFlush(initialPacket, 0);
        client.writeRaw(initialPacket);
        // Expect upgrade
        client.expectUpgradeResponse();
        // Read frames (hopefully text frames)
        EventQueue<WebSocketFrame> frames = client.readFrames(1, 1, TimeUnit.SECONDS);
        WebSocketFrame tf = frames.poll();
        Assert.assertThat("Text Frame/msg1", tf.getPayloadAsUTF8(), is(bigMsg));
    } finally {
        client.close();
    }
}
Also used : BlockheadClient(org.eclipse.jetty.websocket.common.test.BlockheadClient) LeakTrackingByteBufferPool(org.eclipse.jetty.io.LeakTrackingByteBufferPool) TextFrame(org.eclipse.jetty.websocket.common.frames.TextFrame) WebSocketFrame(org.eclipse.jetty.websocket.common.WebSocketFrame) ByteBuffer(java.nio.ByteBuffer) Generator(org.eclipse.jetty.websocket.common.Generator) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

LeakTrackingByteBufferPool (org.eclipse.jetty.io.LeakTrackingByteBufferPool)8 ByteBufferPool (org.eclipse.jetty.io.ByteBufferPool)6 MappedByteBufferPool (org.eclipse.jetty.io.MappedByteBufferPool)6 ServerConnector (org.eclipse.jetty.server.ServerConnector)5 IOException (java.io.IOException)4 ServletException (javax.servlet.ServletException)4 Test (org.junit.Test)4 InputStream (java.io.InputStream)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 HttpServletResponse (javax.servlet.http.HttpServletResponse)3 ArrayByteBufferPool (org.eclipse.jetty.io.ArrayByteBufferPool)3 Server (org.eclipse.jetty.server.Server)3 ByteBuffer (java.nio.ByteBuffer)2 KeyStore (java.security.KeyStore)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 TimeUnit (java.util.concurrent.TimeUnit)2 SSLContext (javax.net.ssl.SSLContext)2 TrustManagerFactory (javax.net.ssl.TrustManagerFactory)2 HttpClient (org.eclipse.jetty.client.HttpClient)2