You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by jb...@apache.org on 2013/11/26 05:30:45 UTC

svn commit: r1545537 - in /tomcat/trunk/test: org/apache/jasper/compiler/TestJspDocumentParser.java webapp/valid.jspx webapp/valid.xsd

Author: jboynes
Date: Tue Nov 26 04:30:45 2013
New Revision: 1545537

URL: http://svn.apache.org/r1545537
Log:
add testcase to show problem with XSD validation of JSP documents

Added:
    tomcat/trunk/test/webapp/valid.jspx   (with props)
    tomcat/trunk/test/webapp/valid.xsd   (with props)
Modified:
    tomcat/trunk/test/org/apache/jasper/compiler/TestJspDocumentParser.java

Modified: tomcat/trunk/test/org/apache/jasper/compiler/TestJspDocumentParser.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/jasper/compiler/TestJspDocumentParser.java?rev=1545537&r1=1545536&r2=1545537&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/jasper/compiler/TestJspDocumentParser.java (original)
+++ tomcat/trunk/test/org/apache/jasper/compiler/TestJspDocumentParser.java Tue Nov 26 04:30:45 2013
@@ -21,13 +21,21 @@ import java.io.File;
 import java.io.IOException;
 
 import javax.servlet.http.HttpServletResponse;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
 
 import org.junit.Assert;
+import org.junit.Ignore;
 import org.junit.Test;
 
+import org.apache.catalina.Context;
 import org.apache.catalina.startup.Tomcat;
 import org.apache.catalina.startup.TomcatBaseTest;
 import org.apache.tomcat.util.buf.ByteChunk;
+import org.w3c.dom.Document;
+import org.xml.sax.ErrorHandler;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
 
 public class TestJspDocumentParser extends TomcatBaseTest {
 
@@ -111,4 +119,44 @@ public class TestJspDocumentParser exten
                 "/test/bug5nnnn/bug54821b.jspx", bc, null);
         Assert.assertEquals(HttpServletResponse.SC_OK, rc);
    }
+
+    @Test
+    @Ignore
+    public void testSchemaValidation() throws Exception {
+        Tomcat tomcat = getTomcatInstance();
+
+        File appDir = new File("test/webapp");
+        // app dir is relative to server home
+        Context context = tomcat.addWebapp(null, "/test", appDir.getAbsolutePath());
+        context.setXmlValidationJspDoc(true);
+
+        tomcat.start();
+
+        ByteChunk bc = new ByteChunk();
+        String path = "http://localhost:" + getPort() + "/test/valid.jspx";
+        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+        dbf.setNamespaceAware(true);
+        dbf.setValidating(true);
+        dbf.setFeature("http://apache.org/xml/features/validation/schema", true);
+        DocumentBuilder db = dbf.newDocumentBuilder();
+        db.setErrorHandler(new ErrorHandler() {
+            @Override
+            public void warning(SAXParseException exception) throws SAXException {
+                throw exception;
+            }
+
+            @Override
+            public void error(SAXParseException exception) throws SAXException {
+                throw exception;
+            }
+
+            @Override
+            public void fatalError(SAXParseException exception) throws SAXException {
+                throw exception;
+            }
+        });
+        Document document = db.parse(path);
+        Assert.assertEquals("urn:valid", document.getDocumentElement().getNamespaceURI());
+        Assert.assertEquals("root", document.getDocumentElement().getLocalName());
+   }
 }

Added: tomcat/trunk/test/webapp/valid.jspx
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/webapp/valid.jspx?rev=1545537&view=auto
==============================================================================
--- tomcat/trunk/test/webapp/valid.jspx (added)
+++ tomcat/trunk/test/webapp/valid.jspx Tue Nov 26 04:30:45 2013
@@ -0,0 +1,22 @@
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<root xmlns="urn:valid"
+      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+      xmlns:jsp="http://java.sun.com/JSP/Page"
+      xsi:schemaLocation="urn:valid valid.xsd">
+    <jsp:text>Hello World</jsp:text>
+</root>
\ No newline at end of file

Propchange: tomcat/trunk/test/webapp/valid.jspx
------------------------------------------------------------------------------
    svn:eol-style = native

Added: tomcat/trunk/test/webapp/valid.xsd
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/webapp/valid.xsd?rev=1545537&view=auto
==============================================================================
--- tomcat/trunk/test/webapp/valid.xsd (added)
+++ tomcat/trunk/test/webapp/valid.xsd Tue Nov 26 04:30:45 2013
@@ -0,0 +1,20 @@
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+<schema xmlns="http://www.w3.org/2001/XMLSchema"
+    targetNamespace="urn:valid">
+  <element name="root" type="string"/>
+</schema>

Propchange: tomcat/trunk/test/webapp/valid.xsd
------------------------------------------------------------------------------
    svn:eol-style = native



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org