Author: sergeyb Date: Fri Jun 22 17:07:03 2012 New Revision: 1352976 URL: http://svn.apache.org/viewvc?rev=1352976&view=rev Log: Merged revisions 1352968 via svnmerge from https://svn.apache.org/repos/asf/cxf/branches/2.6.x-fixes
................ r1352968 | sergeyb | 2012-06-22 17:52:20 +0100 (Fri, 22 Jun 2012) | 13 lines Merged revisions 1352965-1352966 via svnmerge from https://svn.apache.org/repos/asf/cxf/trunk ........ r1352965 | sergeyb | 2012-06-22 17:48:11 +0100 (Fri, 22 Jun 2012) | 1 line [CXF-4393] Initial support for checking custom catalogs when creating JAXB Schemas ........ r1352966 | sergeyb | 2012-06-22 17:49:03 +0100 (Fri, 22 Jun 2012) | 1 line [CXF-4393] One more modified file ........ ................ Added: cxf/branches/2.5.x-fixes/common/common/src/main/java/org/apache/cxf/common/xmlschema/LSInputImpl.java (with props) cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/resources/jaxrs/META-INF/ - copied from r1352968, cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/resources/jaxrs/META-INF/ cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/resources/jaxrs/META-INF/jax-rs-catalog.xml - copied unchanged from r1352968, cxf/branches/2.6.x-fixes/systests/jaxrs/src/test/resources/jaxrs/META-INF/jax-rs-catalog.xml Modified: cxf/branches/2.5.x-fixes/ (props changed) cxf/branches/2.5.x-fixes/api/src/main/java/org/apache/cxf/wsdl/EndpointReferenceUtils.java cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/schemas/SchemaHandler.java cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/resources/book.xsd cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/resources/jaxrs/WEB-INF/beans.xml cxf/branches/2.5.x-fixes/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/SchemaValidator.java Propchange: cxf/branches/2.5.x-fixes/ ------------------------------------------------------------------------------ Merged /cxf/trunk:r1352965-1352966 Merged /cxf/branches/2.6.x-fixes:r1352968 Propchange: cxf/branches/2.5.x-fixes/ ------------------------------------------------------------------------------ Binary property 'svnmerge-integrated' - no diff available. Modified: cxf/branches/2.5.x-fixes/api/src/main/java/org/apache/cxf/wsdl/EndpointReferenceUtils.java URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/api/src/main/java/org/apache/cxf/wsdl/EndpointReferenceUtils.java?rev=1352976&r1=1352975&r2=1352976&view=diff ============================================================================== --- cxf/branches/2.5.x-fixes/api/src/main/java/org/apache/cxf/wsdl/EndpointReferenceUtils.java (original) +++ cxf/branches/2.5.x-fixes/api/src/main/java/org/apache/cxf/wsdl/EndpointReferenceUtils.java Fri Jun 22 17:07:03 2012 @@ -22,7 +22,6 @@ package org.apache.cxf.wsdl; import java.io.ByteArrayInputStream; import java.io.InputStream; import java.io.InputStreamReader; -import java.io.Reader; import java.lang.ref.Reference; import java.lang.ref.SoftReference; import java.net.MalformedURLException; @@ -72,6 +71,7 @@ import org.apache.cxf.common.WSDLConstan 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.LSInputImpl; import org.apache.cxf.endpoint.EndpointResolverRegistry; import org.apache.cxf.endpoint.Server; import org.apache.cxf.endpoint.ServerRegistry; @@ -1097,97 +1097,3 @@ public final class EndpointReferenceUtil } - - -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; - } - -} Added: cxf/branches/2.5.x-fixes/common/common/src/main/java/org/apache/cxf/common/xmlschema/LSInputImpl.java URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/common/common/src/main/java/org/apache/cxf/common/xmlschema/LSInputImpl.java?rev=1352976&view=auto ============================================================================== --- cxf/branches/2.5.x-fixes/common/common/src/main/java/org/apache/cxf/common/xmlschema/LSInputImpl.java (added) +++ cxf/branches/2.5.x-fixes/common/common/src/main/java/org/apache/cxf/common/xmlschema/LSInputImpl.java Fri Jun 22 17:07:03 2012 @@ -0,0 +1,122 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.cxf.common.xmlschema; + +import java.io.InputStream; +import java.io.Reader; + +import org.w3c.dom.ls.LSInput; + +/** + * LSInput implementation that can be used in + * custom LSResourceResolver implementations for getting + * schema import and include references resolved. + */ +public 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; + } + +} Propchange: cxf/branches/2.5.x-fixes/common/common/src/main/java/org/apache/cxf/common/xmlschema/LSInputImpl.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: cxf/branches/2.5.x-fixes/common/common/src/main/java/org/apache/cxf/common/xmlschema/LSInputImpl.java ------------------------------------------------------------------------------ svn:keywords = Rev Date Modified: cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java?rev=1352976&r1=1352975&r2=1352976&view=diff ============================================================================== --- cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java (original) +++ cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/provider/AbstractJAXBProvider.java Fri Jun 22 17:07:03 2012 @@ -110,6 +110,7 @@ public abstract class AbstractJAXBProvid private MessageContext mc; private Schema schema; + private String catalogLocation; private String collectionWrapperName; private Map<String, String> collectionWrapperMap; private List<String> jaxbElementClassNames = Collections.emptyList(); @@ -359,7 +360,11 @@ public abstract class AbstractJAXBProvid } public void setSchemaLocations(List<String> locations) { - schema = SchemaHandler.createSchema(locations, getBus()); + schema = SchemaHandler.createSchema(locations, catalogLocation, getBus()); + } + + public void setCatalogLocation(String name) { + this.catalogLocation = name; } public void setSchema(Schema s) { Modified: cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/schemas/SchemaHandler.java URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/schemas/SchemaHandler.java?rev=1352976&r1=1352975&r2=1352976&view=diff ============================================================================== --- cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/schemas/SchemaHandler.java (original) +++ cxf/branches/2.5.x-fixes/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/utils/schemas/SchemaHandler.java Fri Jun 22 17:07:03 2012 @@ -20,6 +20,8 @@ package org.apache.cxf.jaxrs.utils.schemas; import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; import java.io.InputStreamReader; import java.io.Reader; import java.net.URL; @@ -32,18 +34,26 @@ import javax.xml.transform.stream.Stream import javax.xml.validation.Schema; import javax.xml.validation.SchemaFactory; +import org.w3c.dom.ls.LSInput; +import org.w3c.dom.ls.LSResourceResolver; + import org.apache.cxf.Bus; import org.apache.cxf.BusFactory; +import org.apache.cxf.catalog.OASISCatalogManager; import org.apache.cxf.common.WSDLConstants; import org.apache.cxf.common.logging.LogUtils; +import org.apache.cxf.common.xmlschema.LSInputImpl; import org.apache.cxf.jaxrs.utils.ResourceUtils; public class SchemaHandler { + static final String DEFAULT_CATALOG_LOCATION = "classpath:META-INF/jax-rs-catalog.xml"; + private static final Logger LOG = LogUtils.getL7dLogger(SchemaHandler.class); private Schema schema; private Bus bus; + private String catalogLocation; public SchemaHandler() { @@ -54,14 +64,19 @@ public class SchemaHandler { } public void setSchemas(List<String> locations) { - schema = createSchema(locations, bus == null ? BusFactory.getThreadDefaultBus() : bus); + schema = createSchema(locations, catalogLocation, + bus == null ? BusFactory.getThreadDefaultBus() : bus); + } + + public void setCatalogLocation(String name) { + this.catalogLocation = name; } public Schema getSchema() { return schema; } - public static Schema createSchema(List<String> locations, Bus bus) { + public static Schema createSchema(List<String> locations, String catalogLocation, final Bus bus) { SchemaFactory factory = SchemaFactory.newInstance(WSDLConstants.NS_SCHEMA_XSD); Schema s = null; @@ -78,6 +93,46 @@ public class SchemaHandler { source.setSystemId(url.toString()); sources.add(source); } + final OASISCatalogManager catalogResolver = OASISCatalogManager.getCatalogManager(bus); + if (catalogResolver != null) { + catalogLocation = catalogLocation == null + ? SchemaHandler.DEFAULT_CATALOG_LOCATION : catalogLocation; + URL catalogURL = ResourceUtils.getResourceURL(catalogLocation, bus); + if (catalogURL != null) { + try { + catalogResolver.loadCatalog(catalogURL); + factory.setResourceResolver(new LSResourceResolver() { + + public LSInput resolveResource(String type, String namespaceURI, String publicId, + String systemId, String baseURI) { + try { + String resolvedLocation = catalogResolver.resolveSystem(systemId); + + if (resolvedLocation == null) { + resolvedLocation = catalogResolver.resolveURI(namespaceURI); + } + if (resolvedLocation == null) { + resolvedLocation = catalogResolver.resolvePublic(publicId, systemId); + } + if (resolvedLocation != null) { + InputStream resourceStream = + ResourceUtils.getResourceStream(resolvedLocation, bus); + if (resourceStream != null) { + return new LSInputImpl(publicId, systemId, resourceStream); + } + } + } catch (Exception ex) { + // ignore + } + return null; + } + + }); + } catch (IOException ex) { + LOG.warning("Catalog " + catalogLocation + " can not be loaded"); + } + } + } s = factory.newSchema(sources.toArray(new Source[]{})); } catch (Exception ex) { LOG.warning("Validation will be disabled, failed to create schema : " + ex.getMessage()); @@ -85,4 +140,5 @@ public class SchemaHandler { return s; } + } Modified: cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/resources/book.xsd URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/resources/book.xsd?rev=1352976&r1=1352975&r2=1352976&view=diff ============================================================================== --- cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/resources/book.xsd (original) +++ cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/resources/book.xsd Fri Jun 22 17:07:03 2012 @@ -19,7 +19,7 @@ --> <schema xmlns="http://www.w3.org/2001/XMLSchema" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/books" xmlns:tns="http://www.example.org/books" xmlns:bookids="http://www.example.org/books/id" elementFormDefault="qualified"> - <xs:import namespace="http://www.example.org/books/id"/> + <xs:import namespace="http://www.example.org/books/id" schemaLocation="http://schemas/bookid.xsd"/> <element name="Book"> <complexType> <sequence> Modified: cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/resources/jaxrs/WEB-INF/beans.xml URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/resources/jaxrs/WEB-INF/beans.xml?rev=1352976&r1=1352975&r2=1352976&view=diff ============================================================================== --- cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/resources/jaxrs/WEB-INF/beans.xml (original) +++ cxf/branches/2.5.x-fixes/systests/jaxrs/src/test/resources/jaxrs/WEB-INF/beans.xml Fri Jun 22 17:07:03 2012 @@ -269,8 +269,7 @@ http://cxf.apache.org/schemas/core.xsd"> </bean> <util:list id="theSchemas"> - <value>classpath:/WEB-INF/schemas/bookid.xsd</value> - <value>classpath:/org/apache/cxf/systest/jaxrs/resources/book.xsd</value> + <value>classpath:/org/apache/cxf/systest/jaxrs/resources/book.xsd</value> </util:list> <util:list id="jsonTypes"> Modified: cxf/branches/2.5.x-fixes/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/SchemaValidator.java URL: http://svn.apache.org/viewvc/cxf/branches/2.5.x-fixes/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/SchemaValidator.java?rev=1352976&r1=1352975&r2=1352976&view=diff ============================================================================== --- cxf/branches/2.5.x-fixes/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/SchemaValidator.java (original) +++ cxf/branches/2.5.x-fixes/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/SchemaValidator.java Fri Jun 22 17:07:03 2012 @@ -22,8 +22,6 @@ package org.apache.cxf.tools.validator.i import java.io.File; import java.io.FilenameFilter; import java.io.IOException; -import java.io.InputStream; -import java.io.Reader; import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; @@ -49,6 +47,7 @@ import javax.xml.validation.Validator; import org.w3c.dom.Document; import org.w3c.dom.ls.LSInput; import org.w3c.dom.ls.LSResourceResolver; + import org.xml.sax.ErrorHandler; import org.xml.sax.InputSource; import org.xml.sax.SAXException; @@ -56,6 +55,7 @@ import org.xml.sax.SAXParseException; import org.apache.cxf.common.i18n.Message; import org.apache.cxf.common.logging.LogUtils; +import org.apache.cxf.common.xmlschema.LSInputImpl; import org.apache.cxf.resource.URIResolver; import org.apache.cxf.tools.common.ToolConstants; import org.apache.cxf.tools.common.ToolException; @@ -430,96 +430,4 @@ class SchemaResourceResolver implements } } -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; - } - -}
