fix checkstyle in test sources (#4013)

Signed-off-by: olivier lamy <oliver.lamy@gmail.com>
This commit is contained in:
Olivier Lamy 2019-08-22 19:56:41 +10:00 committed by GitHub
parent 1a0f08b84d
commit fe3d3f7158
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
149 changed files with 1132 additions and 1314 deletions

View File

@ -38,7 +38,7 @@ import javax.servlet.http.HttpSession;
@WebFilter(filterName = "CFilter", dispatcherTypes = {DispatcherType.REQUEST}, urlPatterns = {"/*"}, initParams = {
@WebInitParam(name = "a", value = "99")
}, asyncSupported = false)
}, asyncSupported = false)
@RunAs("admin")
public class FilterC implements Filter
{

View File

@ -38,7 +38,7 @@ import javax.servlet.http.HttpServletResponse;
@DeclareRoles({"alice"})
@WebServlet(urlPatterns = {"/foo/*", "/bah/*"}, name = "CServlet", initParams = {
@WebInitParam(name = "x", value = "y")
}, loadOnStartup = 2, asyncSupported = false)
}, loadOnStartup = 2, asyncSupported = false)
@MultipartConfig(fileSizeThreshold = 1000, maxFileSize = 2000, maxRequestSize = 3000)
@RunAs("admin")
@ServletSecurity(value = @HttpConstraint(rolesAllowed = {"fred", "bill", "dorothy"}), httpMethodConstraints = {

View File

@ -24,8 +24,8 @@ import javax.servlet.http.HttpServlet;
@WebServlet(urlPatterns = {"/", "/bah/*"}, name = "DServlet", initParams = {
@WebInitParam(name = "x", value = "y")
}, loadOnStartup = 1, asyncSupported = false)
}, loadOnStartup = 1, asyncSupported = false)
public class ServletD extends HttpServlet
{
// no op
}

View File

@ -63,16 +63,14 @@ public class TestSecurityAnnotationConversions
@ServletSecurity(value = @HttpConstraint(value = EmptyRoleSemantic.PERMIT, transportGuarantee = TransportGuarantee.CONFIDENTIAL, rolesAllowed = {
"tom", "dick", "harry"
}), httpMethodConstraints =
{@HttpMethodConstraint(value = "GET")})
}), httpMethodConstraints = {@HttpMethodConstraint(value = "GET")})
public static class Method1Servlet extends HttpServlet
{
}
@ServletSecurity(value = @HttpConstraint(value = EmptyRoleSemantic.PERMIT, transportGuarantee = TransportGuarantee.CONFIDENTIAL, rolesAllowed = {
"tom", "dick", "harry"
}), httpMethodConstraints =
{@HttpMethodConstraint(value = "GET", transportGuarantee = TransportGuarantee.CONFIDENTIAL)})
}), httpMethodConstraints = {@HttpMethodConstraint(value = "GET", transportGuarantee = TransportGuarantee.CONFIDENTIAL)})
public static class Method2Servlet extends HttpServlet
{
}

View File

