Issue #8921 Fix normalization of META-INF resources for quickstart (#8922)

* Issue #8921 Fix normalization of META-INF resources for quickstart
This commit is contained in:
Jan Bartel 2022-12-06 08:51:44 +11:00 committed by GitHub
parent f29dd66804
commit 91c7a51cbc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 31 additions and 15 deletions

View File

@ -112,8 +112,6 @@
<pomExclude>jetty-start-gwt-it/pom.xml</pomExclude>
<!-- bean-validation-webapp-2.25.1.war is not jakarta namespace ready -->
<pomExclude>jetty-start-war-mojo-it/pom.xml</pomExclude>
<!-- enable again when METAINF_RESOURCES is not normalized -->
<pomExclude>jetty-effective-web-xml-it/pom.xml</pomExclude>
</pomExcludes>
<scriptVariables>
<jettyStopKey>${jetty.stopKey}</jettyStopKey>

View File

@ -58,6 +58,7 @@ import org.eclipse.jetty.http.MimeTypes;
import org.eclipse.jetty.util.QuotedStringTokenizer;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.resource.AttributeNormalizer;
import org.eclipse.jetty.util.resource.Resource;
import org.eclipse.jetty.util.security.Constraint;
import org.eclipse.jetty.xml.XmlAppendable;
import org.slf4j.Logger;
@ -165,9 +166,9 @@ public class QuickStartGeneratorConfiguration extends AbstractConfiguration
out.tag("display-name", context.getDisplayName());
// Set some special context parameters
// The location of the war file on disk
AttributeNormalizer normalizer = new AttributeNormalizer(context.getBaseResource());
Resource base = context.getBaseResource();
base = (base != null ? base.iterator().next() : null);
AttributeNormalizer normalizer = new AttributeNormalizer(base);
// The library order
addContextParamFromAttribute(context, out, ServletContext.ORDERED_LIBS);

View File

@ -140,12 +140,20 @@ public class QuickStartTest
server.setHandler(webapp);
server.start();
URL url = new URL("http://127.0.0.1:" + server.getBean(NetworkConnector.class).getLocalPort() + "/test/");
//test static content added by fragment
URL url = new URL("http://127.0.0.1:" + server.getBean(NetworkConnector.class).getLocalPort() + "/fragmentA/index.html");
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
assertEquals(200, connection.getResponseCode());
String content = IO.toString((InputStream)connection.getContent());
assertThat(content, Matchers.containsString("Welcome to a Fragment"));
//test annotations etc
url = new URL("http://127.0.0.1:" + server.getBean(NetworkConnector.class).getLocalPort() + "/test/");
connection = (HttpURLConnection)url.openConnection();
connection.setRequestMethod("POST");
assertEquals(200, connection.getResponseCode());
String content = IO.toString((InputStream)connection.getContent());
content = IO.toString((InputStream)connection.getContent());
assertThat(content, Matchers.containsString("Results"));
assertThat(content, Matchers.not(Matchers.containsString("FAIL")));
server.stop();

View File

@ -450,7 +450,7 @@ public class MetaInfConfiguration extends AbstractConfiguration
private static boolean isEmptyResource(Resource resourcesDir)
{
return !Resources.isReadableFile(resourcesDir);
return !Resources.isReadableDirectory(resourcesDir);
}
/**

View File

@ -111,7 +111,7 @@
<!-- bean-validation-webapp-2.25.1.war is not jakarta namespace ready -->
<pomExclude>jetty-start-war-mojo-it/pom.xml</pomExclude>
<!-- enable when normalization of META-INF resources is removed -->
<pomExclude>jetty-effective-web-xml-it/pom.xml</pomExclude>
<!-- pomExclude>jetty-effective-web-xml-it/pom.xml</pomExclude -->
</pomExcludes>
<scriptVariables>
<jettyStopKey>${jetty.stopKey}</jettyStopKey>

View File

@ -58,6 +58,7 @@ import org.eclipse.jetty.http.MimeTypes;
import org.eclipse.jetty.util.QuotedStringTokenizer;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.resource.AttributeNormalizer;
import org.eclipse.jetty.util.resource.Resource;
import org.eclipse.jetty.util.security.Constraint;
import org.eclipse.jetty.xml.XmlAppendable;
import org.slf4j.Logger;
@ -165,9 +166,9 @@ public class QuickStartGeneratorConfiguration extends AbstractConfiguration
out.tag("display-name", context.getDisplayName());
// Set some special context parameters
// The location of the war file on disk
AttributeNormalizer normalizer = new AttributeNormalizer(context.getBaseResource());
Resource base = context.getBaseResource();
base = (base != null ? base.iterator().next() : null);
AttributeNormalizer normalizer = new AttributeNormalizer(base);
// The library order
addContextParamFromAttribute(context, out, ServletContext.ORDERED_LIBS);

View File

@ -149,13 +149,21 @@ public class QuickStartTest
server.setHandler(webapp);
server.start();
URL url = new URL("http://127.0.0.1:" + server.getBean(NetworkConnector.class).getLocalPort() + "/test/");
//test fragment static resource
URL url = new URL("http://127.0.0.1:" + server.getBean(NetworkConnector.class).getLocalPort() + "/fragmentA/index.html");
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
assertEquals(200, connection.getResponseCode());
String content = IO.toString((InputStream)connection.getContent());
assertThat(content, Matchers.containsString("Welcome to a Fragment"));
//test annotations etc etc
url = new URL("http://127.0.0.1:" + server.getBean(NetworkConnector.class).getLocalPort() + "/test/");
connection = (HttpURLConnection)url.openConnection();
connection.setRequestMethod("POST");
assertEquals(200, connection.getResponseCode());
String content = IO.toString((InputStream)connection.getContent());
content = IO.toString((InputStream)connection.getContent());
assertThat(content, Matchers.containsString("Results"));
assertThat(content, Matchers.not(Matchers.containsString("FAIL")));
server.stop();