Author: supun
Date: Fri Apr  1 05:25:39 2011
New Revision: 1087581

URL: http://svn.apache.org/viewvc?rev=1087581&view=rev
Log:
adding user defined wsdl resolvers and schema resolvers, thanks ratha for the 
contribution, SYNAPSE-747

Added:
    
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/resolver/UserDefinedWSDLLocator.java
    
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/resolver/UserDefinedXmlSchemaURIResolver.java
Modified:
    
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/SynapseConstants.java
    
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/ProxyService.java
    synapse/trunk/java/repository/conf/synapse.properties

Modified: 
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/SynapseConstants.java
URL: 
http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/SynapseConstants.java?rev=1087581&r1=1087580&r2=1087581&view=diff
==============================================================================
--- 
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/SynapseConstants.java
 (original)
+++ 
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/SynapseConstants.java
 Fri Apr  1 05:25:39 2011
@@ -105,6 +105,8 @@ public final class SynapseConstants {
     public static final String SERVER_MANAGER_MBEAN = "ServerManager";
     public static final String RECEIVING_SEQUENCE = "RECEIVING_SEQUENCE";
     public static final String SYNAPSE__FUNCTION__STACK = 
"_SYNAPSE_FUNCTION_STACK";
+    public static final String SYNAPSE_WSDL_RESOLVER = "synapse.wsdl.resolver";
+    public static final String SYNAPSE_SCHEMA_RESOLVER = 
"synapse.schema.resolver";
 
     /** Parameter names in the axis2.xml that can be used to configure the 
synapse */
     public static final class Axis2Param {

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=1087581&r1=1087580&r2=1087581&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
 Fri Apr  1 05:25:39 2011
@@ -46,6 +46,8 @@ import org.apache.synapse.util.PolicyInf
 import org.apache.synapse.util.resolver.CustomWSDLLocator;
 import org.apache.synapse.util.resolver.CustomXmlSchemaURIResolver;
 import org.apache.synapse.util.resolver.ResourceMap;
+import org.apache.synapse.util.resolver.UserDefinedWSDLLocator;
+import org.apache.synapse.util.resolver.UserDefinedXmlSchemaURIResolver;
 import org.xml.sax.InputSource;
 
 import javax.xml.stream.XMLStreamException;
@@ -373,34 +375,42 @@ public class ProxyService implements Asp
                         if (trace()) {
                             trace.info("Setting up custom resolvers");
                         }
-                        // Set up the URIResolver
-
-                        if (resourceMap != null) {
-                            // if the resource map is available use it
-                            wsdlToAxisServiceBuilder.setCustomResolver(
-                                new CustomXmlSchemaURIResolver(resourceMap, 
synCfg));
-                            // Axis 2 also needs a WSDLLocator for WSDL 1.1 
documents
-                            if (wsdlToAxisServiceBuilder instanceof 
WSDL11ToAxisServiceBuilder) {
-                                ((WSDL11ToAxisServiceBuilder)
-                                    
wsdlToAxisServiceBuilder).setCustomWSDLResolver(
-                                    new CustomWSDLLocator(new 
InputSource(wsdlInputStream),
-                                                          wsdlURI != null ? 
wsdlURI.toString() : "",
-                                                          resourceMap, 
synCfg));
-                            }
+                        
+                        // load the UserDefined WSDLResolver and 
SchemaURIResolver implementations
+                        if 
(synCfg.getProperty(SynapseConstants.SYNAPSE_WSDL_RESOLVER) != null &&
+                                
synCfg.getProperty(SynapseConstants.SYNAPSE_SCHEMA_RESOLVER) != null) {
+                            setUserDefinedResourceResolvers(synCfg, 
wsdlInputStream,
+                                    wsdlToAxisServiceBuilder);
                         } else {
-                            //if the resource map isn't available ,
-                            //then each import URIs will be resolved using 
base URI 
-                            wsdlToAxisServiceBuilder.setCustomResolver(
-                                new CustomXmlSchemaURIResolver());
-                            // Axis 2 also needs a WSDLLocator for WSDL 1.1 
documents
-                            if (wsdlToAxisServiceBuilder instanceof 
WSDL11ToAxisServiceBuilder) {
-                                ((WSDL11ToAxisServiceBuilder)
-                                    
wsdlToAxisServiceBuilder).setCustomWSDLResolver(
-                                    new CustomWSDLLocator(new 
InputSource(wsdlInputStream),
-                                            wsdlURI != null ? 
wsdlURI.toString() : ""));
+                            //Use the Custom Resolvers
+                            // Set up the URIResolver
+
+                            if (resourceMap != null) {
+                                // if the resource map is available use it
+                                wsdlToAxisServiceBuilder.setCustomResolver(
+                                        new 
CustomXmlSchemaURIResolver(resourceMap, synCfg));
+                                // Axis 2 also needs a WSDLLocator for WSDL 
1.1 documents
+                                if (wsdlToAxisServiceBuilder instanceof 
WSDL11ToAxisServiceBuilder) {
+                                    ((WSDL11ToAxisServiceBuilder)
+                                            
wsdlToAxisServiceBuilder).setCustomWSDLResolver(
+                                            new CustomWSDLLocator(new 
InputSource(wsdlInputStream),
+                                                    wsdlURI != null ? 
wsdlURI.toString() : "",
+                                                    resourceMap, synCfg));
+                                }
+                            } else {
+                                //if the resource map isn't available ,
+                                //then each import URIs will be resolved using 
base URI
+                                wsdlToAxisServiceBuilder.setCustomResolver(
+                                        new CustomXmlSchemaURIResolver());
+                                // Axis 2 also needs a WSDLLocator for WSDL 
1.1 documents
+                                if (wsdlToAxisServiceBuilder instanceof 
WSDL11ToAxisServiceBuilder) {
+                                    ((WSDL11ToAxisServiceBuilder)
+                                            
wsdlToAxisServiceBuilder).setCustomWSDLResolver(
+                                            new CustomWSDLLocator(new 
InputSource(wsdlInputStream),
+                                                    wsdlURI != null ? 
wsdlURI.toString() : ""));
+                                }
                             }
                         }
-
                         if (trace()) {
                             trace.info("Populating Axis2 service using WSDL");
                             if (trace.isTraceEnabled()) {
@@ -618,6 +628,49 @@ public class ProxyService implements Asp
         return proxyService;
     }
 
+    private void setUserDefinedResourceResolvers(SynapseConfiguration synCfg,
+                                                 InputStream wsdlInputStream,
+                                                 WSDLToAxisServiceBuilder 
wsdlToAxisServiceBuilder) {
+        String wsdlResolverName = 
synCfg.getProperty(SynapseConstants.SYNAPSE_WSDL_RESOLVER);
+        String schemaResolverName = 
synCfg.getProperty(SynapseConstants.SYNAPSE_SCHEMA_RESOLVER);
+        Class wsdlClazz, schemaClazz;
+        Object wsdlClzzObject, schemaClazzObject;
+        try {
+            wsdlClazz = Class.forName(wsdlResolverName);
+            schemaClazz = Class.forName(schemaResolverName);
+        } catch (ClassNotFoundException e) {
+            String msg =
+                    "System could not find the class defined for the specific 
properties" +
+                            " \n WSDLResolverImplementation:" + 
wsdlResolverName +
+                            "\n SchemaResolverImplementation:" + 
schemaResolverName;
+            handleException(msg, e);
+            return;
+        }
+
+        try {
+            wsdlClzzObject = wsdlClazz.newInstance();
+            schemaClazzObject = schemaClazz.newInstance();
+        } catch (Exception e) {
+            String msg = "Could not create an instance from the class";
+            handleException(msg, e);
+            return;
+        }
+
+        UserDefinedXmlSchemaURIResolver userDefSchemaResolver =
+                (UserDefinedXmlSchemaURIResolver) schemaClazzObject;
+        userDefSchemaResolver.init(resourceMap, synCfg, wsdlKey);
+
+        wsdlToAxisServiceBuilder.setCustomResolver(userDefSchemaResolver);
+        if (wsdlToAxisServiceBuilder instanceof WSDL11ToAxisServiceBuilder) {
+            UserDefinedWSDLLocator userDefWSDLLocator = 
(UserDefinedWSDLLocator) wsdlClzzObject;
+            userDefWSDLLocator.init(new InputSource(wsdlInputStream),
+                    wsdlURI != null ? wsdlURI.toString() : "", resourceMap, 
synCfg,
+                    wsdlKey);
+            ((WSDL11ToAxisServiceBuilder) wsdlToAxisServiceBuilder).
+                    setCustomWSDLResolver(userDefWSDLLocator);
+        }
+    }
+
     private Policy getPolicyFromKey(String key, SynapseConfiguration synCfg) {
 
         synCfg.getEntryDefinition(key);

Added: 
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/resolver/UserDefinedWSDLLocator.java
URL: 
http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/resolver/UserDefinedWSDLLocator.java?rev=1087581&view=auto
==============================================================================
--- 
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/resolver/UserDefinedWSDLLocator.java
 (added)
+++ 
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/resolver/UserDefinedWSDLLocator.java
 Fri Apr  1 05:25:39 2011
@@ -0,0 +1,45 @@
+/*
+ * 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.synapse.util.resolver;
+
+import javax.wsdl.xml.WSDLLocator;
+
+import org.apache.synapse.config.SynapseConfiguration;
+import org.xml.sax.InputSource;
+
+/**
+ * This interface lets user to write his/her own WSDLResolver rather using 
{@link CustomWSDLLocator} .
+ * Here using WSDLKey, user can perform his/her own mapping between 
Relativelocation 
+ * and Registrypath. User needs to provide a synapse.property 
call,"synapse.wsdl.resolver"
+ * pointing to the implementation.
+ */
+public interface UserDefinedWSDLLocator extends WSDLLocator {
+
+       /**
+        * Initiate the UserDefinedWSDLLocator with the required parameters
+        * 
+        * @param baseInputSource InputSource "pointed at" the base document
+        * @param baseURI URI representing the location of the base document.
+        * @param resourceMap {@link ResourceMap} object
+        * @param synCfg Synapseconfiguration
+        * @param wsdlKey The registry key of the wsdl file
+        */
+       void init(InputSource baseInputSource, String baseURI, ResourceMap 
resourceMap,
+                 SynapseConfiguration synCfg, String wsdlKey);
+}

Added: 
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/resolver/UserDefinedXmlSchemaURIResolver.java
URL: 
http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/resolver/UserDefinedXmlSchemaURIResolver.java?rev=1087581&view=auto
==============================================================================
--- 
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/resolver/UserDefinedXmlSchemaURIResolver.java
 (added)
+++ 
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/resolver/UserDefinedXmlSchemaURIResolver.java
 Fri Apr  1 05:25:39 2011
@@ -0,0 +1,44 @@
+/*
+ * 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.synapse.util.resolver;
+
+import org.apache.synapse.config.SynapseConfiguration;
+import org.apache.ws.commons.schema.resolver.URIResolver;
+
+/**
+ * This interface lets user to write his/her own XmlSchemaURIResolver rather
+ * using {@ link CustomXmlSchemaURIResolver} .
+ * Here using WSDLKey, user can perform his/her own mapping between 
Relativelocation 
+ * and Registrypath . User needs to provide a synapse.property 
call,"synapse.schema.resolver="
+ * pointing to the implementation.
+ */
+/**
+ * Adapting the schema Relativepath to the registry actual path
+ */
+public interface UserDefinedXmlSchemaURIResolver extends URIResolver {
+
+       /**
+        * Initiate the UserDefinedXmlSchemaURIResolver with the required 
parameters
+        * 
+        * @param resourceMap {@link ResourceMap} object
+        * @param synCfg Synapseconfiguration
+        * @param wsdlKey The registry key of the wsdl file
+        */
+       void init(ResourceMap resourceMap, SynapseConfiguration synCfg, String 
wsdlKey);
+}

Modified: synapse/trunk/java/repository/conf/synapse.properties
URL: 
http://svn.apache.org/viewvc/synapse/trunk/java/repository/conf/synapse.properties?rev=1087581&r1=1087580&r2=1087581&view=diff
==============================================================================
--- synapse/trunk/java/repository/conf/synapse.properties (original)
+++ synapse/trunk/java/repository/conf/synapse.properties Fri Apr  1 05:25:39 
2011
@@ -143,4 +143,9 @@ synapse.jmx.jndiPort=0
 # Proxy server user password, this is used for HTTP basic authentication
 #synapse.http.proxy.password=
 #list of host address excluded from going through the proxy, list is comma 
separated
-#synapse.http.proxy.excluded.hosts=localhost, 127.0.0.1
\ No newline at end of file
+#synapse.http.proxy.excluded.hosts=localhost, 127.0.0.1
+
+# Register any UserDefinedWSDLResolver/UserDefinedXmlSchemaURIResolver
+# synapse.wsdl.resolver=samples.userguide.UserDefinedWSDLResolver
+# synapse.schema.resolver=samples.userguide.UserDefinedXmlSchemaURIResolver
+


Reply via email to