@ -171,7 +171,8 @@ public class AntBuild
Matcher mat = pat.getMatcher(line);
if (mat.find())
{
int num = 0, count = mat.groupCount();
int num = 0;
int count = mat.groupCount();
String[] match = new String[count];
while (num++ < count)
{

View File

@ -657,10 +657,10 @@ public class HttpClientAuthenticationTest extends AbstractHttpClientServerTest
assertEquals("1523430383", headerInfo.getParameter("nonce"));
// test multiple authentications
List<HeaderInfo> headerInfoList = aph.getHeaderInfo("Digest qop=\"auth\", realm=\"thermostat\", nonce=\"1523430383\", "
+ "Digest realm=\"thermostat2\", qop=\"auth2\", nonce=\"4522530354\", "
+ "Digest qop=\"auth3\", nonce=\"9523570528\", realm=\"thermostat3\", "
+ "Digest qop=\"auth4\", nonce=\"3526435321\"");
List<HeaderInfo> headerInfoList = aph.getHeaderInfo("Digest qop=\"auth\", realm=\"thermostat\", nonce=\"1523430383\", " +
"Digest realm=\"thermostat2\", qop=\"auth2\", nonce=\"4522530354\", " +
"Digest qop=\"auth3\", nonce=\"9523570528\", realm=\"thermostat3\", " +
"Digest qop=\"auth4\", nonce=\"3526435321\"");
assertTrue(headerInfoList.get(0).getType().equalsIgnoreCase("Digest"));
assertEquals("auth", headerInfoList.get(0).getParameter("qop"));
@ -744,8 +744,8 @@ public class HttpClientAuthenticationTest extends AbstractHttpClientServerTest
assertTrue(headerInfo.getType().equalsIgnoreCase("Negotiate"));
assertEquals("TlRMTVNTUAABAAAAB4IIogAAAAAAAAAAAAAAAAAAAAAFAs4OAAAADw==", headerInfo.getBase64());
headerInfos = aph.getHeaderInfo("Negotiate TlRMTVNTUAABAAAAAAAAAFAs4OAAAADw==, "
+ "Negotiate YIIJvwYGKwYBBQUCoIIJszCCCa+gJDAi=");
headerInfos = aph.getHeaderInfo("Negotiate TlRMTVNTUAABAAAAAAAAAFAs4OAAAADw==, " +
"Negotiate YIIJvwYGKwYBBQUCoIIJszCCCa+gJDAi=");
assertTrue(headerInfos.get(0).getType().equalsIgnoreCase("Negotiate"));
assertEquals("TlRMTVNTUAABAAAAAAAAAFAs4OAAAADw==", headerInfos.get(0).getBase64());
@ -766,9 +766,9 @@ public class HttpClientAuthenticationTest extends AbstractHttpClientServerTest
assertEquals("=1523430383=", headerInfo.getParameter("nonce"));
// test multiple authentications
List<HeaderInfo> headerInfoList = aph.getHeaderInfo("Digest qop=\"=au=th=\", realm=\"=ther=mostat=\", nonce=\"=152343=0383=\", "
+ "Digest realm=\"=thermostat2\", qop=\"=auth2\", nonce=\"=4522530354\", "
+ "Digest qop=\"auth3=\", nonce=\"9523570528=\", realm=\"thermostat3=\", ");
List<HeaderInfo> headerInfoList = aph.getHeaderInfo("Digest qop=\"=au=th=\", realm=\"=ther=mostat=\", nonce=\"=152343=0383=\", " +
"Digest realm=\"=thermostat2\", qop=\"=auth2\", nonce=\"=4522530354\", " +
"Digest qop=\"auth3=\", nonce=\"9523570528=\", realm=\"thermostat3=\", ");
assertTrue(headerInfoList.get(0).getType().equalsIgnoreCase("Digest"));
assertEquals("=au=th=", headerInfoList.get(0).getParameter("qop"));

View File

@ -67,6 +67,8 @@ public class HttpClientTLSTest
private ServerConnector connector;
private HttpClient client;
private SSLSocket sslSocket;
private void startServer(SslContextFactory sslContextFactory, Handler handler) throws Exception
{
ExecutorThreadPool serverThreads = new ExecutorThreadPool();
@ -419,7 +421,7 @@ public class HttpClientTLSTest
String host = "localhost";
int port = connector.getLocalPort();
Socket socket = new Socket(host, port);
SSLSocket sslSocket = (SSLSocket)clientTLSFactory.getSslContext().getSocketFactory().createSocket(socket, host, port, true);
sslSocket = (SSLSocket)clientTLSFactory.getSslContext().getSocketFactory().createSocket(socket, host, port, true);
CountDownLatch handshakeLatch1 = new CountDownLatch(1);
AtomicReference<byte[]> session1 = new AtomicReference<>();
sslSocket.addHandshakeCompletedListener(event ->
@ -432,14 +434,12 @@ public class HttpClientTLSTest
// In TLS 1.3 the server sends a NewSessionTicket post-handshake message
// to enable session resumption and without a read, the message is not processed.
try
assertThrows(SocketTimeoutException.class, () ->
{
sslSocket.setSoTimeout(1000);
sslSocket.getInputStream().read();
}
catch (SocketTimeoutException expected)
{
}
});
// The client closes abruptly.
socket.close();

View File

@ -1810,7 +1810,7 @@ public class HttpClientTest extends AbstractHttpClientServerTest
}
}
public static abstract class RetryListener implements Response.CompleteListener
public abstract static class RetryListener implements Response.CompleteListener
{
private final HttpClient client;
private final String scheme;

View File

@ -45,8 +45,8 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNotSame;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
public class HttpDestinationOverHTTPTest extends AbstractHttpClientServerTest
{
@ -298,14 +298,7 @@ public class HttpDestinationOverHTTPTest extends AbstractHttpClientServerTest
server.stop();
Request request = client.newRequest(host, port).scheme(scenario.getScheme());
try
{
request.send();
fail("Request to a closed port must fail");
}
catch (Exception expected)
{
}
assertThrows(Exception.class, () -> request.send());
long deadline = System.nanoTime() + TimeUnit.SECONDS.toNanos(1);
while (!client.getDestinations().isEmpty() && System.nanoTime() < deadline)

View File

@ -1397,6 +1397,7 @@ public class SslBytesServerTest extends SslBytesTest
{
case APPLICATION:
fail("application data not allows after renegotiate");
return; // this is just to avoid checkstyle warning
case ALERT:
break loop;
default:

View File

@ -435,7 +435,7 @@ public class MultiPartContentProviderTest extends AbstractHttpClientServerTest
assertTrue(responseLatch.await(5, TimeUnit.SECONDS));
}
private static abstract class AbstractMultiPartHandler extends AbstractHandler
private abstract static class AbstractMultiPartHandler extends AbstractHandler
{
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException

View File

@ -206,7 +206,7 @@ public class MultiPartFormInputStream
public Collection<String> getHeaders(String name)
{
Collection<String> headers = _headers.getValues(name);
return headers == null ? Collections.emptyList():headers;
return headers == null ? Collections.emptyList() : headers;
}
@Override

View File

@ -97,7 +97,7 @@ public class HttpParserTest
}
@Test
public void testLineParse_Mock_IP() throws Exception
public void testLineParseMockIP() throws Exception
{
ByteBuffer buffer = BufferUtil.toBuffer("POST /mock/127.0.0.1 HTTP/1.1\r\n" + "\r\n");
@ -125,7 +125,7 @@ public class HttpParserTest
}
@Test
public void testLineParse1_RFC2616() throws Exception
public void testLineParse1RFC2616() throws Exception
{
ByteBuffer buffer = BufferUtil.toBuffer("GET /999\r\n");
@ -154,7 +154,7 @@ public class HttpParserTest
}
@Test
public void testLineParse2_RFC2616() throws Exception
public void testLineParse2RFC2616() throws Exception
{
ByteBuffer buffer = BufferUtil.toBuffer("POST /222 \r\n");
@ -376,7 +376,7 @@ public class HttpParserTest
HttpCompliance.RFC7230, HttpCompliance.RFC2616
};
String whitespaces[][] = new String[][]
String[][] whitespaces = new String[][]
{
{" ", "Illegal character SPACE"},
{"\t", "Illegal character HTAB"},
@ -802,9 +802,9 @@ public class HttpParserTest
public void testBadHeaderEncoding() throws Exception
{
ByteBuffer buffer = BufferUtil.toBuffer(
"GET / HTTP/1.0\r\n"
+ "H\u00e6der0: value0\r\n"
+ "\n\n");
"GET / HTTP/1.0\r\n" +
"H\u00e6der0: value0\r\n" +
"\n\n");
HttpParser.RequestHandler handler = new Handler();
HttpParser parser = new HttpParser(handler);
@ -832,7 +832,7 @@ public class HttpParserTest
"Foo/Bar: value\r\n",
"Foo]Bar: value\r\n",
"Foo[Bar: value\r\n",
};
};
for (int i = 0; i < bad.length; i++)
{
@ -1003,16 +1003,16 @@ public class HttpParserTest
public void testChunkParse() throws Exception
{
ByteBuffer buffer = BufferUtil.toBuffer(
"GET /chunk HTTP/1.0\r\n"
+ "Header1: value1\r\n"
+ "Transfer-Encoding: chunked\r\n"
+ "\r\n"
+ "a;\r\n"
+ "0123456789\r\n"
+ "1a\r\n"
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ\r\n"
+ "0\r\n"
+ "\r\n");
"GET /chunk HTTP/1.0\r\n" +
"Header1: value1\r\n" +
"Transfer-Encoding: chunked\r\n" +
"\r\n" +
"a;\r\n" +
"0123456789\r\n" +
"1a\r\n" +
"ABCDEFGHIJKLMNOPQRSTUVWXYZ\r\n" +
"0\r\n" +
"\r\n");
HttpParser.RequestHandler handler = new Handler();
HttpParser parser = new HttpParser(handler);
parseAll(parser, buffer);
@ -1033,16 +1033,16 @@ public class HttpParserTest
public void testBadChunkParse() throws Exception
{
ByteBuffer buffer = BufferUtil.toBuffer(
"GET /chunk HTTP/1.0\r\n"
+ "Header1: value1\r\n"
+ "Transfer-Encoding: chunked, identity\r\n"
+ "\r\n"
+ "a;\r\n"
+ "0123456789\r\n"
+ "1a\r\n"
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ\r\n"
+ "0\r\n"
+ "\r\n");
"GET /chunk HTTP/1.0\r\n" +
"Header1: value1\r\n" +
"Transfer-Encoding: chunked, identity\r\n" +
"\r\n" +
"a;\r\n" +
"0123456789\r\n" +
"1a\r\n" +
"ABCDEFGHIJKLMNOPQRSTUVWXYZ\r\n" +
"0\r\n" +
"\r\n");
HttpParser.RequestHandler handler = new Handler();
HttpParser parser = new HttpParser(handler);
parseAll(parser, buffer);
@ -1057,17 +1057,17 @@ public class HttpParserTest
public void testChunkParseTrailer() throws Exception
{
ByteBuffer buffer = BufferUtil.toBuffer(
"GET /chunk HTTP/1.0\r\n"
+ "Header1: value1\r\n"
+ "Transfer-Encoding: chunked\r\n"
+ "\r\n"
+ "a;\r\n"
+ "0123456789\r\n"
+ "1a\r\n"
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ\r\n"
+ "0\r\n"
+ "Trailer: value\r\n"
+ "\r\n");
"GET /chunk HTTP/1.0\r\n" +
"Header1: value1\r\n" +
"Transfer-Encoding: chunked\r\n" +
"\r\n" +
"a;\r\n" +
"0123456789\r\n" +
"1a\r\n" +
"ABCDEFGHIJKLMNOPQRSTUVWXYZ\r\n" +
"0\r\n" +
"Trailer: value\r\n" +
"\r\n");
HttpParser.RequestHandler handler = new Handler();
HttpParser parser = new HttpParser(handler);
parseAll(parser, buffer);
@ -1092,17 +1092,17 @@ public class HttpParserTest
public void testChunkParseTrailers() throws Exception
{
ByteBuffer buffer = BufferUtil.toBuffer(
"GET /chunk HTTP/1.0\r\n"
+ "Transfer-Encoding: chunked\r\n"
+ "\r\n"
+ "a;\r\n"
+ "0123456789\r\n"
+ "1a\r\n"
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ\r\n"
+ "0\r\n"
+ "Trailer: value\r\n"
+ "Foo: bar\r\n"
+ "\r\n");
"GET /chunk HTTP/1.0\r\n" +
"Transfer-Encoding: chunked\r\n" +
"\r\n" +
"a;\r\n" +
"0123456789\r\n" +
"1a\r\n" +
"ABCDEFGHIJKLMNOPQRSTUVWXYZ\r\n" +
"0\r\n" +
"Trailer: value\r\n" +
"Foo: bar\r\n" +
"\r\n");
HttpParser.RequestHandler handler = new Handler();
HttpParser parser = new HttpParser(handler);
parseAll(parser, buffer);
@ -1130,16 +1130,16 @@ public class HttpParserTest
public void testChunkParseBadTrailer() throws Exception
{
ByteBuffer buffer = BufferUtil.toBuffer(
"GET /chunk HTTP/1.0\r\n"
+ "Header1: value1\r\n"
+ "Transfer-Encoding: chunked\r\n"
+ "\r\n"
+ "a;\r\n"
+ "0123456789\r\n"
+ "1a\r\n"
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ\r\n"
+ "0\r\n"
+ "Trailer: value");
"GET /chunk HTTP/1.0\r\n" +
"Header1: value1\r\n" +
"Transfer-Encoding: chunked\r\n" +
"\r\n" +
"a;\r\n" +
"0123456789\r\n" +
"1a\r\n" +
"ABCDEFGHIJKLMNOPQRSTUVWXYZ\r\n" +
"0\r\n" +
"Trailer: value");
HttpParser.RequestHandler handler = new Handler();
HttpParser parser = new HttpParser(handler);
parseAll(parser, buffer);
@ -1162,15 +1162,15 @@ public class HttpParserTest
public void testChunkParseNoTrailer() throws Exception
{
ByteBuffer buffer = BufferUtil.toBuffer(
"GET /chunk HTTP/1.0\r\n"
+ "Header1: value1\r\n"
+ "Transfer-Encoding: chunked\r\n"
+ "\r\n"
+ "a;\r\n"
+ "0123456789\r\n"
+ "1a\r\n"
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ\r\n"
+ "0\r\n");
"GET /chunk HTTP/1.0\r\n" +
"Header1: value1\r\n" +
"Transfer-Encoding: chunked\r\n" +
"\r\n" +
"a;\r\n" +
"0123456789\r\n" +
"1a\r\n" +
"ABCDEFGHIJKLMNOPQRSTUVWXYZ\r\n" +
"0\r\n");
HttpParser.RequestHandler handler = new Handler();
HttpParser parser = new HttpParser(handler);
parseAll(parser, buffer);
@ -1205,10 +1205,10 @@ public class HttpParserTest
public void testEarlyEOF() throws Exception
{
ByteBuffer buffer = BufferUtil.toBuffer(
"GET /uri HTTP/1.0\r\n"
+ "Content-Length: 20\r\n"
+ "\r\n"
+ "0123456789");
"GET /uri HTTP/1.0\r\n" +
"Content-Length: 20\r\n" +
"\r\n" +
"0123456789");
HttpParser.RequestHandler handler = new Handler();
HttpParser parser = new HttpParser(handler);
parser.atEOF();
@ -1226,12 +1226,12 @@ public class HttpParserTest
public void testChunkEarlyEOF() throws Exception
{
ByteBuffer buffer = BufferUtil.toBuffer(
"GET /chunk HTTP/1.0\r\n"
+ "Header1: value1\r\n"
+ "Transfer-Encoding: chunked\r\n"
+ "\r\n"
+ "a;\r\n"
+ "0123456789\r\n");
"GET /chunk HTTP/1.0\r\n" +
"Header1: value1\r\n" +
"Transfer-Encoding: chunked\r\n" +
"\r\n" +
"a;\r\n" +
"0123456789\r\n");
HttpParser.RequestHandler handler = new Handler();
HttpParser parser = new HttpParser(handler);
parser.atEOF();
@ -1252,31 +1252,31 @@ public class HttpParserTest
public void testMultiParse() throws Exception
{
ByteBuffer buffer = BufferUtil.toBuffer(
"GET /mp HTTP/1.0\r\n"
+ "Connection: Keep-Alive\r\n"
+ "Header1: value1\r\n"
+ "Transfer-Encoding: chunked\r\n"
+ "\r\n"
+ "a;\r\n"
+ "0123456789\r\n"
+ "1a\r\n"
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ\r\n"
+ "0\r\n"
"GET /mp HTTP/1.0\r\n" +
"Connection: Keep-Alive\r\n" +
"Header1: value1\r\n" +
"Transfer-Encoding: chunked\r\n" +
"\r\n" +
"a;\r\n" +
"0123456789\r\n" +
"1a\r\n" +
"ABCDEFGHIJKLMNOPQRSTUVWXYZ\r\n" +
"0\r\n" +
+ "\r\n"
"\r\n" +
+ "POST /foo HTTP/1.0\r\n"
+ "Connection: Keep-Alive\r\n"
+ "Header2: value2\r\n"
+ "Content-Length: 0\r\n"
+ "\r\n"
"POST /foo HTTP/1.0\r\n" +
"Connection: Keep-Alive\r\n" +
"Header2: value2\r\n" +
"Content-Length: 0\r\n" +
"\r\n" +
+ "PUT /doodle HTTP/1.0\r\n"
+ "Connection: close\r\n"
+ "Header3: value3\r\n"
+ "Content-Length: 10\r\n"
+ "\r\n"
+ "0123456789\r\n");
"PUT /doodle HTTP/1.0\r\n" +
"Connection: close\r\n" +
"Header3: value3\r\n" +
"Content-Length: 10\r\n" +
"\r\n" +
"0123456789\r\n");
HttpParser.RequestHandler handler = new Handler();
HttpParser parser = new HttpParser(handler);
@ -1317,32 +1317,31 @@ public class HttpParserTest
public void testMultiParseEarlyEOF() throws Exception
{
ByteBuffer buffer0 = BufferUtil.toBuffer(
"GET /mp HTTP/1.0\r\n"
+ "Connection: Keep-Alive\r\n");
"GET /mp HTTP/1.0\r\n" +
"Connection: Keep-Alive\r\n");
ByteBuffer buffer1 = BufferUtil.toBuffer("Header1: value1\r\n"
+ "Transfer-Encoding: chunked\r\n"
+ "\r\n"
+ "a;\r\n"
+ "0123456789\r\n"
+ "1a\r\n"
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ\r\n"
+ "0\r\n"
ByteBuffer buffer1 = BufferUtil.toBuffer("Header1: value1\r\n" +
"Transfer-Encoding: chunked\r\n" +
"\r\n" +
"a;\r\n" +
"0123456789\r\n" +
"1a\r\n" +
"ABCDEFGHIJKLMNOPQRSTUVWXYZ\r\n" +
"0\r\n" +
+ "\r\n"
"\r\n" +
+ "POST /foo HTTP/1.0\r\n"
+ "Connection: Keep-Alive\r\n"
+ "Header2: value2\r\n"
+ "Content-Length: 0\r\n"
+ "\r\n"
"POST /foo HTTP/1.0\r\n" +
"Connection: Keep-Alive\r\n" +
"Header2: value2\r\n" +
"Content-Length: 0\r\n" +
"\r\n" +
+ "PUT /doodle HTTP/1.0\r\n"
+ "Connection: close\r\n"
+ "Header3: value3\r\n"
+ "Content-Length: 10\r\n"
+ "\r\n"
+ "0123456789\r\n");
"PUT /doodle HTTP/1.0\r\n" +
"Connection: close\r\n" + "Header3: value3\r\n" +
"Content-Length: 10\r\n" +
"\r\n" +
"0123456789\r\n");
HttpParser.RequestHandler handler = new Handler();
HttpParser parser = new HttpParser(handler);
@ -1384,11 +1383,11 @@ public class HttpParserTest
public void testResponseParse0() throws Exception
{
ByteBuffer buffer = BufferUtil.toBuffer(
"HTTP/1.1 200 Correct\r\n"
+ "Content-Length: 10\r\n"
+ "Content-Type: text/plain\r\n"
+ "\r\n"
+ "0123456789\r\n");
"HTTP/1.1 200 Correct\r\n" +
"Content-Length: 10\r\n" +
"Content-Type: text/plain\r\n" +
"\r\n" +
"0123456789\r\n");
HttpParser.ResponseHandler handler = new Handler();
HttpParser parser = new HttpParser(handler);
@ -1405,9 +1404,9 @@ public class HttpParserTest
public void testResponseParse1() throws Exception
{
ByteBuffer buffer = BufferUtil.toBuffer(
"HTTP/1.1 304 Not-Modified\r\n"
+ "Connection: close\r\n"
+ "\r\n");
"HTTP/1.1 304 Not-Modified\r\n" +
"Connection: close\r\n" +
"\r\n");
HttpParser.ResponseHandler handler = new Handler();
HttpParser parser = new HttpParser(handler);
@ -1423,15 +1422,15 @@ public class HttpParserTest
public void testResponseParse2() throws Exception
{
ByteBuffer buffer = BufferUtil.toBuffer(
"HTTP/1.1 204 No-Content\r\n"
+ "Header: value\r\n"
+ "\r\n"
"HTTP/1.1 204 No-Content\r\n" +
"Header: value\r\n" +
"\r\n" +
+ "HTTP/1.1 200 Correct\r\n"
+ "Content-Length: 10\r\n"
+ "Content-Type: text/plain\r\n"
+ "\r\n"
+ "0123456789\r\n");
"HTTP/1.1 200 Correct\r\n" +
"Content-Length: 10\r\n" +
"Content-Type: text/plain\r\n" +
"\r\n" +
"0123456789\r\n");
HttpParser.ResponseHandler handler = new Handler();
HttpParser parser = new HttpParser(handler);
@ -1459,11 +1458,11 @@ public class HttpParserTest
public void testResponseParse3() throws Exception
{
ByteBuffer buffer = BufferUtil.toBuffer(
"HTTP/1.1 200\r\n"
+ "Content-Length: 10\r\n"
+ "Content-Type: text/plain\r\n"
+ "\r\n"
+ "0123456789\r\n");
"HTTP/1.1 200\r\n" +
"Content-Length: 10\r\n" +
"Content-Type: text/plain\r\n" +
"\r\n" +
"0123456789\r\n");
HttpParser.ResponseHandler handler = new Handler();
HttpParser parser = new HttpParser(handler);
@ -1480,11 +1479,11 @@ public class HttpParserTest
public void testResponseParse4() throws Exception
{
ByteBuffer buffer = BufferUtil.toBuffer(
"HTTP/1.1 200 \r\n"
+ "Content-Length: 10\r\n"
+ "Content-Type: text/plain\r\n"
+ "\r\n"
+ "0123456789\r\n");
"HTTP/1.1 200 \r\n" +
"Content-Length: 10\r\n" +
"Content-Type: text/plain\r\n" +
"\r\n" +
"0123456789\r\n");
HttpParser.ResponseHandler handler = new Handler();
HttpParser parser = new HttpParser(handler);
@ -1501,10 +1500,10 @@ public class HttpParserTest
public void testResponseEOFContent() throws Exception
{
ByteBuffer buffer = BufferUtil.toBuffer(
"HTTP/1.1 200 \r\n"
+ "Content-Type: text/plain\r\n"
+ "\r\n"
+ "0123456789\r\n");
"HTTP/1.1 200 \r\n" +
"Content-Type: text/plain\r\n" +
"\r\n" +
"0123456789\r\n");
HttpParser.ResponseHandler handler = new Handler();
HttpParser parser = new HttpParser(handler);
@ -1524,9 +1523,9 @@ public class HttpParserTest
public void testResponse304WithContentLength() throws Exception
{
ByteBuffer buffer = BufferUtil.toBuffer(
"HTTP/1.1 304 found\r\n"
+ "Content-Length: 10\r\n"
+ "\r\n");
"HTTP/1.1 304 found\r\n" +
"Content-Length: 10\r\n" +
"\r\n");
HttpParser.ResponseHandler handler = new Handler();
HttpParser parser = new HttpParser(handler);
@ -1543,9 +1542,9 @@ public class HttpParserTest
public void testResponse101WithTransferEncoding() throws Exception
{
ByteBuffer buffer = BufferUtil.toBuffer(
"HTTP/1.1 101 switching protocols\r\n"
+ "Transfer-Encoding: chunked\r\n"
+ "\r\n");
"HTTP/1.1 101 switching protocols\r\n" +
"Transfer-Encoding: chunked\r\n" +
"\r\n");
HttpParser.ResponseHandler handler = new Handler();
HttpParser parser = new HttpParser(handler);
@ -1562,9 +1561,9 @@ public class HttpParserTest
public void testResponseReasonIso8859_1() throws Exception
{
ByteBuffer buffer = BufferUtil.toBuffer(
"HTTP/1.1 302 déplacé temporairement\r\n"
+ "Content-Length: 0\r\n"
+ "\r\n", StandardCharsets.ISO_8859_1);
"HTTP/1.1 302 déplacé temporairement\r\n" +
"Content-Length: 0\r\n" +
"\r\n", StandardCharsets.ISO_8859_1);
HttpParser.ResponseHandler handler = new Handler();
HttpParser parser = new HttpParser(handler);
@ -1578,12 +1577,12 @@ public class HttpParserTest
public void testSeekEOF() throws Exception
{
ByteBuffer buffer = BufferUtil.toBuffer(
"HTTP/1.1 200 OK\r\n"
+ "Content-Length: 0\r\n"
+ "Connection: close\r\n"
+ "\r\n"
+ "\r\n" // extra CRLF ignored
+ "HTTP/1.1 400 OK\r\n"); // extra data causes close ??
"HTTP/1.1 200 OK\r\n" +
"Content-Length: 0\r\n" +
"Connection: close\r\n" +
"\r\n" +
"\r\n" + // extra CRLF ignored
"HTTP/1.1 400 OK\r\n"); // extra data causes close ??
HttpParser.ResponseHandler handler = new Handler();
HttpParser parser = new HttpParser(handler);
@ -1610,10 +1609,10 @@ public class HttpParserTest
public void testNoURI() throws Exception
{
ByteBuffer buffer = BufferUtil.toBuffer(
"GET\r\n"
+ "Content-Length: 0\r\n"
+ "Connection: close\r\n"
+ "\r\n");
"GET\r\n" +
"Content-Length: 0\r\n" +
"Connection: close\r\n" +
"\r\n");
HttpParser.RequestHandler handler = new Handler();
HttpParser parser = new HttpParser(handler);
@ -1632,10 +1631,10 @@ public class HttpParserTest
public void testNoURI2() throws Exception
{
ByteBuffer buffer = BufferUtil.toBuffer(
"GET \r\n"
+ "Content-Length: 0\r\n"
+ "Connection: close\r\n"
+ "\r\n");
"GET \r\n" +
"Content-Length: 0\r\n" +
"Connection: close\r\n" +
"\r\n");
HttpParser.RequestHandler handler = new Handler();
HttpParser parser = new HttpParser(handler);
@ -1654,10 +1653,10 @@ public class HttpParserTest
public void testUnknownReponseVersion() throws Exception
{
ByteBuffer buffer = BufferUtil.toBuffer(
"HPPT/7.7 200 OK\r\n"
+ "Content-Length: 0\r\n"
+ "Connection: close\r\n"
+ "\r\n");
"HPPT/7.7 200 OK\r\n" +
"Content-Length: 0\r\n" +
"Connection: close\r\n" +
"\r\n");
HttpParser.ResponseHandler handler = new Handler();
HttpParser parser = new HttpParser(handler);
@ -1676,10 +1675,10 @@ public class HttpParserTest
public void testNoStatus() throws Exception
{
ByteBuffer buffer = BufferUtil.toBuffer(
"HTTP/1.1\r\n"
+ "Content-Length: 0\r\n"
+ "Connection: close\r\n"
+ "\r\n");
"HTTP/1.1\r\n" +
"Content-Length: 0\r\n" +
"Connection: close\r\n" +
"\r\n");
HttpParser.ResponseHandler handler = new Handler();
HttpParser parser = new HttpParser(handler);
@ -1698,10 +1697,10 @@ public class HttpParserTest
public void testNoStatus2() throws Exception
{
ByteBuffer buffer = BufferUtil.toBuffer(
"HTTP/1.1 \r\n"
+ "Content-Length: 0\r\n"
+ "Connection: close\r\n"
+ "\r\n");
"HTTP/1.1 \r\n" +
"Content-Length: 0\r\n" +
"Connection: close\r\n" +
"\r\n");
HttpParser.ResponseHandler handler = new Handler();
HttpParser parser = new HttpParser(handler);
@ -1720,10 +1719,10 @@ public class HttpParserTest
public void testBadRequestVersion() throws Exception
{
ByteBuffer buffer = BufferUtil.toBuffer(
"GET / HPPT/7.7\r\n"
+ "Content-Length: 0\r\n"
+ "Connection: close\r\n"
+ "\r\n");
"GET / HPPT/7.7\r\n" +
"Content-Length: 0\r\n" +
"Connection: close\r\n" +
"\r\n");
HttpParser.RequestHandler handler = new Handler();
HttpParser parser = new HttpParser(handler);
@ -1738,10 +1737,10 @@ public class HttpParserTest
assertEquals(HttpParser.State.CLOSED, parser.getState());
buffer = BufferUtil.toBuffer(
"GET / HTTP/1.01\r\n"
+ "Content-Length: 0\r\n"
+ "Connection: close\r\n"
+ "\r\n");
"GET / HTTP/1.01\r\n" +
"Content-Length: 0\r\n" +
"Connection: close\r\n" +
"\r\n");
handler = new Handler();
parser = new HttpParser(handler);
@ -1760,10 +1759,10 @@ public class HttpParserTest
public void testBadCR() throws Exception
{
ByteBuffer buffer = BufferUtil.toBuffer(
"GET / HTTP/1.0\r\n"
+ "Content-Length: 0\r"
+ "Connection: close\r"
+ "\r");
"GET / HTTP/1.0\r\n" +
"Content-Length: 0\r" +
"Connection: close\r" +
"\r");
HttpParser.RequestHandler handler = new Handler();
HttpParser parser = new HttpParser(handler);
@ -1777,10 +1776,10 @@ public class HttpParserTest
assertEquals(HttpParser.State.CLOSED, parser.getState());
buffer = BufferUtil.toBuffer(
"GET / HTTP/1.0\r"
+ "Content-Length: 0\r"
+ "Connection: close\r"
+ "\r");
"GET / HTTP/1.0\r" +
"Content-Length: 0\r" +
"Connection: close\r" +
"\r");
handler = new Handler();
parser = new HttpParser(handler);
@ -1798,10 +1797,10 @@ public class HttpParserTest
public void testBadContentLength0() throws Exception
{
ByteBuffer buffer = BufferUtil.toBuffer(
"GET / HTTP/1.0\r\n"
+ "Content-Length: abc\r\n"
+ "Connection: close\r\n"
+ "\r\n");
"GET / HTTP/1.0\r\n" +
"Content-Length: abc\r\n" +
"Connection: close\r\n" +
"\r\n");
HttpParser.RequestHandler handler = new Handler();
HttpParser parser = new HttpParser(handler);
@ -1820,10 +1819,10 @@ public class HttpParserTest
public void testBadContentLength1() throws Exception
{
ByteBuffer buffer = BufferUtil.toBuffer(
"GET / HTTP/1.0\r\n"
+ "Content-Length: 9999999999999999999999999999999999999999999999\r\n"
+ "Connection: close\r\n"
+ "\r\n");
"GET / HTTP/1.0\r\n" +
"Content-Length: 9999999999999999999999999999999999999999999999\r\n" +
"Connection: close\r\n" +
"\r\n");
HttpParser.RequestHandler handler = new Handler();
HttpParser parser = new HttpParser(handler);
@ -1842,10 +1841,10 @@ public class HttpParserTest
public void testBadContentLength2() throws Exception
{
ByteBuffer buffer = BufferUtil.toBuffer(
"GET / HTTP/1.0\r\n"
+ "Content-Length: 1.5\r\n"
+ "Connection: close\r\n"
+ "\r\n");
"GET / HTTP/1.0\r\n" +
"Content-Length: 1.5\r\n" +
"Connection: close\r\n" +
"\r\n");
HttpParser.RequestHandler handler = new Handler();
HttpParser parser = new HttpParser(handler);
@ -1864,12 +1863,12 @@ public class HttpParserTest
public void testMultipleContentLengthWithLargerThenCorrectValue()
{
ByteBuffer buffer = BufferUtil.toBuffer(
"POST / HTTP/1.1\r\n"
+ "Content-Length: 2\r\n"
+ "Content-Length: 1\r\n"
+ "Connection: close\r\n"
+ "\r\n"
+ "X");
"POST / HTTP/1.1\r\n" +
"Content-Length: 2\r\n" +
"Content-Length: 1\r\n" +
"Connection: close\r\n" +
"\r\n" +
"X");
HttpParser.RequestHandler handler = new Handler();
HttpParser parser = new HttpParser(handler);
@ -1888,12 +1887,12 @@ public class HttpParserTest
public void testMultipleContentLengthWithCorrectThenLargerValue()
{
ByteBuffer buffer = BufferUtil.toBuffer(
"POST / HTTP/1.1\r\n"
+ "Content-Length: 1\r\n"
+ "Content-Length: 2\r\n"
+ "Connection: close\r\n"
+ "\r\n"
+ "X");
"POST / HTTP/1.1\r\n" +
"Content-Length: 1\r\n" +
"Content-Length: 2\r\n" +
"Connection: close\r\n" +
"\r\n" +
"X");
HttpParser.RequestHandler handler = new Handler();
HttpParser parser = new HttpParser(handler);
@ -1912,15 +1911,15 @@ public class HttpParserTest
public void testTransferEncodingChunkedThenContentLength()
{
ByteBuffer buffer = BufferUtil.toBuffer(
"POST /chunk HTTP/1.1\r\n"
+ "Host: localhost\r\n"
+ "Transfer-Encoding: chunked\r\n"
+ "Content-Length: 1\r\n"
+ "\r\n"
+ "1\r\n"
+ "X\r\n"
+ "0\r\n"
+ "\r\n");
"POST /chunk HTTP/1.1\r\n" +
"Host: localhost\r\n" +
"Transfer-Encoding: chunked\r\n" +
"Content-Length: 1\r\n" +
"\r\n" +
"1\r\n" +
"X\r\n" +
"0\r\n" +
"\r\n");
HttpParser.RequestHandler handler = new Handler();
HttpParser parser = new HttpParser(handler, HttpCompliance.RFC2616_LEGACY);
@ -1941,15 +1940,16 @@ public class HttpParserTest
public void testContentLengthThenTransferEncodingChunked()
{
ByteBuffer buffer = BufferUtil.toBuffer(
"POST /chunk HTTP/1.1\r\n"
+ "Host: localhost\r\n"
+ "Content-Length: 1\r\n"
+ "Transfer-Encoding: chunked\r\n"
+ "\r\n"
+ "1\r\n"
+ "X\r\n"
+ "0\r\n"
+ "\r\n");
"POST /chunk HTTP/1.1\r\n" +
"Host: localhost\r\n" +
"Content-Length: 1\r\n" +
"Transfer-Encoding: chunked\r\n" +
"\r\n" +
"1\r\n" +
"X\r\n" +
"0\r\n" +
"\r\n");
HttpParser.RequestHandler handler = new Handler();
HttpParser parser = new HttpParser(handler, HttpCompliance.RFC2616_LEGACY);
@ -1970,10 +1970,10 @@ public class HttpParserTest
public void testHost() throws Exception
{
ByteBuffer buffer = BufferUtil.toBuffer(
"GET / HTTP/1.1\r\n"
+ "Host: host\r\n"
+ "Connection: close\r\n"
+ "\r\n");
"GET / HTTP/1.1\r\n" +
"Host: host\r\n" +
"Connection: close\r\n" +
"\r\n");
HttpParser.RequestHandler handler = new Handler();
HttpParser parser = new HttpParser(handler);
@ -1986,9 +1986,9 @@ public class HttpParserTest
public void testUriHost11() throws Exception
{
ByteBuffer buffer = BufferUtil.toBuffer(
"GET http://host/ HTTP/1.1\r\n"
+ "Connection: close\r\n"
+ "\r\n");
"GET http://host/ HTTP/1.1\r\n" +
"Connection: close\r\n" +
"\r\n");
HttpParser.RequestHandler handler = new Handler();
HttpParser parser = new HttpParser(handler);
@ -2002,8 +2002,8 @@ public class HttpParserTest
public void testUriHost10() throws Exception
{
ByteBuffer buffer = BufferUtil.toBuffer(
"GET http://host/ HTTP/1.0\r\n"
+ "\r\n");
"GET http://host/ HTTP/1.0\r\n" +
"\r\n");
HttpParser.RequestHandler handler = new Handler();
HttpParser parser = new HttpParser(handler);
@ -2017,9 +2017,9 @@ public class HttpParserTest
public void testNoHost() throws Exception
{
ByteBuffer buffer = BufferUtil.toBuffer(
"GET / HTTP/1.1\r\n"
+ "Connection: close\r\n"
+ "\r\n");
"GET / HTTP/1.1\r\n" +
"Connection: close\r\n" +
"\r\n");
HttpParser.RequestHandler handler = new Handler();
HttpParser parser = new HttpParser(handler);
@ -2031,10 +2031,10 @@ public class HttpParserTest
public void testIPHost() throws Exception
{
ByteBuffer buffer = BufferUtil.toBuffer(
"GET / HTTP/1.1\r\n"
+ "Host: 192.168.0.1\r\n"
+ "Connection: close\r\n"
+ "\r\n");
"GET / HTTP/1.1\r\n" +
"Host: 192.168.0.1\r\n" +
"Connection: close\r\n" +
"\r\n");
HttpParser.RequestHandler handler = new Handler();
HttpParser parser = new HttpParser(handler);
@ -2048,10 +2048,10 @@ public class HttpParserTest
{
Assumptions.assumeTrue(Net.isIpv6InterfaceAvailable());
ByteBuffer buffer = BufferUtil.toBuffer(
"GET / HTTP/1.1\r\n"
+ "Host: [::1]\r\n"
+ "Connection: close\r\n"
+ "\r\n");
"GET / HTTP/1.1\r\n" +
"Host: [::1]\r\n" +
"Connection: close\r\n" +
"\r\n");
HttpParser.RequestHandler handler = new Handler();
HttpParser parser = new HttpParser(handler);
@ -2066,10 +2066,10 @@ public class HttpParserTest
try (StacklessLogging s = new StacklessLogging(HttpParser.class))
{
ByteBuffer buffer = BufferUtil.toBuffer(
"GET / HTTP/1.1\r\n"
+ "Host: [::1\r\n"
+ "Connection: close\r\n"
+ "\r\n");
"GET / HTTP/1.1\r\n" +
"Host: [::1\r\n" +
"Connection: close\r\n" +
"\r\n");
HttpParser.RequestHandler handler = new Handler();
HttpParser parser = new HttpParser(handler);
@ -2082,10 +2082,10 @@ public class HttpParserTest
public void testHostPort() throws Exception
{
ByteBuffer buffer = BufferUtil.toBuffer(
"GET / HTTP/1.1\r\n"
+ "Host: myhost:8888\r\n"
+ "Connection: close\r\n"
+ "\r\n");
"GET / HTTP/1.1\r\n" +
"Host: myhost:8888\r\n" +
"Connection: close\r\n" +
"\r\n");
HttpParser.RequestHandler handler = new Handler();
HttpParser parser = new HttpParser(handler);
@ -2098,10 +2098,10 @@ public class HttpParserTest
public void testHostBadPort() throws Exception
{
ByteBuffer buffer = BufferUtil.toBuffer(
"GET / HTTP/1.1\r\n"
+ "Host: myhost:testBadPort\r\n"
+ "Connection: close\r\n"
+ "\r\n");
"GET / HTTP/1.1\r\n" +
"Host: myhost:testBadPort\r\n" +
"Connection: close\r\n" +
"\r\n");
HttpParser.RequestHandler handler = new Handler();
HttpParser parser = new HttpParser(handler);
@ -2113,10 +2113,10 @@ public class HttpParserTest
public void testIPHostPort() throws Exception
{
ByteBuffer buffer = BufferUtil.toBuffer(
"GET / HTTP/1.1\r\n"
+ "Host: 192.168.0.1:8888\r\n"
+ "Connection: close\r\n"
+ "\r\n");
"GET / HTTP/1.1\r\n" +
"Host: 192.168.0.1:8888\r\n" +
"Connection: close\r\n" +
"\r\n");
HttpParser.RequestHandler handler = new Handler();
HttpParser parser = new HttpParser(handler);
@ -2130,10 +2130,10 @@ public class HttpParserTest
{
Assumptions.assumeTrue(Net.isIpv6InterfaceAvailable());
ByteBuffer buffer = BufferUtil.toBuffer(
"GET / HTTP/1.1\r\n"
+ "Host: [::1]:8888\r\n"
+ "Connection: close\r\n"
+ "\r\n");
"GET / HTTP/1.1\r\n" +
"Host: [::1]:8888\r\n" +
"Connection: close\r\n" +
"\r\n");
HttpParser.RequestHandler handler = new Handler();
HttpParser parser = new HttpParser(handler);
@ -2146,10 +2146,10 @@ public class HttpParserTest
public void testEmptyHostPort() throws Exception
{
ByteBuffer buffer = BufferUtil.toBuffer(
"GET / HTTP/1.1\r\n"
+ "Host:\r\n"
+ "Connection: close\r\n"
+ "\r\n");
"GET / HTTP/1.1\r\n" +
"Host:\r\n" +
"Connection: close\r\n" +
"\r\n");
HttpParser.RequestHandler handler = new Handler();
HttpParser parser = new HttpParser(handler);

View File

@ -493,7 +493,7 @@ public class HttpTester
}
}
abstract public MetaData getInfo();
public abstract MetaData getInfo();
@Override
public int getHeaderCacheSize()

View File

@ -77,9 +77,9 @@ public class MultiPartFormInputStreamTest
"Content-Disposition: form-data; name=\"fileup\"; filename=\"test.upload\"\r\n" +
"Content-Type: application/octet-stream\r\n\r\n" +
"How now brown cow." +
"\r\n--" + boundary + "-\r\n"
+ "Content-Disposition: form-data; name=\"fileup\"; filename=\"test.upload\"\r\n"
+ "\r\n";
"\r\n--" + boundary + "-\r\n" +
"Content-Disposition: form-data; name=\"fileup\"; filename=\"test.upload\"\r\n" +
"\r\n";
MultipartConfigElement config = new MultipartConfigElement(_dirname, 1024, 3072, 50);
MultiPartFormInputStream mpis = new MultiPartFormInputStream(new ByteArrayInputStream(str.getBytes()),

View File

@ -173,13 +173,13 @@ public class MultiPartParserTest
};
MultiPartParser parser = new MultiPartParser(handler, "BOUNDARY");
ByteBuffer data = BufferUtil.toBuffer("--BOUNDARY\r\n"
+ "name0: value0\r\n"
+ "name1 :value1 \r\n"
+ "name2:value\r\n"
+ " 2\r\n"
+ "\r\n"
+ "Content");
ByteBuffer data = BufferUtil.toBuffer("--BOUNDARY\r\n" +
"name0: value0\r\n" +
"name1 :value1 \r\n" +
"name2:value\r\n" +
" 2\r\n" +
"\r\n" +
"Content");
parser.parse(data, false);
assertThat(parser.getState(), is(State.FIRST_OCTETS));
@ -193,11 +193,11 @@ public class MultiPartParserTest
TestHandler handler = new TestHandler();
MultiPartParser parser = new MultiPartParser(handler, "BOUNDARY");
ByteBuffer data = BufferUtil.toBuffer("--BOUNDARY\r\n"
+ "name: value\r\n"
+ "\r\n"
+ "\r\n"
+ "--BOUNDARY");
ByteBuffer data = BufferUtil.toBuffer("--BOUNDARY\r\n" +
"name: value\r\n" +
"\r\n" +
"\r\n" +
"--BOUNDARY");
parser.parse(data, false);
assertThat(parser.getState(), is(State.DELIMITER));
assertThat(data.remaining(), is(0));
@ -211,10 +211,10 @@ public class MultiPartParserTest
TestHandler handler = new TestHandler();
MultiPartParser parser = new MultiPartParser(handler, "BOUNDARY");
ByteBuffer data = BufferUtil.toBuffer("--BOUNDARY\r\n"
+ "name: value\r\n"
+ "\r\n"
+ "--BOUNDARY");
ByteBuffer data = BufferUtil.toBuffer("--BOUNDARY\r\n" +
"name: value\r\n" +
"\r\n" +
"--BOUNDARY");
parser.parse(data, false);
assertThat(parser.getState(), is(State.DELIMITER));
assertThat(data.remaining(), is(0));
@ -228,10 +228,10 @@ public class MultiPartParserTest
TestHandler handler = new TestHandler();
MultiPartParser parser = new MultiPartParser(handler, "BOUNDARY");
ByteBuffer data = BufferUtil.toBuffer("--BOUNDARY\r\n"
+ "name: value\r\n"
+ "\r\n"
+ "-");
ByteBuffer data = BufferUtil.toBuffer("--BOUNDARY\r\n" +
"name: value\r\n" +
"\r\n" +
"-");
parser.parse(data, false);
data = BufferUtil.toBuffer("Content!");
parser.parse(data, false);
@ -248,10 +248,10 @@ public class MultiPartParserTest
TestHandler handler = new TestHandler();
MultiPartParser parser = new MultiPartParser(handler, "BOUNDARY");
ByteBuffer data = BufferUtil.toBuffer("--BOUNDARY\r\n"
+ "name: value\n"
+ "\r\n"
+ "Hello\r\n");
ByteBuffer data = BufferUtil.toBuffer("--BOUNDARY\r\n" +
"name: value\n" +
"\r\n" +
"Hello\r\n");
parser.parse(data, false);
assertThat(parser.getState(), is(State.OCTETS));
assertThat(data.remaining(), is(0));
@ -259,18 +259,18 @@ public class MultiPartParserTest
assertThat(handler.content, Matchers.contains("Hello"));
data = BufferUtil.toBuffer(
"Now is the time for all good ment to come to the aid of the party.\r\n"
+ "How now brown cow.\r\n"
+ "The quick brown fox jumped over the lazy dog.\r\n"
+ "this is not a --BOUNDARY\r\n");
"Now is the time for all good ment to come to the aid of the party.\r\n" +
"How now brown cow.\r\n" +
"The quick brown fox jumped over the lazy dog.\r\n" +
"this is not a --BOUNDARY\r\n");
parser.parse(data, false);
assertThat(parser.getState(), is(State.OCTETS));
assertThat(data.remaining(), is(0));
assertThat(handler.fields, Matchers.contains("name: value", "<<COMPLETE>>"));
assertThat(handler.content, Matchers.contains("Hello", "\r\n", "Now is the time for all good ment to come to the aid of the party.\r\n"
+ "How now brown cow.\r\n"
+ "The quick brown fox jumped over the lazy dog.\r\n"
+ "this is not a --BOUNDARY"));
assertThat(handler.content, Matchers.contains("Hello", "\r\n", "Now is the time for all good ment to come to the aid of the party.\r\n" +
"How now brown cow.\r\n" +
"The quick brown fox jumped over the lazy dog.\r\n" +
"this is not a --BOUNDARY"));
}
@Test
@ -279,11 +279,11 @@ public class MultiPartParserTest
TestHandler handler = new TestHandler();
MultiPartParser parser = new MultiPartParser(handler, "BOUNDARY");
ByteBuffer data = BufferUtil.toBuffer("--BOUNDARY\r\n"
+ "name: value\n"
+ "\r\n"
+ "Hello\r\n"
+ "--BOUNDARY");
ByteBuffer data = BufferUtil.toBuffer("--BOUNDARY\r\n" +
"name: value\n" +
"\r\n" +
"Hello\r\n" +
"--BOUNDARY");
parser.parse(data, false);
assertThat(parser.getState(), is(State.DELIMITER));
assertThat(data.remaining(), is(0));
@ -297,21 +297,21 @@ public class MultiPartParserTest
TestHandler handler = new TestHandler();
MultiPartParser parser = new MultiPartParser(handler, "BOUNDARY");
ByteBuffer data = BufferUtil.toBuffer("--BOUNDARY\r\n"
+ "name: value\n"
+ "\r\n"
+ "Now is the time for all good ment to come to the aid of the party.\r\n"
+ "How now brown cow.\r\n"
+ "The quick brown fox jumped over the lazy dog.\r\n"
+ "\r\n"
+ "--BOUNDARY");
ByteBuffer data = BufferUtil.toBuffer("--BOUNDARY\r\n" +
"name: value\n" +
"\r\n" +
"Now is the time for all good ment to come to the aid of the party.\r\n" +
"How now brown cow.\r\n" +
"The quick brown fox jumped over the lazy dog.\r\n" +
"\r\n" +
"--BOUNDARY");
parser.parse(data, false);
assertThat(parser.getState(), is(State.DELIMITER));
assertThat(data.remaining(), is(0));
assertThat(handler.fields, Matchers.contains("name: value", "<<COMPLETE>>"));
assertThat(handler.content, Matchers.contains("Now is the time for all good ment to come to the aid of the party.\r\n"
+ "How now brown cow.\r\n"
+ "The quick brown fox jumped over the lazy dog.\r\n", "<<LAST>>"));
assertThat(handler.content, Matchers.contains("Now is the time for all good ment to come to the aid of the party.\r\n" +
"How now brown cow.\r\n" +
"The quick brown fox jumped over the lazy dog.\r\n", "<<LAST>>"));
}
@Test
@ -321,21 +321,21 @@ public class MultiPartParserTest
MultiPartParser parser = new MultiPartParser(handler, "BOUNDARY");
//boundary still requires carriage return
ByteBuffer data = BufferUtil.toBuffer("--BOUNDARY\n"
+ "name: value\n"
+ "\n"
+ "Now is the time for all good men to come to the aid of the party.\n"
+ "How now brown cow.\n"
+ "The quick brown fox jumped over the lazy dog.\n"
+ "\r\n"
+ "--BOUNDARY");
ByteBuffer data = BufferUtil.toBuffer("--BOUNDARY\n" +
"name: value\n" +
"\n" +
"Now is the time for all good men to come to the aid of the party.\n" +
"How now brown cow.\n" +
"The quick brown fox jumped over the lazy dog.\n" +
"\r\n" +
"--BOUNDARY");
parser.parse(data, false);
assertThat(parser.getState(), is(State.DELIMITER));
assertThat(data.remaining(), is(0));
assertThat(handler.fields, Matchers.contains("name: value", "<<COMPLETE>>"));
assertThat(handler.content, Matchers.contains("Now is the time for all good men to come to the aid of the party.\n"
+ "How now brown cow.\n"
+ "The quick brown fox jumped over the lazy dog.\n", "<<LAST>>"));
assertThat(handler.content, Matchers.contains("Now is the time for all good men to come to the aid of the party.\n" +
"How now brown cow.\n" +
"The quick brown fox jumped over the lazy dog.\n", "<<LAST>>"));
}
@Test
@ -377,17 +377,17 @@ public class MultiPartParserTest
TestHandler handler = new TestHandler();
MultiPartParser parser = new MultiPartParser(handler, "BOUNDARY");
ByteBuffer data = BufferUtil.toBuffer(""
+ "--BOUNDARY\r\n"
+ "name: value\n"
+ "\r\n"
+ "Hello\r\n"
+ "--BOUNDARY--"
+ "epilogue here:"
+ "\r\n"
+ "--BOUNDARY--"
+ "\r\n"
+ "--BOUNDARY");
ByteBuffer data = BufferUtil.toBuffer("" +
"--BOUNDARY\r\n" +
"name: value\n" +
"\r\n" +
"Hello\r\n" +
"--BOUNDARY--" +
"epilogue here:" +
"\r\n" +
"--BOUNDARY--" +
"\r\n" +
"--BOUNDARY");
parser.parse(data, false);
assertThat(parser.getState(), is(State.DELIMITER));
@ -404,20 +404,20 @@ public class MultiPartParserTest
TestHandler handler = new TestHandler();
MultiPartParser parser = new MultiPartParser(handler, "BOUNDARY");
ByteBuffer data = BufferUtil.toBuffer(""
+ "--BOUNDARY\r\n"
+ "name: value\n"
+ "\r\n"
+ "Hello"
+ "\r\n"
+ "--BOUNDARY\r\n"
+ "powerLevel: 9001\n"
+ "\r\n"
+ "secondary"
+ "\r\n"
+ "content"
+ "\r\n--BOUNDARY--"
+ "epilogue here");
ByteBuffer data = BufferUtil.toBuffer("" +
"--BOUNDARY\r\n" +
"name: value\n" +
"\r\n" +
"Hello" +
"\r\n" +
"--BOUNDARY\r\n" +
"powerLevel: 9001\n" +
"\r\n" +
"secondary" +
"\r\n" +
"content" +
"\r\n--BOUNDARY--" +
"epilogue here");
/* Test First Content Section */
parser.parse(data, false);
@ -612,21 +612,21 @@ public class MultiPartParserTest
dataSeg.limit(length);
assertThat("Third " + i, parser.parse(dataSeg, true), is(true));
assertThat(handler.fields, Matchers.contains("Content-Disposition: form-data; name=\"text\"", "<<COMPLETE>>"
, "Content-Disposition: form-data; name=\"file1\"; filename=\"a.txt\""
, "Content-Type: text/plain", "<<COMPLETE>>"
, "Content-Disposition: form-data; name=\"file2\"; filename=\"a.html\""
, "Content-Type: text/html", "<<COMPLETE>>"
, "Field1: value1", "Field2: value2", "Field3: value3"
, "Field4: value4", "Field5: value5", "Field6: value6"
, "Field7: value7", "Field8: value8", "Field9: value 9", "<<COMPLETE>>"
, "Field1: value1", "<<COMPLETE>>"));
assertThat(handler.fields, Matchers.contains("Content-Disposition: form-data; name=\"text\"", "<<COMPLETE>>",
"Content-Disposition: form-data; name=\"file1\"; filename=\"a.txt\"",
"Content-Type: text/plain", "<<COMPLETE>>",
"Content-Disposition: form-data; name=\"file2\"; filename=\"a.html\"",
"Content-Type: text/html", "<<COMPLETE>>",
"Field1: value1", "Field2: value2", "Field3: value3",
"Field4: value4", "Field5: value5", "Field6: value6",
"Field7: value7", "Field8: value8", "Field9: value 9", "<<COMPLETE>>",
"Field1: value1", "<<COMPLETE>>"));
assertThat(handler.contentString(), is("text default" + "<<LAST>>"
+ "Content of a.txt.\n" + "<<LAST>>"
+ "<!DOCTYPE html><title>Content of a.html.</title>\n" + "<<LAST>>"
+ "<<LAST>>"
+ "But the amount of denudation which the strata have\n" +
assertThat(handler.contentString(), is("text default" + "<<LAST>>" +
"Content of a.txt.\n" + "<<LAST>>" +
"<!DOCTYPE html><title>Content of a.html.</title>\n" + "<<LAST>>" +
"<<LAST>>" +
"But the amount of denudation which the strata have\n" +
"in many places suffered, independently of the rate\n" +
"of accumulation of the degraded matter, probably\n" +
"offers the best evidence of the lapse of time. I remember\n" +
@ -670,18 +670,18 @@ public class MultiPartParserTest
};
MultiPartParser parser = new MultiPartParser(handler, "WebKitFormBoundary7MA4YWf7OaKlSxkTrZu0gW");
ByteBuffer data = BufferUtil.toBuffer(""
+ "Content-Type: multipart/form-data; boundary=WebKitFormBoundary7MA4YWf7OaKlSxkTrZu0gW\r\n" +
"\r\n" +
"--WebKitFormBoundary7MA4YWf7OaKlSxkTrZu0gW\r\n" +
"Content-Disposition: form-data; name=\"part1\"\r\n" +
"\n" +
"wNfミxVam﾿t\r\n" +
"--WebKitFormBoundary7MA4YWf7OaKlSxkTrZu0gW\n" +
"Content-Disposition: form-data; name=\"part2\"\r\n" +
"\r\n" +
"&ᄈᄎ￙ᅱᅢO\r\n" +
"--WebKitFormBoundary7MA4YWf7OaKlSxkTrZu0gW--");
ByteBuffer data = BufferUtil.toBuffer("" +
"Content-Type: multipart/form-data; boundary=WebKitFormBoundary7MA4YWf7OaKlSxkTrZu0gW\r\n" +
"\r\n" +
"--WebKitFormBoundary7MA4YWf7OaKlSxkTrZu0gW\r\n" +
"Content-Disposition: form-data; name=\"part1\"\r\n" +
"\n" +
"wNfミxVam﾿t\r\n" +
"--WebKitFormBoundary7MA4YWf7OaKlSxkTrZu0gW\n" +
"Content-Disposition: form-data; name=\"part2\"\r\n" +
"\r\n" +
"&ᄈᄎ￙ᅱᅢO\r\n" +
"--WebKitFormBoundary7MA4YWf7OaKlSxkTrZu0gW--");
parser.parse(data, true);
assertThat(parser.getState(), is(State.END));

View File

@ -881,7 +881,7 @@ public class StreamResetTest extends AbstractTest
// Try to write again, must fail immediately.
output.write(0xFF);
}
catch (IOException xx)
catch (IOException e)
{
writeLatch2.countDown();
}

View File

@ -104,7 +104,7 @@ public class HpackContextTest
new HttpField("name", "v3"),
new HttpField("name", "v4"),
new HttpField("name", "v5"),
};
};
Entry[] entry = new Entry[field.length];
@ -197,7 +197,7 @@ public class HpackContextTest
new HttpField("fo8", "b8r"),
new HttpField("fo9", "b9r"),
new HttpField("foA", "bAr"),
};
};
Entry[] entry = new Entry[100];
@ -324,7 +324,7 @@ public class HpackContextTest
new HttpField("fo8", "b8r"),
new HttpField("fo9", "b9r"),
new HttpField("foA", "bAr"),
};
};
Entry[] entry = new Entry[field.length];
// Add 5 entries

View File

@ -56,7 +56,7 @@ public class HpackEncoderTest
new HttpField("fo8", "b8r"),
new HttpField("fo9", "b9r"),
new HttpField("foA", "bAr"),
};
};
// Add 4 entries
for (int i = 0; i <= 3; i++)

View File

