Author: klape
Date: 2011-04-19 13:25:14 -0400 (Tue, 19 Apr 2011)
New Revision: 14166
Modified:
stack/native/branches/jbossws-native-3.1.2.SP3-patch-02_JBPAPP-6365/
stack/native/branches/jbossws-native-3.1.2.SP3-patch-02_JBPAPP-6365/modules/core/src/main/java/org/jboss/ws/core/soap/SOAPBodyElementDoc.java
stack/native/branches/jbossws-native-3.1.2.SP3-patch-02_JBPAPP-6365/modules/core/src/main/java/org/jboss/ws/extensions/validation/SchemaExtractor.java
stack/native/branches/jbossws-native-3.1.2.SP3-patch-02_JBPAPP-6365/modules/core/src/main/java/org/jboss/ws/extensions/validation/SchemaValidationHelper.java
stack/native/branches/jbossws-native-3.1.2.SP3-patch-02_JBPAPP-6365/modules/testsuite/native-tests/src/test/java/org/jboss/test/ws/jaxws/jbws1172/JBWS1172TestCase.java
Log:
[JBAPP-6365] Merging schema validation import changes into isolated branch
Property changes on: stack/native/branches/jbossws-native-3.1.2.SP3-patch-02_JBPAPP-6365
___________________________________________________________________
Added: svn:mergeinfo
+ /stack/native/trunk:14157,14160
Modified:
stack/native/branches/jbossws-native-3.1.2.SP3-patch-02_JBPAPP-6365/modules/core/src/main/java/org/jboss/ws/core/soap/SOAPBodyElementDoc.java
===================================================================
---
stack/native/branches/jbossws-native-3.1.2.SP3-patch-02_JBPAPP-6365/modules/core/src/main/java/org/jboss/ws/core/soap/SOAPBodyElementDoc.java 2011-04-19
16:15:06 UTC (rev 14165)
+++
stack/native/branches/jbossws-native-3.1.2.SP3-patch-02_JBPAPP-6365/modules/core/src/main/java/org/jboss/ws/core/soap/SOAPBodyElementDoc.java 2011-04-19
17:25:14 UTC (rev 14166)
@@ -21,6 +21,7 @@
*/
package org.jboss.ws.core.soap;
+import java.io.InputStream;
import java.net.URL;
import javax.xml.namespace.QName;
@@ -102,6 +103,7 @@
EndpointMetaData epMetaData = msgContext.getEndpointMetaData();
feature = epMetaData.getFeature(SchemaValidationFeature.class);
URL xsdURL = feature.getSchemaLocation() != null ? new
URL(feature.getSchemaLocation()) : null;
+ InputStream[] xsdStreams = null;
if (xsdURL == null)
{
URL wsdlURL = epMetaData.getServiceMetaData().getWsdlFileOrLocation();
@@ -111,7 +113,7 @@
}
else
{
- xsdURL = schemaExtractor.getSchemaUrl(wsdlURL);
+ xsdStreams = schemaExtractor.getSchemas(wsdlURL);
}
}
if (xsdURL != null)
@@ -120,6 +122,12 @@
Element xmlDOM = DOMUtils.sourceToElement(source);
new
SchemaValidationHelper(xsdURL).setErrorHandler(errorHandler).validateDocument(xmlDOM);
}
+ else //xsdStreams != null
+ {
+ ErrorHandler errorHandler = feature.getErrorHandler();
+ Element xmlDOM = DOMUtils.sourceToElement(source);
+ new
SchemaValidationHelper(xsdStreams).setErrorHandler(errorHandler).validateDocument(xmlDOM);
+ }
}
catch (RuntimeException rte)
{
@@ -129,10 +137,6 @@
{
WSException.rethrow(ex);
}
- finally
- {
- schemaExtractor.close();
- }
}
private boolean isValidationEnabled()
Modified:
stack/native/branches/jbossws-native-3.1.2.SP3-patch-02_JBPAPP-6365/modules/core/src/main/java/org/jboss/ws/extensions/validation/SchemaExtractor.java
===================================================================
---
stack/native/branches/jbossws-native-3.1.2.SP3-patch-02_JBPAPP-6365/modules/core/src/main/java/org/jboss/ws/extensions/validation/SchemaExtractor.java 2011-04-19
16:15:06 UTC (rev 14165)
+++
stack/native/branches/jbossws-native-3.1.2.SP3-patch-02_JBPAPP-6365/modules/core/src/main/java/org/jboss/ws/extensions/validation/SchemaExtractor.java 2011-04-19
17:25:14 UTC (rev 14166)
@@ -25,8 +25,15 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
+import java.io.ByteArrayOutputStream;
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.io.FileInputStream;
import java.net.URL;
import java.util.List;
+import java.util.ArrayList;
+import java.util.regex.Pattern;
+import java.util.regex.Matcher;
import javax.xml.namespace.QName;
@@ -48,9 +55,15 @@
private static Logger log = Logger.getLogger(SchemaExtractor.class);
private File xsdFile;
+ private String path;
- public URL getSchemaUrl(URL wsdlURL) throws IOException
+ public InputStream[] getSchemas(URL wsdlURL) throws IOException
{
+ //Get the path to the WSDL
+ Pattern p = Pattern.compile("[a-zA-Z]+\\.[a-zA-Z]+$");
+ Matcher m = p.matcher(wsdlURL.getFile());
+ path = m.replaceFirst("");
+
// parse the wsdl
Element root = DOMUtils.parse(wsdlURL.openStream());
@@ -77,25 +90,64 @@
}
Element schemaElement = schemaElements.get(0);
- File tmpdir = IOUtils.createTempDirectory();
- xsdFile = File.createTempFile("jbossws_schema", ".xsd",
tmpdir);
- xsdFile.deleteOnExit();
+ List<InputStream> streams = new ArrayList<InputStream>();
- OutputStreamWriter outwr = new OutputStreamWriter(new FileOutputStream(xsdFile));
+ pullImportedSchemas(schemaElement, streams);
+
+ //Add the WSDL schema to the schema array
+ ByteArrayOutputStream outStream = new ByteArrayOutputStream();
+ OutputStreamWriter outwr = new OutputStreamWriter( outStream );
DOMWriter domWriter = new DOMWriter(outwr);
domWriter.setPrettyprint(true);
domWriter.print(schemaElement);
- outwr.close();
- return xsdFile.toURL();
+ streams.add(new ByteArrayInputStream(outStream.toByteArray()));
+
+ return streams.toArray(new InputStream[streams.size()]);
}
-
- public void close()
+
+ private void pullImportedSchemas(Element schemaElement, List<InputStream>
streams)
{
- if (xsdFile != null)
+ QName importQName = new QName( "http://www.w3.org/2001/XMLSchema",
"import" );
+ List<Element> importElements = DOMUtils.getChildElementsAsList(
schemaElement, importQName );
+
+ ArrayList<String> schemaLocations = new ArrayList<String>();
+ for( Element importElement : importElements )
{
- xsdFile.delete();
- xsdFile = null;
+ String schemaLocation = importElement.getAttribute( "schemaLocation"
);
+ schemaLocations.add( schemaLocation );
}
+
+ ByteArrayOutputStream outStream = null;
+
+ for( int i=0; i < schemaLocations.size(); i++ )
+ {
+ String schemaLocation = schemaLocations.get( i );
+
+ try
+ {
+ FileInputStream in = new FileInputStream( path + schemaLocation );
+ outStream = new ByteArrayOutputStream();
+
+ int bt = 0;
+ while(( bt = in.read() ) != -1 )
+ {
+ outStream.write( (byte)bt );
+ }
+
+ InputStream inputStream = new ByteArrayInputStream(outStream.toByteArray());
+ inputStream.mark(0);
+
+ Element root = DOMUtils.parse(inputStream);
+ pullImportedSchemas(root, streams);
+
+ inputStream.reset();
+ streams.add(inputStream);
+ }
+ catch(IOException ioe)
+ {
+ log.warn("Error obtaining schema: " + path + schemaLocation);
+ }
+ }
}
}
Modified:
stack/native/branches/jbossws-native-3.1.2.SP3-patch-02_JBPAPP-6365/modules/core/src/main/java/org/jboss/ws/extensions/validation/SchemaValidationHelper.java
===================================================================
---
stack/native/branches/jbossws-native-3.1.2.SP3-patch-02_JBPAPP-6365/modules/core/src/main/java/org/jboss/ws/extensions/validation/SchemaValidationHelper.java 2011-04-19
16:15:06 UTC (rev 14165)
+++
stack/native/branches/jbossws-native-3.1.2.SP3-patch-02_JBPAPP-6365/modules/core/src/main/java/org/jboss/ws/extensions/validation/SchemaValidationHelper.java 2011-04-19
17:25:14 UTC (rev 14166)
@@ -30,6 +30,7 @@
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
+import org.jboss.logging.Logger;
import org.jboss.wsf.common.DOMWriter;
import org.w3c.dom.Element;
import org.xml.sax.ErrorHandler;
@@ -44,13 +45,21 @@
public class SchemaValidationHelper
{
private URL xsdURL;
+ private InputStream[] xsdStreams;
private ErrorHandler errorHandler = new StrictlyValidErrorHandler();
+
+ private static Logger log = Logger.getLogger(SchemaValidationHelper.class);
public SchemaValidationHelper(URL xsdURL)
{
this.xsdURL = xsdURL;
}
+ public SchemaValidationHelper(InputStream[] xsdStreams)
+ {
+ this.xsdStreams = xsdStreams;
+ }
+
public SchemaValidationHelper setErrorHandler(ErrorHandler errorHandler)
{
this.errorHandler = errorHandler;
@@ -79,14 +88,23 @@
DocumentBuilder builder = getDocumentBuilder();
builder.parse(inxml);
}
-
+
private DocumentBuilder getDocumentBuilder() throws ParserConfigurationException
{
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setValidating(true);
factory.setNamespaceAware(true);
factory.setAttribute("http://java.sun.com/xml/jaxp/properties/schema...;,
"http://www.w3.org/2001/XMLSchema");
-
factory.setAttribute("http://java.sun.com/xml/jaxp/properties/schema...;,
xsdURL.toExternalForm());
+
+ if(xsdStreams != null)
+ {
+
factory.setAttribute("http://java.sun.com/xml/jaxp/properties/schema...;,
xsdStreams);
+ }
+ else //use xsdURL
+ {
+
factory.setAttribute("http://java.sun.com/xml/jaxp/properties/schema...;,
xsdURL.toExternalForm());
+ }
+
factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
DocumentBuilder builder = factory.newDocumentBuilder();
builder.setErrorHandler(errorHandler);
Modified:
stack/native/branches/jbossws-native-3.1.2.SP3-patch-02_JBPAPP-6365/modules/testsuite/native-tests/src/test/java/org/jboss/test/ws/jaxws/jbws1172/JBWS1172TestCase.java
===================================================================
---
stack/native/branches/jbossws-native-3.1.2.SP3-patch-02_JBPAPP-6365/modules/testsuite/native-tests/src/test/java/org/jboss/test/ws/jaxws/jbws1172/JBWS1172TestCase.java 2011-04-19
16:15:06 UTC (rev 14165)
+++
stack/native/branches/jbossws-native-3.1.2.SP3-patch-02_JBPAPP-6365/modules/testsuite/native-tests/src/test/java/org/jboss/test/ws/jaxws/jbws1172/JBWS1172TestCase.java 2011-04-19
17:25:14 UTC (rev 14166)
@@ -21,6 +21,7 @@
*/
package org.jboss.test.ws.jaxws.jbws1172;
+import java.io.InputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.net.URL;
@@ -60,19 +61,19 @@
public void testSchemaValidationPositive() throws Exception
{
URL wsdlURL =
getResourceURL("jaxws/jbws1172/WEB-INF/wsdl/TestService.wsdl");
- URL xsdURL = new SchemaExtractor().getSchemaUrl(wsdlURL);
+ InputStream[] xsdStreams = new SchemaExtractor().getSchemas(wsdlURL);
String inxml = "<performTest
xmlns='http://www.my-company.it/ws/my-test'><Code>1000</Code></performTest>";
- new SchemaValidationHelper(xsdURL).validateDocument(inxml);
+ new SchemaValidationHelper(xsdStreams).validateDocument(inxml);
}
public void testSchemaValidationNegative() throws Exception
{
URL wsdlURL =
getResourceURL("jaxws/jbws1172/WEB-INF/wsdl/TestService.wsdl");
- URL xsdURL = new SchemaExtractor().getSchemaUrl(wsdlURL);
+ InputStream[] xsdStreams = new SchemaExtractor().getSchemas(wsdlURL);
String inxml = "<performTest
xmlns='http://www.my-company.it/ws/my-test'><Code>2000</Code></performTest>";
try
{
- new SchemaValidationHelper(xsdURL).validateDocument(inxml);
+ new SchemaValidationHelper(xsdStreams).validateDocument(inxml);
}
catch (SAXException ex)
{
@@ -84,18 +85,19 @@
public void testEndpointWsdlValidation() throws Exception
{
URL wsdlURL = new URL("http://" + getServerHost() +
":8080/jaxws-jbws1172/noval?wsdl");
- URL xsdURL = new SchemaExtractor().getSchemaUrl(wsdlURL);
+ InputStream[] xsdStreams = new SchemaExtractor().getSchemas(wsdlURL);
String inxml = "<performTest
xmlns='http://www.my-company.it/ws/my-test'><Code>1000</Code></performTest>";
- new SchemaValidationHelper(xsdURL).validateDocument(inxml);
+ new SchemaValidationHelper(xsdStreams).validateDocument(inxml);
}
public void testValidatingClientWithExplicitSchema() throws Exception
{
URL wsdlURL =
getResourceURL("jaxws/jbws1172/WEB-INF/wsdl/TestService.wsdl");
- URL xsdURL = new SchemaExtractor().getSchemaUrl(wsdlURL);
+ //URL xsdURL = new SchemaExtractor().getSchemaUrl(wsdlURL);
Service service = Service.create(wsdlURL, SERVICE_NAME);
- SchemaValidationFeature feature = new SchemaValidationFeature(xsdURL.toString());
+ //SchemaValidationFeature feature = new
SchemaValidationFeature(xsdURL.toString());
+ SchemaValidationFeature feature = new SchemaValidationFeature();
MyTest port = service.getPort(MyTest.class, feature);
try
{
@@ -113,10 +115,11 @@
public void testValidatingClientWithErrorHandler() throws Exception
{
URL wsdlURL =
getResourceURL("jaxws/jbws1172/WEB-INF/wsdl/TestService.wsdl");
- URL xsdURL = new SchemaExtractor().getSchemaUrl(wsdlURL);
+ //URL xsdURL = new SchemaExtractor().getSchemaUrl(wsdlURL);
Service service = Service.create(wsdlURL, SERVICE_NAME);
- SchemaValidationFeature feature = new SchemaValidationFeature(xsdURL.toString());
+ //SchemaValidationFeature feature = new
SchemaValidationFeature(xsdURL.toString());
+ SchemaValidationFeature feature = new SchemaValidationFeature();
TestErrorHandler errorHandler = new TestErrorHandler();
feature.setErrorHandler(errorHandler);