Author: indika
Date: Tue Jan  8 02:57:46 2008
New Revision: 11983

Log:

update the code to re -initiating synapse configuration with the synapse 
environment  after  updating configuration through config admin (GI) 


Modified:
   
trunk/esb/java/modules/core/src/main/java/org/wso2/esb/services/AbstractESBAdmin.java
   
trunk/esb/java/modules/core/src/main/java/org/wso2/esb/services/ConfigAdmin.java

Modified: 
trunk/esb/java/modules/core/src/main/java/org/wso2/esb/services/AbstractESBAdmin.java
==============================================================================
--- 
trunk/esb/java/modules/core/src/main/java/org/wso2/esb/services/AbstractESBAdmin.java
       (original)
+++ 
trunk/esb/java/modules/core/src/main/java/org/wso2/esb/services/AbstractESBAdmin.java
       Tue Jan  8 02:57:46 2008
@@ -24,14 +24,16 @@
 import org.apache.commons.logging.Log;
 import org.apache.synapse.SynapseConstants;
 import org.apache.synapse.config.SynapseConfiguration;
+import org.apache.synapse.core.SynapseEnvironment;
 
 /*
  *  Abstract Class that handles Admin stuff
  */
 
 public abstract class AbstractESBAdmin {
+
     public static final String LOGGED = "logged";
-    
+
     public AxisConfiguration getAxisConfig() {
         return 
MessageContext.getCurrentMessageContext().getConfigurationContext()
                 .getAxisConfiguration();
@@ -51,6 +53,16 @@
         return (SynapseConfiguration) synapseConfigParam.getValue();
     }
 
+    public SynapseEnvironment getSynapseEnvironment() throws AxisFault {
+        Parameter synapseEnvParam = getAxisConfig().getParameter(
+            SynapseConstants.SYNAPSE_ENV);
+        if (synapseEnvParam == null) {
+            throw new AxisFault("Unable to find the Synapse Environment from" +
+                " the loaded Axis2 configuration");
+        }
+        return (SynapseEnvironment) synapseEnvParam.getValue();
+    }
+
     protected void handleFault(Log log, String message, Exception e) throws 
AxisFault {
 
         if (e == null) {
@@ -59,7 +71,7 @@
             throw af;
 
         } else {
-            message = message + " :: " + e.getMessage(); 
+            message = message + " :: " + e.getMessage();
             log.error(message, e);
             throw new AxisFault(message, e);
         }

Modified: 
trunk/esb/java/modules/core/src/main/java/org/wso2/esb/services/ConfigAdmin.java
==============================================================================
--- 
trunk/esb/java/modules/core/src/main/java/org/wso2/esb/services/ConfigAdmin.java
    (original)
+++ 
trunk/esb/java/modules/core/src/main/java/org/wso2/esb/services/ConfigAdmin.java
    Tue Jan  8 02:57:46 2008
@@ -21,7 +21,9 @@
 import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.impl.builder.StAXOMBuilder;
 import org.apache.axis2.AxisFault;
+import org.apache.axis2.context.ConfigurationContext;
 import org.apache.axis2.description.Parameter;
+import org.apache.axis2.engine.AxisConfiguration;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.synapse.SynapseConstants;
@@ -29,6 +31,7 @@
 import org.apache.synapse.config.SynapseConfiguration;
 import org.apache.synapse.config.xml.XMLConfigurationBuilder;
 import org.apache.synapse.config.xml.XMLConfigurationSerializer;
+import org.apache.synapse.core.axis2.Axis2SynapseEnvironment;
 import org.apache.synapse.core.axis2.MessageContextCreatorForAxis2;
 import org.apache.synapse.core.axis2.ProxyService;
 import org.wso2.esb.util.XMLPrettyPrinter;
@@ -49,27 +52,28 @@
             ByteArrayOutputStream stream = new ByteArrayOutputStream();
             
XMLConfigurationSerializer.serializeConfiguration(getSynapseConfiguration(), 
stream);
             StAXOMBuilder builder
-                    = new StAXOMBuilder(new 
ByteArrayInputStream(stream.toByteArray()));
+                = new StAXOMBuilder(new 
ByteArrayInputStream(stream.toByteArray()));
             stream.reset();
             XMLPrettyPrinter.prettify(builder.getDocumentElement(), stream);
             return new String(stream.toByteArray());
         } catch (XMLStreamException e) {
             log.error("Error serializing the Synapse configuration");
-            throw  AxisFault.makeFault(e);
+            throw AxisFault.makeFault(e);
         } catch (Exception e) {
             log.error("Error serializing the Synapse configuration");
-            throw  AxisFault.makeFault(e);
+            throw AxisFault.makeFault(e);
         }
     }
 
     public void updateConfiguration(OMElement configElement) throws AxisFault {
         try {
             log.info("Stopping Proxy services...");
+            AxisConfiguration axisCfg = getAxisConfig();
             Iterator iter = 
getSynapseConfiguration().getProxyServices().iterator();
             while (iter.hasNext()) {
                 ProxyService proxy = (ProxyService) iter.next();
                 try {
-                    getAxisConfig().removeService(proxy.getName());
+                    axisCfg.removeService(proxy.getName());
                 } catch (AxisFault e) {
                     log.error("Error removing Proxy service : " + 
proxy.getName(), e);
                     throw e;
@@ -81,35 +85,55 @@
             SynapseConfiguration synCfg = 
XMLConfigurationBuilder.getConfiguration(
                 new ByteArrayInputStream(stream.toByteArray()));
             
synCfg.setPathToConfigFile(getSynapseConfiguration().getPathToConfigFile());
-            synCfg.setAxisConfiguration(getAxisConfig());
+            synCfg.setAxisConfiguration(axisCfg);
             Parameter synapseCtxParam = new 
Parameter(SynapseConstants.SYNAPSE_CONFIG, null);
             synapseCtxParam.setValue(synCfg);
-            getAxisConfig().addParameter(synapseCtxParam);
             MessageContextCreatorForAxis2.setSynConfig(synCfg);
 
+            //set up synapse env
+            ConfigurationContext configCtx = getConfigContext();
+            Parameter synapseEnvParam = new 
Parameter(SynapseConstants.SYNAPSE_ENV, null);
+            Axis2SynapseEnvironment synEnv = new 
Axis2SynapseEnvironment(configCtx, synCfg);
+            synapseEnvParam.setValue(synEnv);
+            MessageContextCreatorForAxis2.setSynEnv(synEnv);
+
+            try {
+                axisCfg.addParameter(synapseCtxParam);
+                axisCfg.addParameter(synapseEnvParam);
+
+            } catch (AxisFault e) {
+                String msg =
+                    "Could not set parameters '" + 
SynapseConstants.SYNAPSE_CONFIG +
+                        "' and/or '" + SynapseConstants.SYNAPSE_ENV +
+                        "'to the Axis2 configuration : " + e.getMessage();
+                handleFault(log,msg,e);
+            }
             // redeploy proxy services
             log.info("Re-deploying Proxy services...");
             iter = synCfg.getProxyServices().iterator();
             while (iter.hasNext()) {
                 ProxyService proxy = (ProxyService) iter.next();
-                proxy.buildAxisService(synCfg, getAxisConfig());
+                proxy.buildAxisService(synCfg, axisCfg);
                 log.info("Deployed Proxy service : " + proxy.getName());
                 if (!proxy.isStartOnLoad()) {
                     proxy.stop(synCfg);
                 }
             }
+            // re-init the synapse configuration
+            synCfg.init(synEnv);
+
             log.info("Configuration updated successfully...");
 
         } catch (SynapseException se) {
-            handleFault(log, "Unable to update the Synapse configuration." +   
                                               
-                se.getMessage() +" Check log for more details", se);
+            handleFault(log, "Unable to update the Synapse configuration." +
+                se.getMessage() + " Check log for more details", se);
         } catch (XMLStreamException e) {
             handleFault(log, "Unable to update the Synapse configuration." +
-                e.getMessage() +" Check log for more details", e);
+                e.getMessage() + " Check log for more details", e);
         }
     }
 
-    public boolean saveConfigurationToDisk() throws AxisFault {                
 
+    public boolean saveConfigurationToDisk() throws AxisFault {
         log.info("Saving configuration..");
 
         SynapseConfiguration config = getSynapseConfiguration();

_______________________________________________
Esb-java-dev mailing list
Esb-java-dev@wso2.org
http://wso2.org/cgi-bin/mailman/listinfo/esb-java-dev

Reply via email to