Return-Path: Delivered-To: apmail-incubator-cxf-commits-archive@locus.apache.org Received: (qmail 70510 invoked from network); 31 Oct 2007 17:53:16 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 31 Oct 2007 17:53:16 -0000 Received: (qmail 53390 invoked by uid 500); 31 Oct 2007 17:53:03 -0000 Delivered-To: apmail-incubator-cxf-commits-archive@incubator.apache.org Received: (qmail 53312 invoked by uid 500); 31 Oct 2007 17:53:03 -0000 Mailing-List: contact cxf-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: cxf-dev@incubator.apache.org Delivered-To: mailing list cxf-commits@incubator.apache.org Received: (qmail 53303 invoked by uid 99); 31 Oct 2007 17:53:03 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 31 Oct 2007 10:53:03 -0700 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 31 Oct 2007 17:53:28 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 06E631A9832; Wed, 31 Oct 2007 10:52:52 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r590770 - /incubator/cxf/trunk/api/src/main/java/org/apache/cxf/wsdl/EndpointReferenceUtils.java Date: Wed, 31 Oct 2007 17:52:51 -0000 To: cxf-commits@incubator.apache.org From: dkulp@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20071031175252.06E631A9832@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: dkulp Date: Wed Oct 31 10:52:50 2007 New Revision: 590770 URL: http://svn.apache.org/viewvc?rev=590770&view=rev Log: [CXF-1149] Use the URL's for the schemas from the SchemaCollection for validation. Modified: incubator/cxf/trunk/api/src/main/java/org/apache/cxf/wsdl/EndpointReferenceUtils.java Modified: incubator/cxf/trunk/api/src/main/java/org/apache/cxf/wsdl/EndpointReferenceUtils.java URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/api/src/main/java/org/apache/cxf/wsdl/EndpointReferenceUtils.java?rev=590770&r1=590769&r2=590770&view=diff ============================================================================== --- incubator/cxf/trunk/api/src/main/java/org/apache/cxf/wsdl/EndpointReferenceUtils.java (original) +++ incubator/cxf/trunk/api/src/main/java/org/apache/cxf/wsdl/EndpointReferenceUtils.java Wed Oct 31 10:52:50 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 schemaMap = new WeakHashMap(); - 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 schemaSources = new ArrayList(); + 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; + } + }