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 2007/10/31 20:39:10 UTC
svn commit: r590798 - in /incubator/cxf/branches/2.0.x-fixes: ./
api/src/main/java/org/apache/cxf/wsdl/EndpointReferenceUtils.java
Author: dkulp
Date: Wed Oct 31 12:39:09 2007
New Revision: 590798
URL: http://svn.apache.org/viewvc?rev=590798&view=rev
Log:
Merged revisions 590770 via svnmerge from
https://svn.apache.org/repos/asf/incubator/cxf/trunk
........
r590770 | dkulp | 2007-10-31 13:52:50 -0400 (Wed, 31 Oct 2007) | 2 lines
[CXF-1149] Use the URL's for the schemas from the SchemaCollection for 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
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=590798&r1=590797&r2=590798&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 Wed Oct 31 12:39:09 2007
@@ -19,11 +19,12 @@
package org.apache.cxf.wsdl;
+import java.io.InputStream;
+import java.io.Reader;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
-import java.util.WeakHashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -48,6 +49,9 @@
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
+import org.w3c.dom.ls.LSInput;
+import org.w3c.dom.ls.LSResourceResolver;
+
import org.xml.sax.SAXException;
import org.apache.cxf.Bus;
@@ -57,6 +61,7 @@
import org.apache.cxf.endpoint.EndpointResolverRegistry;
import org.apache.cxf.endpoint.Server;
import org.apache.cxf.endpoint.ServerRegistry;
+import org.apache.cxf.helpers.LoadingByteArrayOutputStream;
import org.apache.cxf.service.model.SchemaInfo;
import org.apache.cxf.service.model.ServiceInfo;
import org.apache.cxf.transport.Destination;
@@ -66,6 +71,8 @@
import org.apache.cxf.ws.addressing.MetadataType;
import org.apache.cxf.ws.addressing.wsdl.AttributedQNameType;
import org.apache.cxf.ws.addressing.wsdl.ServiceNameType;
+import org.apache.ws.commons.schema.XmlSchema;
+import org.apache.ws.commons.schema.XmlSchemaCollection;
/**
@@ -75,8 +82,6 @@
public static final String ANONYMOUS_ADDRESS = "http://www.w3.org/2005/08/addressing/anonymous";
- static WeakHashMap<ServiceInfo, Schema> schemaMap = new WeakHashMap<ServiceInfo, Schema>();
-
private static final Logger LOG = LogUtils.getL7dLogger(EndpointReferenceUtils.class);
private static final String WSDL_INSTANCE_NAMESPACE =
@@ -438,17 +443,12 @@
if (serviceInfo == null) {
return null;
}
- synchronized (schemaMap) {
- if (schemaMap.containsKey(serviceInfo)) {
- return schemaMap.get(serviceInfo);
- }
- }
- Schema schema = schemaMap.get(serviceInfo);
-
+ Schema schema = serviceInfo.getProperty(Schema.class.getName(), Schema.class);
if (schema == null) {
SchemaFactory factory = SchemaFactory.newInstance(
XMLConstants.W3C_XML_SCHEMA_NS_URI);
List<Source> schemaSources = new ArrayList<Source>();
+ final XmlSchemaCollection sc = serviceInfo.getXmlSchemaCollection();
for (SchemaInfo schemaInfo : serviceInfo.getSchemas()) {
Source source = new DOMSource(schemaInfo.getElement());
if (source != null) {
@@ -457,12 +457,39 @@
}
}
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();
+ System.out.println(out.toString());
+ }
+ impl.setByteStream(ins);
+ return impl;
+ }
+ }
+ return null;
+ }
+
+ });
schema = factory.newSchema(schemaSources.toArray(
new Source[schemaSources.size()]));
if (schema != null) {
- synchronized (schemaMap) {
- schemaMap.put(serviceInfo, schema);
- }
+ serviceInfo.setProperty(Schema.class.getName(), schema);
LOG.log(Level.FINE, "Obtained schema from ServiceInfo");
}
} catch (SAXException ex) {
@@ -798,4 +825,97 @@
}
return ret;
}
+}
+
+class LSInputImpl implements LSInput {
+
+ protected String fPublicId;
+
+ protected String fSystemId;
+
+ protected String fBaseSystemId;
+
+ protected InputStream fByteStream;
+
+ protected Reader fCharStream;
+
+ protected String fData;
+
+ protected String fEncoding;
+
+ protected boolean fCertifiedText;
+
+ public LSInputImpl() {
+ }
+
+ public LSInputImpl(String publicId, String systemId, InputStream byteStream) {
+ fPublicId = publicId;
+ fSystemId = systemId;
+ fByteStream = byteStream;
+ }
+
+ public InputStream getByteStream() {
+ return fByteStream;
+ }
+
+ public void setByteStream(InputStream byteStream) {
+ fByteStream = byteStream;
+ }
+
+ public Reader getCharacterStream() {
+ return fCharStream;
+ }
+
+ public void setCharacterStream(Reader characterStream) {
+ fCharStream = characterStream;
+ }
+
+ public String getStringData() {
+ return fData;
+ }
+
+ public void setStringData(String stringData) {
+ fData = stringData;
+ }
+
+ public String getEncoding() {
+ return fEncoding;
+ }
+
+ public void setEncoding(String encoding) {
+ fEncoding = encoding;
+ }
+
+ public String getPublicId() {
+ return fPublicId;
+ }
+
+ public void setPublicId(String publicId) {
+ fPublicId = publicId;
+ }
+
+ public String getSystemId() {
+ return fSystemId;
+ }
+
+ public void setSystemId(String systemId) {
+ fSystemId = systemId;
+ }
+
+ public String getBaseURI() {
+ return fBaseSystemId;
+ }
+
+ public void setBaseURI(String baseURI) {
+ fBaseSystemId = baseURI;
+ }
+
+ public boolean getCertifiedText() {
+ return fCertifiedText;
+ }
+
+ public void setCertifiedText(boolean certifiedText) {
+ fCertifiedText = certifiedText;
+ }
+
}