Skip to content

Commit

Permalink
Fix Servlet 5 Schema redirects (#5765)
Browse files Browse the repository at this point in the history
* Issue #5752 Fix servlet 5 redirects; update default servlet version

Signed-off-by: Jan Bartel <janb@webtide.com>
  • Loading branch information
janbartel authored Dec 8, 2020
1 parent b31f6b3 commit c4f8afc
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 23 deletions.
6 changes: 3 additions & 3 deletions demos/demo-jetty-webapp/src/main/webapp/WEB-INF/web.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-app
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns="https://jakarta.ee/xml/ns/jakartaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_5_0.xsd"
metadata-complete="false"
version="3.1">
version="5.0">

<display-name>Test WebApp</display-name>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-app
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns="https://jakarta.ee/xml/ns/jakartaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_5_0.xsd"
metadata-complete="false"
version="4.0">
version="5.0">

<display-name>Test Annotations WebApp</display-name>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>

<web-fragment
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns="https://jakarta.ee/xml/ns/jakartaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-fragment_3_1.xsd"
version="3.1">
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-fragment_5_0.xsd"
version="5.0">

<name>FragmentA</name>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,11 @@ public void generateQuickStartWebXml(WebAppContext context, OutputStream stream)
Map<String, String> webappAttr = new HashMap<>();
int major = context.getServletContext().getEffectiveMajorVersion();
int minor = context.getServletContext().getEffectiveMinorVersion();
webappAttr.put("xmlns", "http://xmlns.jcp.org/xml/ns/javaee");
String ns = (major < 5) ? "http://xmlns.jcp.org/xml/ns/javaee" : "https://jakarta.ee/xml/ns/jakartaee";

webappAttr.put("xmlns", ns);
webappAttr.put("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
webappAttr.put("xsi:schemaLocation", "http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_" + (major + "_" + minor) + ".xsd");
webappAttr.put("xsi:schemaLocation", String.format("%s %s/web-app_%d_%d.xsd", ns, ns, major, minor));
webappAttr.put("metadata-complete", Boolean.toString(context.getMetaData().isMetaDataComplete()));
webappAttr.put("version", major + "." + minor);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
@ManagedObject("URI Context")
public class ContextHandler extends ScopedHandler implements Attributes, Graceful
{
public static final int SERVLET_MAJOR_VERSION = 4;
public static final int SERVLET_MAJOR_VERSION = 5;
public static final int SERVLET_MINOR_VERSION = 0;
public static final Class<?>[] SERVLET_LISTENER_TYPES =
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,41 +109,48 @@ void mapResources()
final URL javaee6 = Loader.getResource("jakarta/servlet/resources/javaee_6.xsd");
final URL javaee7 = Loader.getResource("jakarta/servlet/resources/javaee_7.xsd");
final URL javaee8 = Loader.getResource("jakarta/servlet/resources/javaee_8.xsd");
final URL jakartaee9 = Loader.getResource("jakarta/servlet/resources/jakartaee_9.xsd");

final URL webapp24xsd = Loader.getResource("jakarta/servlet/resources/web-app_2_4.xsd");
final URL webapp25xsd = Loader.getResource("jakarta/servlet/resources/web-app_2_5.xsd");
final URL webapp30xsd = Loader.getResource("jakarta/servlet/resources/web-app_3_0.xsd");
final URL webapp31xsd = Loader.getResource("jakarta/servlet/resources/web-app_3_1.xsd");
final URL webapp40xsd = Loader.getResource("jakarta/servlet/resources/web-app_4_0.xsd");

final URL webapp50xsd = Loader.getResource("jakarta/servlet/resources/web-app_5_0.xsd");


final URL webcommon30xsd = Loader.getResource("jakarta/servlet/resources/web-common_3_0.xsd");
final URL webcommon31xsd = Loader.getResource("jakarta/servlet/resources/web-common_3_1.xsd");
final URL webcommon40xsd = Loader.getResource("jakarta/servlet/resources/web-common_4_0.xsd");

final URL webcommon50xsd = Loader.getResource("jakarta/servlet/resources/web-common_5_0.xsd");

final URL webfragment30xsd = Loader.getResource("jakarta/servlet/resources/web-fragment_3_0.xsd");
final URL webfragment31xsd = Loader.getResource("jakarta/servlet/resources/web-fragment_3_1.xsd");
final URL webfragment40xsd = Loader.getResource("jakarta/servlet/resources/web-fragment_4_0.xsd");

final URL webfragment50xsd = Loader.getResource("jakarta/servlet/resources/web-fragment_5_0.xsd");

final URL schemadtd = Loader.getResource("jakarta/servlet/resources/XMLSchema.dtd");
final URL xmlxsd = Loader.getResource("jakarta/servlet/resources/xml.xsd");
final URL webservice11xsd = Loader.getResource("jakarta/servlet/resources/j2ee_web_services_client_1_1.xsd");
final URL webservice12xsd = Loader.getResource("jakarta/servlet/resources/javaee_web_services_client_1_2.xsd");
final URL webservice13xsd = Loader.getResource("jakarta/servlet/resources/javaee_web_services_client_1_3.xsd");
final URL webservice14xsd = Loader.getResource("jakarta/servlet/resources/javaee_web_services_client_1_4.xsd");
final URL webservice20xsd = Loader.getResource("jakarta/servlet/resources/jakartaee_web_services_client_2_0.xsd");
final URL datatypesdtd = Loader.getResource("jakarta/servlet/resources/datatypes.dtd");

URL jsp20xsd = null;
URL jsp21xsd = null;
URL jsp22xsd = null;
URL jsp23xsd = null;

URL jsp30xsd = null;
try
{
//try both jakarta/servlet/resources and jakarta/servlet/jsp/resources to load
jsp20xsd = Loader.getResource("jakarta/servlet/resources/jsp_2_0.xsd");
jsp21xsd = Loader.getResource("jakarta/servlet/resources/jsp_2_1.xsd");
jsp22xsd = Loader.getResource("jakarta/servlet/resources/jsp_2_2.xsd");
jsp23xsd = Loader.getResource("jakarta/servlet/resources/jsp_2_3.xsd");
jsp30xsd = Loader.getResource("jakarta/servlet/resources/jsp_3_0.xsd");
}
catch (Exception e)
{
Expand All @@ -159,6 +166,8 @@ void mapResources()
jsp22xsd = Loader.getResource("jakarta/servlet/jsp/resources/jsp_2_2.xsd");
if (jsp23xsd == null)
jsp23xsd = Loader.getResource("jakarta/servlet/jsp/resources/jsp_2_3.xsd");
if (jsp30xsd == null)
jsp30xsd = Loader.getResource("jakarta/servlet/jsp/resources/jsp_3_0.xsd");
}

redirectEntity("web-app_2_2.dtd", dtd22);
Expand All @@ -177,21 +186,26 @@ void mapResources()
redirectEntity("http://java.sun.com/xml/ns/javaee/jsp_2_2.xsd", jsp22xsd);
redirectEntity("jsp_2_3.xsd", jsp23xsd);
redirectEntity("http://xmlns.jcp.org/xml/ns/javaee/jsp_2_3.xsd", jsp23xsd);

redirectEntity("jsp_3_0.xsd", jsp30xsd);
redirectEntity("https://jakarta.ee/xml/ns/jakartaee/jsp_3_0.xsd", jsp30xsd);

redirectEntity("j2ee_1_4.xsd", j2ee14xsd);
redirectEntity("http://java.sun.com/xml/ns/j2ee/j2ee_1_4.xsd", j2ee14xsd);
redirectEntity("http://java.sun.com/xml/ns/javaee/javaee_5.xsd", javaee5);
redirectEntity("http://java.sun.com/xml/ns/javaee/javaee_6.xsd", javaee6);
redirectEntity("http://xmlns.jcp.org/xml/ns/javaee/javaee_7.xsd", javaee7);
redirectEntity("http://xmlns.jcp.org/xml/ns/javaee/javaee_8.xsd", javaee8);
redirectEntity("https://jakarta.ee/xml/ns/jakartaee/javaee_9.xsd", jakartaee9);

redirectEntity("web-common_3_0.xsd", webcommon30xsd);
redirectEntity("http://java.sun.com/xml/ns/javaee/web-common_3_0.xsd", webcommon30xsd);
redirectEntity("web-common_3_1.xsd", webcommon31xsd);
redirectEntity("http://xmlns.jcp.org/xml/ns/javaee/web-common_3_1.xsd", webcommon31xsd);
redirectEntity("web-common_4_0.xsd", webcommon40xsd);
redirectEntity("http://xmlns.jcp.org/xml/ns/javaee/web-common_4_0.xsd", webcommon40xsd);

redirectEntity("web-common_5_0.xsd", webcommon50xsd);
redirectEntity("https://jakarta.ee/xml/ns/jakartaee/web-common_5_0.xsd", webcommon50xsd);

redirectEntity("web-app_2_4.xsd", webapp24xsd);
redirectEntity("http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd", webapp24xsd);
redirectEntity("web-app_2_5.xsd", webapp25xsd);
Expand All @@ -202,21 +216,28 @@ void mapResources()
redirectEntity("http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd", webapp31xsd);
redirectEntity("web-app_4_0.xsd", webapp40xsd);
redirectEntity("http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd", webapp40xsd);

// Handle linewrap hyphon error in PDF spec
redirectEntity("web-app_5_0.xsd", webapp50xsd);
redirectEntity("https://jakarta.ee/xml/ns/jakartaee/web-app_5_0.xsd", webapp50xsd);

// Handle linewrap hyphen error in PDF spec
redirectEntity("webapp_4_0.xsd", webapp40xsd);
redirectEntity("http://xmlns.jcp.org/xml/ns/javaee/webapp_4_0.xsd", webapp40xsd);

redirectEntity("webapp_5_0.xsd", webapp50xsd);
redirectEntity("https://jakarta.ee/xml/ns/jakartaee/webapp_5_0.xsd", webapp50xsd);

// handle jakartaee coordinates
redirectEntity("http://xmlns.eclipse.org/xml/ns/jakartaee/web-app_4_0.xsd", webapp40xsd);

redirectEntity("https://jakarta.ee/xml/ns/jakartaee/web-app_5_0.xsd", webapp50xsd);

redirectEntity("web-fragment_3_0.xsd", webfragment30xsd);
redirectEntity("http://java.sun.com/xml/ns/javaee/web-fragment_3_0.xsd", webfragment30xsd);
redirectEntity("web-fragment_3_1.xsd", webfragment31xsd);
redirectEntity("http://xmlns.jcp.org/xml/ns/javaee/web-fragment_3_1.xsd", webfragment31xsd);
redirectEntity("web-fragment_4_0.xsd", webfragment40xsd);
redirectEntity("http://xmlns.jcp.org/xml/ns/javaee/web-fragment_4_0.xsd", webfragment40xsd);

redirectEntity("web-fragment_5_0.xsd", webfragment50xsd);
redirectEntity("https://jakarta.ee/xml/ns/jakartaee/web-fragment_5_0.xsd", webfragment50xsd);

redirectEntity("xml.xsd", xmlxsd);
redirectEntity("http://www.w3.org/2001/xml.xsd", xmlxsd);
redirectEntity("datatypes.dtd", datatypesdtd);
Expand All @@ -230,6 +251,8 @@ void mapResources()
redirectEntity("http://java.sun.com/xml/ns/javaee/javaee_web_services_client_1_3.xsd", webservice13xsd);
redirectEntity("javaee_web_services_client_1_4.xsd", webservice14xsd);
redirectEntity("http://xmlns.jcp.org/xml/ns/javaee/javaee_web_services_client_1_4.xsd", webservice14xsd);
redirectEntity("jakartaee_web_services_client_2_0.xsd", webservice20xsd);
redirectEntity("https://jakarta.ee/xml/ns/jakartaee/jakartaee_web_services_client_2_0.xsd", webservice20xsd);
}
};

Expand Down

0 comments on commit c4f8afc

Please sign in to comment.