Merge remote-tracking branch 'origin/jetty-9.4.x' into jetty-10.0.x

This commit is contained in:
Lachlan Roberts 2020-10-16 15:37:24 +11:00
commit 5800f4605f
4 changed files with 31 additions and 41 deletions

View File

@ -18,7 +18,6 @@
package org.eclipse.jetty; package org.eclipse.jetty;
import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.lang.management.ManagementFactory; import java.lang.management.ManagementFactory;
import java.nio.file.FileSystems; import java.nio.file.FileSystems;
@ -111,8 +110,8 @@ public class TestServer
login.setConfig(jettyRoot.resolve("tests/test-webapps/test-jetty-webapp/src/main/config/demo-base/etc/realm.properties").toString()); login.setConfig(jettyRoot.resolve("tests/test-webapps/test-jetty-webapp/src/main/config/demo-base/etc/realm.properties").toString());
server.addBean(login); server.addBean(login);
File log = File.createTempFile("jetty-yyyy_mm_dd", "log"); Path logPath = Files.createTempFile("jetty-yyyy_mm_dd", "log");
CustomRequestLog requestLog = new CustomRequestLog(log.toString()); CustomRequestLog requestLog = new CustomRequestLog(logPath.toString());
server.setRequestLog(requestLog); server.setRequestLog(requestLog);
server.setStopAtShutdown(true); server.setStopAtShutdown(true);
@ -127,15 +126,11 @@ public class TestServer
); );
webapp.setAttribute("testAttribute", "testValue"); webapp.setAttribute("testAttribute", "testValue");
File sessiondir = File.createTempFile("sessions", null); Path sessionDir = Files.createTempDirectory("sessions");
if (sessiondir.exists())
sessiondir.delete();
sessiondir.mkdir();
sessiondir.deleteOnExit();
DefaultSessionCache ss = new DefaultSessionCache(webapp.getSessionHandler()); DefaultSessionCache ss = new DefaultSessionCache(webapp.getSessionHandler());
FileSessionDataStore sds = new FileSessionDataStore(); FileSessionDataStore sds = new FileSessionDataStore();
ss.setSessionDataStore(sds); ss.setSessionDataStore(sds);
sds.setStoreDir(sessiondir); sds.setStoreDir(sessionDir.toFile());
webapp.getSessionHandler().setSessionCache(ss); webapp.getSessionHandler().setSessionCache(ss);
contexts.addHandler(webapp); contexts.addHandler(webapp);

View File

