You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ode.apache.org by Guillaume Nodet <gn...@gmail.com> on 2007/01/08 17:20:25 UTC

Resolving imported documents from wsdl / xsds

I'm trying to deploy a JBI service unit wich has the following struture:

  - deploy.xml
  - process.bpel
  - svc1/svc1-abstract.wsdl
  - svc1/svc1-plinks.wsdl
  - svc1/svc1-types.xsd
  - common/common-msgs.wsdl
  - common/common-types.xsd

The wsdl are importing wsdls and xsds with relative URI
with a "../common/common-msgs.wsdl".
There are several bugs in the deployment where documents
are resolved incorrectly, because all relative URIs are
resolved from the root folder, instead of being resolved
from the importing document.

I have a small patch that fixed some of these problems
that I will check in if nobody objects, but I don't think
this is the best solution.
The patch for the WSDLLocatorImpl is good imho, but
the one for the WsdlFindXMLEntityResolver is a bit of a hack.
The problem is that in the failing case, the
 literalSystemId = "../common/common-types.xsd"
which is loaded from the svc1/svc1-types.xsd file.
But when no baseUri is set, xerces assumes that files
are loaded from the current directory, so the
expandedSystemId are invalid absolute URIs.
So this patch relativize the uri wrt to the current dir,
so that the files can be found.

I think it may be more robust to use absolute URIs everywhere,
starting from the bpel file.  I think it would ease the process.
It could also support jar resources.  Would it be a problem ?


Index: src/main/java/org/apache/ode/bpel/compiler/WsdlFinderXMLEntityResolver.java
===================================================================
--- src/main/java/org/apache/ode/bpel/compiler/WsdlFinderXMLEntityResolver.java	(revision
492785)
+++ src/main/java/org/apache/ode/bpel/compiler/WsdlFinderXMLEntityResolver.java	(working
copy)
@@ -27,6 +27,7 @@
 import org.apache.xerces.xni.parser.XMLInputSource;

 import java.io.ByteArrayInputStream;
+import java.io.File;
 import java.io.IOException;
 import java.net.URI;
 import java.net.URISyntaxException;
@@ -64,7 +65,9 @@
         try {
             if (resourceIdentifier.getLiteralSystemId() == null)
                 location = new URI(resourceIdentifier.getNamespace());
-            else
+            else if (resourceIdentifier.getExpandedSystemId() != null
&& resourceIdentifier.getExpandedSystemId().startsWith("file:")) {
+                location = new
File(".").getAbsoluteFile().toURI().relativize(URI.create(resourceIdentifier.getExpandedSystemId()));
+            } else
                 location = new
URI(FileUtils.encodePath(resourceIdentifier.getLiteralSystemId()));
         } catch (URISyntaxException e) {
             __log.debug("resolveEntity: URI syntax error", e);
Index: src/main/java/org/apache/ode/bpel/compiler/WSDLLocatorImpl.java
===================================================================
--- src/main/java/org/apache/ode/bpel/compiler/WSDLLocatorImpl.java	(revision
492785)
+++ src/main/java/org/apache/ode/bpel/compiler/WSDLLocatorImpl.java	(working
copy)
@@ -33,7 +33,7 @@
     }

     public InputSource getImportInputSource(String parent, String imprt) {
-        URI uri = parent == null ? _base.resolve(imprt) :
_base.resolve(parent).resolve(imprt);
+        URI uri = (parent == null || parent.equals(_base.toString()))
? _base.resolve(imprt) : URI.create(parent).resolve(imprt);
         InputSource is = new InputSource();
         try {
             is.setByteStream(_resourceFinder.openResource(uri));

-- 
Cheers,
Guillaume Nodet