You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2008/01/14 17:46:15 UTC
svn commit: r611850 - in /incubator/cxf/branches/2.0.x-fixes: ./
api/src/main/java/org/apache/cxf/wsdl/EndpointReferenceUtils.java
rt/core/src/main/java/org/apache/cxf/databinding/source/AbstractDataBinding.java
Author: dkulp
Date: Mon Jan 14 08:46:13 2008
New Revision: 611850
URL: http://svn.apache.org/viewvc?rev=611850&view=rev
Log:
Merged revisions 611188 via svnmerge from
https://svn.apache.org/repos/asf/incubator/cxf/trunk
........
r611188 | bimargulies | 2008-01-11 09:42:26 -0500 (Fri, 11 Jan 2008) | 2 lines
Improve esthetics of some of the code related to schema validation.
........
Modified:
incubator/cxf/branches/2.0.x-fixes/ (props changed)
incubator/cxf/branches/2.0.x-fixes/api/src/main/java/org/apache/cxf/wsdl/EndpointReferenceUtils.java
incubator/cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/databinding/source/AbstractDataBinding.java
Propchange: incubator/cxf/branches/2.0.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.
Modified: incubator/cxf/branches/2.0.x-fixes/api/src/main/java/org/apache/cxf/wsdl/EndpointReferenceUtils.java
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/2.0.x-fixes/api/src/main/java/org/apache/cxf/wsdl/EndpointReferenceUtils.java?rev=611850&r1=611849&r2=611850&view=diff
==============================================================================
--- incubator/cxf/branches/2.0.x-fixes/api/src/main/java/org/apache/cxf/wsdl/EndpointReferenceUtils.java (original)
+++ incubator/cxf/branches/2.0.x-fixes/api/src/main/java/org/apache/cxf/wsdl/EndpointReferenceUtils.java Mon Jan 14 08:46:13 2008
@@ -21,6 +21,8 @@
import java.io.InputStream;
import java.io.Reader;
+import java.io.StringReader;
+import java.io.StringWriter;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
@@ -58,7 +60,6 @@
import org.apache.cxf.common.i18n.Message;
import org.apache.cxf.common.logging.LogUtils;
import org.apache.cxf.common.util.StringUtils;
-import org.apache.cxf.common.xmlschema.SchemaCollection;
import org.apache.cxf.endpoint.EndpointResolverRegistry;
import org.apache.cxf.endpoint.Server;
import org.apache.cxf.endpoint.ServerRegistry;
@@ -80,6 +81,70 @@
*/
public final class EndpointReferenceUtils {
+ /**
+ * We want to load the schemas, including references to external schemas, into a SchemaFactory
+ * to validate. There seem to be bugs in resolving inter-schema references in Xerces, so even when we are
+ * handing the factory all the schemas, interrelated with <import> elements, we need
+ * to also hand over extra copies (!) as character images when requested.
+ *
+ * To do this, we use the DOM representation kept in the SchemaInfo. This has the bonus
+ * of benefiting from the use of the catalog resolver in there, which is missing from
+ * the code in here.
+ */
+ private static final class SchemaLSResourceResolver implements LSResourceResolver {
+ private final ServiceInfo si;
+
+ private SchemaLSResourceResolver(ServiceInfo serviceInfo) {
+ this.si = serviceInfo;
+ }
+
+ private Reader getSchemaAsStream(Element schemaElement) {
+ DOMSource source = new DOMSource(schemaElement);
+ StringWriter writer = new StringWriter();
+ StreamResult result = new StreamResult(writer);
+ try {
+ TransformerFactory.newInstance().newTransformer().transform(source, result);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ return new StringReader(writer.toString());
+ }
+
+ public LSInput resolveResource(String type, String namespaceURI, String publicId,
+ String systemId, String baseURI) {
+ for (SchemaInfo schemaInfo : si.getSchemas()) {
+ XmlSchema sch = schemaInfo.getSchema();
+ if (namespaceURI.equals(sch.getTargetNamespace())) {
+ LSInputImpl impl = new LSInputImpl();
+ Element schemaAsDom = schemaInfo.getElement();
+ if (schemaAsDom != null) {
+ impl.setCharacterStream(getSchemaAsStream(schemaAsDom));
+ return impl;
+ }
+ // otherwise, go ahead and assume it's out there somewhere.
+ // this needs catalog support, does it not?
+ InputStream ins = null;
+ try {
+ URL url = new URL(sch.getSourceURI());
+ ins = url.openStream();
+ } catch (Exception e) {
+ //ignore, we'll just use what we have. (though
+ //bugs in XmlSchema could make this less useful)
+ }
+
+ if (ins == null) {
+ LoadingByteArrayOutputStream out = new LoadingByteArrayOutputStream();
+ sch.write(out);
+ ins = out.createInputStream();
+ }
+ impl.setByteStream(ins);
+ return impl;
+ }
+ }
+ return null;
+ }
+ }
+
public static final String ANONYMOUS_ADDRESS = "http://www.w3.org/2005/08/addressing/anonymous";
private static final Logger LOG = LogUtils.getL7dLogger(EndpointReferenceUtils.class);
@@ -445,52 +510,26 @@
SchemaFactory factory = SchemaFactory.newInstance(
XMLConstants.W3C_XML_SCHEMA_NS_URI);
List<Source> schemaSources = new ArrayList<Source>();
- final SchemaCollection sc = serviceInfo.getXmlSchemaCollection();
for (SchemaInfo schemaInfo : serviceInfo.getSchemas()) {
Source source = new DOMSource(schemaInfo.getElement());
- if (source != null) {
- source.setSystemId(schemaInfo.getElement().getBaseURI());
- schemaSources.add(source);
+ String baseURI = schemaInfo.getElement().getBaseURI();
+ if (baseURI != null) {
+ source.setSystemId(baseURI);
+ } else {
+ source.setSystemId(schemaInfo.getSystemId());
}
+ schemaSources.add(source);
}
try {
- factory.setResourceResolver(new LSResourceResolver() {
- public LSInput resolveResource(String type, String namespaceURI, String publicId,
- String systemId, String baseURI) {
- for (XmlSchema sch : sc.getXmlSchemas()) {
- if (namespaceURI.equals(sch.getTargetNamespace())) {
- LSInputImpl impl = new LSInputImpl();
- InputStream ins = null;
- try {
- URL url = new URL(sch.getSourceURI());
- ins = url.openStream();
- } catch (Exception e) {
- //ignore, we'll just use what we have. (though
- //bugs in XmlSchema could make this less useful)
- }
-
- if (ins == null) {
- LoadingByteArrayOutputStream out = new LoadingByteArrayOutputStream();
- sch.write(out);
- ins = out.createInputStream();
- }
- impl.setByteStream(ins);
- return impl;
- }
- }
- return null;
- }
-
- });
- schema = factory.newSchema(schemaSources.toArray(
- new Source[schemaSources.size()]));
+ factory.setResourceResolver(new SchemaLSResourceResolver(serviceInfo));
+ schema = factory.newSchema(schemaSources.toArray(new Source[schemaSources.size()]));
if (schema != null) {
serviceInfo.setProperty(Schema.class.getName(), schema);
LOG.log(Level.FINE, "Obtained schema from ServiceInfo");
}
} catch (SAXException ex) {
// Something not right with the schema from the wsdl.
- LOG.log(Level.WARNING, "SAXException for newSchema()", ex);
+ LOG.log(Level.WARNING, "SAXException for newSchema() on ", ex);
}
}
Modified: incubator/cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/databinding/source/AbstractDataBinding.java
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/databinding/source/AbstractDataBinding.java?rev=611850&r1=611849&r2=611850&view=diff
==============================================================================
--- incubator/cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/databinding/source/AbstractDataBinding.java (original)
+++ incubator/cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/databinding/source/AbstractDataBinding.java Mon Jan 14 08:46:13 2008
@@ -69,7 +69,7 @@
}
SchemaInfo schema = new SchemaInfo(serviceInfo, ns);
schema.setSystemId(systemId);
- XmlSchema xmlSchema = col.read(d.getDocumentElement());
+ XmlSchema xmlSchema = col.read(d, null);
schema.setSchema(xmlSchema);
serviceInfo.addSchema(schema);
return xmlSchema;