You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@synapse.apache.org by in...@apache.org on 2007/08/06 14:38:10 UTC

svn commit: r563123 - in /webservices/synapse/trunk/java/modules: core/src/main/java/org/apache/synapse/ core/src/main/java/org/apache/synapse/config/ extensions/src/main/java/org/apache/synapse/mediators/bsf/ extensions/src/test/java/org/apache/synaps...

Author: indika
Date: Mon Aug  6 05:38:07 2007
New Revision: 563123

URL: http://svn.apache.org/viewvc?view=rev&rev=563123
Log:
fixed some bugs when reading resorce using url
fixed some possible CCE

Modified:
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/Constants.java
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/SynapseConfiguration.java
    webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/Util.java
    webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/bsf/ScriptMediator.java
    webservices/synapse/trunk/java/modules/extensions/src/test/java/org/apache/synapse/mediators/throttle/ThrottleMediatorSerializationTest.java

Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/Constants.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/Constants.java?view=diff&rev=563123&r1=563122&r2=563123
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/Constants.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/Constants.java Mon Aug  6 05:38:07 2007
@@ -19,10 +19,8 @@
 
 package org.apache.synapse;
 
-import org.apache.axiom.om.OMNamespace;
 import org.apache.axiom.om.OMAbstractFactory;
-
-import javax.xml.namespace.QName;
+import org.apache.axiom.om.OMNamespace;
 
 /**
  * Global constants for the Synapse project
@@ -47,6 +45,9 @@
 
     /** The system property used to specify/override the synapse configuration XML location */
     String SYNAPSE_XML = "synapse.xml";
+
+    /** The system property used to specify/override the synapse home location */
+    String SYNAPSE_HOME = "synapse.home";
 
     /** a message context property set to hold the relates to for POX responses */
     String RELATES_TO_FOR_POX = "RelatesToForPox";

Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/SynapseConfiguration.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/SynapseConfiguration.java?view=diff&rev=563123&r1=563122&r2=563123
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/SynapseConfiguration.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/SynapseConfiguration.java Mon Aug  6 05:38:07 2007
@@ -19,24 +19,25 @@
 
 package org.apache.synapse.config;
 
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.engine.AxisConfiguration;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.synapse.Constants;
 import org.apache.synapse.ManagedLifecycle;
-import org.apache.synapse.SynapseException;
 import org.apache.synapse.Mediator;
-import org.apache.synapse.Constants;
-import org.apache.synapse.endpoints.Endpoint;
-import org.apache.synapse.mediators.base.SequenceMediator;
+import org.apache.synapse.SynapseException;
 import org.apache.synapse.config.xml.MediatorFactoryFinder;
 import org.apache.synapse.config.xml.endpoints.XMLToEndpointMapper;
 import org.apache.synapse.core.SynapseEnvironment;
 import org.apache.synapse.core.axis2.ProxyService;
+import org.apache.synapse.endpoints.Endpoint;
+import org.apache.synapse.mediators.base.SequenceMediator;
 import org.apache.synapse.registry.Registry;
-import org.apache.axis2.AxisFault;
-import org.apache.axis2.engine.AxisConfiguration;
+
 import javax.xml.namespace.QName;
-import java.util.*;
 import java.io.IOException;
