Merge branch 'jetty-9.3.x' into jetty-9.4.x
This commit is contained in:
commit
6cf0663fe8
|
@ -372,7 +372,7 @@ public class AttributeNormalizer
|
|||
}
|
||||
|
||||
if (path.startsWith(a.path))
|
||||
return String.format("${%s}/%s",a.key,a.path.relativize(path).toString());
|
||||
return String.format("${%s}%c%s",a.key,File.separatorChar,a.path.relativize(path).toString());
|
||||
}
|
||||
|
||||
return path.toString();
|
||||
|
|
|
@ -18,13 +18,19 @@
|
|||
|
||||
package org.eclipse.jetty.server;
|
||||
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.Socket;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
@ -39,9 +45,6 @@ import org.junit.Assert;
|
|||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class ServerConnectorTimeoutTest extends ConnectorTimeoutTest
|
||||
{
|
||||
@Before
|
||||
|
@ -114,7 +117,7 @@ public class ServerConnectorTimeoutTest extends ConnectorTimeoutTest
|
|||
try (Socket socket = new Socket((String)null,connector.getLocalPort()))
|
||||
{
|
||||
socket.setSoTimeout(10 * MAX_IDLE_TIME);
|
||||
socket.getOutputStream().write(request.getBytes(StandardCharsets.UTF_8));
|
||||
socket.getOutputStream().write(request.getBytes(UTF_8));
|
||||
InputStream inputStream = socket.getInputStream();
|
||||
long start = System.currentTimeMillis();
|
||||
String response = IO.toString(inputStream);
|
||||
|
@ -137,35 +140,64 @@ public class ServerConnectorTimeoutTest extends ConnectorTimeoutTest
|
|||
IO.copy(request.getInputStream(), response.getOutputStream());
|
||||
}
|
||||
});
|
||||
Socket client=newSocket(_serverURI.getHost(),_serverURI.getPort());
|
||||
Socket client = newSocket(_serverURI.getHost(), _serverURI.getPort());
|
||||
client.setSoTimeout(10000);
|
||||
|
||||
|
||||
Assert.assertFalse(client.isClosed());
|
||||
|
||||
OutputStream os=client.getOutputStream();
|
||||
InputStream is=client.getInputStream();
|
||||
|
||||
|
||||
final OutputStream os = client.getOutputStream();
|
||||
final InputStream is = client.getInputStream();
|
||||
final StringBuilder response = new StringBuilder();
|
||||
|
||||
CompletableFuture<Void> responseFuture = CompletableFuture.runAsync(() ->
|
||||
{
|
||||
try (InputStreamReader reader = new InputStreamReader(is, UTF_8))
|
||||
{
|
||||
int c;
|
||||
while ((c = reader.read()) != -1)
|
||||
{
|
||||
response.append((char) c);
|
||||
}
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
// Valid path (as connection is forcibly closed)
|
||||
// t.printStackTrace(System.err);
|
||||
}
|
||||
});
|
||||
|
||||
CompletableFuture<Void> requestFuture = CompletableFuture.runAsync(() ->
|
||||
{
|
||||
try
|
||||
{
|
||||
os.write((
|
||||
"POST /echo HTTP/1.0\r\n" +
|
||||
"host: " + _serverURI.getHost() + ":" + _serverURI.getPort() + "\r\n" +
|
||||
"content-type: text/plain; charset=utf-8\r\n" +
|
||||
"content-length: 20\r\n" +
|
||||
"\r\n").getBytes("utf-8"));
|
||||
os.flush();
|
||||
|
||||
os.write("123456789\n".getBytes("utf-8"));
|
||||
os.flush();
|
||||
TimeUnit.SECONDS.sleep(1);
|
||||
os.write("=========\n".getBytes("utf-8"));
|
||||
os.flush();
|
||||
}
|
||||
catch (InterruptedException | IOException e)
|
||||
{
|
||||
// Valid path, as write of second half of content can fail
|
||||
// e.printStackTrace(System.err);
|
||||
}
|
||||
});
|
||||
|
||||
try (StacklessLogging scope = new StacklessLogging(HttpChannel.class))
|
||||
{
|
||||
os.write((
|
||||
"POST /echo HTTP/1.0\r\n"+
|
||||
"host: "+_serverURI.getHost()+":"+_serverURI.getPort()+"\r\n"+
|
||||
"content-type: text/plain; charset=utf-8\r\n"+
|
||||
"content-length: 20\r\n"+
|
||||
"\r\n").getBytes("utf-8"));
|
||||
os.flush();
|
||||
|
||||
os.write("123456789\n".getBytes("utf-8"));
|
||||
os.flush();
|
||||
Thread.sleep(1000);
|
||||
os.write("=========\n".getBytes("utf-8"));
|
||||
os.flush();
|
||||
|
||||
Thread.sleep(2000);
|
||||
|
||||
String response =IO.toString(is);
|
||||
Assert.assertThat(response,containsString(" 500 "));
|
||||
Assert.assertThat(response, Matchers.not(containsString("=========")));
|
||||
requestFuture.get(2, TimeUnit.SECONDS);
|
||||
responseFuture.get(3, TimeUnit.SECONDS);
|
||||
|
||||
Assert.assertThat(response.toString(), containsString(" 500 "));
|
||||
Assert.assertThat(response.toString(), Matchers.not(containsString("=========")));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,12 +18,17 @@
|
|||
|
||||
package org.eclipse.jetty.websocket.server;
|
||||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import javax.servlet.DispatcherType;
|
||||
|
||||
|
@ -42,10 +47,6 @@ import org.junit.Test;
|
|||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
@RunWith(Parameterized.class)
|
||||
public class WebSocketUpgradeFilterTest
|
||||
{
|
||||
|
@ -54,6 +55,13 @@ public class WebSocketUpgradeFilterTest
|
|||
Server newServer() throws Exception;
|
||||
}
|
||||
|
||||
private static AtomicInteger uniqTestDirId = new AtomicInteger(0);
|
||||
|
||||
private static File getNewTestDir()
|
||||
{
|
||||
return MavenTestingUtils.getTargetTestingDir("WSUF-webxml-" + uniqTestDirId.getAndIncrement());
|
||||
}
|
||||
|
||||
@Parameterized.Parameters(name = "{0}")
|
||||
public static List<Object[]> data()
|
||||
{
|
||||
|
@ -188,7 +196,7 @@ public class WebSocketUpgradeFilterTest
|
|||
|
||||
cases.add(new Object[]{"wsuf/WebAppContext/web.xml/ServletContextListener", (ServerProvider) () ->
|
||||
{
|
||||
File testDir = MavenTestingUtils.getTargetTestingDir("WSUF-webxml");
|
||||
File testDir = getNewTestDir();
|
||||
|
||||
WSServer server15 = new WSServer(testDir, "/");
|
||||
|
||||
|
@ -210,7 +218,7 @@ public class WebSocketUpgradeFilterTest
|
|||
@Override
|
||||
public Server newServer() throws Exception
|
||||
{
|
||||
File testDir = MavenTestingUtils.getTargetTestingDir("WSUF-webxml");
|
||||
File testDir = getNewTestDir();
|
||||
|
||||
WSServer server = new WSServer(testDir, "/");
|
||||
|
||||
|
@ -234,7 +242,7 @@ public class WebSocketUpgradeFilterTest
|
|||
|
||||
cases.add(new Object[]{"wsuf/WebAppContext/web.xml/Servlet.init", (ServerProvider) () ->
|
||||
{
|
||||
File testDir = MavenTestingUtils.getTargetTestingDir("WSUF-webxml");
|
||||
File testDir = getNewTestDir();
|
||||
|
||||
WSServer server16 = new WSServer(testDir, "/");
|
||||
|
||||
|
@ -253,7 +261,7 @@ public class WebSocketUpgradeFilterTest
|
|||
|
||||
cases.add(new Object[]{"wsuf/WebAppContext/web.xml/ServletContextListener/alt-config", (ServerProvider) () ->
|
||||
{
|
||||
File testDir = MavenTestingUtils.getTargetTestingDir("WSUF-webxml");
|
||||
File testDir = getNewTestDir();
|
||||
|
||||
WSServer server17 = new WSServer(testDir, "/");
|
||||
|
||||
|
|
|
@ -227,7 +227,7 @@ public class AttributeNormalizerTest
|
|||
{
|
||||
// Normalize WAR deep path as File
|
||||
File testWarDeep = new File(new File(war), OS.separators("deep/ref")).getAbsoluteFile();
|
||||
assertNormalize(testWarDeep, "${WAR.path}/deep/ref");
|
||||
assertNormalize(testWarDeep, "${WAR.path}" + OS.separators("/deep/ref"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in New Issue