@ -35,6 +35,7 @@ public interface SslHandshakeListener extends EventListener
* <p>Callback method invoked when the TLS handshake succeeds.</p>
*
* @param event the event object carrying information about the TLS handshake event
* @throws SSLException if any error happen during handshake
*/
default void handshakeSucceeded(Event event) throws SSLException
{

View File

@ -43,6 +43,7 @@ import java.util.concurrent.TimeUnit;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.IO;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.OS;
@ -93,14 +94,8 @@ public class IOTest
assertEquals(-1, server.getInputStream().read());
// but cannot write
try
{
client.getOutputStream().write(1);
fail("exception expected");
}
catch (SocketException expected)
{
}
Assertions.assertThrows(SocketException.class, () -> client.getOutputStream().write(1));
// but can still write in opposite direction.
server.getOutputStream().write(1);
@ -110,14 +105,7 @@ public class IOTest
server.shutdownInput();
// now we EOF instead of reading -1
try
{
server.getInputStream().read();
fail("exception expected");
}
catch (SocketException expected)
{
}
Assertions.assertThrows(SocketException.class, () -> server.getInputStream().read());
// but can still write in opposite direction.
server.getOutputStream().write(1);
@ -127,14 +115,7 @@ public class IOTest
client.shutdownInput();
// now we EOF instead of reading -1
try
{
client.getInputStream().read();
fail("exception expected");
}
catch (SocketException expected)
{
}
Assertions.assertThrows(SocketException.class, () -> client.getInputStream().read());
// But we can still write at the server (data which will never be read)
server.getOutputStream().write(1);
@ -146,14 +127,7 @@ public class IOTest
server.shutdownOutput();
// and now we can't write
try
{
server.getOutputStream().write(1);
fail("exception expected");
}
catch (SocketException expected)
{
}
Assertions.assertThrows(SocketException.class, () -> server.getOutputStream().write(1));
// but the sockets are still open
assertFalse(client.isClosed());

View File

@ -461,6 +461,7 @@ public class SslConnectionTest
}
catch (SocketTimeoutException e)
{
// no op
}
assertTrue(__onIncompleteFlush.get());
@ -507,6 +508,7 @@ public class SslConnectionTest
}
catch (SocketTimeoutException e)
{
// no op
}
__blockFor.set(0);

View File

@ -18,12 +18,6 @@
package org.eclipse.jetty.jaas.spi;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.not;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.File;
import java.util.HashMap;
@ -33,6 +27,12 @@ import org.eclipse.jetty.jaas.callback.DefaultCallbackHandler;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.not;
import static org.junit.jupiter.api.Assertions.assertEquals;
public class PropertyFileLoginModuleTest
{
@Test

View File

@ -472,9 +472,9 @@ public class TestJNDI
((Context)zzz.lookup("java:comp")).bind("crud2", "xxx2");
fail("Should not be able to write to locked context");
}
catch (NamingException ne)
catch (NamingException e)
{
assertThat(ne.getMessage(), Matchers.containsString("immutable"));
assertThat(e.getMessage(), Matchers.containsString("immutable"));
}
finally
{
@ -492,9 +492,9 @@ public class TestJNDI
((Context)zzz.lookup("java:comp")).bind("foo", "bar");
fail("Should not be able to write to locked context");
}
catch (NamingException ne)
catch (NamingException e)
{
assertThat(ne.getMessage(), Matchers.containsString("immutable"));
assertThat(e.getMessage(), Matchers.containsString("immutable"));
}
finally
{

View File

@ -73,8 +73,8 @@ public class TestGetContent
url += pathToCheck;
}
String response = httpClient.GET(url).getContentAsString();
assertTrue(response.contains(contentCheck), "it test " + System.getProperty("maven.it.name")
+ ", response not contentCheck: " + contentCheck + ", response:" + response);
assertTrue(response.contains(contentCheck), "it test " + System.getProperty("maven.it.name") +
", response not contentCheck: " + contentCheck + ", response:" + response);
System.out.println("contentCheck");
}
if (Boolean.getBoolean("helloTestServlet"))

View File

@ -24,6 +24,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
@ -113,15 +114,15 @@ public class TestOSGiUtil
String mavenRepoPath = System.getProperty("mavenRepoPath");
if (!StringUtil.isBlank(mavenRepoPath))
{
res.add( systemProperty( "org.ops4j.pax.url.mvn.localRepository" ).value( mavenRepoPath ) );
res.add( systemProperty( "org.ops4j.pax.url.mvn.defaultRepositories" ).value( "file://" + mavenRepoPath + "@id=local.repo") );
res.add( systemProperty( "org.ops4j.pax.url.mvn.useFallbackRepositories").value( Boolean.FALSE.toString() ) );
res.add( systemProperty( "org.ops4j.pax.url.mvn.repositories").value( "+https://repo1.maven.org/maven2@id=maven.central.repo" ) );
res.add(systemProperty("org.ops4j.pax.url.mvn.localRepository").value(mavenRepoPath));
res.add(systemProperty("org.ops4j.pax.url.mvn.defaultRepositories").value("file://" + mavenRepoPath + "@id=local.repo"));
res.add(systemProperty("org.ops4j.pax.url.mvn.useFallbackRepositories").value(Boolean.FALSE.toString()));
res.add(systemProperty("org.ops4j.pax.url.mvn.repositories").value("+https://repo1.maven.org/maven2@id=maven.central.repo"));
}
String settingsFilePath = System.getProperty("settingsFilePath");
if (!StringUtil.isBlank(settingsFilePath))
{
res.add( systemProperty( "org.ops4j.pax.url.mvn.settings" ).value( System.getProperty( "settingsFilePath" ) ) );
res.add(systemProperty("org.ops4j.pax.url.mvn.settings").value(System.getProperty("settingsFilePath")));
}
res.add(mavenBundle().groupId("org.ow2.asm").artifactId("asm").versionAsInProject().start());
res.add(mavenBundle().groupId("org.ow2.asm").artifactId("asm-commons").versionAsInProject().start());
@ -194,11 +195,11 @@ public class TestOSGiUtil
for (Bundle b : bundleContext.getBundles())
{
Bundle prevBundle = _bundles.put(b.getSymbolicName(), b);
String err = prevBundle != null ? "2 versions of the bundle " + b.getSymbolicName()
+ " "
+ b.getHeaders().get("Bundle-Version")
+ " and "
+ prevBundle.getHeaders().get("Bundle-Version") : "";
String err = prevBundle != null ? "2 versions of the bundle " + b.getSymbolicName() +
" " +
b.getHeaders().get("Bundle-Version") +
" and " +
prevBundle.getHeaders().get("Bundle-Version") : "";
assertNull(err, prevBundle);
}
return _bundles.get(symbolicName);
@ -229,16 +230,16 @@ public class TestOSGiUtil
{
diagnoseNonActiveOrNonResolvedBundle(b);
}
assertTrue("Bundle: " + b
+ " (state should be "
+ "ACTIVE["
+ Bundle.ACTIVE
+ "] or RESOLVED["
+ Bundle.RESOLVED
+ "]"
+ ", but was ["
+ b.getState()
+ "])", (b.getState() == Bundle.ACTIVE) || (b.getState() == Bundle.RESOLVED));
assertTrue("Bundle: " + b +
" (state should be " +
"ACTIVE[" +
Bundle.ACTIVE +
"] or RESOLVED[" +
Bundle.RESOLVED +
"]" +
", but was [" +
b.getState() +
"])", (b.getState() == Bundle.ACTIVE) || (b.getState() == Bundle.RESOLVED));
}
}

View File

@ -18,20 +18,15 @@
package org.eclipse.jetty.plus.annotation;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.anEmptyMap;
import static org.hamcrest.Matchers.hasEntry;
import static org.hamcrest.Matchers.hasKey;
import static org.hamcrest.Matchers.hasSize;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.fail;
import java.lang.reflect.Method;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.hasSize;
import static org.junit.jupiter.api.Assertions.fail;
public class LifeCycleCallbackCollectionTest
{

View File

@ -1533,7 +1533,7 @@ public class AsyncMiddleManServletTest
return out.toByteArray();
}
private static abstract class HrefTransformer implements AsyncMiddleManServlet.ContentTransformer
private abstract static class HrefTransformer implements AsyncMiddleManServlet.ContentTransformer
{
private static final String PREFIX = "http://localhost/q=";
private final HrefParser parser = new HrefParser();

View File

@ -141,9 +141,11 @@ public class ReverseProxyTest
}
});
startProxy(new HashMap<String, String>()
{{
put("preserveHost", "true");
}});
{
{
put("preserveHost", "true");
}
});
startClient();
ContentResponse response = client.newRequest("localhost", proxyConnector.getLocalPort()).send();

View File

