Return-Path: Delivered-To: apmail-ws-synapse-dev-archive@www.apache.org Received: (qmail 69441 invoked from network); 30 Jul 2007 12:37:40 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 30 Jul 2007 12:37:40 -0000 Received: (qmail 59515 invoked by uid 500); 30 Jul 2007 12:37:40 -0000 Delivered-To: apmail-ws-synapse-dev-archive@ws.apache.org Received: (qmail 59468 invoked by uid 500); 30 Jul 2007 12:37:40 -0000 Mailing-List: contact synapse-dev-help@ws.apache.org; run by ezmlm Precedence: bulk Reply-To: synapse-dev@ws.apache.org list-help: list-unsubscribe: List-Post: List-Id: Delivered-To: mailing list synapse-dev@ws.apache.org Received: (qmail 59457 invoked by uid 500); 30 Jul 2007 12:37:40 -0000 Delivered-To: apmail-ws-synapse-cvs@ws.apache.org Received: (qmail 59454 invoked by uid 99); 30 Jul 2007 12:37:40 -0000 Received: from Unknown (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 30 Jul 2007 05:37:40 -0700 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 30 Jul 2007 12:37:39 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 03C4F1A981A; Mon, 30 Jul 2007 05:37:19 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r560948 - in /webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config: SynapseConfiguration.java xml/XMLConfigurationBuilder.java Date: Mon, 30 Jul 2007 12:37:18 -0000 To: synapse-cvs@ws.apache.org From: pzf@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070730123719.03C4F1A981A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: pzf Date: Mon Jul 30 05:37:18 2007 New Revision: 560948 URL: http://svn.apache.org/viewvc?view=rev&rev=560948 Log: updated synapse to support pluggable configuration XML file types see JIRA https://issues.apache.org/jira/browse/SYNAPSE-111 Modified: 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/xml/XMLConfigurationBuilder.java 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=560948&r1=560947&r2=560948 ============================================================================== --- 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 Jul 30 05:37:18 2007 @@ -32,13 +32,9 @@ import org.apache.synapse.registry.Registry; import org.apache.axis2.AxisFault; import org.apache.axis2.engine.AxisConfiguration; -import org.apache.axiom.om.impl.builder.StAXOMBuilder; -import javax.xml.stream.XMLStreamReader; -import javax.xml.stream.XMLInputFactory; -import javax.xml.stream.XMLStreamException; +import javax.xml.namespace.QName; import java.util.*; -import java.net.URLConnection; import java.io.IOException; /** @@ -52,6 +48,7 @@ /** The remote registry made available to the Synapse configuration. Only one is supported */ Registry registry = null; + private QName defaultQName = null; /** Holds Proxy services defined through Synapse */ private Map proxyServices = new HashMap(); @@ -435,4 +432,12 @@ log.error(msg); throw new SynapseException(msg); } + + public void setDefaultQName(QName defaultQName) { + this.defaultQName = defaultQName; + } + + public QName getDefaultQName() { + return defaultQName; + } } Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/XMLConfigurationBuilder.java URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/XMLConfigurationBuilder.java?view=diff&rev=560948&r1=560947&r2=560948 ============================================================================== --- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/XMLConfigurationBuilder.java (original) +++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/XMLConfigurationBuilder.java Mon Jul 30 05:37:18 2007 @@ -19,27 +19,15 @@ package org.apache.synapse.config.xml; +import java.io.InputStream; + import org.apache.axiom.om.*; import org.apache.axiom.om.impl.builder.StAXOMBuilder; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.synapse.SynapseException; -import org.apache.synapse.Mediator; import org.apache.synapse.config.SynapseConfiguration; -import org.apache.synapse.config.Entry; -import org.apache.synapse.config.Util; -import org.apache.synapse.config.xml.endpoints.EndpointAbstractFactory; -import org.apache.synapse.core.axis2.ProxyService; -import org.apache.synapse.mediators.base.SequenceMediator; -import org.apache.synapse.mediators.builtin.SendMediator; -import org.apache.synapse.endpoints.Endpoint; -import org.apache.synapse.mediators.builtin.LogMediator; -import javax.xml.namespace.QName; import javax.xml.stream.XMLStreamException; -import java.io.IOException; -import java.io.InputStream; -import java.util.Iterator; /** @@ -49,183 +37,17 @@ private static Log log = LogFactory.getLog(XMLConfigurationBuilder.class); - public static SynapseConfiguration getConfiguration(InputStream is) { + public static SynapseConfiguration getConfiguration(InputStream is) throws XMLStreamException { + log.info("Generating the Synapse configuration model by parsing the XML configuration"); - SynapseConfiguration config = new SynapseConfiguration(); - - SequenceMediator rootSequence = new SequenceMediator(); - rootSequence.setName(org.apache.synapse.Constants.MAIN_SEQUENCE_KEY); - OMElement definitions = null; - try { - definitions = new StAXOMBuilder(is).getDocumentElement(); - definitions.build(); - - OMNamespace namespace = definitions.getNamespace(); - if(namespace == null){ - handleException("No namespace is defined for definitions element"); - } - - if (Constants.SYNAPSE_NAMESPACE.equals(namespace.getNamespaceURI()) - && Constants.DEFINITIONS_ELT.getLocalPart() - .equals(definitions.getQName().getLocalPart())) { - - Iterator iter = definitions.getChildren(); - - while (iter.hasNext()) { - Object o = iter.next(); - if (o instanceof OMElement) { - OMElement elt = (OMElement) o; - if (Constants.SEQUENCE_ELT.equals(elt.getQName())) { - String key = elt.getAttributeValue( - new QName(Constants.NULL_NAMESPACE, "key")); - // this could be a sequence def or a mediator of the main sequence - if (key != null) { - Mediator m = MediatorFactoryFinder.getInstance().getMediator(elt); - rootSequence.addChild(m); - } else { - defineSequence(config, elt); - } - } else if (Constants.ENDPOINT_ELT.equals(elt.getQName())) { - defineEndpoint(config, elt); - } else if (Constants.ENTRY_ELT.equals(elt.getQName())) { - defineEntry(config, elt); - } else if (Constants.PROXY_ELT.equals(elt.getQName())) { - defineProxy(config, elt); - } else if (Constants.REGISTRY_ELT.equals(elt.getQName())) { - defineRegistry(config, elt); - } else { - Mediator m = MediatorFactoryFinder.getInstance().getMediator(elt); - rootSequence.addChild(m); - } - } - } - } else { - handleException("Invalid Synapse Configuration : No definition element found"); - } - - } catch (XMLStreamException e) { - handleException("Error parsing Synapse configuration : " + e.getMessage(), e); - } - - if (is != null) { - try { - is.close(); - } catch (IOException ignore) {} - } - - if (config.getLocalRegistry().isEmpty() && config.getProxyServices().isEmpty() && - rootSequence.getList().isEmpty() && config.getRegistry() != null) { - OMNode remoteConfigNode = config.getRegistry().lookup("synapse.xml"); - config = getConfiguration(Util.getStreamSource(remoteConfigNode).getInputStream()); - } - - if (config.getMainSequence() == null) { - if (rootSequence.getList().isEmpty()) { - setDefaultMainSequence(config); - } else { - config.addSequence(rootSequence.getName(), rootSequence); - } - } else if (!rootSequence.getList().isEmpty()) { - handleException("Invalid Synapse Configuration : Conflict in resolving the \"main\" " + - "mediator\n\tSynapse Configuration cannot have sequence named \"main\" and " + - "toplevel mediators simultaniously"); - } - - if (config.getFaultSequence() == null) { - setDefaultFaultSequence(config); - } - + + definitions = new StAXOMBuilder(is).getDocumentElement(); + definitions.build(); + + SynapseConfiguration config = ConfigurationFactoryAndSerializerFinder.getInstance().getConfiguration(definitions); return config; + } - - private static void defineRegistry(SynapseConfiguration config, OMElement elem) { - if (config.getRegistry() != null) { - handleException("Only one remote registry can be defined within a configuration"); - } - config.setRegistry(RegistryFactory.createRegistry(elem)); - } - - private static void defineProxy(SynapseConfiguration config, OMElement elem) { - ProxyService proxy = ProxyServiceFactory.createProxy(elem); - if (config.getProxyService(proxy.getName()) != null) { - handleException("Duplicate proxy service with name : " + proxy.getName()); - } - config.addProxyService(proxy.getName(), proxy); - } - - private static void defineEntry(SynapseConfiguration config, OMElement elem) { - Entry entry = EntryFactory.createEntry(elem); - if (config.getLocalRegistry().get(entry.getKey()) != null) { - handleException("Duplicate registry entry definition for key : " + entry.getKey()); - } - config.addEntry(entry.getKey(), entry); - } - - public static void defineSequence(SynapseConfiguration config, OMElement ele) { - - String name = ele.getAttributeValue(new QName(Constants.NULL_NAMESPACE, "name")); - if (name != null) { - if (config.getLocalRegistry().get(name) != null) { - handleException("Duplicate sequence definition : " + name); - } - config.addSequence(name, MediatorFactoryFinder.getInstance().getMediator(ele)); - } else { - handleException("Invalid sequence definition without a name"); - } - } - - public static void defineEndpoint(SynapseConfiguration config, OMElement ele) { - - String name = ele.getAttributeValue(new QName(Constants.NULL_NAMESPACE, "name")); - if (name != null) { - if (config.getLocalRegistry().get(name.trim()) != null) { - handleException("Duplicate endpoint definition : " + name); - } - Endpoint endpoint = - EndpointAbstractFactory.getEndpointFactroy(ele).createEndpoint(ele, false); - config.addEndpoint(name.trim(), endpoint); - } else { - handleException("Invalid endpoint definition without a name"); - } - } - - /** - * Return the main sequence if one is not defined. This implementation defaults to - * a simple sequence with a - * - * @param config the configuration to be updated - */ - private static void setDefaultMainSequence(SynapseConfiguration config) { - SequenceMediator main = new SequenceMediator(); - main.setName(org.apache.synapse.Constants.MAIN_SEQUENCE_KEY); - main.addChild(new SendMediator()); - config.addSequence(org.apache.synapse.Constants.MAIN_SEQUENCE_KEY, main); - } - - /** - * Return the fault sequence if one is not defined. This implementation defaults to - * a simple sequence with a - * - * @param config the configuration to be updated - */ - private static void setDefaultFaultSequence(SynapseConfiguration config) { - SequenceMediator fault = new SequenceMediator(); - fault.setName(org.apache.synapse.Constants.FAULT_SEQUENCE_KEY); - LogMediator log = new LogMediator(); - log.setLogLevel(LogMediator.FULL); - fault.addChild(log); - config.addSequence(org.apache.synapse.Constants.FAULT_SEQUENCE_KEY, fault); - } - - private static void handleException(String msg) { - log.error(msg); - throw new SynapseException(msg); - } - - private static void handleException(String msg, Exception e) { - log.error(msg, e); - throw new SynapseException(msg, e); - } -} +} \ No newline at end of file --------------------------------------------------------------------- To unsubscribe, e-mail: synapse-dev-unsubscribe@ws.apache.org For additional commands, e-mail: synapse-dev-help@ws.apache.org