Return-Path: Delivered-To: apmail-cxf-commits-archive@www.apache.org Received: (qmail 38842 invoked from network); 2 Nov 2009 22:08:50 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 2 Nov 2009 22:08:50 -0000 Received: (qmail 4687 invoked by uid 500); 2 Nov 2009 22:08:50 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 4623 invoked by uid 500); 2 Nov 2009 22:08:50 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 4614 invoked by uid 99); 2 Nov 2009 22:08:50 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 02 Nov 2009 22:08:50 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 02 Nov 2009 22:08:47 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 36B8123889BA; Mon, 2 Nov 2009 22:08:26 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r832135 - in /cxf/branches/2.2.x-fixes: ./ api/src/main/java/org/apache/cxf/wsdl/EndpointReferenceUtils.java common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java Date: Mon, 02 Nov 2009 22:08:26 -0000 To: commits@cxf.apache.org From: dkulp@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20091102220826.36B8123889BA@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: dkulp Date: Mon Nov 2 22:08:25 2009 New Revision: 832135 URL: http://svn.apache.org/viewvc?rev=832135&view=rev Log: Merged revisions 832126 via svnmerge from https://svn.apache.org/repos/asf/cxf/trunk ........ r832126 | dkulp | 2009-11-02 17:02:47 -0500 (Mon, 02 Nov 2009) | 2 lines [CXF-2516] Make more attempts to get the schema loaded for use with validation. ........ Modified: cxf/branches/2.2.x-fixes/ (props changed) cxf/branches/2.2.x-fixes/api/src/main/java/org/apache/cxf/wsdl/EndpointReferenceUtils.java cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java Propchange: cxf/branches/2.2.x-fixes/ ------------------------------------------------------------------------------ Binary property 'svnmerge-integrated' - no diff available. Modified: cxf/branches/2.2.x-fixes/api/src/main/java/org/apache/cxf/wsdl/EndpointReferenceUtils.java URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/api/src/main/java/org/apache/cxf/wsdl/EndpointReferenceUtils.java?rev=832135&r1=832134&r2=832135&view=diff ============================================================================== --- cxf/branches/2.2.x-fixes/api/src/main/java/org/apache/cxf/wsdl/EndpointReferenceUtils.java (original) +++ cxf/branches/2.2.x-fixes/api/src/main/java/org/apache/cxf/wsdl/EndpointReferenceUtils.java Mon Nov 2 22:08:25 2009 @@ -23,13 +23,15 @@ import java.io.InputStream; import java.io.Reader; import java.io.StringReader; -import java.io.StringWriter; +import java.net.MalformedURLException; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; +import java.util.HashSet; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; @@ -51,7 +53,6 @@ import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMResult; import javax.xml.transform.dom.DOMSource; -import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamSource; import javax.xml.validation.Schema; import javax.xml.validation.SchemaFactory; @@ -77,6 +78,7 @@ import org.apache.cxf.resource.ExtendedURIResolver; import org.apache.cxf.service.model.SchemaInfo; import org.apache.cxf.service.model.ServiceInfo; +import org.apache.cxf.staxutils.StaxUtils; import org.apache.cxf.staxutils.W3CDOMStreamWriter; import org.apache.cxf.transport.Destination; import org.apache.cxf.transport.MultiplexDestination; @@ -104,24 +106,14 @@ * the code in here. */ private static final class SchemaLSResourceResolver implements LSResourceResolver { - private final Map schemas; + private final Map schemas; + private final Set done = new HashSet(); private final ExtendedURIResolver resolver = new ExtendedURIResolver(); - private SchemaLSResourceResolver(Map schemas) { + private SchemaLSResourceResolver(Map schemas) { this.schemas = schemas; } - private Reader getSchemaAsStream(DOMSource source) { - 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) { @@ -131,28 +123,37 @@ URI uri = new URI(baseURI); uri = uri.resolve(systemId); newId = uri.toString(); + if (newId.equals(systemId)) { + URL url = new URL(baseURI); + url = new URL(url, systemId); + newId = url.toExternalForm(); + } } catch (URISyntaxException e) { //ignore + } catch (MalformedURLException e) { + //ignore } } + if (done.contains(newId + ":" + namespaceURI)) { + return null; + } if (schemas.containsKey(newId + ":" + namespaceURI)) { - DOMSource ds = schemas.remove(newId + ":" + namespaceURI); + String ds = schemas.remove(newId + ":" + namespaceURI); LSInputImpl impl = new LSInputImpl(); impl.setSystemId(newId); impl.setBaseURI(newId); - impl.setCharacterStream(getSchemaAsStream(ds)); + impl.setCharacterStream(new StringReader(ds)); + done.add(newId + ":" + namespaceURI); return impl; } - - for (Map.Entry ent : schemas.entrySet()) { - if (ent.getKey().endsWith(namespaceURI)) { - schemas.remove(ent.getKey()); - LSInputImpl impl = new LSInputImpl(); - impl.setSystemId(newId); - impl.setBaseURI(newId); - impl.setCharacterStream(getSchemaAsStream(ent.getValue())); - return impl; - } + if (schemas.containsKey(newId + ":null")) { + String ds = schemas.get(newId + ":null"); + LSInputImpl impl = new LSInputImpl(); + impl.setSystemId(newId); + impl.setBaseURI(newId); + impl.setCharacterStream(new StringReader(ds)); + done.add(newId + ":" + namespaceURI); + return impl; } //REVIST - we need to get catalogs in here somehow :-( @@ -585,18 +586,24 @@ Schema schema = serviceInfo.getProperty(Schema.class.getName(), Schema.class); if (schema == null) { SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); - Map schemaSourcesMap = new LinkedHashMap(); - for (SchemaInfo si : serviceInfo.getSchemas()) { - Element el = si.getElement(); - String baseURI = el.getBaseURI(); - if (baseURI == null) { - baseURI = si.getSystemId(); - } - DOMSource ds = new DOMSource(el, baseURI); - schemaSourcesMap.put(si.getSystemId() + ":" + si.getNamespaceURI(), ds); - } + Map schemaSourcesMap = new LinkedHashMap(); + Map schemaSourcesMap2 = new LinkedHashMap(); try { + for (SchemaInfo si : serviceInfo.getSchemas()) { + Element el = si.getElement(); + String baseURI = el.getBaseURI(); + if (baseURI == null) { + baseURI = si.getSystemId(); + } + DOMSource ds = new DOMSource(el, baseURI); + schemaSourcesMap2.put(si.getSystemId() + ":" + si.getNamespaceURI(), ds); + + String s = StaxUtils.toString(el); + schemaSourcesMap.put(si.getSystemId() + ":" + si.getNamespaceURI(), s); + } + + for (XmlSchema sch : serviceInfo.getXmlSchemaCollection().getXmlSchemas()) { if (sch.getSourceURI() != null && !schemaSourcesMap.containsKey(sch.getSourceURI() + ":" @@ -622,16 +629,22 @@ } catch (IOException ex) { //ignore } - - DOMSource ss = new DOMSource(doc, sch.getSourceURI()); + String s = StaxUtils.toString(doc); schemaSourcesMap.put(sch.getSourceURI() + ":" - + sch.getTargetNamespace(), ss); + + sch.getTargetNamespace(), s); + + Source source = new StreamSource(new StringReader(s), sch.getSourceURI()); + schemaSourcesMap2.put(sch.getSourceURI() + ":" + + sch.getTargetNamespace(), source); } } + factory.setResourceResolver(new SchemaLSResourceResolver(schemaSourcesMap)); - schema = factory.newSchema(schemaSourcesMap.values() - .toArray(new Source[schemaSourcesMap.size()])); + schema = factory.newSchema(schemaSourcesMap2.values() + .toArray(new Source[schemaSourcesMap2.size()])); + + } catch (Exception ex) { // Something not right with the schema from the wsdl. LOG.log(Level.WARNING, "SAXException for newSchema() on ", ex); Modified: cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java URL: http://svn.apache.org/viewvc/cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java?rev=832135&r1=832134&r2=832135&view=diff ============================================================================== --- cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java (original) +++ cxf/branches/2.2.x-fixes/common/common/src/main/java/org/apache/cxf/staxutils/StaxUtils.java Mon Nov 2 22:08:25 2009 @@ -22,6 +22,7 @@ import java.io.InputStream; import java.io.OutputStream; import java.io.Reader; +import java.io.StringWriter; import java.io.Writer; import java.util.Iterator; import java.util.concurrent.BlockingQueue; @@ -1174,4 +1175,19 @@ //shouldn't get here } } + public static String toString(Document doc) throws XMLStreamException { + StringWriter sw = new StringWriter(1024); + XMLStreamWriter writer = createXMLStreamWriter(sw); + copy(doc, writer); + writer.flush(); + return sw.toString(); + } + public static String toString(Element el) throws XMLStreamException { + StringWriter sw = new StringWriter(1024); + XMLStreamWriter writer = createXMLStreamWriter(sw); + copy(el, writer); + writer.flush(); + return sw.toString(); + } + }