Author: hiranya
Date: Thu Aug 8 21:58:24 2013
New Revision: 1512065
URL: http://svn.apache.org/r1512065
Log:
Resolving relative paths of WSDLs relative to SynapseHome. This is important in
WAR deployments. Patch applied from SYNAPSE-896
Modified:
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/SynapseConfigUtils.java
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/WSDLEndpointFactory.java
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/ProxyService.java
Modified:
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/SynapseConfigUtils.java
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/SynapseConfigUtils.java?rev=1512065&r1=1512064&r2=1512065&view=diff
==============================================================================
---
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/SynapseConfigUtils.java
(original)
+++
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/SynapseConfigUtils.java
Thu Aug 8 21:58:24 2013
@@ -636,6 +636,34 @@ public class SynapseConfigUtils {
return url;
}
+ /**
+ * Resolve a relative URI. If the URI is a file and it's path is relative,
the basePath will be
+ * used as parent location. If the URI is null the basePath will be
returned as URI.
+ *
+ * @param uri the URI to resolve
+ * @param basePath the base path
+ * @return the absolute URI
+ */
+ public static URI resolveRelativeURI(URI uri, String basePath) {
+ URI baseURI;
+ if (uri != null) {
+ if ("file".equals(uri.getScheme())) {
+ String wsdlPath = uri.getSchemeSpecificPart();
+ if (!new File(wsdlPath).isAbsolute()) {
+ baseURI = new File(new File(basePath),
+ wsdlPath).toURI();
+ } else {
+ baseURI = uri;
+ }
+ } else {
+ baseURI = uri;
+ }
+ } else {
+ baseURI = new File(basePath).toURI();
+ }
+ return baseURI;
+ }
+
public static String resolveRelativeURI(String parentLocation, String
relativeLocation) {
if (relativeLocation == null) {
Modified:
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/WSDLEndpointFactory.java
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/WSDLEndpointFactory.java?rev=1512065&r1=1512064&r2=1512065&view=diff
==============================================================================
---
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/WSDLEndpointFactory.java
(original)
+++
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/WSDLEndpointFactory.java
Thu Aug 8 21:58:24 2013
@@ -34,6 +34,7 @@ import org.apache.synapse.endpoints.Endp
import javax.xml.namespace.QName;
import java.io.File;
+import java.net.URI;
import java.net.URL;
import java.util.Properties;
@@ -126,20 +127,22 @@ public class WSDLEndpointFactory extends
if (wsdlURI != null) {
wsdlEndpoint.setWsdlURI(wsdlURI.trim());
if (noParsing == null ||
!JavaUtils.isTrueExplicitly(noParsing)) {
+ String synapseHome =
properties.get(SynapseConstants.SYNAPSE_HOME) != null ?
+
properties.get(SynapseConstants.SYNAPSE_HOME).toString() : "";
try {
OMNode wsdlOM =
SynapseConfigUtils.getOMElementFromURL(new URL(wsdlURI)
- .toString(),
properties.get(SynapseConstants.SYNAPSE_HOME) != null ?
-
properties.get(SynapseConstants.SYNAPSE_HOME).toString() : "");
+ .toString(), synapseHome);
if (wsdlOM != null && wsdlOM instanceof OMElement) {
OMElement omElement = (OMElement) wsdlOM;
OMNamespace ns = omElement.getNamespace();
if (ns != null) {
String nsUri =
omElement.getNamespace().getNamespaceURI();
if
(org.apache.axis2.namespace.Constants.NS_URI_WSDL11.equals(nsUri)) {
-
+ URI baseURI =
SynapseConfigUtils.resolveRelativeURI(
+ new URI(wsdlURI), synapseHome);
new WSDL11EndpointBuilder().
populateEndpointDefinitionFromWSDL(endpoint,
- wsdlURI.trim(), omElement,
serviceName, portName);
+ baseURI.toString(),
omElement, serviceName, portName);
} else if
(WSDL2Constants.WSDL_NAMESPACE.equals(nsUri)) {
//endpoint = new WSDL20EndpointBuilder().
Modified:
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/ProxyService.java
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/ProxyService.java?rev=1512065&r1=1512064&r2=1512065&view=diff
==============================================================================
---
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/ProxyService.java
(original)
+++
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/ProxyService.java
Thu Aug 8 21:58:24 2013
@@ -251,9 +251,8 @@ public class ProxyService implements Asp
boolean wsdlFound = false;
String publishWSDL = null;
- SynapseEnvironment synEnv =
SynapseConfigUtils.getSynapseEnvironment(axisCfg);
- String synapseHome = synEnv != null ?
synEnv.getServerContextInformation()
- .getServerConfigurationInformation().getSynapseHome() : "";
+ String synapseHome = synCfg.getProperty(SynapseConstants.SYNAPSE_HOME)
!= null ?
+ synCfg.getProperty(SynapseConstants.SYNAPSE_HOME) : "";
if (wsdlKey != null) {
synCfg.getEntryDefinition(wsdlKey);
@@ -374,8 +373,8 @@ public class ProxyService implements Asp
"Could not get the WSDL to Axis Service
Builder");
}
- wsdlToAxisServiceBuilder.setBaseUri(wsdlURI != null ?
- wsdlURI.toString() : synapseHome);
+ URI baseURI =
SynapseConfigUtils.resolveRelativeURI(wsdlURI, synapseHome);
+
wsdlToAxisServiceBuilder.setBaseUri(baseURI.toString());
if (trace()) {
trace.info("Setting up custom resolvers");
@@ -399,8 +398,7 @@ public class ProxyService implements Asp
((WSDL11ToAxisServiceBuilder)
wsdlToAxisServiceBuilder).setCustomWSDLResolver(
new CustomWSDLLocator(new
InputSource(wsdlInputStream),
- wsdlURI != null ?
wsdlURI.toString() : "",
- resourceMap, synCfg));
+ baseURI.toString(),
resourceMap, synCfg));
}
} else {
//if the resource map isn't available ,
@@ -412,7 +410,7 @@ public class ProxyService implements Asp
((WSDL11ToAxisServiceBuilder)
wsdlToAxisServiceBuilder).setCustomWSDLResolver(
new CustomWSDLLocator(new
InputSource(wsdlInputStream),
- wsdlURI != null ?
wsdlURI.toString() : ""));
+ baseURI.toString()));
}
}
}