Author: mmao
Date: Tue Apr 3 02:32:32 2007
New Revision: 525111
URL: http://svn.apache.org/viewvc?view=rev&rev=525111
Log:
[CXF-503]
Maven 2 code generation plugin fails if passed in -validate as extraarg
Couple reasons failed the validate function
* If the schema is a http url, we did not return after we get the wsdl from
remote site
* load only one schema from cxf jars into default schemas, which may cause
validate fail, now we load all schemas from cxf jars.
Modified:
incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/util/URIParserUtil.java
incubator/cxf/trunk/tools/common/src/test/java/org/apache/cxf/tools/util/URIParserUtilTest.java
incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/Messages.properties
incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/SchemaValidator.java
incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/WSDL11Validator.java
Modified:
incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/util/URIParserUtil.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/util/URIParserUtil.java?view=diff&rev=525111&r1=525110&r2=525111
==============================================================================
---
incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/util/URIParserUtil.java
(original)
+++
incubator/cxf/trunk/tools/common/src/main/java/org/apache/cxf/tools/util/URIParserUtil.java
Tue Apr 3 02:32:32 2007
@@ -223,7 +223,7 @@
} catch (MalformedURLException e1) {
try {
String f = null;
- if (uri.indexOf(":") != -1) {
+ if (uri.indexOf(":") != -1 && !uri.startsWith("/")) {
f = "file:/" + uri;
} else {
f = "file:" + uri;
Modified:
incubator/cxf/trunk/tools/common/src/test/java/org/apache/cxf/tools/util/URIParserUtilTest.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/common/src/test/java/org/apache/cxf/tools/util/URIParserUtilTest.java?view=diff&rev=525111&r1=525110&r2=525111
==============================================================================
---
incubator/cxf/trunk/tools/common/src/test/java/org/apache/cxf/tools/util/URIParserUtilTest.java
(original)
+++
incubator/cxf/trunk/tools/common/src/test/java/org/apache/cxf/tools/util/URIParserUtilTest.java
Tue Apr 3 02:32:32 2007
@@ -48,6 +48,9 @@
uri = "c:\\hello.wsdl";
assertEquals("file:/c:/hello.wsdl", URIParserUtil.normalize(uri));
+
+ uri = "/c:\\hello.wsdl";
+ assertEquals("file:/c:/hello.wsdl", URIParserUtil.normalize(uri));
}
public void testGetAbsoluteURI() throws Exception {
@@ -66,6 +69,11 @@
assertTrue(uri2.contains(new java.io.File("").toString()));
uri = "c:\\wsdl\\hello_world.wsdl";
+ uri2 = URIParserUtil.getAbsoluteURI(uri);
+ assertNotNull(uri2);
+ assertEquals("file:/c:/wsdl/hello_world.wsdl", uri2);
+
+ uri = "/c:\\wsdl\\hello_world.wsdl";
uri2 = URIParserUtil.getAbsoluteURI(uri);
assertNotNull(uri2);
assertEquals("file:/c:/wsdl/hello_world.wsdl", uri2);
Modified:
incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/Messages.properties
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/Messages.properties?view=diff&rev=525111&r1=525110&r2=525111
==============================================================================
---
incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/Messages.properties
(original)
+++
incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/Messages.properties
Tue Apr 3 02:32:32 2007
@@ -20,5 +20,9 @@
#
NOT_A_WSDLFILE = {0} is not a wsdl file
+CREATE_SCHEMA_LOADED_FROM_JAR = Create Schema {0} which was loaded from jar
+VALIDATE_WSDL = Validate wsdl {0}
+RESOLVE_SCHEMA = Resolve schema {1} from baseURI: {2}, namespace: {0}
-
+RESOLVE_FROM_REMOTE = Load and resolve schema from remote host {0}
+RESOLVE_FROM_LOCAL = Load and resolve schema from local file {0}
\ No newline at end of file
Modified:
incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/SchemaValidator.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/SchemaValidator.java?view=diff&rev=525111&r1=525110&r2=525111
==============================================================================
---
incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/SchemaValidator.java
(original)
+++
incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/SchemaValidator.java
Tue Apr 3 02:32:32 2007
@@ -31,8 +31,8 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.logging.Level;
import java.util.logging.Logger;
-
import javax.wsdl.WSDLException;
import javax.wsdl.factory.WSDLFactory;
import javax.wsdl.xml.WSDLReader;
@@ -53,7 +53,6 @@
import org.w3c.dom.Node;
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;
@@ -65,9 +64,9 @@
import org.apache.cxf.resource.URIResolver;
import org.apache.cxf.tools.common.ToolConstants;
import org.apache.cxf.tools.common.ToolException;
+import org.apache.cxf.tools.util.URIParserUtil;
public class SchemaValidator extends AbstractDefinitionValidator {
-
protected static final Logger LOG =
LogUtils.getL7dLogger(SchemaValidator.class);
protected String[] defaultSchemas;
@@ -118,11 +117,7 @@
}
String systemId = null;
- try {
- systemId = getWsdlUrl(wsdlsource);
- } catch (IOException ioe) {
- throw new ToolException(ioe);
- }
+ systemId = URIParserUtil.getAbsoluteURI(wsdlsource);
InputSource is = new InputSource(systemId);
return validate(is, schemas);
@@ -140,6 +135,8 @@
List<Source> sources = new ArrayList<Source>();
for (InputSource is : xsdsInJar) {
+ Message msg = new Message("CREATE_SCHEMA_LOADED_FROM_JAR", LOG,
is.getSystemId());
+ LOG.log(Level.INFO, msg.toString());
Document doc = docBuilder.parse(is.getByteStream());
DOMSource stream = new DOMSource(doc, is.getSystemId());
stream.setSystemId(is.getSystemId());
@@ -186,12 +183,13 @@
boolean isValid = false;
Schema schema;
try {
-
+ Message msg = new Message("VALIDATE_WSDL", LOG,
wsdlsource.getSystemId());
+ LOG.log(Level.INFO, msg.toString());
Document document = docBuilder.parse(wsdlsource.getSystemId());
Node node = DOMUtils.getChild(document, null);
if (node != null && !"definitions".equals(node.getLocalName())) {
- Message msg = new Message("NOT_A_WSDLFILE", LOG,
wsdlsource.getSystemId());
+ msg = new Message("NOT_A_WSDLFILE", LOG,
wsdlsource.getSystemId());
throw new ToolException(msg);
}
@@ -301,16 +299,6 @@
}
return null;
}
-
- private String getWsdlUrl(String path) throws IOException {
- File file = new File(path);
- if (file != null && file.exists()) {
- return file.toURL().toString();
- }
-
- return null;
- }
-
}
class NewStackTraceErrorHandler implements ErrorHandler {
@@ -386,6 +374,7 @@
}
class SchemaResourceResolver implements LSResourceResolver {
+ private static final Logger LOG =
LogUtils.getL7dLogger(SchemaValidator.class);
private static final Map<String, String> NSFILEMAP = new HashMap<String,
String>();
static {
NSFILEMAP.put(ToolConstants.XML_NAMESPACE_URI, "xml.xsd");
@@ -408,6 +397,8 @@
public LSInput resolveResource(String type, String namespaceURI, String
publicId, String systemId,
String baseURI) {
+ Message msg = new Message("RESOLVE_SCHEMA", LOG, namespaceURI,
systemId, baseURI);
+ LOG.log(Level.INFO, msg.toString());
if (NSFILEMAP.containsKey(namespaceURI)) {
return loadLSInput(namespaceURI);
}
@@ -428,24 +419,28 @@
} else if (namespaceURI != null) {
resURL = namespaceURI;
}
-
+
if (resURL != null && resURL.startsWith("http://")) {
String filename = NSFILEMAP.get(resURL);
if (filename != null) {
localFile = ToolConstants.CXF_SCHEMAS_DIR_INJAR + filename;
} else {
URL url;
+ URLConnection urlCon = null;
try {
url = new URL(resURL);
- URLConnection urlCon = url.openConnection();
+ urlCon = url.openConnection();
urlCon.setUseCaches(false);
lsin = new LSInputImpl();
lsin.setSystemId(resURL);
lsin.setByteStream(urlCon.getInputStream());
+ msg = new Message("RESOLVE_FROM_REMOTE", LOG, url);
+ LOG.log(Level.INFO, msg.toString());
+ return lsin;
} catch (Exception e) {
+ e.printStackTrace();
return null;
}
-
}
} else if (resURL != null && !resURL.startsWith("http:")) {
localFile = resURL;
@@ -455,7 +450,10 @@
URIResolver resolver;
- try {
+ try {
+ msg = new Message("RESOLVE_FROM_LOCAL", LOG, localFile);
+ LOG.log(Level.INFO, msg.toString());
+
resolver = new URIResolver(localFile);
if (resolver.isResolved()) {
lsin = new LSInputImpl();
@@ -464,7 +462,7 @@
}
} catch (IOException e) {
return null;
- }
+ }
return lsin;
}
}
@@ -561,3 +559,4 @@
}
}
+
Modified:
incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/WSDL11Validator.java
URL:
http://svn.apache.org/viewvc/incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/WSDL11Validator.java?view=diff&rev=525111&r1=525110&r2=525111
==============================================================================
---
incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/WSDL11Validator.java
(original)
+++
incubator/cxf/trunk/tools/validator/src/main/java/org/apache/cxf/tools/validator/internal/WSDL11Validator.java
Tue Apr 3 02:32:32 2007
@@ -33,7 +33,6 @@
import java.util.List;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
-
import javax.wsdl.Definition;
import org.xml.sax.InputSource;
@@ -65,7 +64,6 @@
// 1.ToolConstants.CFG_SCHEMA_DIR from ToolContext
// 2.ToolConstants.CXF_SCHEMA_DIR from System property
// 3.If 1 and 2 is null , then load these schema files from jar file
-
if (!StringUtils.isEmpty(schemaDir)) {
schemaValidator = new SchemaValidator(schemaDir,
(String)env.get(ToolConstants.CFG_WSDLURL),
schemas);
@@ -113,63 +111,66 @@
protected List<InputSource> getDefaultSchemas() throws IOException {
List<InputSource> xsdList = new ArrayList<InputSource>();
ClassLoader clzLoader = Thread.currentThread().getContextClassLoader();
- URL url = clzLoader.getResource(ToolConstants.CXF_SCHEMAS_DIR_INJAR);
- //from jar files
- if (url.toString().startsWith("jar")) {
-
- JarURLConnection jarConnection =
(JarURLConnection)url.openConnection();
-
- JarFile jarFile = jarConnection.getJarFile();
-
- Enumeration<JarEntry> entry = jarFile.entries();
-
- while (entry.hasMoreElements()) {
- JarEntry ele = (JarEntry)entry.nextElement();
- if (ele.getName().endsWith(".xsd")
- &&
ele.getName().indexOf(ToolConstants.CXF_SCHEMAS_DIR_INJAR) > -1) {
-
- URIResolver resolver = new URIResolver(ele.getName());
- if (resolver.isResolved()) {
- InputSource is = new
InputSource(resolver.getInputStream());
- // Use the resolved URI of the schema if available.
- // The ibm jdk won't resolve the schema if we set
- // the id to the relative path.
- if (resolver.getURI() != null) {
- is.setSystemId(resolver.getURI().toString());
- } else {
- is.setSystemId(ele.getName());
+ Enumeration<URL> urls =
clzLoader.getResources(ToolConstants.CXF_SCHEMAS_DIR_INJAR);
+ while (urls.hasMoreElements()) {
+ URL url = urls.nextElement();
+ //from jar files
+ if (url.toString().startsWith("jar")) {
+
+ JarURLConnection jarConnection =
(JarURLConnection)url.openConnection();
+
+ JarFile jarFile = jarConnection.getJarFile();
+
+ Enumeration<JarEntry> entry = jarFile.entries();
+
+ while (entry.hasMoreElements()) {
+ JarEntry ele = (JarEntry)entry.nextElement();
+ if (ele.getName().endsWith(".xsd")
+ &&
ele.getName().indexOf(ToolConstants.CXF_SCHEMAS_DIR_INJAR) > -1) {
+
+ URIResolver resolver = new URIResolver(ele.getName());
+ if (resolver.isResolved()) {
+ InputSource is = new
InputSource(resolver.getInputStream());
+ // Use the resolved URI of the schema if available.
+ // The ibm jdk won't resolve the schema if we set
+ // the id to the relative path.
+ if (resolver.getURI() != null) {
+ is.setSystemId(resolver.getURI().toString());
+ } else {
+ is.setSystemId(ele.getName());
+ }
+ xsdList.add(is);
}
- xsdList.add(is);
}
}
- }
- //from class path direcotry
- } else if (url.toString().startsWith("file")) {
- URI loc = null;
- try {
- loc = url.toURI();
- } catch (URISyntaxException e) {
- //
- }
- java.io.File file = new java.io.File(loc);
- if (file.exists()) {
- File[] files = file.listFiles(new FileFilter() {
- public boolean accept(File pathname) {
- if (pathname.getAbsolutePath().endsWith(".xsd")) {
- return true;
- }
- return false;
+ //from class path direcotry
+ } else if (url.toString().startsWith("file")) {
+ URI loc = null;
+ try {
+ loc = url.toURI();
+ } catch (URISyntaxException e) {
+ //
+ }
+ java.io.File file = new java.io.File(loc);
+ if (file.exists()) {
+ File[] files = file.listFiles(new FileFilter() {
+ public boolean accept(File pathname) {
+ if
(pathname.getAbsolutePath().endsWith(".xsd")) {
+ return true;
+ }
+ return false;
+ }
+ });
+ for (int i = 0; i < files.length; i++) {
+ InputSource is = new
InputSource(files[i].toURL().openStream());
+ is.setSystemId(files[i].toURL().toString());
+ xsdList.add(is);
}
- });
- for (int i = 0; i < files.length; i++) {
- InputSource is = new
InputSource(files[i].toURL().openStream());
- is.setSystemId(files[i].toURL().toString());
- xsdList.add(is);
}
+
}
-
}
-
+
sort(xsdList);
return xsdList;
}