diff --git a/jetty-http/src/main/java/org/eclipse/jetty/http/HttpURI.java b/jetty-http/src/main/java/org/eclipse/jetty/http/HttpURI.java index a2b2a06e5f3..422a24c1406 100644 --- a/jetty-http/src/main/java/org/eclipse/jetty/http/HttpURI.java +++ b/jetty-http/src/main/java/org/eclipse/jetty/http/HttpURI.java @@ -608,6 +608,15 @@ public class HttpURI return _param; } + public void setParam(String param) + { + _param = param; + if (_path != null && !_path.contains(_param)) + { + _path += ";" + _param; + } + } + public String getQuery() { return _query; diff --git a/jetty-rewrite/src/main/java/org/eclipse/jetty/rewrite/handler/RuleContainer.java b/jetty-rewrite/src/main/java/org/eclipse/jetty/rewrite/handler/RuleContainer.java index f04b7f3c1bd..11ea53e5bea 100644 --- a/jetty-rewrite/src/main/java/org/eclipse/jetty/rewrite/handler/RuleContainer.java +++ b/jetty-rewrite/src/main/java/org/eclipse/jetty/rewrite/handler/RuleContainer.java @@ -22,8 +22,10 @@ import java.io.IOException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.eclipse.jetty.http.HttpURI; import org.eclipse.jetty.server.Request; import org.eclipse.jetty.util.ArrayUtil; +import org.eclipse.jetty.util.StringUtil; import org.eclipse.jetty.util.URIUtil; import org.eclipse.jetty.util.component.Dumpable; import org.eclipse.jetty.util.log.Log; @@ -185,7 +187,18 @@ public class RuleContainer extends Rule implements Dumpable if (rule instanceof Rule.ApplyURI) ((Rule.ApplyURI)rule).applyURI(baseRequest, baseRequest.getRequestURI(), encoded); else - baseRequest.setURIPathQuery(encoded); + { + String uriPathQuery = encoded; + HttpURI baseUri = baseRequest.getHttpURI(); + // Copy path params from original URI if present + if ((baseUri != null) && StringUtil.isNotBlank(baseUri.getParam())) + { + HttpURI uri = new HttpURI(uriPathQuery); + uri.setParam(baseUri.getParam()); + uriPathQuery = uri.toString(); + } + baseRequest.setURIPathQuery(uriPathQuery); + } } if (_rewritePathInfo) diff --git a/jetty-rewrite/src/test/java/org/eclipse/jetty/rewrite/handler/CookiePatternRuleTest.java b/jetty-rewrite/src/test/java/org/eclipse/jetty/rewrite/handler/CookiePatternRuleTest.java index 45a59faa1fd..9ba8bb68bca 100644 --- a/jetty-rewrite/src/test/java/org/eclipse/jetty/rewrite/handler/CookiePatternRuleTest.java +++ b/jetty-rewrite/src/test/java/org/eclipse/jetty/rewrite/handler/CookiePatternRuleTest.java @@ -37,7 +37,6 @@ import org.eclipse.jetty.server.handler.AbstractHandler; import org.eclipse.jetty.server.handler.HandlerList; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import static org.hamcrest.MatcherAssert.assertThat; @@ -48,7 +47,6 @@ import static org.junit.jupiter.api.Assertions.fail; public class CookiePatternRuleTest { - private Server server; private LocalConnector localConnector; @@ -150,7 +148,6 @@ public class CookiePatternRuleTest } @Test - @Disabled("See #2675 for details") // TODO: needs to be fixed in RuleContainer public void testUrlParameter() throws Exception { CookiePatternRule rule = new CookiePatternRule(); @@ -170,7 +167,6 @@ public class CookiePatternRuleTest HttpTester.Response response = HttpTester.parseResponse(rawResponse); String responseContent = response.getContent(); - System.out.println(responseContent); assertResponseContentLine(responseContent, "baseRequest.requestUri=", "/other;fruit=apple"); // verify diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/StartArgs.java b/jetty-start/src/main/java/org/eclipse/jetty/start/StartArgs.java index b6151380187..d69ba92929b 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/StartArgs.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/StartArgs.java @@ -706,7 +706,7 @@ public class StartArgs } else { - cmd.addRawArg(x); + cmd.addRawArg(getProperties().expand(x)); } } diff --git a/jetty-start/src/test/java/org/eclipse/jetty/start/MainTest.java b/jetty-start/src/test/java/org/eclipse/jetty/start/MainTest.java index 0029aba2af2..e8fe18e9d38 100644 --- a/jetty-start/src/test/java/org/eclipse/jetty/start/MainTest.java +++ b/jetty-start/src/test/java/org/eclipse/jetty/start/MainTest.java @@ -31,6 +31,7 @@ import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.startsWith; @@ -169,6 +170,37 @@ public class MainTest ConfigurationAssert.assertConfiguration(baseHome, args, "assert-home-with-jvm.txt"); } + @Test + public void testJvmArgExpansion() throws Exception + { + List cmdLineArgs = new ArrayList<>(); + + Path homePath = MavenTestingUtils.getTestResourceDir("dist-home").toPath().toRealPath(); + cmdLineArgs.add("jetty.home=" + homePath.toString()); + cmdLineArgs.add("user.dir=" + homePath.toString()); + + // JVM args + cmdLineArgs.add("--exec"); + cmdLineArgs.add("-Xms1g"); + cmdLineArgs.add("-Xmx4g"); + cmdLineArgs.add("-Xloggc:${jetty.base}/logs/gc-${java.version}.log"); + + Main main = new Main(); + + StartArgs args = main.processCommandLine(cmdLineArgs.toArray(new String[cmdLineArgs.size()])); + BaseHome baseHome = main.getBaseHome(); + + assertThat("jetty.home", baseHome.getHome(), is(homePath.toString())); + assertThat("jetty.base", baseHome.getBase(), is(homePath.toString())); + + CommandLineBuilder commandLineBuilder = args.getMainArgs(true); + String commandLine = commandLineBuilder.toString("\n"); + String expectedExpansion = String.format("-Xloggc:%s/logs/gc-%s.log", + baseHome.getBase(), System.getProperty("java.version") + ); + assertThat(commandLine, containsString(expectedExpansion)); + } + @Test public void testWithModules() throws Exception { diff --git a/tests/test-distribution/src/test/java/org/eclipse/jetty/tests/distribution/DemoBaseTests.java b/tests/test-distribution/src/test/java/org/eclipse/jetty/tests/distribution/DemoBaseTests.java index 4590273f4c8..a866a22438f 100644 --- a/tests/test-distribution/src/test/java/org/eclipse/jetty/tests/distribution/DemoBaseTests.java +++ b/tests/test-distribution/src/test/java/org/eclipse/jetty/tests/distribution/DemoBaseTests.java @@ -18,11 +18,14 @@ package org.eclipse.jetty.tests.distribution; +import java.net.URI; import java.nio.file.Paths; import java.util.concurrent.TimeUnit; import org.eclipse.jetty.client.api.ContentResponse; +import org.eclipse.jetty.client.util.FormContentProvider; import org.eclipse.jetty.http.HttpStatus; +import org.eclipse.jetty.util.Fields; import org.junit.jupiter.api.Test; import static org.hamcrest.MatcherAssert.assertThat; @@ -170,4 +173,58 @@ public class DemoBaseTests extends AbstractDistributionTest assertEquals(HttpStatus.OK_200, response.getStatus()); } } + + @Test + public void testSessionDump() throws Exception + { + String jettyVersion = System.getProperty("jettyVersion"); + DistributionTester distribution = DistributionTester.Builder.newInstance() + .jettyVersion(jettyVersion) + .jettyBase(Paths.get("demo-base")) + .mavenLocalRepository(System.getProperty("mavenRepoPath")) + .build(); + + int httpPort = distribution.freePort(); + int httpsPort = distribution.freePort(); + String[] args = { + "jetty.http.port=" + httpPort, + "jetty.httpConfig.port=" + httpsPort, + "jetty.ssl.port=" + httpsPort + }; + try (DistributionTester.Run run = distribution.start(args)) + { + assertTrue(run.awaitConsoleLogsFor("Started @", 10, TimeUnit.SECONDS)); + + startHttpClient(); + client.setFollowRedirects(true); + ContentResponse response = client.GET("http://localhost:" + httpPort + "/test/session/"); + assertEquals(HttpStatus.OK_200, response.getStatus()); + + // Submit "New Session" + Fields form = new Fields(); + form.add("Action", "New Session"); + response = client.POST("http://localhost:" + httpPort + "/test/session/") + .content(new FormContentProvider(form)) + .send(); + assertEquals(HttpStatus.OK_200, response.getStatus()); + String content = response.getContentAsString(); + assertThat("Content", content, containsString("test: value
")); + assertThat("Content", content, containsString("WEBCL: {}
")); + + // Last Location + URI location = response.getRequest().getURI(); + + // Submit a "Set" for a new entry in the cookie + form = new Fields(); + form.add("Action", "Set"); + form.add("Name", "Zed"); + form.add("Value", "[alpha]"); + response = client.POST(location) + .content(new FormContentProvider(form)) + .send(); + assertEquals(HttpStatus.OK_200, response.getStatus()); + content = response.getContentAsString(); + assertThat("Content", content, containsString("Zed: [alpha]
")); + } + } } diff --git a/tests/test-webapps/test-jetty-webapp/src/main/java/com/acme/SessionDump.java b/tests/test-webapps/test-jetty-webapp/src/main/java/com/acme/SessionDump.java index 5f5d9703ba8..977771f94ab 100644 --- a/tests/test-webapps/test-jetty-webapp/src/main/java/com/acme/SessionDump.java +++ b/tests/test-webapps/test-jetty-webapp/src/main/java/com/acme/SessionDump.java @@ -41,7 +41,7 @@ public class SessionDump extends HttpServlet /** * Simple object attribute to test serialization */ - public class ObjectAttributeValue implements java.io.Serializable + public static class ObjectAttributeValue implements java.io.Serializable { long l; @@ -58,8 +58,6 @@ public class SessionDump extends HttpServlet int redirectCount = 0; - String pageType; - @Override public void init(ServletConfig config) throws ServletException @@ -67,8 +65,7 @@ public class SessionDump extends HttpServlet super.init(config); } - protected void handleForm(HttpServletRequest request, - HttpServletResponse response) + protected void handleForm(HttpServletRequest request) { HttpSession session = request.getSession(false); String action = request.getParameter("Action"); @@ -99,9 +96,9 @@ public class SessionDump extends HttpServlet @Override public void doPost(HttpServletRequest request, HttpServletResponse response) - throws ServletException, IOException + throws IOException { - handleForm(request, response); + handleForm(request); String nextUrl = getURI(request) + "?R=" + redirectCount++; String encodedUrl = response.encodeRedirectURL(nextUrl); response.sendRedirect(encodedUrl); @@ -110,9 +107,9 @@ public class SessionDump extends HttpServlet @Override public void doGet(HttpServletRequest request, HttpServletResponse response) - throws ServletException, IOException + throws IOException { - handleForm(request, response); + handleForm(request); response.setContentType("text/html"); @@ -124,6 +121,7 @@ public class SessionDump extends HttpServlet } catch (IllegalStateException e) { + log("Session already invalidated", e); session = null; }