@ -71,7 +71,6 @@ import org.eclipse.jetty.io.ClientConnector;
import org.eclipse.jetty.io.MappedByteBufferPool; import org.eclipse.jetty.io.MappedByteBufferPool;
import org.eclipse.jetty.server.HttpConfiguration; import org.eclipse.jetty.server.HttpConfiguration;
import org.eclipse.jetty.server.Request; import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.handler.AbstractHandler;
import org.eclipse.jetty.util.BufferUtil; import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.ssl.SslContextFactory; import org.eclipse.jetty.util.ssl.SslContextFactory;
@ -187,12 +186,11 @@ public class HttpClientTransportOverHTTP2Test extends AbstractTest
@Test @Test
public void testRequestHasHTTP2Version() throws Exception public void testRequestHasHTTP2Version() throws Exception
{ {
start(new AbstractHandler() start(new EmptyServerHandler()
{ {
@Override @Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) protected void service(String target, Request jettyRequest, HttpServletRequest request, HttpServletResponse response)
{ {
baseRequest.setHandled(true);
HttpVersion version = HttpVersion.fromString(request.getProtocol()); HttpVersion version = HttpVersion.fromString(request.getProtocol());
response.setStatus(version == HttpVersion.HTTP_2 ? HttpStatus.OK_200 : HttpStatus.INTERNAL_SERVER_ERROR_500); response.setStatus(version == HttpVersion.HTTP_2 ? HttpStatus.OK_200 : HttpStatus.INTERNAL_SERVER_ERROR_500);
} }
@ -313,12 +311,11 @@ public class HttpClientTransportOverHTTP2Test extends AbstractTest
{ {
String path = "/path"; String path = "/path";
String query = "a=b"; String query = "a=b";
start(new AbstractHandler() start(new EmptyServerHandler()
{ {
@Override @Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) protected void service(String target, Request jettyRequest, HttpServletRequest request, HttpServletResponse response)
{ {
baseRequest.setHandled(true);
assertEquals(path, request.getRequestURI()); assertEquals(path, request.getRequestURI());
assertEquals(query, request.getQueryString()); assertEquals(query, request.getQueryString());
} }
@ -337,12 +334,11 @@ public class HttpClientTransportOverHTTP2Test extends AbstractTest
{ {
String path = "/path"; String path = "/path";
String query = "a=b"; String query = "a=b";
start(new AbstractHandler() start(new EmptyServerHandler()
{ {
@Override @Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) protected void service(String target, Request jettyRequest, HttpServletRequest request, HttpServletResponse response)
{ {
baseRequest.setHandled(true);
assertEquals(path, request.getRequestURI()); assertEquals(path, request.getRequestURI());
assertEquals(query, request.getQueryString()); assertEquals(query, request.getQueryString());
} }

View File

@ -21,6 +21,8 @@ package org.eclipse.jetty.webapp;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.URI; import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Locale; import java.util.Locale;
import org.eclipse.jetty.server.Connector; import org.eclipse.jetty.server.Connector;
@ -102,14 +104,10 @@ public class WebInfConfiguration extends AbstractConfiguration
@Override @Override
public void cloneConfigure(WebAppContext template, WebAppContext context) throws Exception public void cloneConfigure(WebAppContext template, WebAppContext context) throws Exception
{ {
File tmpDir = File.createTempFile(WebInfConfiguration.getCanonicalNameForWebAppTmpDir(context), "", template.getTempDirectory().getParentFile()); Path tmpDir = Files.createTempDirectory(template.getTempDirectory().getParentFile().toPath(), WebInfConfiguration.getCanonicalNameForWebAppTmpDir(context));
if (tmpDir.exists()) File tmpDirAsFile = tmpDir.toFile();
{ tmpDirAsFile.deleteOnExit();
IO.delete(tmpDir); context.setTempDirectory(tmpDirAsFile);
}
tmpDir.mkdir();
tmpDir.deleteOnExit();
context.setTempDirectory(tmpDir);
} }
/** /**
@ -237,11 +235,7 @@ public class WebInfConfiguration extends AbstractConfiguration
else else
{ {
//ensure file will always be unique by appending random digits //ensure file will always be unique by appending random digits
tmpDir = File.createTempFile(temp, ".dir", parent); tmpDir = Files.createTempDirectory(parent.toPath(), temp).toFile();
//delete the file that was created
tmpDir.delete();
//and make a directory of the same name
tmpDir.mkdirs();
} }
configureTempDirectory(tmpDir, context); configureTempDirectory(tmpDir, context);

View File

@ -20,9 +20,13 @@ package org.eclipse.jetty.server.session;
import java.io.File; import java.io.File;
import java.lang.annotation.ElementType; import java.lang.annotation.ElementType;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Properties; import java.util.Properties;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils; import org.eclipse.jetty.toolchain.test.FS;
import org.eclipse.jetty.toolchain.test.jupiter.WorkDir;
import org.eclipse.jetty.toolchain.test.jupiter.WorkDirExtension;
import org.eclipse.jetty.util.IO; import org.eclipse.jetty.util.IO;
import org.hibernate.search.cfg.Environment; import org.hibernate.search.cfg.Environment;
import org.hibernate.search.cfg.SearchMapping; import org.hibernate.search.cfg.SearchMapping;
@ -33,6 +37,7 @@ import org.infinispan.configuration.cache.Index;
import org.infinispan.configuration.global.GlobalConfigurationBuilder; import org.infinispan.configuration.global.GlobalConfigurationBuilder;
import org.infinispan.manager.DefaultCacheManager; import org.infinispan.manager.DefaultCacheManager;
import org.infinispan.manager.EmbeddedCacheManager; import org.infinispan.manager.EmbeddedCacheManager;
import org.junit.jupiter.api.extension.ExtendWith;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
@ -40,8 +45,10 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
/** /**
* InfinispanTestSupport * InfinispanTestSupport
*/ */
@ExtendWith(WorkDirExtension.class)
public class InfinispanTestSupport public class InfinispanTestSupport
{ {
public WorkDir workDir;
public static final String DEFAULT_CACHE_NAME = "session_test_cache"; public static final String DEFAULT_CACHE_NAME = "session_test_cache";
public Cache _cache; public Cache _cache;
@ -95,22 +102,20 @@ public class InfinispanTestSupport
public void setup() throws Exception public void setup() throws Exception
{ {
File testdir = MavenTestingUtils.getTargetTestingDir(); Path root = workDir.getEmptyPathDir();
File tmp = new File(testdir, "indexes"); Path indexesDir = root.resolve("indexes");
IO.delete(tmp); FS.ensureDirExists(indexesDir);
tmp.mkdirs();
SearchMapping mapping = new SearchMapping(); SearchMapping mapping = new SearchMapping();
mapping.entity(SessionData.class).indexed().providedId().property("expiry", ElementType.FIELD).field(); mapping.entity(SessionData.class).indexed().providedId().property("expiry", ElementType.FIELD).field();
Properties properties = new Properties(); Properties properties = new Properties();
properties.put(Environment.MODEL_MAPPING, mapping); properties.put(Environment.MODEL_MAPPING, mapping);
properties.put("hibernate.search.default.indexBase", tmp.getAbsolutePath()); properties.put("hibernate.search.default.indexBase", indexesDir.toString());
if (_useFileStore) if (_useFileStore)
{ {
_tmpdir = File.createTempFile("infini", "span"); Path tmpDir = Files.createTempDirectory("infinispan");
_tmpdir.delete(); _tmpdir = tmpDir.toFile();
_tmpdir.mkdir();
ConfigurationChildBuilder b = _builder.indexing() ConfigurationChildBuilder b = _builder.indexing()
.index(Index.ALL) .index(Index.ALL)