You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@synapse.apache.org by ru...@apache.org on 2009/08/16 18:57:16 UTC
svn commit: r804718 - in
/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config:
SynapseConfigUtils.java SynapseConfigurationBuilder.java
xml/MultiXMLConfigurationBuilder.java xml/SynapseXMLConfigurationFactory.java
Author: ruwan
Date: Sun Aug 16 16:57:16 2009
New Revision: 804718
URL: http://svn.apache.org/viewvc?rev=804718&view=rev
Log:
moving the registry lookup for synapse.xml to the SynapseConfigBuilder making it consistent
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/SynapseConfigurationBuilder.java
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/MultiXMLConfigurationBuilder.java
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/SynapseXMLConfigurationFactory.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=804718&r1=804717&r2=804718&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 Sun Aug 16 16:57:16 2009
@@ -26,13 +26,20 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.synapse.*;
+import org.apache.synapse.aspects.AspectConfiguration;
import org.apache.synapse.aspects.statistics.StatisticsCollector;
-import org.apache.synapse.core.SynapseEnvironment;
import org.apache.synapse.commons.security.definition.IdentityKeyStoreInformation;
import org.apache.synapse.commons.security.definition.KeyStoreInformation;
import org.apache.synapse.commons.security.definition.TrustKeyStoreInformation;
import org.apache.synapse.commons.security.definition.factory.KeyStoreInformationFactory;
+import org.apache.synapse.core.SynapseEnvironment;
+import org.apache.synapse.mediators.MediatorProperty;
+import org.apache.synapse.mediators.base.SequenceMediator;
+import org.apache.synapse.mediators.builtin.DropMediator;
+import org.apache.synapse.mediators.builtin.LogMediator;
import org.apache.synapse.util.SynapseBinaryDataSource;
+import org.apache.synapse.util.xpath.SynapseXPath;
+import org.jaxen.JaxenException;
import org.xml.sax.InputSource;
import javax.activation.DataHandler;
@@ -730,5 +737,69 @@
}
return synConfig;
}
+
+ /**
+ * Return the main sequence if one is not defined. This implementation defaults to
+ * a simple sequence with a <send/>
+ *
+ * @param config the configuration to be updated
+ */
+ public static void setDefaultMainSequence(SynapseConfiguration config) {
+ SequenceMediator main = new SequenceMediator();
+ main.setName(SynapseConstants.MAIN_SEQUENCE_KEY);
+ main.addChild(new LogMediator());
+ main.addChild(new DropMediator());
+ config.addSequence(SynapseConstants.MAIN_SEQUENCE_KEY, main);
+ // set the aspect configuration
+ AspectConfiguration configuration = new AspectConfiguration(main.getName());
+ main.configure(configuration);
+ }
+
+ /**
+ * Return the fault sequence if one is not defined. This implementation defaults to
+ * a simple sequence :
+ * <log level="full">
+ * <property name="MESSAGE" value="Executing default "fault" sequence"/>
+ * <property name="ERROR_CODE" expression="get-property('ERROR_CODE')"/>
+ * <property name="ERROR_MESSAGE" expression="get-property('ERROR_MESSAGE')"/>
+ * </log>
+ * <drop/>
+ *
+ * @param config the configuration to be updated
+ */
+ public static void setDefaultFaultSequence(SynapseConfiguration config) {
+ SequenceMediator fault = new SequenceMediator();
+ fault.setName(org.apache.synapse.SynapseConstants.FAULT_SEQUENCE_KEY);
+ LogMediator log = new LogMediator();
+ log.setLogLevel(LogMediator.FULL);
+
+ MediatorProperty mp = new MediatorProperty();
+ mp.setName("MESSAGE");
+ mp.setValue("Executing default \"fault\" sequence");
+ log.addProperty(mp);
+
+ mp = new MediatorProperty();
+ mp.setName("ERROR_CODE");
+ try {
+ mp.setExpression(new SynapseXPath("get-property('ERROR_CODE')"));
+ } catch (JaxenException ignore) {}
+ log.addProperty(mp);
+
+ mp = new MediatorProperty();
+ mp.setName("ERROR_MESSAGE");
+ try {
+ mp.setExpression(new SynapseXPath("get-property('ERROR_MESSAGE')"));
+ } catch (JaxenException ignore) {}
+ log.addProperty(mp);
+
+ fault.addChild(log);
+ fault.addChild(new DropMediator());
+
+ // set aspect configuration
+ AspectConfiguration configuration = new AspectConfiguration(fault.getName());
+ fault.configure(configuration);
+
+ config.addSequence(org.apache.synapse.SynapseConstants.FAULT_SEQUENCE_KEY, fault);
+ }
}
Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/SynapseConfigurationBuilder.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/SynapseConfigurationBuilder.java?rev=804718&r1=804717&r2=804718&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/SynapseConfigurationBuilder.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/SynapseConfigurationBuilder.java Sun Aug 16 16:57:16 2009
@@ -19,22 +19,21 @@
package org.apache.synapse.config;
+import org.apache.axiom.om.OMNode;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.synapse.SynapseConstants;
import org.apache.synapse.SynapseException;
-import org.apache.synapse.config.xml.XMLConfigurationBuilder;
import org.apache.synapse.config.xml.MultiXMLConfigurationBuilder;
-import org.apache.synapse.config.xml.MultiXMLConfigurationSerializer;
-import org.apache.synapse.config.xml.SynapseXMLConfigurationFactory;
+import org.apache.synapse.config.xml.XMLConfigurationBuilder;
import org.apache.synapse.mediators.base.SequenceMediator;
import org.apache.synapse.mediators.builtin.DropMediator;
import org.apache.synapse.mediators.builtin.LogMediator;
+import org.apache.synapse.registry.Registry;
import javax.xml.stream.XMLStreamException;
import java.io.File;
import java.io.FileInputStream;
-import java.io.FileNotFoundException;
/**
* Builds a Synapse Configuration model with a given input
@@ -75,7 +74,10 @@
File synapseConfigLocation = new File(configFile);
if (!synapseConfigLocation.exists()) {
- throw new SynapseException("Unable to load the Synapse configuration from : " + configFile);
+ String message = "Unable to load the Synapse configuration from : "
+ + configFile + ". Specified file not found";
+ log.fatal(message);
+ throw new SynapseException(message);
}
SynapseConfiguration synCfg = null;
@@ -100,14 +102,45 @@
}
}
+ assert synCfg != null;
+ Registry localConfigReg = synCfg.getRegistry();
+ if (synCfg.getLocalRegistry().isEmpty() && synCfg.getProxyServices().isEmpty()
+ && localConfigReg != null) {
+ if (log.isDebugEnabled()) {
+ log.debug("Only the registry is defined in the synapse configuration, trying " +
+ "to fetch a configuration from the registry");
+ }
+ // TODO: support a artifact repo for registry as well instead of just the synapse.xml
+ OMNode remoteConfigNode = localConfigReg.lookup("synapse.xml");
+ if (remoteConfigNode != null) {
+ try {
+ synCfg = XMLConfigurationBuilder.getConfiguration(SynapseConfigUtils
+ .getStreamSource(remoteConfigNode).getInputStream());
+ // TODO: when you fetch the configuration and serialize the config in any case
+ // TODO: the remote config is serialized to the synapse.xml we should prevent
+ // TODO: that, and should serialize the config to the registry
+ if (synCfg.getRegistry() == null) {
+ synCfg.setRegistry(localConfigReg);
+ } else {
+ log.warn("Registry declaration has been overwriten by the registry " +
+ "declaration found at the remote configuration");
+ }
+ } catch (XMLStreamException xse) {
+ throw new SynapseException("Problem loading remote synapse.xml ", xse);
+ }
+ } else if (log.isDebugEnabled()) {
+ log.debug("Couldn't find a synapse configuration on the registry");
+ }
+ }
+
// Check for the main sequence and add a default main sequence if not present
if (synCfg.getMainSequence() == null) {
- SynapseXMLConfigurationFactory.setDefaultMainSequence(synCfg);
+ SynapseConfigUtils.setDefaultMainSequence(synCfg);
}
// Check for the fault sequence and add a deafult fault sequence if not present
if (synCfg.getFaultSequence() == null) {
- SynapseXMLConfigurationFactory.setDefaultFaultSequence(synCfg);
+ SynapseConfigUtils.setDefaultFaultSequence(synCfg);
}
return synCfg;
Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/MultiXMLConfigurationBuilder.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/MultiXMLConfigurationBuilder.java?rev=804718&r1=804717&r2=804718&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/MultiXMLConfigurationBuilder.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/MultiXMLConfigurationBuilder.java Sun Aug 16 16:57:16 2009
@@ -18,24 +18,23 @@
*/
package org.apache.synapse.config.xml;
-import org.apache.synapse.config.SynapseConfiguration;
-import org.apache.synapse.config.SynapseConfigUtils;
-import org.apache.synapse.config.Entry;
-import org.apache.synapse.SynapseException;
-import org.apache.synapse.Startup;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.impl.builder.StAXOMBuilder;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.apache.synapse.Mediator;
+import org.apache.synapse.Startup;
import org.apache.synapse.SynapseConstants;
-import org.apache.synapse.eventing.SynapseEventSource;
-import org.apache.synapse.endpoints.Endpoint;
+import org.apache.synapse.SynapseException;
+import org.apache.synapse.config.Entry;
+import org.apache.synapse.config.SynapseConfigUtils;
+import org.apache.synapse.config.SynapseConfiguration;
+import org.apache.synapse.core.axis2.ProxyService;
import org.apache.synapse.endpoints.AbstractEndpoint;
+import org.apache.synapse.endpoints.Endpoint;
+import org.apache.synapse.eventing.SynapseEventSource;
import org.apache.synapse.mediators.base.SequenceMediator;
import org.apache.synapse.startup.AbstractStartup;
-import org.apache.synapse.core.axis2.ProxyService;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.axiom.om.impl.builder.StAXOMBuilder;
-import org.apache.axiom.om.OMElement;
-import org.apache.axiom.om.OMNode;
import javax.xml.stream.XMLStreamException;
import java.io.*;
@@ -51,7 +50,7 @@
* <li>CONF_HOME/endpoints</li>
* <li>CONF_HOME/local-entries</li>
* <li>CONF_HOME/tasks</li>
- * <li>CONF_HOME/events</li>
+ * <li>CONF_HOME/event-sources</li>
* </ul>
*
* Each of these directories will house a set of XML files. Each file will define exactly
@@ -117,25 +116,6 @@
createTasks(synapseConfig, root);
createEventSources(synapseConfig, root);
-
- if (synapseConfig.getLocalRegistry().isEmpty() &&
- synapseConfig.getProxyServices().isEmpty() && synapseConfig.getRegistry() != null) {
-
- if (log.isDebugEnabled()) {
- log.debug("No definitions were found at artifact repository : " + root +
- " except the registry definition. Attempting to load the configuration " +
- "from the defined registry.");
- }
-
- OMNode remoteConfigNode = synapseConfig.getRegistry().lookup("synapse.xml");
- if (remoteConfigNode != null) {
- synapseConfig = XMLConfigurationBuilder.getConfiguration(
- SynapseConfigUtils.getStreamSource(remoteConfigNode).getInputStream());
- } else if (log.isDebugEnabled()) {
- log.debug("The resource synapse.xml is not available in the Synapse registry.");
- }
- }
-
return synapseConfig;
}
Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/SynapseXMLConfigurationFactory.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/SynapseXMLConfigurationFactory.java?rev=804718&r1=804717&r2=804718&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/SynapseXMLConfigurationFactory.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/SynapseXMLConfigurationFactory.java Sun Aug 16 16:57:16 2009
@@ -20,16 +20,13 @@
package org.apache.synapse.config.xml;
import org.apache.axiom.om.OMElement;
-import org.apache.axiom.om.OMNode;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.synapse.Mediator;
import org.apache.synapse.Startup;
import org.apache.synapse.SynapseConstants;
import org.apache.synapse.SynapseException;
-import org.apache.synapse.registry.Registry;
import org.apache.synapse.aspects.AspectConfiguration;
-import org.apache.synapse.eventing.SynapseEventSource;
import org.apache.synapse.config.Entry;
import org.apache.synapse.config.SynapseConfigUtils;
import org.apache.synapse.config.SynapseConfiguration;
@@ -37,15 +34,11 @@
import org.apache.synapse.config.xml.eventing.EventSourceFactory;
import org.apache.synapse.core.axis2.ProxyService;
import org.apache.synapse.endpoints.Endpoint;
-import org.apache.synapse.mediators.MediatorProperty;
+import org.apache.synapse.eventing.SynapseEventSource;
import org.apache.synapse.mediators.base.SequenceMediator;
-import org.apache.synapse.mediators.builtin.DropMediator;
-import org.apache.synapse.mediators.builtin.LogMediator;
-import org.apache.synapse.util.xpath.SynapseXPath;
-import org.jaxen.JaxenException;
+import org.apache.synapse.registry.Registry;
import javax.xml.namespace.QName;
-import javax.xml.stream.XMLStreamException;
import java.util.Iterator;
public class SynapseXMLConfigurationFactory implements ConfigurationFactory {
@@ -102,22 +95,6 @@
}
}
- Registry localConfigReg = config.getRegistry();
- if (config.getLocalRegistry().isEmpty() && config.getProxyServices().isEmpty() &&
- rootSequence.getList().isEmpty() && localConfigReg != null) {
- OMNode remoteConfigNode = localConfigReg.lookup("synapse.xml");
- try {
- config = XMLConfigurationBuilder.getConfiguration(SynapseConfigUtils
- .getStreamSource(remoteConfigNode).getInputStream());
- if (config.getRegistry() == null) {
- config.setRegistry(localConfigReg);
- }
- } catch (XMLStreamException xse) {
- throw new SynapseException("Problem loading remote synapse.xml ", xse);
- }
-
- }
-
// if there is no sequence named main defined locally look for the set of mediators in
// the root level before trying to look in the registry (hence config.getMainSequence
// can not be used here)
@@ -195,76 +172,13 @@
return null;
}
- public static SynapseEventSource defineEventSource(SynapseConfiguration config, OMElement elem) {
+ public static SynapseEventSource defineEventSource(SynapseConfiguration config,
+ OMElement elem) {
SynapseEventSource eventSource = EventSourceFactory.createEventSource(elem);
config.addEventSource(eventSource.getName(), eventSource);
return eventSource;
}
- /**
- * Return the main sequence if one is not defined. This implementation defaults to
- * a simple sequence with a <send/>
- *
- * @param config the configuration to be updated
- */
- public static void setDefaultMainSequence(SynapseConfiguration config) {
- SequenceMediator main = new SequenceMediator();
- main.setName(SynapseConstants.MAIN_SEQUENCE_KEY);
- main.addChild(new LogMediator());
- main.addChild(new DropMediator());
- config.addSequence(SynapseConstants.MAIN_SEQUENCE_KEY, main);
- // set the aspect configuration
- AspectConfiguration configuration = new AspectConfiguration(main.getName());
- main.configure(configuration);
- }
-
- /**
- * Return the fault sequence if one is not defined. This implementation defaults to
- * a simple sequence :
- * <log level="full">
- * <property name="MESSAGE" value="Executing default "fault" sequence"/>
- * <property name="ERROR_CODE" expression="get-property('ERROR_CODE')"/>
- * <property name="ERROR_MESSAGE" expression="get-property('ERROR_MESSAGE')"/>
- * </log>
- * <drop/>
- *
- * @param config the configuration to be updated
- */
- public static void setDefaultFaultSequence(SynapseConfiguration config) {
- SequenceMediator fault = new SequenceMediator();
- fault.setName(org.apache.synapse.SynapseConstants.FAULT_SEQUENCE_KEY);
- LogMediator log = new LogMediator();
- log.setLogLevel(LogMediator.FULL);
-
- MediatorProperty mp = new MediatorProperty();
- mp.setName("MESSAGE");
- mp.setValue("Executing default \"fault\" sequence");
- log.addProperty(mp);
-
- mp = new MediatorProperty();
- mp.setName("ERROR_CODE");
- try {
- mp.setExpression(new SynapseXPath("get-property('ERROR_CODE')"));
- } catch (JaxenException ignore) {}
- log.addProperty(mp);
-
- mp = new MediatorProperty();
- mp.setName("ERROR_MESSAGE");
- try {
- mp.setExpression(new SynapseXPath("get-property('ERROR_MESSAGE')"));
- } catch (JaxenException ignore) {}
- log.addProperty(mp);
-
- fault.addChild(log);
- fault.addChild(new DropMediator());
-
- // set aspect configuration
- AspectConfiguration configuration = new AspectConfiguration(fault.getName());
- fault.configure(configuration);
-
- config.addSequence(org.apache.synapse.SynapseConstants.FAULT_SEQUENCE_KEY, fault);
- }
-
private static void handleException(String msg) {
log.error(msg);
throw new SynapseException(msg);