Author: klape
Date: 2014-03-03 13:23:18 -0500 (Mon, 03 Mar 2014)
New Revision: 18455
Modified:
stack/native/branches/jbossws-native-3.1.2/modules/core/src/main/java/org/jboss/ws/core/soap/SOAPBodyElementDoc.java
stack/native/branches/jbossws-native-3.1.2/modules/core/src/main/java/org/jboss/ws/extensions/validation/SchemaExtractor.java
Log:
[JBPAPP-10869] fix the case where schemaLocation is explicitly set in annotation
Modified:
stack/native/branches/jbossws-native-3.1.2/modules/core/src/main/java/org/jboss/ws/core/soap/SOAPBodyElementDoc.java
===================================================================
---
stack/native/branches/jbossws-native-3.1.2/modules/core/src/main/java/org/jboss/ws/core/soap/SOAPBodyElementDoc.java 2014-03-03
16:58:07 UTC (rev 18454)
+++
stack/native/branches/jbossws-native-3.1.2/modules/core/src/main/java/org/jboss/ws/core/soap/SOAPBodyElementDoc.java 2014-03-03
18:23:18 UTC (rev 18455)
@@ -98,14 +98,13 @@
private void validatePayload(Source source)
{
- SchemaExtractor schemaExtractor = new SchemaExtractor();
try
{
CommonMessageContext msgContext =
MessageContextAssociation.peekMessageContext();
EndpointMetaData epMetaData = msgContext.getEndpointMetaData();
feature = epMetaData.getFeature(SchemaValidationFeature.class);
URL xsdURL = feature.getSchemaLocation() != null ? new
URL(feature.getSchemaLocation()) : null;
- Map<String, byte[]> xsdStreams = new HashMap<String, byte[]>();
+ Map<String, byte[]> xsdStreams = null;
if (xsdURL == null)
{
URL wsdlURL = epMetaData.getServiceMetaData().getWsdlFileOrLocation();
@@ -115,21 +114,18 @@
}
else
{
- xsdStreams = schemaExtractor.getSchemas(wsdlURL);
+ SchemaExtractor schemaExtractor = new SchemaExtractor(wsdlURL);
+ xsdStreams = schemaExtractor.getSchemasFromWsdl();
}
}
- if (xsdURL != null)
+ else
{
- ErrorHandler errorHandler = feature.getErrorHandler();
- Element xmlDOM = DOMUtils.sourceToElement(source);
- new
SchemaValidationHelper(xsdURL).setErrorHandler(errorHandler).validateDocument(xmlDOM);
+ SchemaExtractor schemaExtractor = new SchemaExtractor(xsdURL);
+ xsdStreams = schemaExtractor.getSchemas();
}
- else //xsdStreams != null
- {
- ErrorHandler errorHandler = feature.getErrorHandler();
- Element xmlDOM = DOMUtils.sourceToElement(source);
- new
SchemaValidationHelper(xsdStreams).setErrorHandler(errorHandler).validateDocument(xmlDOM);
- }
+ ErrorHandler errorHandler = feature.getErrorHandler();
+ Element xmlDOM = DOMUtils.sourceToElement(source);
+ new
SchemaValidationHelper(xsdStreams).setErrorHandler(errorHandler).validateDocument(xmlDOM);
}
catch (RuntimeException rte)
{
Modified:
stack/native/branches/jbossws-native-3.1.2/modules/core/src/main/java/org/jboss/ws/extensions/validation/SchemaExtractor.java
===================================================================
---
stack/native/branches/jbossws-native-3.1.2/modules/core/src/main/java/org/jboss/ws/extensions/validation/SchemaExtractor.java 2014-03-03
16:58:07 UTC (rev 18454)
+++
stack/native/branches/jbossws-native-3.1.2/modules/core/src/main/java/org/jboss/ws/extensions/validation/SchemaExtractor.java 2014-03-03
18:23:18 UTC (rev 18455)
@@ -23,10 +23,10 @@
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
+import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.io.File;
import java.io.OutputStreamWriter;
import java.net.URL;
import java.util.ArrayList;
@@ -62,8 +62,10 @@
// provide logging
private static Logger log = Logger.getLogger(SchemaExtractor.class);
private static Transformer transformer = null;
- private String path;
- static {
+ private URL topLevelResource;
+
+ static
+ {
try
{
transformer = TransformerFactory.newInstance().newTransformer();
@@ -72,18 +74,31 @@
{
throw new RuntimeException(e);
}
+ }
+ public SchemaExtractor(URL wsdlURL)
+ {
+ this.topLevelResource = wsdlURL;
}
- public Map<String, byte[]> getSchemas(URL wsdlURL) throws IOException
+
+ public Map<String, byte[]> getSchemas() throws IOException
{
Map<String, byte[]> streams = new HashMap<String, byte[]>();
- //Get the path to the WSDL
- String wsdlFile = wsdlURL.getFile();
- int lastSlash = wsdlFile.lastIndexOf(File.separator);
- path = wsdlFile.substring(0, lastSlash+1);
+ Element root = DOMUtils.parse(topLevelResource.openStream());
+ List<Element> list = new ArrayList<Element>();
+ list.add(root);
+ //no need to propagate any namespaces here
+ List<Attr> nsAttrs = new ArrayList<Attr>();
+ processSchemas(streams, list, nsAttrs);
+ return streams;
+ }
+ public Map<String, byte[]> getSchemasFromWsdl() throws IOException
+ {
+ Map<String, byte[]> streams = new HashMap<String, byte[]>();
+
// parse the wsdl
- Element root = DOMUtils.parse(wsdlURL.openStream());
+ Element root = DOMUtils.parse(topLevelResource.openStream());
List<Attr> nsAttrs = getNamespaceAttrs(root);
@@ -105,6 +120,14 @@
return null;
}
+ processSchemas(streams, schemaElements, nsAttrs);
+
+ return streams;
+ }
+
+ private void processSchemas(Map<String, byte[]> streams, List<Element>
schemaElements, List<Attr> nsAttrs)
+ throws IOException
+ {
for (Element schemaElement : schemaElements)
{
@@ -124,8 +147,6 @@
+ schemaElement.getAttribute("targetNamespace"));
}
-
-
for (Attr nsAttr : nsAttrs)
{
@@ -147,8 +168,6 @@
String tns = newSchemeElement.getAttribute("targetNamespace");
streams.put(tns, outStream.toByteArray());
}
-
- return streams;
}
private List<Attr> getNamespaceAttrs(Element element)
@@ -191,7 +210,9 @@
try
{
- FileInputStream in = new FileInputStream( path + schemaLocation );
+ URL url = new URL(topLevelResource, schemaLocation);
+ schemaLocation = url.toString();
+ InputStream in = url.openStream();
outStream = new ByteArrayOutputStream();
int bt = 0;
@@ -212,7 +233,7 @@
}
catch(IOException ioe)
{
- log.warn("Error obtaining schema: " + path + schemaLocation);
+ log.warn("Error obtaining schema: " + schemaLocation);
}
}
}