Skip to content

Commit

Permalink
Jetty 9.4.x 2233 ssl flush try again 2 (#2726)
Browse files Browse the repository at this point in the history
Major refactor of SslConnection to address #2233 and to simplify in preparation for java-11 support.

Made the `needFillInterest` and `onIncompleteFlush` methods the primary stateful methods with state for fill and flush side that does not reproduce state already held by the SslEngine itself.

Signed-off-by: Greg Wilkins <gregw@webtide.com>
Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
  • Loading branch information
gregw committed Jul 18, 2018
1 parent 9eca404 commit 17b6eee
Show file tree
Hide file tree
Showing 11 changed files with 608 additions and 680 deletions.
Expand Up @@ -26,6 +26,7 @@

import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.handler.AbstractHandler;
import org.eclipse.jetty.util.log.Log;

public class EmptyServerHandler extends AbstractHandler.ErrorDispatchHandler
{
Expand All @@ -38,5 +39,6 @@ protected final void doNonErrorHandle(String target, Request jettyRequest, HttpS

protected void service(String target, Request jettyRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
Log.getRootLogger().info("EMPTY service {}",target);
}
}
Expand Up @@ -510,7 +510,26 @@ public void handle(String target, org.eclipse.jetty.server.Request baseRequest,
@Test
public void test_ExchangeIsComplete_OnlyWhenBothRequestAndResponseAreComplete() throws Exception
{
start(new RespondThenConsumeHandler());
start(new AbstractHandler.ErrorDispatchHandler()
{
@Override
protected void doNonErrorHandle(String target, org.eclipse.jetty.server.Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException
{
baseRequest.setHandled(true);
response.setContentLength(0);
response.setStatus(200);
response.flushBuffer();

byte[] buffer = new byte[1024];
InputStream in = request.getInputStream();
while(true)
{
int read = in.read(buffer);
if (read < 0)
break;
}
}
});

// Prepare a big file to upload
Path targetTestsDir = testdir.getEmptyPathDir();
Expand Down

This file was deleted.

Expand Up @@ -43,7 +43,6 @@
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLEngine;
import javax.net.ssl.SSLSocket;
import javax.servlet.ServletException;
import javax.servlet.ServletInputStream;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
Expand Down Expand Up @@ -75,7 +74,6 @@
import org.junit.Assert;
import org.junit.Assume;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;

public class SslBytesServerTest extends SslBytesTest
Expand All @@ -99,6 +97,11 @@ public void init() throws Exception
threadPool = Executors.newCachedThreadPool();
server = new Server();

sslFills.set(0);
sslFlushes.set(0);
httpParses.set(0);
serverEndPoint.set(null);

File keyStore = MavenTestingUtils.getTestResourceFile("keystore.jks");
sslContextFactory = new SslContextFactory();
sslContextFactory.setKeyStorePath(keyStore.getAbsolutePath());
Expand Down Expand Up @@ -185,7 +188,7 @@ protected ChannelEndPoint newEndPoint(SocketChannel channel, ManagedSelector sel
server.setHandler(new AbstractHandler()
{
@Override
public void handle(String target, Request request, HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws IOException, ServletException
public void handle(String target, Request request, HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws IOException
{
try
{
Expand Down Expand Up @@ -1319,10 +1322,8 @@ public void testRequestWithBigContentWithSplitBoundary() throws Exception

closeClient(client);
}

// TODO work out why this test frequently fails
@Ignore
@Test(timeout=10000)

@Test(timeout=60000)
public void testRequestWithContentWithRenegotiationInMiddleOfContentWhenRenegotiationIsForbidden() throws Exception
{
assumeJavaVersionSupportsTLSRenegotiations();
Expand Down Expand Up @@ -1367,37 +1368,28 @@ public void testRequestWithContentWithRenegotiationInMiddleOfContentWhenRenegoti
Assert.assertEquals(TLSRecord.Type.HANDSHAKE, record.getType());
proxy.flushToServer(record);

// Renegotiation now allowed, server has closed
record = proxy.readFromServer();
// Renegotiation not allowed, server has closed
loop: while(true)
{
record = proxy.readFromServer();
if (record==null)
break;
switch(record.getType())
{
case APPLICATION:
Assert.fail("application data not allows after renegotiate");
case ALERT:
break loop;
default:
continue;
}
}
Assert.assertEquals(TLSRecord.Type.ALERT, record.getType());
proxy.flushToClient(record);

record = proxy.readFromServer();
Assert.assertNull(record);

// Write the rest of the request
threadPool.submit(() ->
{
clientOutput.write(content2.getBytes(StandardCharsets.UTF_8));
clientOutput.flush();
return null;
});

// Trying to write more application data results in an exception since the server closed
record = proxy.readFromClient();
proxy.flushToServer(record);
try
{
record = proxy.readFromClient();
Assert.assertNotNull(record);
proxy.flushToServer(record);
Assert.fail();
}
catch (IOException expected)
{
// Expected
}

// Check that we did not spin
TimeUnit.MILLISECONDS.sleep(500);
Assert.assertThat(sslFills.get(), Matchers.lessThan(50));
Expand Down
1 change: 1 addition & 0 deletions jetty-client/src/test/resources/jetty-logging.properties
Expand Up @@ -2,4 +2,5 @@ class=org.eclipse.jetty.util.log.StdErrLog
#org.eclipse.jetty.LEVEL=INFO
#org.eclipse.jetty.client.LEVEL=DEBUG
#org.eclipse.jetty.io.ChannelEndPoint.LEVEL=DEBUG
#org.eclipse.jetty.io.ssl.LEVEL=DEBUG
#org.eclipse.jetty.http.LEVEL=DEBUG
Expand Up @@ -263,7 +263,7 @@ public long getCreatedTimeStamp()
@Override
public final String toString()
{
return String.format("%s<-%s",toConnectionString(),getEndPoint());
return String.format("%s@%h::%s",getClass().getSimpleName(),this,getEndPoint());
}

public String toConnectionString()
Expand Down

0 comments on commit 17b6eee

Please sign in to comment.