@ -42,7 +42,7 @@ public class HeaderPatternRuleTest extends AbstractRuleTestCase
public void testHeaderWithTextValues() throws IOException
{
// different keys
String headers[][] = {
String[][] headers = {
{"hnum#1", "test1"},
{"hnum#2", "2test2"},
{"hnum#3", "test3"}
@ -53,7 +53,7 @@ public class HeaderPatternRuleTest extends AbstractRuleTestCase
@Test
public void testHeaderWithNumberValues() throws IOException
{
String headers[][] = {
String[][] headers = {
{"hello", "1"},
{"hello", "-1"},
{"hello", "100"},
@ -70,7 +70,7 @@ public class HeaderPatternRuleTest extends AbstractRuleTestCase
@Test
public void testHeaderOverwriteValues() throws IOException
{
String headers[][] = {
String[][] headers = {
{"size", "100"},
{"size", "200"},
{"size", "300"},
@ -100,7 +100,7 @@ public class HeaderPatternRuleTest extends AbstractRuleTestCase
assertEquals("abba1", _response.getHeader("title1"));
}
private void assertHeaders(String headers[][]) throws IOException
private void assertHeaders(String[][] headers) throws IOException
{
for (String[] header : headers)
{

View File

@ -43,7 +43,7 @@ public class HeaderRegexRuleTest extends AbstractRuleTestCase
public void testHeaderWithTextValues() throws IOException
{
// different keys
String headers[][] =
String[][] headers =
{
{"hnum#1", "test1"},
{"hnum#2", "2test2"},
@ -55,7 +55,7 @@ public class HeaderRegexRuleTest extends AbstractRuleTestCase
@Test
public void testHeaderWithNumberValues() throws IOException
{
String headers[][] =
String[][] headers =
{
{"hello", "1"},
{"hello", "-1"},
@ -72,7 +72,7 @@ public class HeaderRegexRuleTest extends AbstractRuleTestCase
@Test
public void testHeaderOverwriteValues() throws IOException
{
String headers[][] =
String[][] headers =
{
{"size", "100"},
{"size", "200"},
@ -122,7 +122,7 @@ public class HeaderRegexRuleTest extends AbstractRuleTestCase
assertEquals(null, _response.getHeader("cache-control"));
}
private void assertHeaders(String headers[][]) throws IOException
private void assertHeaders(String[][] headers) throws IOException
{
for (String[] header : headers)
{

View File

@ -37,7 +37,7 @@ public class RewritePatternRuleTest extends AbstractRuleTestCase
{"/foo/bar", "/foo/bar", "/replace"},
{"/foo/bar.txt", "*.txt", "/replace"},
{"/foo/bar/%20x", "/foo/*", "/replace/bar/%20x"},
};
};
private RewritePatternRule _rule;
@BeforeEach

View File

@ -119,7 +119,9 @@ public class ValidUrlRuleTest extends AbstractRuleTestCase
// space
assertTrue(_rule.isValidChar("\u0020".charAt(0)));
// form feed
//@checkstyle-disable-check : IllegalTokenText
assertFalse(_rule.isValidChar("\u000c".charAt(0)));
//@checkstyle-enable-check : IllegalTokenText
}
}

View File

@ -1708,7 +1708,7 @@ public class ConstraintTest
{
request.login("admin", "fail");
}
catch (ServletException se)
catch (ServletException e)
{
request.login("admin", "password");
}

View File

@ -723,8 +723,8 @@ public abstract class AbstractSessionCache extends ContainerLifeCycle implements
LOG.debug("Checking for idle {}", session.getId());
try (Lock s = session.lock())
{
if (getEvictionPolicy() > 0 && session.isIdleLongerThan(getEvictionPolicy())
&& session.isValid() && session.isResident() && session.getRequests() <= 0)
if (getEvictionPolicy() > 0 && session.isIdleLongerThan(getEvictionPolicy()) &&
session.isValid() && session.isResident() && session.getRequests() <= 0)
{
//Be careful with saveOnInactiveEviction - you may be able to re-animate a session that was
//being managed on another node and has expired.

View File

@ -18,8 +18,6 @@
package org.eclipse.jetty.server.session;
import static java.lang.Math.round;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
@ -65,6 +63,8 @@ import org.eclipse.jetty.util.thread.Locker.Lock;
import org.eclipse.jetty.util.thread.ScheduledExecutorScheduler;
import org.eclipse.jetty.util.thread.Scheduler;
import static java.lang.Math.round;
/**
* SessionHandler.
*/
@ -237,8 +237,8 @@ public class SessionHandler extends ScopedHandler
// Do we need to refresh the cookie?
if (isUsingCookies() &&
(s.isIdChanged() ||
(getSessionCookieConfig().getMaxAge() > 0 && getRefreshCookieAge() > 0
&& ((now - s.getCookieSetTime())/1000 > getRefreshCookieAge()))))
(getSessionCookieConfig().getMaxAge() > 0 && getRefreshCookieAge() > 0 &&
((now - s.getCookieSetTime()) / 1000 > getRefreshCookieAge()))))
{
HttpCookie cookie = getSessionCookie(session, _context == null ? "/" : (_context.getContextPath()), secure);
s.cookieSet();
@ -847,8 +847,8 @@ public class SessionHandler extends ScopedHandler
public void setSessionIdPathParameterName(String param)
{
_sessionIdPathParameterName = (param == null || "none".equals(param)) ? null : param;
_sessionIdPathParameterNamePrefix = (param == null || "none".equals(param)) ?
null : (";" + _sessionIdPathParameterName + "=");
_sessionIdPathParameterNamePrefix = (param == null || "none".equals(param))
? null : (";" + _sessionIdPathParameterName + "=");
}
/**
@ -1023,7 +1023,7 @@ public class SessionHandler extends ScopedHandler
sessionTrackingModes.size() > 1 &&
sessionTrackingModes.contains(SessionTrackingMode.SSL))
{
throw new IllegalArgumentException ("sessionTrackingModes specifies a combination of SessionTrackingMode.SSL with a session tracking mode other than SessionTrackingMode.SSL");
throw new IllegalArgumentException("sessionTrackingModes specifies a combination of SessionTrackingMode.SSL with a session tracking mode other than SessionTrackingMode.SSL");
}
_sessionTrackingModes = new HashSet<>(sessionTrackingModes);
_usingCookies = _sessionTrackingModes.contains(SessionTrackingMode.COOKIE);
@ -1294,8 +1294,8 @@ public class SessionHandler extends ScopedHandler
//most efficient if it can be done as a bulk operation to eg reduce
//roundtrips to the persistent store. Only do this if the HouseKeeper that
//does the scavenging is configured to actually scavenge
if (_sessionIdManager.getSessionHouseKeeper() != null
&& _sessionIdManager.getSessionHouseKeeper().getIntervalSec() > 0)
if (_sessionIdManager.getSessionHouseKeeper() != null &&
_sessionIdManager.getSessionHouseKeeper().getIntervalSec() > 0)
{
_candidateSessionIdsForExpiry.add(session.getId());
if (LOG.isDebugEnabled())
@ -1525,9 +1525,9 @@ public class SessionHandler extends ScopedHandler
{
HttpCookie cookie = access(existingSession, request.isSecure());
// Handle changed ID or max-age refresh, but only if this is not a redispatched request
if ((cookie != null)
&& (request.getDispatcherType() == DispatcherType.ASYNC
|| request.getDispatcherType() == DispatcherType.REQUEST))
if ((cookie != null) &&
(request.getDispatcherType() == DispatcherType.ASYNC ||
request.getDispatcherType() == DispatcherType.REQUEST))
baseRequest.getResponse().replaceCookie(cookie);
}

View File

@ -86,11 +86,11 @@ public abstract class AbstractHttpTest
HttpTester.Input input = HttpTester.from(socket.getInputStream());
HttpTester.parseResponse(input, response);
if (httpVersion.is("HTTP/1.1")
&& response.isComplete()
&& response.get("content-length") == null
&& response.get("transfer-encoding") == null
&& !__noBodyCodes.contains(response.getStatus()))
if (httpVersion.is("HTTP/1.1") &&
response.isComplete() &&
response.get("content-length") == null &&
response.get("transfer-encoding") == null &&
!__noBodyCodes.contains(response.getStatus()))
assertThat("If HTTP/1.1 response doesn't contain transfer-encoding or content-length headers, " +
"it should contain connection:close", response.get("connection"), is("close"));
return response;

View File

@ -70,7 +70,7 @@ public class AsyncStressTest
{"/path?suspend=<PERIOD>", "TIMEOUT"},
{"/path?suspend=60000&resume=<PERIOD>", "RESUMED"},
{"/path?suspend=60000&complete=<PERIOD>", "COMPLETED"},
};
};
@BeforeEach
public void init() throws Exception

View File

@ -41,10 +41,7 @@ public class CheckReverseProxyHeadersTest
// Classic ProxyPass from example.com:80 to localhost:8080
testRequest("Host: localhost:8080\n" +
"X-Forwarded-For: 10.20.30.40\n" +
"X-Forwarded-Host: example.com", new RequestValidator()
{
@Override
public void validate(HttpServletRequest request)
"X-Forwarded-Host: example.com", request ->
{
assertEquals("example.com", request.getServerName());
assertEquals(80, request.getServerPort());
@ -53,16 +50,12 @@ public class CheckReverseProxyHeadersTest
assertEquals("example.com", request.getHeader("Host"));
assertEquals("http", request.getScheme());
assertFalse(request.isSecure());
}
});
});
// IPv6 ProxyPass from example.com:80 to localhost:8080
testRequest("Host: localhost:8080\n" +
"X-Forwarded-For: 10.20.30.40\n" +
"X-Forwarded-Host: [::1]", new RequestValidator()
{
@Override
public void validate(HttpServletRequest request)
"X-Forwarded-Host: [::1]", request ->
{
assertEquals("[::1]", request.getServerName());
assertEquals(80, request.getServerPort());
@ -71,16 +64,12 @@ public class CheckReverseProxyHeadersTest
assertEquals("[::1]", request.getHeader("Host"));
assertEquals("http", request.getScheme());
assertFalse(request.isSecure());
}
});
});
// IPv6 ProxyPass from example.com:80 to localhost:8080
testRequest("Host: localhost:8080\n" +
"X-Forwarded-For: 10.20.30.40\n" +
"X-Forwarded-Host: [::1]:8888", new RequestValidator()
{
@Override
public void validate(HttpServletRequest request)
"X-Forwarded-Host: [::1]:8888", request ->
{
assertEquals("[::1]", request.getServerName());
assertEquals(8888, request.getServerPort());
@ -89,18 +78,14 @@ public class CheckReverseProxyHeadersTest
assertEquals("[::1]:8888", request.getHeader("Host"));
assertEquals("http", request.getScheme());
assertFalse(request.isSecure());
}
});
});
// ProxyPass from example.com:81 to localhost:8080
testRequest("Host: localhost:8080\n" +
"X-Forwarded-For: 10.20.30.40\n" +
"X-Forwarded-Host: example.com:81\n" +
"X-Forwarded-Server: example.com\n" +
"X-Forwarded-Proto: https", new RequestValidator()
{
@Override
public void validate(HttpServletRequest request)
"X-Forwarded-Proto: https", request ->
{
assertEquals("example.com", request.getServerName());
assertEquals(81, request.getServerPort());
@ -109,18 +94,15 @@ public class CheckReverseProxyHeadersTest
assertEquals("example.com:81", request.getHeader("Host"));
assertEquals("https", request.getScheme());
assertTrue(request.isSecure());
}
});
});
// Multiple ProxyPass from example.com:80 to rp.example.com:82 to localhost:8080
testRequest("Host: localhost:8080\n" +
"X-Forwarded-For: 10.20.30.40, 10.0.0.1\n" +
"X-Forwarded-Host: example.com, rp.example.com:82\n" +
"X-Forwarded-Server: example.com, rp.example.com\n" +
"X-Forwarded-Proto: https, http", new RequestValidator()
{
@Override
public void validate(HttpServletRequest request)
"X-Forwarded-Proto: https, http", request ->
{
assertEquals("example.com", request.getServerName());
assertEquals(443, request.getServerPort());
@ -129,8 +111,7 @@ public class CheckReverseProxyHeadersTest
assertEquals("example.com", request.getHeader("Host"));
assertEquals("https", request.getScheme());
assertTrue(request.isSecure());
}
});
});
}
private void testRequest(String headers, RequestValidator requestValidator) throws Exception

View File

@ -59,10 +59,9 @@ public abstract class ConnectorCloseTestBase extends HttpServerTestFixture
final CountDownLatch latch = new CountDownLatch(requestCount);
configureServer(new HelloWorldHandler());
URI uri = _server.getURI();
Socket client = newSocket(uri.getHost(), uri.getPort());
try
try (Socket client = newSocket(uri.getHost(), uri.getPort()))
{
OutputStream os = client.getOutputStream();
@ -119,10 +118,6 @@ public abstract class ConnectorCloseTestBase extends HttpServerTestFixture
reader.setDone();
runner.join();
}
finally
{
client.close();
}
}
private int iterations(int cnt)
@ -136,8 +131,8 @@ public abstract class ConnectorCloseTestBase extends HttpServerTestFixture
configureServer(new EchoHandler());
URI uri = _server.getURI();
Socket client = newSocket(uri.getHost(), uri.getPort());
try
try (Socket client = newSocket(uri.getHost(), uri.getPort()))
{
OutputStream os = client.getOutputStream();
@ -181,10 +176,6 @@ public abstract class ConnectorCloseTestBase extends HttpServerTestFixture
String in = reader.getResponse().toString();
assertTrue(in.indexOf(__content.substring(__length - 64)) > 0);
}
finally
{
client.close();
}
}
public class ResponseReader implements Runnable
@ -226,11 +217,9 @@ public abstract class ConnectorCloseTestBase extends HttpServerTestFixture
count = doRead();
}
}
catch (IOException ex)
{
}
catch (InterruptedException ex)
catch (IOException | InterruptedException e)
{
// ignore
}
finally
{
@ -240,6 +229,7 @@ public abstract class ConnectorCloseTestBase extends HttpServerTestFixture
}
catch (IOException e)
{
// ignore
}
}
}

View File

@ -392,22 +392,15 @@ public abstract class ConnectorTimeoutTest extends HttpServerTestFixture
os.write("\r\n".getBytes("utf-8"));
os.flush();
}
catch (Exception e)
{
}
long duration = TimeUnit.NANOSECONDS.toMillis(System.nanoTime()) - start;
assertThat(duration, greaterThan(500L));
try
{
// read the response
String response = IO.toString(is);
assertThat(response, startsWith("HTTP/1.1 500 "));
assertThat(response, containsString("InterruptedIOException"));
}
catch (SSLException e)
{
}
// read the response
String response = IO.toString(is);
assertThat(response, startsWith("HTTP/1.1 500 "));
assertThat(response, containsString("InterruptedIOException"));
}
@Test
@ -499,9 +492,6 @@ public abstract class ConnectorTimeoutTest extends HttpServerTestFixture
break;
}
}
catch (Throwable e)
{
}
long end = TimeUnit.NANOSECONDS.toMillis(System.nanoTime());
long duration = end - start;
assertThat(duration, lessThan(20L * 128L));

View File

@ -223,12 +223,13 @@ public class GracefulStopTest
{
try (Socket s = new Socket("127.0.0.1", port))
{
// no op
}
throw new IllegalStateException();
}
catch (ConnectException e)
{
// no op
}
// Try another request on existing connection
@ -298,6 +299,7 @@ public class GracefulStopTest
}
catch (InterruptedException e)
{
// no op
}
finally
{

View File

@ -22,6 +22,7 @@
* To change the template for this generated file go to
* Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
*/
package org.eclipse.jetty.server;
import java.io.BufferedReader;
@ -145,7 +146,7 @@ public class HttpConnectionTest
* HTTP/0.9 does not support HttpVersion (this is a bad request)
*/
@Test
public void testHttp09_NoVersion() throws Exception
public void testHttp09NoVersion() throws Exception
{
connector.getConnectionFactory(HttpConnectionFactory.class).setHttpCompliance(HttpCompliance.RFC2616);
String request = "GET / HTTP/0.9\r\n\r\n";
@ -162,7 +163,7 @@ public class HttpConnectionTest
* HTTP/0.9 does not support headers
*/
@Test
public void testHttp09_NoHeaders() throws Exception
public void testHttp09NoHeaders() throws Exception
{
connector.getConnectionFactory(HttpConnectionFactory.class).setHttpCompliance(HttpCompliance.RFC2616);
// header looking like another request is ignored
@ -176,7 +177,7 @@ public class HttpConnectionTest
* Http/0.9 does not support pipelining.
*/
@Test
public void testHttp09_MultipleRequests() throws Exception
public void testHttp09MultipleRequests() throws Exception
{
connector.getConnectionFactory(HttpConnectionFactory.class).setHttpCompliance(HttpCompliance.RFC2616);
@ -193,7 +194,7 @@ public class HttpConnectionTest
* Ensure that excessively large hexadecimal chunk body length is parsed properly.
*/
@Test
public void testHttp11_ChunkedBodyTruncation() throws Exception
public void testHttp11ChunkedBodyTruncation() throws Exception
{
String request = "POST /?id=123 HTTP/1.1\r\n" +
"Host: local\r\n" +
@ -222,10 +223,10 @@ public class HttpConnectionTest
* More then 1 Content-Length is a bad requests per HTTP rfcs.
*/
@Test
public void testHttp11_MultipleContentLength() throws Exception
public void testHttp11MultipleContentLength() throws Exception
{
HttpParser.LOG.info("badMessage: 400 Bad messages EXPECTED...");
int contentLengths[][] = {
int[][] contentLengths = {
{0, 8},
{8, 0},
{8, 8},
@ -266,10 +267,10 @@ public class HttpConnectionTest
* More then 1 Content-Length is a bad requests per HTTP rfcs.
*/
@Test
public void testHttp11_ContentLengthAndChunk() throws Exception
public void testHttp11ContentLengthAndChunk() throws Exception
{
HttpParser.LOG.info("badMessage: 400 Bad messages EXPECTED...");
int contentLengths[][] = {
int[][] contentLengths = {
{-1, 8},
{8, -1},
{8, -1, 8},
@ -403,7 +404,7 @@ public class HttpConnectionTest
}
@Test
public void test_0_9() throws Exception
public void test09() throws Exception
{
connector.getConnectionFactory(HttpConnectionFactory.class).setHttpCompliance(HttpCompliance.RFC2616_LEGACY);
LocalEndPoint endp = connector.executeRequest("GET /R1\n");

View File

@ -46,7 +46,7 @@ import static org.hamcrest.Matchers.is;
public class HttpManyWaysToAsyncCommitBadBehaviourTest extends AbstractHttpTest
{
private final String CONTEXT_ATTRIBUTE = getClass().getName() + ".asyncContext";
private final String contextAttribute = getClass().getName() + ".asyncContext";
public static Stream<Arguments> httpVersions()
{
@ -95,7 +95,7 @@ public class HttpManyWaysToAsyncCommitBadBehaviourTest extends AbstractHttpTest
return;
}
if (request.getAttribute(CONTEXT_ATTRIBUTE) == null)
if (request.getAttribute(contextAttribute) == null)
{
final AsyncContext asyncContext = baseRequest.startAsync();
new Thread(new Runnable()

View File

@ -44,7 +44,7 @@ import static org.hamcrest.Matchers.nullValue;
//TODO: add protocol specific tests for connection: close and/or chunking
public class HttpManyWaysToAsyncCommitTest extends AbstractHttpTest
{
private final String CONTEXT_ATTRIBUTE = getClass().getName() + ".asyncContext";
private final String contextAttribute = getClass().getName() + ".asyncContext";
public static Stream<Arguments> httpVersion()
{
@ -101,10 +101,10 @@ public class HttpManyWaysToAsyncCommitTest extends AbstractHttpTest
@Override
public void doNonErrorHandle(String target, Request baseRequest, final HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
if (request.getAttribute(CONTEXT_ATTRIBUTE) == null)
if (request.getAttribute(contextAttribute) == null)
{
final AsyncContext asyncContext = baseRequest.startAsync();
request.setAttribute(CONTEXT_ATTRIBUTE, asyncContext);
request.setAttribute(contextAttribute, asyncContext);
new Thread(new Runnable()
{
@Override
@ -164,10 +164,10 @@ public class HttpManyWaysToAsyncCommitTest extends AbstractHttpTest
@Override
public void doNonErrorHandle(String target, Request baseRequest, final HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
if (request.getAttribute(CONTEXT_ATTRIBUTE) == null)
if (request.getAttribute(contextAttribute) == null)
{
final AsyncContext asyncContext = baseRequest.startAsync();
request.setAttribute(CONTEXT_ATTRIBUTE, asyncContext);
request.setAttribute(contextAttribute, asyncContext);
new Thread(new Runnable()
{
@Override
@ -227,10 +227,10 @@ public class HttpManyWaysToAsyncCommitTest extends AbstractHttpTest
@Override
public void doNonErrorHandle(String target, Request baseRequest, final HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
if (request.getAttribute(CONTEXT_ATTRIBUTE) == null)
if (request.getAttribute(contextAttribute) == null)
{
final AsyncContext asyncContext = baseRequest.startAsync();
request.setAttribute(CONTEXT_ATTRIBUTE, asyncContext);
request.setAttribute(contextAttribute, asyncContext);
new Thread(new Runnable()
{
@Override
@ -301,10 +301,10 @@ public class HttpManyWaysToAsyncCommitTest extends AbstractHttpTest
@Override
public void doNonErrorHandle(String target, Request baseRequest, final HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
if (request.getAttribute(CONTEXT_ATTRIBUTE) == null)
if (request.getAttribute(contextAttribute) == null)
{
final AsyncContext asyncContext = baseRequest.startAsync();
request.setAttribute(CONTEXT_ATTRIBUTE, asyncContext);
request.setAttribute(contextAttribute, asyncContext);
new Thread(new Runnable()
{
@Override
@ -377,10 +377,10 @@ public class HttpManyWaysToAsyncCommitTest extends AbstractHttpTest
@Override
public void doNonErrorHandle(String target, Request baseRequest, final HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
if (request.getAttribute(CONTEXT_ATTRIBUTE) == null)
if (request.getAttribute(contextAttribute) == null)
{
final AsyncContext asyncContext = baseRequest.startAsync();
request.setAttribute(CONTEXT_ATTRIBUTE, asyncContext);
request.setAttribute(contextAttribute, asyncContext);
new Thread(new Runnable()
{
@Override
@ -453,10 +453,10 @@ public class HttpManyWaysToAsyncCommitTest extends AbstractHttpTest
@Override
public void doNonErrorHandle(String target, Request baseRequest, final HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
if (request.getAttribute(CONTEXT_ATTRIBUTE) == null)
if (request.getAttribute(contextAttribute) == null)
{
final AsyncContext asyncContext = baseRequest.startAsync();
request.setAttribute(CONTEXT_ATTRIBUTE, asyncContext);
request.setAttribute(contextAttribute, asyncContext);
new Thread(new Runnable()
{
@Override
@ -533,10 +533,10 @@ public class HttpManyWaysToAsyncCommitTest extends AbstractHttpTest
@Override
public void doNonErrorHandle(String target, Request baseRequest, final HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
if (request.getAttribute(CONTEXT_ATTRIBUTE) == null)
if (request.getAttribute(contextAttribute) == null)
{
final AsyncContext asyncContext = baseRequest.startAsync();
request.setAttribute(CONTEXT_ATTRIBUTE, asyncContext);
request.setAttribute(contextAttribute, asyncContext);
new Thread(new Runnable()
{
@Override
@ -610,10 +610,10 @@ public class HttpManyWaysToAsyncCommitTest extends AbstractHttpTest
@Override
public void doNonErrorHandle(String target, Request baseRequest, final HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
if (request.getAttribute(CONTEXT_ATTRIBUTE) == null)
if (request.getAttribute(contextAttribute) == null)
{
final AsyncContext asyncContext = baseRequest.startAsync();
request.setAttribute(CONTEXT_ATTRIBUTE, asyncContext);
request.setAttribute(contextAttribute, asyncContext);
new Thread(new Runnable()
{
@Override
@ -688,10 +688,10 @@ public class HttpManyWaysToAsyncCommitTest extends AbstractHttpTest
@Override
public void doNonErrorHandle(String target, Request baseRequest, final HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
if (request.getAttribute(CONTEXT_ATTRIBUTE) == null)
if (request.getAttribute(contextAttribute) == null)
{
final AsyncContext asyncContext = baseRequest.startAsync();
request.setAttribute(CONTEXT_ATTRIBUTE, asyncContext);
request.setAttribute(contextAttribute, asyncContext);
new Thread(new Runnable()
{
@Override
@ -761,10 +761,10 @@ public class HttpManyWaysToAsyncCommitTest extends AbstractHttpTest
@Override
public void doNonErrorHandle(String target, Request baseRequest, final HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
if (request.getAttribute(CONTEXT_ATTRIBUTE) == null)
if (request.getAttribute(contextAttribute) == null)
{
final AsyncContext asyncContext = baseRequest.startAsync();
request.setAttribute(CONTEXT_ATTRIBUTE, asyncContext);
request.setAttribute(contextAttribute, asyncContext);
new Thread(new Runnable()
{
@Override
@ -835,10 +835,10 @@ public class HttpManyWaysToAsyncCommitTest extends AbstractHttpTest
@Override
public void doNonErrorHandle(String target, Request baseRequest, final HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
{
if (request.getAttribute(CONTEXT_ATTRIBUTE) == null)
if (request.getAttribute(contextAttribute) == null)
{
final AsyncContext asyncContext = baseRequest.startAsync();
request.setAttribute(CONTEXT_ATTRIBUTE, asyncContext);
request.setAttribute(contextAttribute, asyncContext);
new Thread(new Runnable()
{
@Override

View File

@ -60,14 +60,15 @@ import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.startsWith;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
public abstract class HttpServerTestBase extends HttpServerTestFixture
{
private static final String REQUEST1_HEADER = "POST / HTTP/1.0\n" + "Host: localhost\n" + "Content-Type: text/xml; charset=utf-8\n" + "Connection: close\n" + "Content-Length: ";
private static final String REQUEST1_CONTENT = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+ "<nimbus xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" + " xsi:noNamespaceSchemaLocation=\"nimbus.xsd\" version=\"1.0\">\n"
+ "</nimbus>";
private static final String REQUEST1_CONTENT = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<nimbus xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n" + " xsi:noNamespaceSchemaLocation=\"nimbus.xsd\" version=\"1.0\">\n" +
"</nimbus>";
private static final String REQUEST1 = REQUEST1_HEADER + REQUEST1_CONTENT.getBytes().length + "\n\n" + REQUEST1_CONTENT;
private static final String RESPONSE1 = "HTTP/1.1 200 OK\n" + "Content-Length: 13\n" + "Server: Jetty(" + Server.getVersion() + ")\n" + "\n" + "Hello world\n";
@ -102,8 +103,8 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture
" <getJobDetails>\n" +
" <jobId>73</jobId>\n" +
" </getJobDetails>\n" +
" </request>\n"
+ "</nimbus>\n";
" </request>\n" +
"</nimbus>\n";
protected static final String RESPONSE2 =
"HTTP/1.1 200 OK\n" +
"Content-Type: text/xml;charset=iso-8859-1\n" +
@ -141,10 +142,10 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture
{
OutputStream os = client.getOutputStream();
os.write(("OPTIONS * HTTP/1.1\r\n"
+ "Host: " + _serverURI.getHost() + "\r\n"
+ "Connection: close\r\n"
+ "\r\n").getBytes(StandardCharsets.ISO_8859_1));
os.write(("OPTIONS * HTTP/1.1\r\n" +
"Host: " + _serverURI.getHost() + "\r\n" +
"Connection: close\r\n" +
"\r\n").getBytes(StandardCharsets.ISO_8859_1));
os.flush();
// Read the response.
@ -158,10 +159,10 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture
{
OutputStream os = client.getOutputStream();
os.write(("GET * HTTP/1.1\r\n"
+ "Host: " + _serverURI.getHost() + "\r\n"
+ "Connection: close\r\n"
+ "\r\n").getBytes(StandardCharsets.ISO_8859_1));
os.write(("GET * HTTP/1.1\r\n" +
"Host: " + _serverURI.getHost() + "\r\n" +
"Connection: close\r\n" +
"\r\n").getBytes(StandardCharsets.ISO_8859_1));
os.flush();
// Read the response.
@ -184,7 +185,7 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture
StacklessLogging stackless = new StacklessLogging(HttpConnection.class))
{
client.setSoTimeout(10000);
((AbstractLogger)Log.getLogger(HttpConnection.class)).info("expect request is too large, then ISE extra data ...");
Log.getLogger(HttpConnection.class).info("expect request is too large, then ISE extra data ...");
OutputStream os = client.getOutputStream();
byte[] buffer = new byte[64 * 1024];
@ -433,22 +434,27 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture
try (Socket client = newSocket(_serverURI.getHost(), _serverURI.getPort()))
{
OutputStream os = client.getOutputStream();
//@checkstyle-disable-check : IllegalTokenText
os.write(("GET /R2 HTTP/1.1\015\012" +
"Host: localhost\015\012" +
"Transfer-Encoding: chunked\015\012" +
"Content-Type: text/plain\015\012" +
"Connection: close\015\012" +
"\015\012").getBytes());
//@checkstyle-enable-check : IllegalTokenText
os.flush();
Thread.sleep(1000);
os.write(("5").getBytes());
Thread.sleep(1000);
//@checkstyle-disable-check : IllegalTokenText
os.write(("\015\012").getBytes());
//@checkstyle-enable-check : IllegalTokenText
os.flush();
Thread.sleep(1000);
//@checkstyle-disable-check : IllegalTokenText
os.write(("ABCDE\015\012" +
"0;\015\012\015\012").getBytes());
//@checkstyle-enable-check : IllegalTokenText
os.flush();
// Read the response.
@ -465,7 +471,7 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture
try (Socket client = newSocket(_serverURI.getHost(), _serverURI.getPort()))
{
OutputStream os = client.getOutputStream();
//@checkstyle-disable-check : IllegalTokenText
os.write(("GET /R2 HTTP/1.1\015\012" +
"Host: localhost\015\012" +
"Content-Length: 5\015\012" +
@ -474,6 +480,7 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture
"\015\012" +
"ABCDE\015\012" +
"\015\012"
//@checkstyle-enable-check : IllegalTokenText
).getBytes());
os.flush();
@ -939,7 +946,7 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture
}
// check close
assertTrue(in.readLine() == null);
assertNull(in.readLine());
}
}
@ -1127,6 +1134,7 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture
OutputStream os = client.getOutputStream();
InputStream is = client.getInputStream();
//@checkstyle-disable-check : IllegalTokenText
os.write((
"POST /R1 HTTP/1.1\015\012" +
"Host: " + _serverURI.getHost() + ":" + _serverURI.getPort() + "\r\n" +
@ -1149,7 +1157,7 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture
"Connection: close\015\012" +
"\015\012" +
"abcdefghi\n"
//@checkstyle-enable-check : IllegalTokenText
).getBytes(StandardCharsets.ISO_8859_1));
String in = IO.toString(is);
@ -1281,7 +1289,7 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture
client.close();
Thread.sleep(200);
assertTrue(!handler._endp.isOpen());
assertFalse(handler._endp.isOpen());
}
}
@ -1547,8 +1555,8 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture
{
byte[] bytes = (
"GET / HTTP/1.1\r\n" +
"Host: localhost\r\n"
+ "Content-Length: " + cl + "\r\n" +
"Host: localhost\r\n" +
"Content-Length: " + cl + "\r\n" +
"\r\n" +
content).getBytes(StandardCharsets.ISO_8859_1);

View File

@ -328,7 +328,7 @@ public class LocalAsyncContextTest
final AsyncContext asyncContext = baseRequest.startAsync();
response.getOutputStream().println("STARTASYNC");
asyncContext.addListener(__asyncListener);
asyncContext.addListener(_asyncListener);
if (_suspendFor > 0)
asyncContext.setTimeout(_suspendFor);
@ -465,7 +465,7 @@ public class LocalAsyncContextTest
}
}
private AsyncListener __asyncListener = new AsyncListener()
private AsyncListener _asyncListener = new AsyncListener()
{
@Override
public void onComplete(AsyncEvent event) throws IOException

View File

@ -45,7 +45,7 @@ import static org.junit.jupiter.api.Assertions.fail;
public class NotAcceptingTest
{
private final long IDLE_TIMEOUT = 2000;
private final long idleTimeout = 2000;
Server server;
LocalConnector localConnector;
ServerConnector blockingConnector;
@ -57,18 +57,18 @@ public class NotAcceptingTest
server = new Server();
localConnector = new LocalConnector(server);
localConnector.setIdleTimeout(IDLE_TIMEOUT);
localConnector.setIdleTimeout(idleTimeout);
server.addConnector(localConnector);
blockingConnector = new ServerConnector(server, 1, 1);
blockingConnector.setPort(0);
blockingConnector.setIdleTimeout(IDLE_TIMEOUT);
blockingConnector.setIdleTimeout(idleTimeout);
blockingConnector.setAcceptQueueSize(10);
server.addConnector(blockingConnector);
asyncConnector = new ServerConnector(server, 0, 1);
asyncConnector.setPort(0);
asyncConnector.setIdleTimeout(IDLE_TIMEOUT);
asyncConnector.setIdleTimeout(idleTimeout);
asyncConnector.setAcceptQueueSize(10);
server.addConnector(asyncConnector);
}
@ -128,7 +128,7 @@ public class NotAcceptingTest
try
{
uri = handler.exchange.exchange("delayed connection", IDLE_TIMEOUT, TimeUnit.MILLISECONDS);
uri = handler.exchange.exchange("delayed connection", idleTimeout, TimeUnit.MILLISECONDS);
fail("Failed near URI: " + uri); // this displays last URI, not current (obviously)
}
catch (TimeoutException e)
@ -177,7 +177,7 @@ public class NotAcceptingTest
{
local[i] = client;
client.addInputAndExecute(BufferUtil.toBuffer("GET /three HTTP/1.1\r\nHost:localhost\r\n\r\n"));
response = HttpTester.parseResponse(client.getResponse(false, IDLE_TIMEOUT, TimeUnit.MILLISECONDS));
response = HttpTester.parseResponse(client.getResponse(false, idleTimeout, TimeUnit.MILLISECONDS));
// A few local connections may succeed
if (i == local.length - 1)
@ -245,7 +245,7 @@ public class NotAcceptingTest
try
{
uri = handler.exchange.exchange("delayed connection", IDLE_TIMEOUT, TimeUnit.MILLISECONDS);
uri = handler.exchange.exchange("delayed connection", idleTimeout, TimeUnit.MILLISECONDS);
fail(uri);
}
catch (TimeoutException e)
@ -415,9 +415,9 @@ public class NotAcceptingTest
}
}
waitFor(localConnector::isAccepting, is(true), 2 * IDLE_TIMEOUT, TimeUnit.MILLISECONDS);
waitFor(blockingConnector::isAccepting, is(true), 2 * IDLE_TIMEOUT, TimeUnit.MILLISECONDS);
waitFor(asyncConnector::isAccepting, is(true), 2 * IDLE_TIMEOUT, TimeUnit.MILLISECONDS);
waitFor(localConnector::isAccepting, is(true), 2 * idleTimeout, TimeUnit.MILLISECONDS);
waitFor(blockingConnector::isAccepting, is(true), 2 * idleTimeout, TimeUnit.MILLISECONDS);
waitFor(asyncConnector::isAccepting, is(true), 2 * idleTimeout, TimeUnit.MILLISECONDS);
}
public static class HelloHandler extends AbstractHandler
@ -459,6 +459,7 @@ public class NotAcceptingTest
}
catch (InterruptedException e)
{
// no op
}
}
}

View File

@ -39,6 +39,7 @@ import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
public class PartialRFC2616Test
{
@ -116,10 +117,12 @@ public class PartialRFC2616Test
"Host: localhost\n" +
"Transfer-Encoding: chunked,identity\n" +
"Content-Type: text/plain\n" +
//@checkstyle-disable-check : IllegalTokenText
"\015\012" +
"5;\015\012" +
"123\015\012\015\012" +
"0;\015\012\015\012");
//@checkstyle-enable-check : IllegalTokenText
checkContains(response, offset, "HTTP/1.1 400 Bad", "Chunked last");
}
@ -308,8 +311,9 @@ public class PartialRFC2616Test
"Content-Type: text/plain\n" +
"Content-Length: 5\n" +
"\n" +
//@checkstyle-disable-check : IllegalTokenText
"123\015\012" +
//@checkstyle-enable-check : IllegalTokenText
"GET /R2 HTTP/1.1\n" +
"Host: localhost\n" +
"Transfer-Encoding: other\n" +
@ -440,7 +444,9 @@ public class PartialRFC2616Test
{
int offset = 0;
String response = connector.getResponse("GET /R1 HTTP/1.1\n" + "Host: localhost\n" + "\n", 250, TimeUnit.MILLISECONDS);
//@checkstyle-disable-check : IllegalTokenText
offset = checkContains(response, offset, "HTTP/1.1 200 OK\015\012", "8.1.2 default") + 10;
//@checkstyle-enable-check : IllegalTokenText
checkContains(response, offset, "Content-Length: ", "8.1.2 default");
LocalEndPoint endp = connector.executeRequest("GET /R1 HTTP/1.1\n" + "Host: localhost\n" + "\n" +
@ -449,12 +455,16 @@ public class PartialRFC2616Test
offset = 0;
response = endp.getResponse();
//@checkstyle-disable-check : IllegalTokenText
offset = checkContains(response, offset, "HTTP/1.1 200 OK\015\012", "8.1.2 default") + 1;
//@checkstyle-enable-check : IllegalTokenText
offset = checkContains(response, offset, "/R1", "8.1.2 default") + 1;
offset = 0;
response = endp.getResponse();
//@checkstyle-disable-check : IllegalTokenText
offset = checkContains(response, offset, "HTTP/1.1 200 OK\015\012", "8.1.2.2 pipeline") + 11;
//@checkstyle-enable-check : IllegalTokenText
offset = checkContains(response, offset, "Connection: close", "8.1.2.2 pipeline") + 1;
offset = checkContains(response, offset, "/R2", "8.1.2.1 close") + 3;
@ -491,7 +501,9 @@ public class PartialRFC2616Test
"Content-Length: 8\n" +
"Connection: close\n" +
"\n" +
//@checkstyle-disable-check : IllegalTokenText
"123456\015\012");
//@checkstyle-enable-check : IllegalTokenText
checkNotContained(response, offset, "HTTP/1.1 100 ", "8.2.3 expect 100");
offset = checkContains(response, offset, "HTTP/1.1 200 OK", "8.2.3 expect with body") + 1;
}
@ -511,9 +523,9 @@ public class PartialRFC2616Test
String infomational = endp.getResponse();
offset = checkContains(infomational, offset, "HTTP/1.1 100 ", "8.2.3 expect 100") + 1;
checkNotContained(infomational, offset, "HTTP/1.1 200", "8.2.3 expect 100");
//@checkstyle-disable-check : IllegalTokenText
endp.addInput("654321\015\012");
//@checkstyle-enable-check : IllegalTokenText
String response = endp.getResponse();
offset = 0;
offset = checkContains(response, offset, "HTTP/1.1 200", "8.2.3 expect 100") + 1;
@ -608,6 +620,7 @@ public class PartialRFC2616Test
{
int offset = 0;
String response = connector.getResponse("GET /R1 HTTP/1.0\n" + "\n");
//@checkstyle-disable-check : IllegalTokenText
offset = checkContains(response, offset, "HTTP/1.1 200 OK\015\012", "19.6.2 default close") + 10;
checkNotContained(response, offset, "Connection: close", "19.6.2 not assumed");
@ -659,7 +672,7 @@ public class PartialRFC2616Test
response = endp.getResponse();
offset = checkContains(response, offset, "HTTP/1.1 200 OK\015\012", "19.6.2 Keep-alive 2") + 11;
offset = checkContains(response, offset, "/R2", "19.6.2 Keep-alive close") + 3;
//@checkstyle-enable-check : IllegalTokenText
offset = 0;
response = endp.getResponse();
assertThat("19.6.2 closed", response, nullValue());
@ -667,7 +680,7 @@ public class PartialRFC2616Test
catch (Exception e)
{
e.printStackTrace();
assertTrue(false);
fail(e.getMessage());
}
}

View File

@ -226,15 +226,7 @@ public class RequestTest
assertNull(request.getCookies());
assertEquals("", request.getHeader("Name"));
assertTrue(request.getHeaders("Name").hasMoreElements()); // empty
try
{
request.getDateHeader("Name");
assertTrue(false);
}
catch (IllegalArgumentException e)
{
}
assertThrows(IllegalArgumentException.class, () -> request.getDateHeader("Name"));
assertEquals(-1, request.getDateHeader("Other"));
return true;
}
@ -640,26 +632,26 @@ public class RequestTest
}
@Test
public void testContentLength_ExceedsMaxInteger() throws Exception
public void testContentLengthExceedsMaxInteger() throws Exception
{
final long HUGE_LENGTH = (long) Integer.MAX_VALUE * 10L;
final long HUGE_LENGTH = (long)Integer.MAX_VALUE * 10L;
_handler._checker = (request, response) ->
request.getContentLength() == (-1) // per HttpServletRequest javadoc this must return (-1);
&& request.getContentLengthLong() == HUGE_LENGTH;
request.getContentLength() == (-1) && // per HttpServletRequest javadoc this must return (-1);
request.getContentLengthLong() == HUGE_LENGTH;
//Send a request with encoded form content
String request="POST / HTTP/1.1\r\n"+
"Host: whatever\r\n"+
"Content-Type: application/octet-stream\n"+
"Content-Length: " + HUGE_LENGTH + "\n"+
"Connection: close\n"+
"\n"+
String request = "POST / HTTP/1.1\r\n" +
"Host: whatever\r\n" +
"Content-Type: application/octet-stream\n" +
"Content-Length: " + HUGE_LENGTH + "\n" +
"Connection: close\n" +
"\n" +
"<insert huge amount of content here>\n";
System.out.println(request);
String responses=_connector.getResponse(request);
String responses = _connector.getResponse(request);
assertThat(responses,startsWith("HTTP/1.1 200"));
}
@ -667,25 +659,25 @@ public class RequestTest
* The Servlet spec and API cannot parse Content-Length that exceeds Long.MAX_VALUE
*/
@Test
public void testContentLength_ExceedsMaxLong() throws Exception
public void testContentLengthExceedsMaxLong() throws Exception
{
String HUGE_LENGTH = Long.MAX_VALUE + "0";
String hugeLength = Long.MAX_VALUE + "0";
_handler._checker = (request, response) ->
request.getHeader("Content-Length").equals(HUGE_LENGTH)
&& request.getContentLength() == (-1) // per HttpServletRequest javadoc this must return (-1);
&& request.getContentLengthLong() == (-1); // exact behavior here not specified in Servlet javadoc
request.getHeader("Content-Length").equals(hugeLength) &&
request.getContentLength() == (-1) && // per HttpServletRequest javadoc this must return (-1);
request.getContentLengthLong() == (-1); // exact behavior here not specified in Servlet javadoc
//Send a request with encoded form content
String request="POST / HTTP/1.1\r\n"+
"Host: whatever\r\n"+
"Content-Type: application/octet-stream\n"+
"Content-Length: " + HUGE_LENGTH + "\n"+
"Connection: close\n"+
"\n"+
String request = "POST / HTTP/1.1\r\n" +
"Host: whatever\r\n" +
"Content-Type: application/octet-stream\n" +
"Content-Length: " + hugeLength + "\n" +
"Connection: close\n" +
"\n" +
"<insert huge amount of content here>\n";
String responses=_connector.getResponse(request);
String responses = _connector.getResponse(request);
assertThat(responses, startsWith("HTTP/1.1 400"));
}
@ -1667,8 +1659,7 @@ public class RequestTest
String request = "POST / HTTP/1.1\r\n" +
"Host: whatever\r\n" +
"Cookie: other=cookie\r\n" +
"\r\n"
+
"\r\n" +
"POST / HTTP/1.1\r\n" +
"Host: whatever\r\n" +
"Cookie: name=value\r\n" +
@ -1683,8 +1674,7 @@ public class RequestTest
request = "POST / HTTP/1.1\r\n" +
"Host: whatever\r\n" +
"Cookie: name=value\r\n" +
"\r\n"
+
"\r\n" +
"POST / HTTP/1.1\r\n" +
"Host: whatever\r\n" +
"Cookie: \r\n" +
@ -1699,8 +1689,7 @@ public class RequestTest
"Host: whatever\r\n" +
"Cookie: name=value\r\n" +
"Cookie: other=cookie\r\n" +
"\r\n"
+
"\r\n" +
"POST / HTTP/1.1\r\n" +
"Host: whatever\r\n" +
"Cookie: name=value\r\n" +
@ -1727,11 +1716,11 @@ public class RequestTest
buf.append("a=b");
// The evil keys file is not distributed - as it is dangerous
File evil_keys = new File("/tmp/keys_mapping_to_zero_2m");
if (evil_keys.exists())
File evilKeys = new File("/tmp/keys_mapping_to_zero_2m");
if (evilKeys.exists())
{
// Using real evil keys!
try (BufferedReader in = new BufferedReader(new FileReader(evil_keys)))
try (BufferedReader in = new BufferedReader(new FileReader(evilKeys)))
{
String key = null;
while ((key = in.readLine()) != null)
@ -1879,9 +1868,9 @@ public class RequestTest
{
((Request)request).setHandled(true);
if (request.getContentLength() > 0
&& !request.getContentType().startsWith(MimeTypes.Type.FORM_ENCODED.asString())
&& !request.getContentType().startsWith("multipart/form-data"))
if (request.getContentLength() > 0 &&
!request.getContentType().startsWith(MimeTypes.Type.FORM_ENCODED.asString()) &&
!request.getContentType().startsWith("multipart/form-data"))
_content = IO.toString(request.getInputStream());
if (_checker != null && _checker.check(request, response))

View File

@ -18,17 +18,17 @@
package org.eclipse.jetty.server;
import org.eclipse.jetty.server.handler.AbstractHandler;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import javax.servlet.AsyncContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletRequestWrapper;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import org.eclipse.jetty.server.handler.AbstractHandler;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;

View File

@ -89,7 +89,7 @@ public class StressTest
"/path/d",
"/path/e",
"/path/f",
};
};
@BeforeAll
public static void init() throws Exception

View File

@ -40,6 +40,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import static org.junit.jupiter.api.Assumptions.assumeTrue;
@ -138,23 +139,8 @@ public class ContextHandlerGetResourceTest
public void testBadPath() throws Exception
{
final String path = "bad";
try
{
context.getResource(path);
fail("Expected " + MalformedURLException.class);
}
catch (MalformedURLException e)
{
}
try
{
context.getServletContext().getResource(path);
fail("Expected " + MalformedURLException.class);
}
catch (MalformedURLException e)
{
}
assertThrows(MalformedURLException.class,() -> context.getResource(path));
assertThrows(MalformedURLException.class,() -> context.getServletContext().getResource(path));
}
@Test

View File

@ -169,7 +169,7 @@ public class InetAccessHandlerTest
{"127.0.0.1-127.0.0.254", "", "", "nothttp", "200"},
{"192.0.0.1", "", "", "nothttp", "403"},
{"192.0.0.1-192.0.0.254", "", "", "nothttp", "403"},
};
};
return Arrays.asList(data).stream().map(Arguments::of);
}
}

View File

@ -625,7 +625,7 @@ public class NcsaRequestLogTest
}
}
private static abstract class AbstractTestHandler extends AbstractHandler
private abstract static class AbstractTestHandler extends AbstractHandler
{
@Override
public String toString()

View File

@ -26,7 +26,6 @@ import javax.servlet.SessionTrackingMode;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class SessionHandlerTest
{
@Test

View File

@ -254,6 +254,7 @@ public class SSLEngineTest
}
catch (SocketException e)
{
// no op
}
}
}

View File

@ -73,7 +73,7 @@ public class SniSslConnectionFactoryTest
{
private Server _server;
private ServerConnector _connector;
private HttpConfiguration _https_config;
private HttpConfiguration _httpsConfiguration;
private int _port;
@BeforeEach
@ -85,11 +85,11 @@ public class SniSslConnectionFactoryTest
http_config.setSecureScheme("https");
http_config.setSecurePort(8443);
http_config.setOutputBufferSize(32768);
_https_config = new HttpConfiguration(http_config);
_httpsConfiguration = new HttpConfiguration(http_config);
SecureRequestCustomizer src = new SecureRequestCustomizer();
src.setSniHostCheck(true);
_https_config.addCustomizer(src);
_https_config.addCustomizer((connector, httpConfig, request) ->
_httpsConfiguration.addCustomizer(src);
_httpsConfiguration.addCustomizer((connector, httpConfig, request) ->
{
EndPoint endp = request.getHttpChannel().getEndPoint();
if (endp instanceof SslConnection.DecryptedEndPoint)
@ -126,7 +126,7 @@ public class SniSslConnectionFactoryTest
ServerConnector https = _connector = new ServerConnector(_server,
new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()),
new HttpConnectionFactory(_https_config));
new HttpConnectionFactory(_httpsConfiguration));
_server.addConnector(https);
_server.setHandler(new AbstractHandler.ErrorDispatchHandler()

View File

@ -2120,6 +2120,7 @@ public class DefaultServletTest
}
catch (InvalidPathException | IOException ignore)
{
// ignore
}
assumeTrue(ret != null, "Directory creation not supported on OS: " + path + File.separator + subpath);

View File

@ -225,6 +225,7 @@ public class ErrorPageTest
}
catch (Throwable ignore)
{
// no opEchoSocket
}
}
}

View File

@ -45,11 +45,11 @@ import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
/**
* @version $Rev$ $Date$
*
*/
public class HolderTest
{
@ -59,44 +59,19 @@ public class HolderTest
{
ServletHolder holder = new ServletHolder(Source.JAVAX_API);
ServletRegistration reg = holder.getRegistration();
try
{
reg.setInitParameter(null, "foo");
fail("null name accepted");
}
catch (IllegalArgumentException e)
{
}
try
{
reg.setInitParameter("foo", null);
fail("null value accepted");
}
catch (IllegalArgumentException e)
{
}
assertThrows(IllegalArgumentException.class,() -> reg.setInitParameter(null, "foo"));
assertThrows(IllegalArgumentException.class,() -> reg.setInitParameter("foo", null));
reg.setInitParameter("foo", "bar");
assertFalse(reg.setInitParameter("foo", "foo"));
Set<String> clash = reg.setInitParameters(Collections.singletonMap("foo", "bax"));
assertTrue(clash != null && clash.size() == 1, "should be one clash");
try
{
reg.setInitParameters(Collections.singletonMap((String)null, "bax"));
fail("null name in map accepted");
}
catch (IllegalArgumentException e)
{
}
try
{
reg.setInitParameters(Collections.singletonMap("foo", (String)null));
fail("null value in map accepted");
}
catch (IllegalArgumentException e)
{
}
assertThrows(IllegalArgumentException.class,() -> reg.setInitParameters(Collections.singletonMap((String)null, "bax")));
assertThrows(IllegalArgumentException.class,() -> reg.setInitParameters(Collections.singletonMap("foo", (String)null)));
Set<String> clash2 = reg.setInitParameters(Collections.singletonMap("FOO", "bax"));
assertTrue(clash2.isEmpty(), "should be no clash");

View File

@ -68,18 +68,18 @@ public class PostServletTest
len = request.getInputStream().read(buffer);
}
}
catch (Exception e0)
catch (Exception e)
{
ex0.set(e0);
ex0.set(e);
try
{
// this read-call should fail immediately
request.getInputStream().read(buffer);
}
catch (Exception e1)
catch (Exception ex)
{
ex1.set(e1);
LOG.warn(e1.toString());
ex1.set(ex);
LOG.warn(ex.toString());
}
}
finally

View File

@ -18,17 +18,6 @@
package org.eclipse.jetty.servlet;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
@ -84,6 +73,17 @@ import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
public class ServletContextHandlerTest
{
private Server _server;
@ -119,15 +119,8 @@ public class ServletContextHandlerTest
{
super.doStart();
//call the SCI
try
{
_ctx.setExtendedListenerTypes(true);
_sci.onStartup(Collections.emptySet(), _ctx);
}
finally
{
}
_ctx.setExtendedListenerTypes(true);
_sci.onStartup(Collections.emptySet(), _ctx);
}
}
@ -268,8 +261,8 @@ public class ServletContextHandlerTest
public static class MySListener implements HttpSessionListener
{
public static int creates = 0;
public static int destroys = 0;
public static int creates = 0;
public static int destroys = 0;
@Override
public void sessionCreated(HttpSessionEvent se)
@ -309,8 +302,7 @@ public class ServletContextHandlerTest
++replaces;
}
}
public static class MySIListener implements HttpSessionIdListener
{
public static int changes = 0;
@ -485,7 +477,7 @@ public class ServletContextHandlerTest
StringBuffer request = new StringBuffer();
request.append("GET /test?session=replace HTTP/1.0\n");
request.append("Host: localhost\n");
request.append("Cookie: "+sessionid+"\n");
request.append("Cookie: " + sessionid + "\n");
request.append("\n");
response = _connector.getResponse(request.toString());
assertThat(response, Matchers.containsString("200 OK"));
@ -496,7 +488,7 @@ public class ServletContextHandlerTest
request = new StringBuffer();
request.append("GET /test?session=remove HTTP/1.0\n");
request.append("Host: localhost\n");
request.append("Cookie: "+sessionid+"\n");
request.append("Cookie: " + sessionid + "\n");
request.append("\n");
response = _connector.getResponse(request.toString());
assertThat(response, Matchers.containsString("200 OK"));
@ -509,7 +501,7 @@ public class ServletContextHandlerTest
request = new StringBuffer();
request.append("GET /test?session=change HTTP/1.0\n");
request.append("Host: localhost\n");
request.append("Cookie: "+sessionid+"\n");
request.append("Cookie: " + sessionid + "\n");
request.append("\n");
response = _connector.getResponse(request.toString());
assertThat(response, Matchers.containsString("200 OK"));
@ -520,7 +512,7 @@ public class ServletContextHandlerTest
request = new StringBuffer();
request.append("GET /test?session=delete HTTP/1.0\n");
request.append("Host: localhost\n");
request.append("Cookie: "+sessionid+"\n");
request.append("Cookie: " + sessionid + "\n");
request.append("\n");
response = _connector.getResponse(request.toString());
assertThat(response, Matchers.containsString("200 OK"));
@ -1025,8 +1017,6 @@ public class ServletContextHandlerTest
//change and remove context attribute
req.getServletContext().setAttribute("foo", "foo");
req.getServletContext().removeAttribute("foo");
return;
}
}
}

View File

@ -108,9 +108,9 @@ public class ServletHolderTest
{
assertThat(e.getMessage(), containsString("foo"));
}
catch (MultiException m)
catch (MultiException e)
{
assertThat(m.getCause().getMessage(), containsString("foo"));
assertThat(e.getCause().getMessage(), containsString("foo"));
}
}
@ -132,9 +132,9 @@ public class ServletHolderTest
{
assertThat(e.getMessage(), containsString("foo"));
}
catch (MultiException m)
catch (MultiException e)
{
assertThat(m.getCause().getMessage(), containsString("foo"));
assertThat(e.getCause().getMessage(), containsString("foo"));
}
}
}

View File

@ -83,7 +83,7 @@ public class ServletRequestLogTest
}
@SuppressWarnings("serial")
private static abstract class AbstractTestServlet extends HttpServlet
private abstract static class AbstractTestServlet extends HttpServlet
{
@Override
public String toString()

View File

@ -244,9 +244,9 @@ public class ServletTester extends ContainerLifeCycle
else
connector.open();
return "http://" + (localhost ? "127.0.0.1" :
InetAddress.getLocalHost().getHostAddress()
) + ":" + connector.getLocalPort();
return "http://" + (localhost ? "127.0.0.1"
: InetAddress.getLocalHost().getHostAddress()) +
":" + connector.getLocalPort();
}
public LocalConnector createLocalConnector()

View File

@ -128,7 +128,8 @@ public class StatisticsServletTest
public static class Stats
{
int responses2xx, responses4xx;
int responses2xx;
int responses4xx;
public Stats(int responses2xx, int responses4xx)
{

View File

@ -42,7 +42,7 @@ public class GzipDefaultNoRecompressTest
{
public static Stream<Arguments> data()
{
return Arrays.asList(new Object[][]
return Arrays.stream(new Object[][]
{
// Some already compressed files
{"test_quotes.gz", "application/gzip", GzipHandler.GZIP},
@ -64,7 +64,7 @@ public class GzipDefaultNoRecompressTest
//qvalue disables compression
{"test_quotes.txt", "text/plain", GzipHandler.GZIP + ";q=0"},
{"test_quotes.txt", "text/plain", GzipHandler.GZIP + "; q = 0 "},
}).stream().map(Arguments::of);
}).map(Arguments::of);
}
public WorkDir testingdir;

View File

@ -101,10 +101,10 @@ public class GzipDefaultTest
@SuppressWarnings("serial")
public static class HttpContentTypeWithEncoding extends HttpServlet
{
public static final String COMPRESSED_CONTENT = "<html><head></head><body><h1>COMPRESSABLE CONTENT</h1>"
+ "This content must be longer than the default min gzip length, which is 256 bytes. "
+ "The moon is blue to a fish in love. How now brown cow. The quick brown fox jumped over the lazy dog. A woman needs a man like a fish needs a bicycle!"
+ "</body></html>";
public static final String COMPRESSED_CONTENT = "<html><head></head><body><h1>COMPRESSABLE CONTENT</h1>" +
"This content must be longer than the default min gzip length, which is 256 bytes. " +
"The moon is blue to a fish in love. How now brown cow. The quick brown fox jumped over the lazy dog. A woman needs a man like a fish needs a bicycle!" +
"</body></html>";
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException

View File

@ -57,7 +57,7 @@ public final class Hex
return buf;
}
public static String asHex(byte buf[])
public static String asHex(byte[] buf)
{
int len = buf.length;
char[] out = new char[len * 2];

View File

@ -341,6 +341,7 @@ public abstract class AbstractDoSFilterTest
}
catch (InterruptedException e)
{
// no op
}
}
@ -358,6 +359,7 @@ public abstract class AbstractDoSFilterTest
}
catch (InterruptedException e)
{
// no op
}
}
}

View File

@ -58,9 +58,9 @@ public class QoSFilterTest
private ServletTester _tester;
private LocalConnector[] _connectors;
private final int NUM_CONNECTIONS = 8;
private final int NUM_LOOPS = 6;
private final int MAX_QOS = 4;
private final int numConnections = 8;
private final int numLoops = 6;
private final int maxQos = 4;
@BeforeEach
public void setUp() throws Exception
@ -71,7 +71,7 @@ public class QoSFilterTest
TestServlet.__maxSleepers = 0;
TestServlet.__sleepers = 0;
_connectors = new LocalConnector[NUM_CONNECTIONS];
_connectors = new LocalConnector[numConnections];
for (int i = 0; i < _connectors.length; ++i)
{
_connectors[i] = _tester.createLocalConnector();
@ -90,20 +90,20 @@ public class QoSFilterTest
public void testNoFilter() throws Exception
{
List<Worker> workers = new ArrayList<>();
for (int i = 0; i < NUM_CONNECTIONS; ++i)
for (int i = 0; i < numConnections; ++i)
{
workers.add(new Worker(i));
}
ExecutorService executor = Executors.newFixedThreadPool(NUM_CONNECTIONS);
ExecutorService executor = Executors.newFixedThreadPool(numConnections);
List<Future<Void>> futures = executor.invokeAll(workers, 10, TimeUnit.SECONDS);
rethrowExceptions(futures);
if (TestServlet.__maxSleepers <= MAX_QOS)
if (TestServlet.__maxSleepers <= maxQos)
LOG.warn("TEST WAS NOT PARALLEL ENOUGH!");
else
assertThat(TestServlet.__maxSleepers, Matchers.lessThanOrEqualTo(NUM_CONNECTIONS));
assertThat(TestServlet.__maxSleepers, Matchers.lessThanOrEqualTo(numConnections));
}
@Disabled("Issue #2627")
@ -112,24 +112,24 @@ public class QoSFilterTest
{
FilterHolder holder = new FilterHolder(QoSFilter2.class);
holder.setAsyncSupported(true);
holder.setInitParameter(QoSFilter.MAX_REQUESTS_INIT_PARAM, "" + MAX_QOS);
holder.setInitParameter(QoSFilter.MAX_REQUESTS_INIT_PARAM, "" + maxQos);
_tester.getContext().getServletHandler().addFilterWithMapping(holder, "/*", EnumSet.of(DispatcherType.REQUEST, DispatcherType.ASYNC));
List<Worker> workers = new ArrayList<>();
for (int i = 0; i < NUM_CONNECTIONS; ++i)
for (int i = 0; i < numConnections; ++i)
{
workers.add(new Worker(i));
}
ExecutorService executor = Executors.newFixedThreadPool(NUM_CONNECTIONS);
ExecutorService executor = Executors.newFixedThreadPool(numConnections);
List<Future<Void>> futures = executor.invokeAll(workers, 10, TimeUnit.SECONDS);
rethrowExceptions(futures);
if (TestServlet.__maxSleepers < MAX_QOS)
if (TestServlet.__maxSleepers < maxQos)
LOG.warn("TEST WAS NOT PARALLEL ENOUGH!");
else
assertEquals(TestServlet.__maxSleepers, MAX_QOS);
assertEquals(TestServlet.__maxSleepers, maxQos);
}
@Test
@ -137,24 +137,24 @@ public class QoSFilterTest
{
FilterHolder holder = new FilterHolder(QoSFilter2.class);
holder.setAsyncSupported(true);
holder.setInitParameter(QoSFilter.MAX_REQUESTS_INIT_PARAM, String.valueOf(MAX_QOS));
holder.setInitParameter(QoSFilter.MAX_REQUESTS_INIT_PARAM, String.valueOf(maxQos));
_tester.getContext().getServletHandler().addFilterWithMapping(holder, "/*", EnumSet.of(DispatcherType.REQUEST, DispatcherType.ASYNC));
List<Worker2> workers = new ArrayList<>();
for (int i = 0; i < NUM_CONNECTIONS; ++i)
for (int i = 0; i < numConnections; ++i)
{
workers.add(new Worker2(i));
}
ExecutorService executor = Executors.newFixedThreadPool(NUM_CONNECTIONS);
ExecutorService executor = Executors.newFixedThreadPool(numConnections);
List<Future<Void>> futures = executor.invokeAll(workers, 20, TimeUnit.SECONDS);
rethrowExceptions(futures);
if (TestServlet.__maxSleepers < MAX_QOS)
if (TestServlet.__maxSleepers < maxQos)
LOG.warn("TEST WAS NOT PARALLEL ENOUGH!");
else
assertEquals(TestServlet.__maxSleepers, MAX_QOS);
assertEquals(TestServlet.__maxSleepers, maxQos);
}
private void rethrowExceptions(List<Future<Void>> futures) throws Exception
@ -177,7 +177,7 @@ public class QoSFilterTest
@Override
public Void call() throws Exception
{
for (int i = 0; i < NUM_LOOPS; i++)
for (int i = 0; i < numLoops; i++)
{
HttpTester.Request request = HttpTester.newRequest();
@ -211,7 +211,7 @@ public class QoSFilterTest
try
{
String addr = _tester.createConnector(true);
for (int i = 0; i < NUM_LOOPS; i++)
for (int i = 0; i < numLoops; i++)
{
url = new URL(addr + "/context/test?priority=" + (_num % QoSFilter.DEFAULT_MAX_PRIORITY) + "&n=" + _num + "&l=" + i);
url.getContent();

View File

@ -43,7 +43,9 @@ public class PathMatchersAbsoluteTest
arguments.add(Arguments.of("/opt/florb", true));
arguments.add(Arguments.of("/home/user/benfranklin", true));
arguments.add(Arguments.of("glob:/home/user/benfranklin/*.jar", true));
//@checkstyle-disable-check : LegacyMethodSeparators
arguments.add(Arguments.of("glob:/**/*.jar", true));
//@checkstyle-enable-check : LegacyMethodSeparators
arguments.add(Arguments.of("regex:/*-[^dev].ini", true));
}

View File

@ -41,7 +41,9 @@ public class PathMatchersSearchRootTest
{
// absolute first
arguments.add(Arguments.of("/opt/app/*.jar", "/opt/app"));
//@checkstyle-disable-check : LegacyMethodSeparators
arguments.add(Arguments.of("/lib/jvm/**/jre/lib/*.jar", "/lib/jvm"));
//@checkstyle-enable-check : LegacyMethodSeparators
arguments.add(Arguments.of("glob:/var/lib/*.xml", "/var/lib"));
arguments.add(Arguments.of("glob:/var/lib/*.{xml,java}", "/var/lib"));
arguments.add(Arguments.of("glob:/opt/corporate/lib-{dev,prod}/*.ini", "/opt/corporate"));

View File

@ -45,11 +45,11 @@ public class UnixSocketClient
body = IO.readToString(content);
content_length = body.length();
}
String data = method + " / HTTP/1.1\r\n"
+ "Host: unixsock\r\n"
+ "Content-Length: " + content_length + "\r\n"
+ "Connection: close\r\n"
+ "\r\n";
String data = method + " / HTTP/1.1\r\n" +
"Host: unixsock\r\n" +
"Content-Length: " + content_length + "\r\n" +
"Connection: close\r\n" +
"\r\n";
if (body != null)
data += body;

View File

@ -45,13 +45,13 @@ public class JSONPojoConvertorFactoryTest
Foo foo = new Foo();
foo._name = "Foo @ " + TimeUnit.NANOSECONDS.toMillis(System.nanoTime());
foo._int1 = 1;
foo._int2 = new Integer(2);
foo._long1 = 1000001l;
foo._long2 = new Long(1000002l);
foo._int2 = Integer.valueOf(2);
foo._long1 = 1000001L;
foo._long2 = Long.valueOf(1000002L);
foo._float1 = 10.11f;
foo._float2 = new Float(10.22f);
foo._float2 = Float.valueOf(10.22f);
foo._double1 = 10000.11111d;
foo._double2 = new Double(10000.22222d);
foo._double2 = Double.valueOf(10000.22222d);
Bar bar = new Bar("Hello", true, new Baz("World", Boolean.FALSE, foo), new Baz[]{
new Baz("baz0", Boolean.TRUE, null), new Baz("baz1", Boolean.FALSE, null)
@ -91,13 +91,13 @@ public class JSONPojoConvertorFactoryTest
Foo foo = new Foo();
foo._name = "Foo @ " + TimeUnit.NANOSECONDS.toMillis(System.nanoTime());
foo._int1 = 1;
foo._int2 = new Integer(2);
foo._long1 = 1000001l;
foo._long2 = new Long(1000002l);
foo._int2 = Integer.valueOf(2);
foo._long1 = 1000001L;
foo._long2 = Long.valueOf(1000002L);
foo._float1 = 10.11f;
foo._float2 = new Float(10.22f);
foo._float2 = Float.valueOf(10.22f);
foo._double1 = 10000.11111d;
foo._double2 = new Double(10000.22222d);
foo._double2 = Double.valueOf(10000.22222d);
Bar bar = new Bar("Hello", true, new Baz("World", Boolean.FALSE, foo), new Baz[]{
new Baz("baz0", Boolean.TRUE, null), new Baz("baz1", Boolean.FALSE, null)
@ -134,7 +134,8 @@ public class JSONPojoConvertorFactoryTest
public static class Bar
{
private String _title, _nullTest;
private String _title;
private String _nullTest;
private Baz _baz;
private boolean _boolean1;
private Baz[] _bazs;
@ -328,15 +329,15 @@ public class JSONPojoConvertorFactoryTest
if (another instanceof Foo)
{
Foo foo = (Foo)another;
return getName().equals(foo.getName())
&& getInt1() == foo.getInt1()
&& getInt2().equals(foo.getInt2())
&& getLong1() == foo.getLong1()
&& getLong2().equals(foo.getLong2())
&& getFloat1() == foo.getFloat1()
&& getFloat2().equals(foo.getFloat2())
&& getDouble1() == foo.getDouble1()
&& getDouble2().equals(foo.getDouble2());
return getName().equals(foo.getName()) &&
getInt1() == foo.getInt1() &&
getInt2().equals(foo.getInt2()) &&
getLong1() == foo.getLong1() &&
getLong2().equals(foo.getLong2()) &&
getFloat1() == foo.getFloat1() &&
getFloat2().equals(foo.getFloat2()) &&
getDouble1() == foo.getDouble1() &&
getDouble2().equals(foo.getDouble2());
}
return false;

View File

@ -44,15 +44,15 @@ public class JSONPojoConvertorTest
Foo foo = new Foo();
foo._name = "Foo @ " + TimeUnit.NANOSECONDS.toMillis(System.nanoTime());
foo._int1 = 1;
foo._int2 = new Integer(2);
foo._long1 = 1000001l;
foo._long2 = new Long(1000002l);
foo._int2 = Integer.valueOf(2);
foo._long1 = 1000001L;
foo._long2 = Long.valueOf(1000002L);
foo._float1 = 10.11f;
foo._float2 = new Float(10.22f);
foo._float2 = Float.valueOf(10.22f);
foo._double1 = 10000.11111d;
foo._double2 = new Double(10000.22222d);
foo._double2 = Double.valueOf(10000.22222d);
foo._char1 = 'a';
foo._char2 = new Character('b');
foo._char2 = Character.valueOf('b');
Bar bar = new Bar("Hello", true, new Baz("World", Boolean.FALSE, foo), new Baz[]{
new Baz("baz0", Boolean.TRUE, null), new Baz("baz1", Boolean.FALSE, null)
@ -92,15 +92,15 @@ public class JSONPojoConvertorTest
Foo foo = new Foo();
foo._name = "Foo @ " + TimeUnit.NANOSECONDS.toMillis(System.nanoTime());
foo._int1 = 1;
foo._int2 = new Integer(2);
foo._long1 = 1000001l;
foo._long2 = new Long(1000002l);
foo._int2 = Integer.valueOf(2);
foo._long1 = 1000001L;
foo._long2 = Long.valueOf(1000002L);
foo._float1 = 10.11f;
foo._float2 = new Float(10.22f);
foo._float2 = Float.valueOf(10.22f);
foo._double1 = 10000.11111d;
foo._double2 = new Double(10000.22222d);
foo._double2 = Double.valueOf(10000.22222d);
foo._char1 = 'a';
foo._char2 = new Character('b');
foo._char2 = Character.valueOf('b');
Bar bar = new Bar("Hello", true, new Baz("World", Boolean.FALSE, foo));
// bar.setColor(Color.Blue);
@ -135,7 +135,8 @@ public class JSONPojoConvertorTest
public static class Bar
{
private String _title, _nullTest;
private String _title;
private String _nullTest;
private Baz _baz;
private boolean _boolean1;
private Baz[] _bazs;
@ -334,17 +335,17 @@ public class JSONPojoConvertorTest
if (another instanceof Foo)
{
Foo foo = (Foo)another;
return getName().equals(foo.getName())
&& getInt1() == foo.getInt1()
&& getInt2().equals(foo.getInt2())
&& getLong1() == foo.getLong1()
&& getLong2().equals(foo.getLong2())
&& getFloat1() == foo.getFloat1()
&& getFloat2().equals(foo.getFloat2())
&& getDouble1() == foo.getDouble1()
&& getDouble2().equals(foo.getDouble2())
&& getChar1() == foo.getChar1()
&& getChar2().equals(foo.getChar2());
return getName().equals(foo.getName()) &&
getInt1() == foo.getInt1() &&
getInt2().equals(foo.getInt2()) &&
getLong1() == foo.getLong1() &&
getLong2().equals(foo.getLong2()) &&
getFloat1() == foo.getFloat1() &&
getFloat2().equals(foo.getFloat2()) &&
getDouble1() == foo.getDouble1() &&
getDouble2().equals(foo.getDouble2()) &&
getChar1() == foo.getChar1() &&
getChar2().equals(foo.getChar2());
}
return false;

View File

@ -42,7 +42,7 @@ public class BufferUtilTest
@Test
public void testToInt() throws Exception
{
ByteBuffer buf[] =
ByteBuffer[] buf =
{
BufferUtil.toBuffer("0"),
BufferUtil.toBuffer(" 42 "),
@ -51,9 +51,9 @@ public class BufferUtilTest
BufferUtil.toBuffer(" - 45;"),
BufferUtil.toBuffer("-2147483648"),
BufferUtil.toBuffer("2147483647"),
};
};
int val[] =
int[] val =
{
0, 42, 43, -44, -45, -2147483648, 2147483647
};
@ -67,12 +67,12 @@ public class BufferUtilTest
@Test
public void testPutInt() throws Exception
{
int val[] =
int[] val =
{
0, 42, 43, -44, -45, Integer.MIN_VALUE, Integer.MAX_VALUE
};
String str[] =
String[] str =
{
"0", "42", "43", "-44", "-45", "" + Integer.MIN_VALUE, "" + Integer.MAX_VALUE
};
@ -91,12 +91,12 @@ public class BufferUtilTest
@Test
public void testPutLong() throws Exception
{
long val[] =
long[] val =
{
0L, 42L, 43L, -44L, -45L, Long.MIN_VALUE, Long.MAX_VALUE
};
String str[] =
String[] str =
{
"0", "42", "43", "-44", "-45", "" + Long.MIN_VALUE, "" + Long.MAX_VALUE
};
@ -115,12 +115,12 @@ public class BufferUtilTest
@Test
public void testPutHexInt() throws Exception
{
int val[] =
int[] val =
{
0, 42, 43, -44, -45, -2147483648, 2147483647
};
String str[] =
String[] str =
{
"0", "2A", "2B", "-2C", "-2D", "-80000000", "7FFFFFFF"
};

View File

@ -28,8 +28,10 @@ import org.hamcrest.Matchers;
import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
@ -49,14 +51,7 @@ public class FutureCallbackTest
FutureCallback fcb = new FutureCallback();
long start = TimeUnit.NANOSECONDS.toMillis(System.nanoTime());
try
{
fcb.get(500, TimeUnit.MILLISECONDS);
fail("Expected a TimeoutException");
}
catch (TimeoutException e)
{
}
assertThrows(TimeoutException.class, () -> fcb.get(500, TimeUnit.MILLISECONDS));
assertThat(TimeUnit.NANOSECONDS.toMillis(System.nanoTime()) - start, Matchers.greaterThan(50L));
}
@ -79,22 +74,18 @@ public class FutureCallbackTest
final FutureCallback fcb = new FutureCallback();
final CountDownLatch latch = new CountDownLatch(1);
new Thread(new Runnable()
new Thread(() ->
{
@Override
public void run()
latch.countDown();
try
{
latch.countDown();
try
{
TimeUnit.MILLISECONDS.sleep(100);
}
catch (Exception e)
{
e.printStackTrace();
}
fcb.succeeded();
TimeUnit.MILLISECONDS.sleep(100);
}
catch (Exception e)
{
e.printStackTrace();
}
fcb.succeeded();
}).start();
latch.await();
@ -117,15 +108,9 @@ public class FutureCallbackTest
assertFalse(fcb.isCancelled());
long start = TimeUnit.NANOSECONDS.toMillis(System.nanoTime());
try
{
fcb.get();
fail("Expected an ExecutionException");
}
catch (ExecutionException ee)
{
assertEquals(ex, ee.getCause());
}
ExecutionException e = assertThrows(ExecutionException.class, () -> fcb.get());
assertEquals(ex, e.getCause());
assertThat(TimeUnit.NANOSECONDS.toMillis(System.nanoTime()) - start, Matchers.lessThan(100L));
}
@ -136,35 +121,24 @@ public class FutureCallbackTest
final Exception ex = new Exception("FAILED");
final CountDownLatch latch = new CountDownLatch(1);
new Thread(new Runnable()
new Thread(() ->
{
@Override
public void run()
latch.countDown();
try
{
latch.countDown();
try
{
TimeUnit.MILLISECONDS.sleep(100);
}
catch (Exception e)
{
e.printStackTrace();
}
fcb.failed(ex);
TimeUnit.MILLISECONDS.sleep(100);
}
catch (Exception e)
{
e.printStackTrace();
}
fcb.failed(ex);
}).start();
latch.await();
long start = TimeUnit.NANOSECONDS.toMillis(System.nanoTime());
try
{
fcb.get(10000, TimeUnit.MILLISECONDS);
fail("Expected an ExecutionException");
}
catch (ExecutionException ee)
{
assertEquals(ex, ee.getCause());
}
ExecutionException e = assertThrows(ExecutionException.class, () -> fcb.get(10000, TimeUnit.MILLISECONDS));
assertEquals(ex, e.getCause());
assertThat(TimeUnit.NANOSECONDS.toMillis(System.nanoTime()) - start, Matchers.greaterThan(10L));
assertThat(TimeUnit.NANOSECONDS.toMillis(System.nanoTime()) - start, Matchers.lessThan(5000L));
@ -181,15 +155,8 @@ public class FutureCallbackTest
assertTrue(fcb.isCancelled());
long start = TimeUnit.NANOSECONDS.toMillis(System.nanoTime());
try
{
fcb.get();
fail("Expected a CancellationException");
}
catch (CancellationException e)
{
assertThat(e.getCause(), Matchers.instanceOf(CancellationException.class));
}
CancellationException e = assertThrows(CancellationException.class, () -> fcb.get());
assertThat(e.getCause(), Matchers.instanceOf(CancellationException.class));
assertThat(TimeUnit.NANOSECONDS.toMillis(System.nanoTime()) - start, Matchers.lessThan(100L));
}
@ -199,35 +166,25 @@ public class FutureCallbackTest
final FutureCallback fcb = new FutureCallback();
final CountDownLatch latch = new CountDownLatch(1);
new Thread(new Runnable()
new Thread(() ->
{
@Override
public void run()
latch.countDown();
try
{
latch.countDown();
try
{
TimeUnit.MILLISECONDS.sleep(100);
}
catch (Exception e)
{
e.printStackTrace();
}
fcb.cancel(true);
TimeUnit.MILLISECONDS.sleep(100);
}
catch (Exception e)
{
e.printStackTrace();
}
fcb.cancel(true);
}).start();
latch.await();
long start = TimeUnit.NANOSECONDS.toMillis(System.nanoTime());
try
{
fcb.get(10000, TimeUnit.MILLISECONDS);
fail("Expected a CancellationException");
}
catch (CancellationException e)
{
assertThat(e.getCause(), Matchers.instanceOf(CancellationException.class));
}
CancellationException e = assertThrows(CancellationException.class,() -> fcb.get(10000, TimeUnit.MILLISECONDS));
assertThat(e.getCause(), Matchers.instanceOf(CancellationException.class));
assertThat(TimeUnit.NANOSECONDS.toMillis(System.nanoTime()) - start, Matchers.greaterThan(10L));
assertThat(TimeUnit.NANOSECONDS.toMillis(System.nanoTime()) - start, Matchers.lessThan(1000L));

View File

@ -82,7 +82,7 @@ public class InetAddressSetTest
"[::1",
"[xxx]",
"[:::1]",
};
};
InetAddressSet set = new InetAddressSet();
@ -159,7 +159,7 @@ public class InetAddressSetTest
"255.255.8.0/16",
"255.255.8.1/17",
"[::1]/129",
};
};
InetAddressSet set = new InetAddressSet();
@ -214,7 +214,7 @@ public class InetAddressSetTest
{
"10.0.0.0-9.0.0.0",
"9.0.0.0-[::10.0.0.0]",
};
};
InetAddressSet set = new InetAddressSet();
@ -266,7 +266,7 @@ public class InetAddressSetTest
"9.0-10.0",
"10.0.0--1.1",
"10.0.0-256.1",
};
};
InetAddressSet set = new InetAddressSet();

View File

@ -94,7 +94,7 @@ public class RolloverFileOutputStreamTest
ZonedDateTime midnight = RolloverFileOutputStream.toMidnight(initialDate);
assertThat("Midnight", toString(midnight), is("2017.04.27-12:00:00.0 AM PDT"));
Object expected[][] = {
Object[][] expected = {
{"2017.04.27-12:00:00.0 AM PDT", 14_400_000L},
{"2017.04.28-12:00:00.0 AM PDT", 86_400_000L},
{"2017.04.29-12:00:00.0 AM PDT", 86_400_000L},
@ -115,7 +115,7 @@ public class RolloverFileOutputStreamTest
ZonedDateTime midnight = RolloverFileOutputStream.toMidnight(initialDate);
assertThat("Midnight", toString(midnight), is("2016.03.11-12:00:00.0 AM PST"));
Object expected[][] = {
Object[][] expected = {
{"2016.03.12-12:00:00.0 AM PST", 86_400_000L},
{"2016.03.13-12:00:00.0 AM PST", 86_400_000L},
{"2016.03.14-12:00:00.0 AM PDT", 82_800_000L}, // the short day
@ -135,7 +135,7 @@ public class RolloverFileOutputStreamTest
ZonedDateTime midnight = RolloverFileOutputStream.toMidnight(initialDate);
assertThat("Midnight", toString(midnight), is("2016.11.04-12:00:00.0 AM PDT"));
Object expected[][] = {
Object[][] expected = {
{"2016.11.05-12:00:00.0 AM PDT", 86_400_000L},
{"2016.11.06-12:00:00.0 AM PDT", 86_400_000L},
{"2016.11.07-12:00:00.0 AM PST", 90_000_000L}, // the long day
@ -155,7 +155,7 @@ public class RolloverFileOutputStreamTest
ZonedDateTime midnight = RolloverFileOutputStream.toMidnight(initialDate);
assertThat("Midnight", toString(midnight), is("2016.10.01-12:00:00.0 AM AEST"));
Object expected[][] = {
Object[][] expected = {
{"2016.10.02-12:00:00.0 AM AEST", 86_400_000L},
{"2016.10.03-12:00:00.0 AM AEDT", 82_800_000L}, // the short day
{"2016.10.04-12:00:00.0 AM AEDT", 86_400_000L},
@ -175,7 +175,7 @@ public class RolloverFileOutputStreamTest
ZonedDateTime midnight = RolloverFileOutputStream.toMidnight(initialDate);
assertThat("Midnight", toString(midnight), is("2016.04.02-12:00:00.0 AM AEDT"));
Object expected[][] = {
Object[][] expected = {
{"2016.04.03-12:00:00.0 AM AEDT", 86_400_000L},
{"2016.04.04-12:00:00.0 AM AEST", 90_000_000L}, // The long day
{"2016.04.05-12:00:00.0 AM AEST", 86_400_000L},

View File

@ -123,10 +123,10 @@ public class SharedBlockingCallbackTest
}
fail("Should have thrown IOException");
}
catch (IOException ee)
catch (IOException e)
{
start = TimeUnit.NANOSECONDS.toMillis(System.nanoTime());
assertEquals(ex, ee.getCause());
assertEquals(ex, e.getCause());
}
assertThat(TimeUnit.NANOSECONDS.toMillis(System.nanoTime()) - start, lessThan(100L));
assertEquals(0, notComplete.get());
@ -168,9 +168,9 @@ public class SharedBlockingCallbackTest
}
fail("Should have thrown IOException");
}
catch (IOException ee)
catch (IOException e)
{
assertEquals(ex, ee.getCause());
assertEquals(ex, e.getCause());
}
assertThat(TimeUnit.NANOSECONDS.toMillis(System.nanoTime()) - start, greaterThan(10L));
assertThat(TimeUnit.NANOSECONDS.toMillis(System.nanoTime()) - start, lessThan(1000L));

View File

@ -204,7 +204,9 @@ public class StringUtilTest
assertThat(StringUtil.indexOfControlChars("\t"), is(0));
assertThat(StringUtil.indexOfControlChars(";\n"), is(1));
assertThat(StringUtil.indexOfControlChars("abc\fz"), is(3));
//@checkstyle-disable-check : IllegalTokenText
assertThat(StringUtil.indexOfControlChars("z\010"), is(1));
//@checkstyle-enable-check : IllegalTokenText
assertThat(StringUtil.indexOfControlChars(":\u001c"), is(1));
assertThat(StringUtil.indexOfControlChars(null), is(-1));

View File

@ -114,7 +114,7 @@ public class URIUtilCanonicalPathTest
// paths with encoded segments should remain encoded
// canonicalPath() is not responsible for decoding characters
{"%2e%2e/", "%2e%2e/"},
};
};
ArrayList<Arguments> ret = new ArrayList<>();
for (String[] args : canonical)

View File

@ -167,7 +167,7 @@ public class URLEncodedTest
{StringUtil.__ISO_8859_1, StringUtil.__ISO_8859_1, "%30"},
{StringUtil.__UTF8, StringUtil.__UTF8, "%30"},
{StringUtil.__UTF16, StringUtil.__UTF16, "%00%30"},
};
};
// Note: "%30" -> decode -> "0"

View File

@ -375,9 +375,8 @@ public class ContainerLifeCycleTest
child.add(c);
}
public
@Override
String toString()
public String toString()
{
return "listener";
}
@ -385,18 +384,16 @@ public class ContainerLifeCycleTest
ContainerLifeCycle c0 = new ContainerLifeCycle()
{
public
@Override
String toString()
public String toString()
{
return "c0";
}
};
ContainerLifeCycle c00 = new ContainerLifeCycle()
{
public
@Override
String toString()
public String toString()
{
return "c00";
}
@ -437,9 +434,8 @@ public class ContainerLifeCycleTest
child.add(c);
}
public
@Override
String toString()
public String toString()
{
return "inherited";
}
@ -526,27 +522,24 @@ public class ContainerLifeCycleTest
{
ContainerLifeCycle c0 = new ContainerLifeCycle()
{
public
@Override
String toString()
public String toString()
{
return "c0";
}
};
ContainerLifeCycle c00 = new ContainerLifeCycle()
{
public
@Override
String toString()
public String toString()
{
return "c00";
}
};
ContainerLifeCycle c01 = new ContainerLifeCycle()
{
public
@Override
String toString()
public String toString()
{
return "c01";
}

View File

@ -37,7 +37,7 @@ import static org.hamcrest.Matchers.is;
public class LifeCycleListenerNestedTest
{
// Set this true to use test-specific workaround.
private final boolean WORKAROUND = false;
private final boolean workaround = false;
public static class Foo extends ContainerLifeCycle
{
@ -186,7 +186,7 @@ public class LifeCycleListenerNestedTest
CapturingListener listener = new CapturingListener();
foo.addLifeCycleListener(listener);
if (WORKAROUND)
if (workaround)
foo.addEventListener(listener);
try
@ -217,7 +217,7 @@ public class LifeCycleListenerNestedTest
CapturingListener listener = new CapturingListener();
foo.addLifeCycleListener(listener);
if (WORKAROUND)
if (workaround)
foo.addEventListener(listener);
Bar bara = new Bar("a");
@ -255,7 +255,7 @@ public class LifeCycleListenerNestedTest
CapturingListener listener = new CapturingListener();
foo.addLifeCycleListener(listener);
if (WORKAROUND)
if (workaround)
foo.addEventListener(listener);
try

View File

@ -726,19 +726,25 @@ public class StdErrLogTest
Exception inner = new Exception("inner");
inner.addSuppressed(new IllegalStateException()
{{
addSuppressed(new Exception("branch0"));
}});
{
{
addSuppressed(new Exception("branch0"));
}
});
IOException outer = new IOException("outer", inner);
outer.addSuppressed(new IllegalStateException()
{{
addSuppressed(new Exception("branch1"));
}});
{
{
addSuppressed(new Exception("branch1"));
}
});
outer.addSuppressed(new IllegalArgumentException()
{{
addSuppressed(new Exception("branch2"));
}});
{
{
addSuppressed(new Exception("branch2"));
}
});
log.warn("problem", outer);

View File

@ -336,6 +336,7 @@ public class FileSystemResourceTest
}
catch (Exception e)
{
// FIXME why ignoring exceptions??
}
}

View File

@ -89,10 +89,7 @@ public class CounterStatisticTest
for (int i = N; i-- > 0; )
{
threads[i] = (i >= N / 2)
? new Thread()
{
@Override
public void run()
? new Thread(() ->
{
try
{
@ -110,12 +107,9 @@ public class CounterStatisticTest
if (random.nextInt(5) == 0)
Thread.yield();
}
}
}
: new Thread()
{
@Override
public void run()
})
: new Thread(() ->
{
try
{
@ -134,8 +128,7 @@ public class CounterStatisticTest
if (random.nextInt(5) == 0)
Thread.yield();
}
}
};
});
threads[i].start();
}

View File

@ -35,15 +35,15 @@ public class SampleStatisticTest
100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 90, 110, 95, 105, 97,
103
},
};
};
private static double[][] results =
{ /* {mean,stddev}*/
{100.0, 0.0},
{100.0, Math.sqrt((10 * 10 + 10 * 10) / 12.0)},
{100.0, Math.sqrt((10 * 10 + 10 * 10 + 5 * 5 + 5 * 5 + 3 * 3 + 3 * 3) / 14.0)},
{100.0, Math.sqrt((10 * 10 + 10 * 10 + 5 * 5 + 5 * 5 + 3 * 3 + 3 * 3) / 24.0)},
{100.0, Math.sqrt((10 * 10 + 10 * 10 + 5 * 5 + 5 * 5 + 3 * 3 + 3 * 3) / 104.0)}
/* {mean,stddev}*/
{{100.0, 0.0},
{100.0, Math.sqrt((10 * 10 + 10 * 10) / 12.0)},
{100.0, Math.sqrt((10 * 10 + 10 * 10 + 5 * 5 + 5 * 5 + 3 * 3 + 3 * 3) / 14.0)},
{100.0, Math.sqrt((10 * 10 + 10 * 10 + 5 * 5 + 5 * 5 + 3 * 3 + 3 * 3) / 24.0)},
{100.0, Math.sqrt((10 * 10 + 10 * 10 + 5 * 5 + 5 * 5 + 3 * 3 + 3 * 3) / 104.0)}
};
@Test

View File

@ -44,7 +44,7 @@ public abstract class AbstractThreadPoolTest
ProcessorUtils.setAvailableProcessors(originalCoreCount);
}
abstract protected SizedThreadPool newPool(int max);
protected abstract SizedThreadPool newPool(int max);
@Test
public void testBudget_constructMaxThenLease()

View File

@ -466,6 +466,7 @@ public class QueuedThreadPoolTest extends AbstractThreadPoolTest
}
catch (InterruptedException expected)
{
// no op
}
}
});

View File

@ -70,6 +70,7 @@ public class SchedulerTest
}
catch (Exception ignore)
{
// no op
}
});
}

View File

@ -78,7 +78,7 @@ public class ExecutionStrategyTest
_threads.stop();
}
public static abstract class TestProducer implements Producer
public abstract static class TestProducer implements Producer
{
@Override
public String toString()
@ -122,14 +122,7 @@ public class ExecutionStrategyTest
{
if (tasks-- > 0)
{
return new Runnable()
{
@Override
public void run()
{
latch.countDown();
}
};
return () -> latch.countDown();
}
return null;
@ -175,15 +168,7 @@ public class ExecutionStrategyTest
try
{
final CountDownLatch latch = q.take();
return new Runnable()
{
@Override
public void run()
{
// System.err.println("RUN "+id);
latch.countDown();
}
};
return () -> latch.countDown();
}
catch (InterruptedException e)
{

View File

@ -605,6 +605,7 @@ public class WebAppClassLoader extends URLClassLoader implements ClassVisibility
* @param name the name of the class to load
* @param checkSystemResource if true and the class isn't a system class we return it
* @return the loaded class
* @throws ClassNotFoundException if the class cannot be found
*/
protected Class<?> loadAsResource(final String name, boolean checkSystemResource) throws ClassNotFoundException
{

View File

@ -407,9 +407,6 @@ public class WebAppContextTest
}
history.add(e.getMessage());
}
finally
{
}
}
assertThat(history, contains("I0", "I1", "I2", "Listener2 init broken", "D1", "D0", "Listener1 destroy broken"));

View File

@ -59,13 +59,13 @@ public class MessageReceivingTest
private static EchoHandler handler;
private static URI serverUri;
private WebSocketContainer container;
private final String VERY_LONG_STRING;
private final String veryLongString;
public MessageReceivingTest()
{
byte[] raw = new byte[1024 * 1024];
Arrays.fill(raw, (byte)'x');
VERY_LONG_STRING = new String(raw, StandardCharsets.UTF_8);
veryLongString = new String(raw, StandardCharsets.UTF_8);
}
@BeforeAll
@ -137,7 +137,7 @@ public class MessageReceivingTest
LOG.debug("Client Connected: {}", session);
session.getBasicRemote().sendText("");
session.getBasicRemote().sendText("Echo");
session.getBasicRemote().sendText(VERY_LONG_STRING);
session.getBasicRemote().sendText(veryLongString);
session.getBasicRemote().sendText("Echo");
if (LOG.isDebugEnabled())
LOG.debug("Client Message Sent");
@ -232,7 +232,7 @@ public class MessageReceivingTest
/**
* Abstract message handler implementation, used for tests.
*/
private static abstract class AbstractHandler implements MessageHandler
private abstract static class AbstractHandler implements MessageHandler
{
/**
* Message queue to put the result messages.

View File

@ -142,7 +142,7 @@ public class ClientAnnotatedEndpointScanner_GoodSignaturesTest
// The JsrAnnotatedMetadata field that should be populated
Field metadataField;
// The expected parameters for the Callable found by the scanner
Class<?> expectedParameters[];
Class<?>[] expectedParameters;
public Scenario(Class<?> pojo, Field metadataField, Class<?>... expectedParams)
{

View File

@ -39,15 +39,15 @@ public class ReflectUtilsTest
{
}
public static abstract class Apple<T extends Object> implements Fruit<T>, Color<String>
public abstract static class Apple<T extends Object> implements Fruit<T>, Color<String>
{
}
public static abstract class Cherry<A extends Object, B extends Number> implements Fruit<A>, Color<B>
public abstract static class Cherry<A extends Object, B extends Number> implements Fruit<A>, Color<B>
{
}
public static abstract class Banana implements Fruit<String>, Color<String>
public abstract static class Banana implements Fruit<String>, Color<String>
{
}

Some files were not shown because too many files have changed in this diff Show More