+import java.util.*;
 
 /**
  * The SynapseConfiguration holds the global configuration for a Synapse
@@ -521,53 +522,71 @@
 		return startup;
 	}
 
-	public void destroy() {
-		log.debug("destroy");
-		for (Iterator it = getProxyServices().iterator(); it.hasNext(); ) {
-			ProxyService p = (ProxyService)it.next();
-			if (p.getTargetInLineInSequence()!=null) {
-				p.getTargetInLineInSequence().destroy();
-			}
-			if (p.getTargetInLineOutSequence()!=null) {
-				p.getTargetInLineOutSequence().destroy();
-			}
-		}
-		
-		Map sequences = getDefinedSequences();
-		for (Iterator it = sequences.entrySet().iterator(); it.hasNext();) {
-			ManagedLifecycle m = (ManagedLifecycle) it.next();
-			m.destroy();
-		}
-		if (startup != null) {
-			for (Iterator it = startup.iterator(); it.hasNext();) {
-				ManagedLifecycle m = (ManagedLifecycle) it.next();
-				m.destroy();
-			}
-		}
-	}
-
-	public void init(SynapseEnvironment se) {
-		log.debug("init");
-		for (Iterator it = getProxyServices().iterator(); it.hasNext(); ) {
-			ProxyService p = (ProxyService)it.next();
-			if (p.getTargetInLineInSequence()!=null) {
-				p.getTargetInLineInSequence().init(se);
-			}
-			if (p.getTargetInLineOutSequence()!=null) {
-				p.getTargetInLineOutSequence().init(se);
-			}
-		}
-		
-		Map sequences = getDefinedSequences();
-		for (Iterator it = sequences.values().iterator(); it.hasNext();) {
-			ManagedLifecycle m = (ManagedLifecycle) it.next();
-			m.init(se);
-		}
-		if (startup != null) {
-			for (Iterator it = startup.iterator(); it.hasNext();) {
-				ManagedLifecycle m = (ManagedLifecycle) it.next();
-				m.init(se);
-			}
-		}
-	}
+    public void destroy() {
+        log.debug("destroy");
+        for (Iterator it = getProxyServices().iterator(); it.hasNext();) {
+            Object o = it.next();
+            if (o instanceof ProxyService) {
+                ProxyService p = (ProxyService) o;
+                if (p.getTargetInLineInSequence() != null) {
+                    p.getTargetInLineInSequence().destroy();
+                }
+                if (p.getTargetInLineOutSequence() != null) {
+                    p.getTargetInLineOutSequence().destroy();
+                }
+            }
+        }
+
+        Map sequences = getDefinedSequences();
+        for (Iterator it = sequences.entrySet().iterator(); it.hasNext();) {
+            Object o = it.next();
+            if (o instanceof ManagedLifecycle) {
+                ManagedLifecycle m = (ManagedLifecycle) o;
+                m.destroy();
+            }
+        }
+        if (startup != null) {
+            for (Iterator it = startup.iterator(); it.hasNext();) {
+                Object o = it.next();
+                if (o instanceof ManagedLifecycle) {
+                    ManagedLifecycle m = (ManagedLifecycle) o;
+                    m.destroy();
+                }
+            }
+        }
+    }
+
+    public void init(SynapseEnvironment se) {
+        log.debug("init");
+        for (Iterator it = getProxyServices().iterator(); it.hasNext();) {
+            Object o = it.next();
+            if (o instanceof ProxyService) {
+                ProxyService p = (ProxyService) o;
+                if (p.getTargetInLineInSequence() != null) {
+                    p.getTargetInLineInSequence().init(se);
+                }
+                if (p.getTargetInLineOutSequence() != null) {
+                    p.getTargetInLineOutSequence().init(se);
+                }
+            }
+        }
+
+        Map sequences = getDefinedSequences();
+        for (Iterator it = sequences.values().iterator(); it.hasNext();) {
+            Object o = it.next();
+            if (o instanceof ManagedLifecycle) {
+                ManagedLifecycle m = (ManagedLifecycle) o;
+                m.init(se);
+            }
+        }
+        if (startup != null) {
+            for (Iterator it = startup.iterator(); it.hasNext();) {
+                Object o = it.next();
+                if (o instanceof ManagedLifecycle) {
+                    ManagedLifecycle m = (ManagedLifecycle) o;
+                    m.init(se);
+                }
+            }
+        }
+    }
 }

Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/Util.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/Util.java?view=diff&rev=563123&r1=563122&r2=563123
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/Util.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/Util.java Mon Aug  6 05:38:07 2007
@@ -24,6 +24,7 @@
 import org.apache.axiom.om.impl.builder.StAXOMBuilder;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.synapse.Constants;
 import org.apache.synapse.SynapseException;
 
 import javax.xml.stream.XMLInputFactory;
@@ -34,10 +35,9 @@
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.net.URI;
 import java.net.URL;
 import java.net.URLConnection;
-import java.net.URI;
-import java.net.MalformedURLException;
 
 public class Util {
 
@@ -108,6 +108,28 @@
      */
     public static Object getObject(URL url) {
         try {
+            if (url != null && "file".equals(url.getProtocol())) {
+                try {
+                    url.openStream();
+                } catch (IOException ignored) {
+                    String synapseHome = System.getProperty(Constants.SYNAPSE_HOME);
+                    if (synapseHome != null) {
+                        if (synapseHome.endsWith("/")) {
+                            synapseHome = synapseHome.substring(0, synapseHome.lastIndexOf("/"));
+                        }
+                        url = new URL(url.getProtocol() + ":" + synapseHome + "/" + url.getPath());
+                        try {
+                            url.openStream();
+                        } catch (IOException e) {
+                            e.printStackTrace();
+                            log.error(e);
+                        }
+                    }
+                }
+            }
+            if (url == null) {
+                return null;
+            }
             URLConnection urlc = url.openConnection();
             XMLToObjectMapper xmlToObject =
                 getXmlToObjectMapper(urlc.getContentType());
@@ -141,12 +163,32 @@
 
     /**
      * Return an OMElement from a URL source
-     * @param url a URL string
+     * @param urlStr a URL string
      * @return an OMElement of the resource
      * @throws IOException for invalid URL's or IO errors
      */
-    public static OMElement getOMElementFromURL(String url) throws IOException {
-        URLConnection conn = new URL(url).openConnection();
+    public static OMElement getOMElementFromURL(String urlStr) throws IOException {
+        URL url = new URL(urlStr);
+        if ("file".equals(url.getProtocol())) {
+            try {
+                url.openStream();
+            } catch (IOException ignored) {
+                String synapseHome = System.getProperty(Constants.SYNAPSE_HOME);
+                if (synapseHome != null) {
+                    if (synapseHome.endsWith("/")) {
+                        synapseHome = synapseHome.substring(0, synapseHome.lastIndexOf("/"));
+                    }
+                    url = new URL(url.getProtocol() + ":" + synapseHome + "/" + url.getPath());
+                    try {
+                        url.openStream();
+                    } catch (IOException e) {
+                        e.printStackTrace();
+                        log.error(e);
+                    }
+                }
+            }
+        }
+        URLConnection conn = url.openConnection();
         conn.setReadTimeout(10000);
         conn.setConnectTimeout(2000);
         conn.setRequestProperty("Connection", "close"); // if http is being used

Modified: webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/bsf/ScriptMediator.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/bsf/ScriptMediator.java?view=diff&rev=563123&r1=563122&r2=563123
==============================================================================
--- webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/bsf/ScriptMediator.java (original)
+++ webservices/synapse/trunk/java/modules/extensions/src/main/java/org/apache/synapse/mediators/bsf/ScriptMediator.java Mon Aug  6 05:38:07 2007
@@ -95,6 +95,9 @@
      */
     private XMLHelper xmlHelper;
 
+    /** Lock used to ensure thread-safe lookup of the object from the registry */
+    private final Object resourceLock = new Object();
+
     /**
      * Create a script mediator for the given language and given script source
      *
@@ -263,16 +266,17 @@
 
         Entry entry = synCtx.getConfiguration().getEntryDefinition(key);
         boolean needsReload = (entry != null) && entry.isDynamic() && (!entry.isCached() || entry.isExpired());
+        synchronized (resourceLock) {
+            if (scriptSourceCode == null || needsReload) {
+                Object o = synCtx.getEntry(key);
+                if (o instanceof OMElement) {
+                    scriptSourceCode = ((OMElement) (o)).getText();
+                } else if (o instanceof String) {
+                    scriptSourceCode = (String) o;
+                }
 
-        if (scriptSourceCode == null || needsReload) {
-            Object o = synCtx.getEntry(key);
-            if (o instanceof OMElement) {
-                scriptSourceCode = ((OMElement) (o)).getText();
-            } else if (o instanceof String) {
-                scriptSourceCode = (String) o;
+                scriptEngine.eval(scriptSourceCode);
             }
-
-            scriptEngine.eval(scriptSourceCode);
         }
     }
 

Modified: webservices/synapse/trunk/java/modules/extensions/src/test/java/org/apache/synapse/mediators/throttle/ThrottleMediatorSerializationTest.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/extensions/src/test/java/org/apache/synapse/mediators/throttle/ThrottleMediatorSerializationTest.java?view=diff&rev=563123&r1=563122&r2=563123
==============================================================================
--- webservices/synapse/trunk/java/modules/extensions/src/test/java/org/apache/synapse/mediators/throttle/ThrottleMediatorSerializationTest.java (original)
+++ webservices/synapse/trunk/java/modules/extensions/src/test/java/org/apache/synapse/mediators/throttle/ThrottleMediatorSerializationTest.java Mon Aug  6 05:38:07 2007
@@ -36,16 +36,10 @@
         throttleMediatorSerializer = new ThrottleMediatorSerializer();
     }
 
-    public void testPropertyMediatorSerializationSenarioOne() throws Exception {
+    public void testThrottleMediatorSerializationSenarioOne() throws Exception {
         String inputXml = "<throttle:throttle xmlns:throttle=\"http://ws.apache.org/ns/synapse/throttle\" xmlns=\"http://ws.apache.org/ns/synapse\" >" +
                 "<policy key=\"thottleKey\"/></throttle:throttle>";
         assertTrue(serialization(inputXml, throttleMediatorFactory, throttleMediatorSerializer));
         assertTrue(serialization(inputXml, throttleMediatorSerializer));
     }
-//     public void testPropertyMediatorSerializationSenarioTwo() throws Exception {
-//        String inputXml = "<throttle:throttle xmlns:throttle=\"http://ws.apache.org/ns/synapse/throttle\" xmlns=\"http://ws.apache.org/ns/synapse\" >" +
-//                "<policy><inXml/></policy></throttle:throttle>";
-//        assertTrue(serialization(inputXml, throttleMediatorFactory, throttleMediatorSerializer));
-//        assertTrue(serialization(inputXml, throttleMediatorSerializer));
-//    }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: synapse-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: synapse-dev-help@ws.apache.org