Merge pull request #4337 from eclipse/jetty-9.4.x-4329-rewrite-rules-demobase
Issue #4329 - Fixing RuleContainer to handle path parameters
This commit is contained in:
commit
380cebc3bb
|
@ -573,6 +573,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;
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 org.junit.jupiter.api.condition.DisabledOnJre;
|
||||
import org.junit.jupiter.api.condition.JRE;
|
||||
|
@ -173,4 +176,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("<b>test:</b> value<br/>"));
|
||||
assertThat("Content", content, containsString("<b>WEBCL:</b> {}<br/>"));
|
||||
|
||||
// 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("<b>Zed:</b> [alpha]<br/>"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue