You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@synapse.apache.org by su...@apache.org on 2011/03/10 10:16:33 UTC

svn commit: r1080161 [1/2] - in /synapse/trunk/java/modules/core/src/main/java/org/apache/synapse: ./ config/ config/xml/ config/xml/endpoints/ config/xml/endpoints/utils/ endpoints/

Author: supun
Date: Thu Mar 10 09:16:32 2011
New Revision: 1080161

URL: http://svn.apache.org/viewvc?rev=1080161&view=rev
Log:
adding endpoint templates capabilities

Added:
    synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/EndpointDefinitionFactory.java
    synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/EndpointDefinitionSerializer.java
    synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/TemplateEndpointFactory.java
    synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/TemplateEndpointSerializer.java
    synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/TemplateFactory.java
    synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/TemplateSerializer.java
    synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/Template.java
    synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/TemplateEndpoint.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/config/SynapseConfiguration.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
    synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/SynapseXMLConfigurationSerializer.java
    synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/XMLConfigConstants.java
    synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/AddressEndpointFactory.java
    synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/AddressEndpointSerializer.java
    synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/DefaultEndpointFactory.java
    synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/DefaultEndpointSerializer.java
    synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/EndpointFactory.java
    synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/EndpointSerializer.java
    synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/WSDLEndpointFactory.java
    synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/WSDLEndpointSerializer.java
    synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/utils/WSDL11EndpointBuilder.java

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=1080161&r1=1080160&r2=1080161&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 Thu Mar 10 09:16:32 2011
@@ -413,7 +413,5 @@ public final class SynapseConstants {
     public static final String FAIL_SAFE_MODE_SEQUENCES = "sequences";
     public static final String FAIL_SAFE_MODE_EVENT_SOURCE = "eventsources";
     public static final String FAIL_SAFE_MODE_EXECUTORS = "executors";
-
-    
-
+    public static final String FAIL_SAFE_MODE_TEMPLATES = "executors";
 }

Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/SynapseConfiguration.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/SynapseConfiguration.java?rev=1080161&r1=1080160&r2=1080161&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/SynapseConfiguration.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/SynapseConfiguration.java Thu Mar 10 09:16:32 2011
@@ -24,6 +24,8 @@ import org.apache.axis2.engine.AxisConfi
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.synapse.*;
+import org.apache.synapse.endpoints.Template;
+import org.apache.synapse.endpoints.TemplateEndpoint;
 import org.apache.synapse.message.processors.MessageProcessor;
 import org.apache.synapse.message.store.MessageStore;
 import org.apache.synapse.deployers.SynapseArtifactDeploymentStore;
@@ -137,6 +139,16 @@ public class SynapseConfiguration implem
     private Map<String , MessageProcessor> messageProcessors = new ConcurrentHashMap<String ,MessageProcessor>();
 
     /**
+     * Endpoint templates to create actual endpoints
+     */
+    private Map<String, Template> endpointTemplates = new ConcurrentHashMap<String, Template>();
+
+    /**
+     * Endpoints map for holding the endpoints references
+     */
+    private Map<String, TemplateEndpoint> endpointGroups = new ConcurrentHashMap<String, TemplateEndpoint>();
+
+    /**
      * Description/documentation of the configuration
      */
     private String description = null;
@@ -1395,4 +1407,20 @@ public class SynapseConfiguration implem
             handleException("Cannot locate an either local or remote enrty for key : " + key);
         }
     }
+
+    public void addEndpointGroup(String name, TemplateEndpoint group) {
+        endpointGroups.put(name, group);
+    }
+
+    public Map<String, TemplateEndpoint> getEndpointGroups() {
+        return endpointGroups;
+    }
+
+    public void addEndpointTemplate(String name, Template template) {
+        endpointTemplates.put(name, template);
+    }
+
+    public Map<String, Template> getEndpointTemplates() {
+        return endpointTemplates;
+    }
 }

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=1080161&r1=1080160&r2=1080161&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 Thu Mar 10 09:16:32 2011
@@ -287,7 +287,7 @@ public class MultiXMLConfigurationBuilde
             for (File file : sequences) {
                 try {
                     OMElement document = parseFile(file);
-                    Mediator seq = SynapseXMLConfigurationFactory.defineTemplate(
+                    Mediator seq = SynapseXMLConfigurationFactory.defineMediatorTemplate(
                             synapseConfig, document, properties);
                     if (seq != null && seq instanceof TemplateMediator) {
                         TemplateMediator templateSeq = (TemplateMediator) seq;

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=1080161&r1=1080160&r2=1080161&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 Thu Mar 10 09:16:32 2011
@@ -26,6 +26,8 @@ import org.apache.synapse.Mediator;
 import org.apache.synapse.Startup;
 import org.apache.synapse.SynapseConstants;
 import org.apache.synapse.SynapseException;
+import org.apache.synapse.config.xml.endpoints.TemplateFactory;
+import org.apache.synapse.endpoints.Template;
 import org.apache.synapse.message.processors.MessageProcessor;
 import org.apache.synapse.message.store.MessageStore;
 import org.apache.synapse.commons.executors.PriorityExecutor;
@@ -95,7 +97,7 @@ public class SynapseXMLConfigurationFact
                     defineMessageStore(config, elt, properties);
                 } else if (XMLConfigConstants.MESSAGE_PROCESSOR_ELT.equals(elt.getQName())){
                     defineMessageProcessor(config,elt,properties);
-                }else if (StartupFinder.getInstance().isStartup(elt.getQName())) {
+                } else if (StartupFinder.getInstance().isStartup(elt.getQName())) {
                     defineStartup(config, elt, properties);
                 } else if (XMLConfigConstants.DESCRIPTION_ELT.equals(elt.getQName())) {
                     config.setDescription(elt.getText());
@@ -210,16 +212,21 @@ public class SynapseXMLConfigurationFact
             }
             return mediator;
         } else {
-            handleException("Invalid sequence definition without a name");
+            if (failSafeSequenceEnabled) {
+                log.warn("Invalid sequence definition without a name");
+                log.warn("Continue in Sequence fail-safe mode.");
+            } else {
+                handleException("Invalid sequence definition without a name");
+            }
         }
         return null;
     }
 
-    public static Mediator defineTemplate(SynapseConfiguration config, OMElement ele,
-                                          Properties properties) {
+    public static Mediator defineMediatorTemplate(SynapseConfiguration config, OMElement ele,
+                                                  Properties properties) {
 
         boolean failSafeSequenceEnabled = isFailSafeEnabled(
-                SynapseConstants.FAIL_SAFE_MODE_SEQUENCES);
+                SynapseConstants.FAIL_SAFE_MODE_TEMPLATES);
 
         Mediator mediator = null;
         String name = ele.getAttributeValue(new QName(XMLConfigConstants.NULL_NAMESPACE, "name"));
@@ -239,7 +246,12 @@ public class SynapseXMLConfigurationFact
             }
             return mediator;
         } else {
-            handleException("Invalid template definition without a name");
+            if (failSafeSequenceEnabled) {
+                log.warn("Invalid template definition without a name");
+                log.warn("Continue in fail-safe mode.");
+            } else {
+                handleException("Invalid template definition without a name");
+            }
         }
         return null;
     }
@@ -266,7 +278,12 @@ public class SynapseXMLConfigurationFact
             }
             return endpoint;
         } else {
-            handleException("Invalid endpoint definition without a name");
+            if (failSafeEpEnabled) {
+                log.warn("Invalid endpoint definition without a name");
+                log.warn("Continue in Endpoint fail-safe mode.");
+            } else {
+                handleException("Invalid endpoint definition without a name");
+            }
         }
         return null;
     }
@@ -329,6 +346,44 @@ public class SynapseXMLConfigurationFact
         return processor;
     }
 
+    public static Template defineEndpointTemplate(SynapseConfiguration config,
+                                                    OMElement elem, Properties properties) {
+        boolean failSafeExecutorsEnabled = isFailSafeEnabled(
+                SynapseConstants.FAIL_SAFE_MODE_TEMPLATES);
+        TemplateFactory templateFactory = new TemplateFactory();
+        String name = elem.getAttributeValue(new QName(XMLConfigConstants.NULL_NAMESPACE, "name"));
+        try {
+            Template template = templateFactory.createEndpointTemplate(elem, properties);
+            if (template != null) {
+                config.addEndpointTemplate(template.getName(), template);
+            }
+            return template;
+        } catch (Exception e) {
+            if (failSafeExecutorsEnabled) {
+                log.warn("Endpoint Template: " + name + "configuration cannot be built.", e);
+                log.warn("Continue in Endpoint Template fail-safe mode.");
+            } else {
+                handleException("Endpoint Template configuration cannot be built.");
+            }
+        }
+        return null;
+    }
+
+    public static void defineTemplate(SynapseConfiguration config,
+                                      OMElement elem, Properties properties) {
+        OMElement element = elem.getFirstChildWithName(
+                new QName(SynapseConstants.SYNAPSE_NAMESPACE, "sequence"));
+        if (element != null) {
+            defineMediatorTemplate(config, elem, properties);
+        }
+
+        element = elem.getFirstChildWithName(
+                new QName(SynapseConstants.SYNAPSE_NAMESPACE, "endpoint"));
+        if (element != null) {
+            defineEndpointTemplate(config, elem, properties);
+        }
+    }
+
     private static void handleException(String msg) {
         log.error(msg);
         throw new SynapseException(msg);

Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/SynapseXMLConfigurationSerializer.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/SynapseXMLConfigurationSerializer.java?rev=1080161&r1=1080160&r2=1080161&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/SynapseXMLConfigurationSerializer.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/SynapseXMLConfigurationSerializer.java Thu Mar 10 09:16:32 2011
@@ -28,6 +28,8 @@ import org.apache.commons.logging.LogFac
 import org.apache.synapse.Startup;
 import org.apache.synapse.SynapseConstants;
 import org.apache.synapse.SynapseException;
+import org.apache.synapse.config.xml.endpoints.TemplateSerializer;
+import org.apache.synapse.endpoints.Template;
 import org.apache.synapse.mediators.template.TemplateMediator;
 import org.apache.synapse.message.processors.MessageProcessor;
 import org.apache.synapse.message.store.MessageStore;
@@ -129,7 +131,10 @@ public class SynapseXMLConfigurationSeri
         serializeSequences(definitions, sequences);
 
         // process templates
-        serializeTemplates(definitions, templates);
+        serializeMediatorTemplates(definitions, templates);
+
+        // serialize the endpoint templates
+        serializeEndpointTemplates(definitions, synCfg.getEndpointTemplates());
 
         // handle startups
         serializeStartups(definitions, synCfg.getStartups());
@@ -175,8 +180,8 @@ public class SynapseXMLConfigurationSeri
         }
     }
 
-    private static void serializeTemplates(OMElement definitions,
-                                           Map<String, TemplateMediator> eipSequences) {
+    private static void serializeMediatorTemplates(OMElement definitions,
+                                                   Map<String, TemplateMediator> eipSequences) {
         for (TemplateMediator template : eipSequences.values()) {
             MediatorSerializerFinder.getInstance().getSerializer(template)
                     .serializeMediator(definitions, template);
@@ -207,6 +212,14 @@ public class SynapseXMLConfigurationSeri
         }
     }
 
+    private static void serializeEndpointTemplates(OMElement definitions,
+                                                   Map<String, Template> templateMap) {
+        for (Template template : templateMap.values()) {
+            TemplateSerializer serializer = new TemplateSerializer();
+            serializer.serializeEndpointTemplate(template, definitions);
+        }
+    }
+
     private static void handleException(String msg) {
         log.error(msg);
         throw new SynapseException(msg);

Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/XMLConfigConstants.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/XMLConfigConstants.java?rev=1080161&r1=1080160&r2=1080161&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/XMLConfigConstants.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/XMLConfigConstants.java Thu Mar 10 09:16:32 2011
@@ -74,6 +74,7 @@ public class XMLConfigConstants {
     public static final QName MESSAGE_STORE_ELT = new QName(SYNAPSE_NAMESPACE, "messageStore");
     public static final QName MESSAGE_PROCESSOR_ELT = new QName(SYNAPSE_NAMESPACE ,
                                                                                 "messageProcessor");
+
     public static final String NULL_NAMESPACE = "";
     public static final Object QUARTZ_QNAME   =
         new QName("http://www.opensymphony.com/quartz/JobSchedulingData", "quartz");

Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/AddressEndpointFactory.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/AddressEndpointFactory.java?rev=1080161&r1=1080160&r2=1080161&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/AddressEndpointFactory.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/AddressEndpointFactory.java Thu Mar 10 09:16:32 2011
@@ -106,13 +106,13 @@ public class AddressEndpointFactory exte
     public EndpointDefinition createEndpointDefinition(OMElement elem) {
 
         OMAttribute address = elem.getAttribute(new QName("uri"));
-        EndpointDefinition endpointDefinition = new EndpointDefinition();
+        EndpointDefinitionFactory fac = new EndpointDefinitionFactory();
+        EndpointDefinition endpointDefinition = fac.createDefinition(elem);
 
         if (address != null) {
             endpointDefinition.setAddress(address.getAttributeValue().trim());
         }
 
-        extractCommonEndpointProperties(endpointDefinition, elem);
         extractSpecificEndpointProperties(endpointDefinition, elem);
         return endpointDefinition;
     }

Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/AddressEndpointSerializer.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/AddressEndpointSerializer.java?rev=1080161&r1=1080160&r2=1080161&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/AddressEndpointSerializer.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/AddressEndpointSerializer.java Thu Mar 10 09:16:32 2011
@@ -49,7 +49,7 @@ public class AddressEndpointSerializer e
         // serialize the properties
         serializeProperties(addressEndpoint, endpointElement);
         //serialize attributes
-        serializeCommonAttributes(endpoint,endpointElement);
+        serializeCommonAttributes(endpoint, endpointElement);
 
         EndpointDefinition epAddress = addressEndpoint.getDefinition();
         OMElement addressElement = serializeEndpointDefinition(epAddress);
@@ -70,9 +70,10 @@ public class AddressEndpointSerializer e
             handleException("Invalid Endpoint. Address is required");
         }
 
-        serializeCommonEndpointProperties(endpointDefinition, element);
-        serializeSpecificEndpointProperties(endpointDefinition, element);
+        EndpointDefinitionSerializer serializer = new EndpointDefinitionSerializer();
+        serializer.serializeEndpointDefinition(endpointDefinition, element);
 
+        serializeSpecificEndpointProperties(endpointDefinition, element);
         return element;
     }
 }

Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/DefaultEndpointFactory.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/DefaultEndpointFactory.java?rev=1080161&r1=1080160&r2=1080161&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/DefaultEndpointFactory.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/DefaultEndpointFactory.java Thu Mar 10 09:16:32 2011
@@ -137,8 +137,8 @@ public class DefaultEndpointFactory exte
      * @return EndpointDefinition object containing the endpoint details.
      */
     public EndpointDefinition createEndpointDefinition(OMElement elem) {
-        EndpointDefinition endpointDefinition = new EndpointDefinition();
-        extractCommonEndpointProperties(endpointDefinition, elem);
+        EndpointDefinitionFactory fac = new EndpointDefinitionFactory();
+        EndpointDefinition endpointDefinition = fac.createDefinition(elem);
         extractSpecificEndpointProperties(endpointDefinition, elem);
         return endpointDefinition;
     }

Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/DefaultEndpointSerializer.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/DefaultEndpointSerializer.java?rev=1080161&r1=1080160&r2=1080161&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/DefaultEndpointSerializer.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/DefaultEndpointSerializer.java Thu Mar 10 09:16:32 2011
@@ -88,8 +88,10 @@ public class DefaultEndpointSerializer e
     }
 
     public OMElement serializeEndpointDefinition(EndpointDefinition endpointDefinition) {
+        EndpointDefinitionSerializer serializer = new EndpointDefinitionSerializer();
+
         OMElement element = fac.createOMElement("default", SynapseConstants.SYNAPSE_OMNAMESPACE);
-        serializeCommonEndpointProperties(endpointDefinition, element);
+        serializer.serializeEndpointDefinition(endpointDefinition, element);
         serializeSpecificEndpointProperties(endpointDefinition, element);
         return element;
     }

Added: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/EndpointDefinitionFactory.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/EndpointDefinitionFactory.java?rev=1080161&view=auto
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/EndpointDefinitionFactory.java (added)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/EndpointDefinitionFactory.java Thu Mar 10 09:16:32 2011
@@ -0,0 +1,353 @@
+/*
+ *  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.config.xml.endpoints;
+
+import org.apache.axiom.om.OMAttribute;
+import org.apache.axiom.om.OMElement;
+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.XMLConfigConstants;
+import org.apache.synapse.endpoints.EndpointDefinition;
+
+import javax.xml.namespace.QName;
+import java.util.StringTokenizer;
+
+public class EndpointDefinitionFactory {
+    public static final Log log = LogFactory.getLog(EndpointDefinitionFactory.class);
+
+    /**
+     * Extracts the QoS information from the XML which represents a WSDL/Address/Default endpoints
+     *
+     * @param elem XML which represents the endpoint with QoS information
+     * @return the created endpoint definition
+     */
+    public EndpointDefinition createDefinition(OMElement elem) {
+        EndpointDefinition definition = new EndpointDefinition();
+
+        OMAttribute optimize
+                = elem.getAttribute(new QName(XMLConfigConstants.NULL_NAMESPACE, "optimize"));
+        OMAttribute encoding
+                = elem.getAttribute(new QName(XMLConfigConstants.NULL_NAMESPACE, "encoding"));
+
+        OMAttribute trace = elem.getAttribute(new QName(
+                XMLConfigConstants.NULL_NAMESPACE, XMLConfigConstants.TRACE_ATTRIB_NAME));
+        if (trace != null && trace.getAttributeValue() != null) {
+            String traceValue = trace.getAttributeValue();
+            if (XMLConfigConstants.TRACE_ENABLE.equals(traceValue)) {
+                definition.setTraceState(SynapseConstants.TRACING_ON);
+            } else if (XMLConfigConstants.TRACE_DISABLE.equals(traceValue)) {
+                definition.setTraceState(SynapseConstants.TRACING_OFF);
+            }
+        } else {
+            definition.setTraceState(SynapseConstants.TRACING_UNSET);
+        }
+
+
+        if (optimize != null && optimize.getAttributeValue().length() > 0) {
+            String method = optimize.getAttributeValue().trim();
+            if ("mtom".equalsIgnoreCase(method)) {
+                definition.setUseMTOM(true);
+            } else if ("swa".equalsIgnoreCase(method)) {
+                definition.setUseSwa(true);
+            }
+        }
+
+        if (encoding != null && encoding.getAttributeValue() != null) {
+            definition.setCharSetEncoding(encoding.getAttributeValue());
+        }
+
+        OMElement wsAddr = elem.getFirstChildWithName(
+                new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, "enableAddressing"));
+        if (wsAddr != null) {
+
+            definition.setAddressingOn(true);
+
+            OMAttribute version = wsAddr.getAttribute(new QName("version"));
+            if (version != null && version.getAttributeValue() != null) {
+                String versionValue = version.getAttributeValue().trim().toLowerCase();
+                if (SynapseConstants.ADDRESSING_VERSION_FINAL.equals(versionValue) ||
+                        SynapseConstants.ADDRESSING_VERSION_SUBMISSION.equals(versionValue)) {
+                    definition.setAddressingVersion(version.getAttributeValue());
+                } else {
+                    handleException("Unknown value for the addressing version. Possible values " +
+                            "for the addressing version are 'final' and 'submission' only.");
+                }
+            }
+
+            String useSepList = wsAddr.getAttributeValue(new QName("separateListener"));
+            if (useSepList != null) {
+                if ("true".equals(useSepList.trim().toLowerCase())) {
+                    definition.setUseSeparateListener(true);
+                }
+            }
+        }
+
+        OMElement wsSec = elem.getFirstChildWithName(
+                new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, "enableSec"));
+        if (wsSec != null) {
+
+            definition.setSecurityOn(true);
+
+            OMAttribute policyKey      = wsSec.getAttribute(
+                    new QName(XMLConfigConstants.NULL_NAMESPACE, "policy"));
+            OMAttribute inboundPolicyKey  = wsSec.getAttribute(
+                    new QName(XMLConfigConstants.NULL_NAMESPACE, "inboundPolicy"));
+            OMAttribute outboundPolicyKey = wsSec.getAttribute(
+                    new QName(XMLConfigConstants.NULL_NAMESPACE, "outboundPolicy"));
+
+            if (policyKey != null && policyKey.getAttributeValue() != null) {
+                definition.setWsSecPolicyKey(policyKey.getAttributeValue());
+            } else {
+                if (inboundPolicyKey != null && inboundPolicyKey.getAttributeValue() != null) {
+                    definition.setInboundWsSecPolicyKey(inboundPolicyKey.getAttributeValue());
+                }
+                if (outboundPolicyKey != null && outboundPolicyKey.getAttributeValue() != null) {
+                    definition.setOutboundWsSecPolicyKey(outboundPolicyKey.getAttributeValue());
+                }
+            }
+        }
+
+        OMElement wsRm = elem.getFirstChildWithName(
+                new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, "enableRM"));
+        if (wsRm != null) {
+
+            definition.setReliableMessagingOn(true);
+
+            OMAttribute policy
+                    = wsRm.getAttribute(new QName(XMLConfigConstants.NULL_NAMESPACE, "policy"));
+            if (policy != null) {
+                definition.setWsRMPolicyKey(policy.getAttributeValue());
+            }
+        }
+
+        // set the timeout configuration
+        OMElement timeout = elem.getFirstChildWithName(
+                new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, "timeout"));
+        if (timeout != null) {
+            OMElement duration = timeout.getFirstChildWithName(
+                    new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, "duration"));
+
+            if (duration != null) {
+                String d = duration.getText();
+                if (d != null) {
+                    try {
+                        long timeoutMilliSeconds = Long.parseLong(d.trim());
+                        definition.setTimeoutDuration(timeoutMilliSeconds);
+                    } catch (NumberFormatException e) {
+                        handleException("Endpoint timeout duration expected as a " +
+                                "number but was not a number");
+                    }
+                }
+            }
+
+            OMElement action = timeout.getFirstChildWithName(
+                    new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, "responseAction"));
+            if (action != null && action.getText() != null) {
+                String actionString = action.getText();
+                if ("discard".equalsIgnoreCase(actionString.trim())) {
+
+                    definition.setTimeoutAction(SynapseConstants.DISCARD);
+
+                    // set timeout duration to 30 seconds, if it is not set explicitly
+                    if (definition.getTimeoutDuration() == 0) {
+                        definition.setTimeoutDuration(30000);
+                    }
+                } else if ("fault".equalsIgnoreCase(actionString.trim())) {
+
+                    definition.setTimeoutAction(SynapseConstants.DISCARD_AND_FAULT);
+
+                    // set timeout duration to 30 seconds, if it is not set explicitly
+                    if (definition.getTimeoutDuration() == 0) {
+                        definition.setTimeoutDuration(30000);
+                    }
+                } else {
+                    handleException("Invalid timeout action, action : "
+                            + actionString + " is not supported");
+                }
+            }
+        }
+
+        OMElement markAsTimedOut = elem.getFirstChildWithName(new QName(
+            SynapseConstants.SYNAPSE_NAMESPACE,
+            XMLConfigConstants.MARK_FOR_SUSPENSION));
+
+        if (markAsTimedOut != null) {
+
+            OMElement timeoutCodes = markAsTimedOut.getFirstChildWithName(new QName(
+                SynapseConstants.SYNAPSE_NAMESPACE,
+                XMLConfigConstants.ERROR_CODES));
+            if (timeoutCodes != null && timeoutCodes.getText() != null) {
+                StringTokenizer st = new StringTokenizer(timeoutCodes.getText().trim(), ", ");
+                while (st.hasMoreTokens()) {
+                    String s = st.nextToken();
+                    try {
+                        definition.addTimeoutErrorCode(Integer.parseInt(s));
+                    } catch (NumberFormatException e) {
+                        handleException("The timeout error codes should be specified " +
+                            "as valid numbers separated by commas : " + timeoutCodes.getText(), e);
+                    }
+                }
+            }
+
+            OMElement retriesBeforeSuspend = markAsTimedOut.getFirstChildWithName(new QName(
+                SynapseConstants.SYNAPSE_NAMESPACE,
+                XMLConfigConstants.RETRIES_BEFORE_SUSPENSION));
+            if (retriesBeforeSuspend != null && retriesBeforeSuspend.getText() != null) {
+                try {
+                    definition.setRetriesOnTimeoutBeforeSuspend(
+                        Integer.parseInt(retriesBeforeSuspend.getText().trim()));
+                } catch (NumberFormatException e) {
+                    handleException("The retries before suspend [for timeouts] should be " +
+                        "specified as a valid number : " + retriesBeforeSuspend.getText(), e);
+                }
+            }
+
+            OMElement retryDelay = markAsTimedOut.getFirstChildWithName(new QName(
+                SynapseConstants.SYNAPSE_NAMESPACE,
+                XMLConfigConstants.RETRY_DELAY));
+            if (retryDelay != null && retryDelay.getText() != null) {
+                try {
+                    definition.setRetryDurationOnTimeout(
+                        Integer.parseInt(retryDelay.getText().trim()));
+                } catch (NumberFormatException e) {
+                    handleException("The retry delay for timeouts should be specified " +
+                        "as a valid number : " + retryDelay.getText(), e);
+                }
+            }
+        }
+
+        // support backwards compatibility with Synapse 1.2 - for suspendDurationOnFailure
+        OMElement suspendDurationOnFailure = elem.getFirstChildWithName(new QName(
+            SynapseConstants.SYNAPSE_NAMESPACE, "suspendDurationOnFailure"));
+        if (suspendDurationOnFailure != null && suspendDurationOnFailure.getText() != null) {
+
+            log.warn("Configuration uses deprecated style for endpoint 'suspendDurationOnFailure'");
+            try {
+                definition.setInitialSuspendDuration(
+                        1000 * Long.parseLong(suspendDurationOnFailure.getText().trim()));
+                definition.setSuspendProgressionFactor((float) 1.0);
+            } catch (NumberFormatException e) {
+                handleException("The initial suspend duration should be specified " +
+                    "as a valid number : " + suspendDurationOnFailure.getText(), e);
+            }
+        }
+
+        OMElement suspendOnFailure = elem.getFirstChildWithName(new QName(
+            SynapseConstants.SYNAPSE_NAMESPACE,
+            XMLConfigConstants.SUSPEND_ON_FAILURE));
+
+        if (suspendOnFailure != null) {
+
+            OMElement suspendCodes = suspendOnFailure.getFirstChildWithName(new QName(
+                SynapseConstants.SYNAPSE_NAMESPACE,
+                XMLConfigConstants.ERROR_CODES));
+            if (suspendCodes != null && suspendCodes.getText() != null) {
+
+                StringTokenizer st = new StringTokenizer(suspendCodes.getText().trim(), ", ");
+                while (st.hasMoreTokens()) {
+                    String s = st.nextToken();
+                    try {
+                        definition.addSuspendErrorCode(Integer.parseInt(s));
+                    } catch (NumberFormatException e) {
+                        handleException("The suspend error codes should be specified " +
+                            "as valid numbers separated by commas : " + suspendCodes.getText(), e);
+                    }
+                }
+            }
+
+            OMElement initialDuration = suspendOnFailure.getFirstChildWithName(new QName(
+                SynapseConstants.SYNAPSE_NAMESPACE,
+                XMLConfigConstants.SUSPEND_INITIAL_DURATION));
+            if (initialDuration != null && initialDuration.getText() != null) {
+                try {
+                    definition.setInitialSuspendDuration(
+                        Integer.parseInt(initialDuration.getText().trim()));
+                } catch (NumberFormatException e) {
+                    handleException("The initial suspend duration should be specified " +
+                        "as a valid number : " + initialDuration.getText(), e);
+                }
+            }
+
+            OMElement progressionFactor = suspendOnFailure.getFirstChildWithName(new QName(
+                SynapseConstants.SYNAPSE_NAMESPACE,
+                XMLConfigConstants.SUSPEND_PROGRESSION_FACTOR));
+            if (progressionFactor != null && progressionFactor.getText() != null) {
+                try {
+                    definition.setSuspendProgressionFactor(
+                        Float.parseFloat(progressionFactor.getText().trim()));
+                } catch (NumberFormatException e) {
+                    handleException("The suspend duration progression factor should be specified " +
+                        "as a valid float : " + progressionFactor.getText(), e);
+                }
+            }
+
+            OMElement maximumDuration = suspendOnFailure.getFirstChildWithName(new QName(
+                SynapseConstants.SYNAPSE_NAMESPACE,
+                XMLConfigConstants.SUSPEND_MAXIMUM_DURATION));
+            if (maximumDuration != null && maximumDuration.getText() != null) {
+                try {
+                    definition.setSuspendMaximumDuration(
+                        Long.parseLong(maximumDuration.getText().trim()));
+                } catch (NumberFormatException e) {
+                    handleException("The maximum suspend duration should be specified " +
+                        "as a valid number : " + maximumDuration.getText(), e);
+                }
+            }
+        }
+
+        OMElement retryConfig = elem.getFirstChildWithName(new QName(
+            SynapseConstants.SYNAPSE_NAMESPACE, XMLConfigConstants.RETRY_CONFIG));
+
+        if (retryConfig != null) {
+
+            OMElement retryDisabledErrorCodes = retryConfig.getFirstChildWithName(new QName(
+                SynapseConstants.SYNAPSE_NAMESPACE, "disabledErrorCodes"));
+            if (retryDisabledErrorCodes != null && retryDisabledErrorCodes.getText() != null) {
+
+                StringTokenizer st = new StringTokenizer(
+                        retryDisabledErrorCodes.getText().trim(), ", ");
+                while (st.hasMoreTokens()) {
+                    String s = st.nextToken();
+                    try {
+                        definition.addRetryDisabledErrorCode(Integer.parseInt(s));
+                    } catch (NumberFormatException e) {
+                        handleException("The suspend error codes should be specified as valid " +
+                                "numbers separated by commas : "
+                                + retryDisabledErrorCodes.getText(), e);
+                    }
+                }
+            }
+        }
+
+        return definition;
+    }
+
+    protected static void handleException(String msg) {
+        log.error(msg);
+        throw new SynapseException(msg);
+    }
+
+    protected static void handleException(String msg, Exception e) {
+        log.error(msg, e);
+        throw new SynapseException(msg, e);
+    }
+}

Added: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/EndpointDefinitionSerializer.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/EndpointDefinitionSerializer.java?rev=1080161&view=auto
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/EndpointDefinitionSerializer.java (added)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/EndpointDefinitionSerializer.java Thu Mar 10 09:16:32 2011
@@ -0,0 +1,221 @@
+/*
+ *  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.config.xml.endpoints;
+
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.synapse.SynapseConstants;
+import org.apache.synapse.aspects.statistics.StatisticsConfigurable;
+import org.apache.synapse.config.xml.XMLConfigConstants;
+import org.apache.synapse.endpoints.EndpointDefinition;
+
+public class EndpointDefinitionSerializer {
+    private OMFactory fac = OMAbstractFactory.getOMFactory();
+
+    public void serializeEndpointDefinition(EndpointDefinition endpointDefinition,
+                                                 OMElement element) {
+        if (endpointDefinition.getTraceState() == SynapseConstants.TRACING_ON) {
+            element.addAttribute(fac.createOMAttribute(XMLConfigConstants.TRACE_ATTRIB_NAME,
+                    null, XMLConfigConstants.TRACE_ENABLE));
+        } else if (endpointDefinition.getTraceState() == SynapseConstants.TRACING_OFF) {
+            element.addAttribute(fac.createOMAttribute(XMLConfigConstants.TRACE_ATTRIB_NAME,
+                    null, XMLConfigConstants.TRACE_DISABLE));
+        }
+
+        StatisticsConfigurable statisticsConfigurable =
+                endpointDefinition.getAspectConfiguration();
+
+        if (statisticsConfigurable != null &&
+                statisticsConfigurable.isStatisticsEnable()) {
+
+            element.addAttribute(fac.createOMAttribute(
+                    XMLConfigConstants.STATISTICS_ATTRIB_NAME, null,
+                    XMLConfigConstants.STATISTICS_ENABLE));
+        }
+
+        if (endpointDefinition.isUseSwa()) {
+            element.addAttribute(fac.createOMAttribute("optimize", null, "swa"));
+        } else if (endpointDefinition.isUseMTOM()) {
+            element.addAttribute(fac.createOMAttribute("optimize", null, "mtom"));
+        }
+
+        if (endpointDefinition.getCharSetEncoding() != null) {
+            element.addAttribute(fac.createOMAttribute(
+                    "encoding", null, endpointDefinition.getCharSetEncoding()));
+        }
+
+        if (endpointDefinition.isAddressingOn()) {
+            OMElement addressing = fac.createOMElement(
+                    "enableAddressing", SynapseConstants.SYNAPSE_OMNAMESPACE);
+
+            if (endpointDefinition.getAddressingVersion() != null) {
+                addressing.addAttribute(fac.createOMAttribute(
+                        "version", null, endpointDefinition.getAddressingVersion()));
+            }
+
+            if (endpointDefinition.isUseSeparateListener()) {
+                addressing.addAttribute(fac.createOMAttribute("separateListener", null, "true"));
+            }
+            element.addChild(addressing);
+        }
+
+        if (endpointDefinition.isReliableMessagingOn()) {
+            OMElement rm = fac.createOMElement("enableRM", SynapseConstants.SYNAPSE_OMNAMESPACE);
+
+            if (endpointDefinition.getWsRMPolicyKey() != null) {
+                rm.addAttribute(fac.createOMAttribute(
+                        "policy", null, endpointDefinition.getWsRMPolicyKey()));
+            }
+            element.addChild(rm);
+        }
+
+        if (endpointDefinition.isSecurityOn()) {
+            OMElement sec = fac.createOMElement("enableSec", SynapseConstants.SYNAPSE_OMNAMESPACE);
+
+            if (endpointDefinition.getWsSecPolicyKey() != null) {
+                sec.addAttribute(fac.createOMAttribute(
+                        "policy", null, endpointDefinition.getWsSecPolicyKey()));
+            } else {
+                if (endpointDefinition.getInboundWsSecPolicyKey() != null) {
+                    sec.addAttribute(fac.createOMAttribute(
+                            "inboundPolicy", null, endpointDefinition.getInboundWsSecPolicyKey()));
+                }
+                if (endpointDefinition.getOutboundWsSecPolicyKey() != null) {
+                    sec.addAttribute(fac.createOMAttribute("outboundPolicy",
+                            null, endpointDefinition.getOutboundWsSecPolicyKey()));
+                }
+            }
+            element.addChild(sec);
+        }
+
+        if (endpointDefinition.getTimeoutAction() != SynapseConstants.NONE ||
+                endpointDefinition.getTimeoutDuration() > 0) {
+
+            OMElement timeout = fac.createOMElement(
+                    "timeout", SynapseConstants.SYNAPSE_OMNAMESPACE);
+            element.addChild(timeout);
+
+            OMElement duration = fac.createOMElement(
+                    "duration", SynapseConstants.SYNAPSE_OMNAMESPACE);
+            duration.setText(Long.toString(endpointDefinition.getTimeoutDuration()));
+            timeout.addChild(duration);
+
+            OMElement action = fac.createOMElement("responseAction", SynapseConstants.SYNAPSE_OMNAMESPACE);
+            if (endpointDefinition.getTimeoutAction() == SynapseConstants.DISCARD) {
+                action.setText("discard");
+            } else if (endpointDefinition.getTimeoutAction()
+                    == SynapseConstants.DISCARD_AND_FAULT) {
+                action.setText("fault");
+            }
+            timeout.addChild(action);
+        }
+
+        if (endpointDefinition.getInitialSuspendDuration() != -1 ||
+            !endpointDefinition.getSuspendErrorCodes().isEmpty()) {
+
+            OMElement suspendOnFailure = fac.createOMElement(
+                org.apache.synapse.config.xml.XMLConfigConstants.SUSPEND_ON_FAILURE,
+                SynapseConstants.SYNAPSE_OMNAMESPACE);
+
+            if (!endpointDefinition.getSuspendErrorCodes().isEmpty()) {
+                OMElement errorCodes = fac.createOMElement(
+                    org.apache.synapse.config.xml.XMLConfigConstants.ERROR_CODES,
+                    SynapseConstants.SYNAPSE_OMNAMESPACE);
+                errorCodes.setText(endpointDefinition.getSuspendErrorCodes().
+                    toString().replaceAll("[\\[\\] ]", ""));
+                suspendOnFailure.addChild(errorCodes);
+            }
+
+            if (endpointDefinition.getInitialSuspendDuration() != -1) {
+                OMElement initialDuration = fac.createOMElement(
+                    org.apache.synapse.config.xml.XMLConfigConstants.SUSPEND_INITIAL_DURATION,
+                    SynapseConstants.SYNAPSE_OMNAMESPACE);
+                initialDuration.setText(Long.toString(endpointDefinition.getInitialSuspendDuration()));
+                suspendOnFailure.addChild(initialDuration);
+            }
+
+            if (endpointDefinition.getSuspendProgressionFactor() != -1) {
+                OMElement progressionFactor = fac.createOMElement(
+                    org.apache.synapse.config.xml.XMLConfigConstants.SUSPEND_PROGRESSION_FACTOR,
+                    SynapseConstants.SYNAPSE_OMNAMESPACE);
+                progressionFactor.setText(Float.toString(endpointDefinition.getSuspendProgressionFactor()));
+                suspendOnFailure.addChild(progressionFactor);
+            }
+
+            if (endpointDefinition.getSuspendMaximumDuration() != -1 &&
+                    endpointDefinition.getSuspendMaximumDuration() != Long.MAX_VALUE) {
+                OMElement suspendMaximum = fac.createOMElement(
+                    org.apache.synapse.config.xml.XMLConfigConstants.SUSPEND_MAXIMUM_DURATION,
+                    SynapseConstants.SYNAPSE_OMNAMESPACE);
+                suspendMaximum.setText(Long.toString(endpointDefinition.getSuspendMaximumDuration()));
+                suspendOnFailure.addChild(suspendMaximum);
+            }
+
+            element.addChild(suspendOnFailure);
+        }
+
+        if (endpointDefinition.getRetryDurationOnTimeout() > 0 ||
+            !endpointDefinition.getTimeoutErrorCodes().isEmpty()) {
+
+            OMElement markAsTimedout = fac.createOMElement(
+                org.apache.synapse.config.xml.XMLConfigConstants.MARK_FOR_SUSPENSION,
+                SynapseConstants.SYNAPSE_OMNAMESPACE);
+
+            if (!endpointDefinition.getTimeoutErrorCodes().isEmpty()) {
+                OMElement errorCodes = fac.createOMElement(
+                    org.apache.synapse.config.xml.XMLConfigConstants.ERROR_CODES,
+                    SynapseConstants.SYNAPSE_OMNAMESPACE);
+                errorCodes.setText(endpointDefinition.getTimeoutErrorCodes().
+                    toString().replaceAll("[\\[\\] ]", ""));
+                markAsTimedout.addChild(errorCodes);
+            }
+
+            if (endpointDefinition.getRetriesOnTimeoutBeforeSuspend() > 0) {
+                OMElement retries = fac.createOMElement(
+                    org.apache.synapse.config.xml.XMLConfigConstants.RETRIES_BEFORE_SUSPENSION,
+                    SynapseConstants.SYNAPSE_OMNAMESPACE);
+                retries.setText(Long.toString(endpointDefinition.getRetriesOnTimeoutBeforeSuspend()));
+                markAsTimedout.addChild(retries);
+            }
+
+            if (endpointDefinition.getRetryDurationOnTimeout() > 0) {
+                OMElement retryDelay = fac.createOMElement(
+                    org.apache.synapse.config.xml.XMLConfigConstants.RETRY_DELAY,
+                    SynapseConstants.SYNAPSE_OMNAMESPACE);
+                retryDelay.setText(Long.toString(endpointDefinition.getRetryDurationOnTimeout()));
+                markAsTimedout.addChild(retryDelay);
+            }
+
+            element.addChild(markAsTimedout);
+        }
+
+         if (!endpointDefinition.getRetryDisabledErrorCodes().isEmpty()) {
+            OMElement retryConfig = fac.createOMElement(XMLConfigConstants.RETRY_CONFIG,
+                    SynapseConstants.SYNAPSE_OMNAMESPACE);
+            OMElement errorCodes = fac.createOMElement("disabledErrorCodes",
+                    SynapseConstants.SYNAPSE_OMNAMESPACE);
+                errorCodes.setText(endpointDefinition.getRetryDisabledErrorCodes().
+                        toString().replaceAll("[\\[\\] ]", ""));
+                retryConfig.addChild(errorCodes);
+            element.addChild(retryConfig);
+        }
+    }
+}

Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/EndpointFactory.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/EndpointFactory.java?rev=1080161&r1=1080160&r2=1080161&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/EndpointFactory.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/EndpointFactory.java Thu Mar 10 09:16:32 2011
@@ -143,310 +143,6 @@ public abstract class EndpointFactory im
         return ep;
     }
 
-    /**
-     * Extracts the QoS information from the XML which represents a WSDL/Address/Default endpoints
-     *
-     * @param definition to be filled with the extracted information
-     * @param elem       XML which represents the endpoint with QoS information
-     */
-    protected void extractCommonEndpointProperties(EndpointDefinition definition, OMElement elem) {
-
-        OMAttribute optimize
-                = elem.getAttribute(new QName(XMLConfigConstants.NULL_NAMESPACE, "optimize"));
-        OMAttribute encoding
-                = elem.getAttribute(new QName(XMLConfigConstants.NULL_NAMESPACE, "encoding"));
-        
-        OMAttribute trace = elem.getAttribute(new QName(
-                XMLConfigConstants.NULL_NAMESPACE, XMLConfigConstants.TRACE_ATTRIB_NAME));
-        if (trace != null && trace.getAttributeValue() != null) {
-            String traceValue = trace.getAttributeValue();
-            if (XMLConfigConstants.TRACE_ENABLE.equals(traceValue)) {
-                definition.setTraceState(SynapseConstants.TRACING_ON);
-            } else if (XMLConfigConstants.TRACE_DISABLE.equals(traceValue)) {
-                definition.setTraceState(SynapseConstants.TRACING_OFF);
-            }
-        } else {
-            definition.setTraceState(SynapseConstants.TRACING_UNSET);
-        }
-
-
-        if (optimize != null && optimize.getAttributeValue().length() > 0) {
-            String method = optimize.getAttributeValue().trim();
-            if ("mtom".equalsIgnoreCase(method)) {
-                definition.setUseMTOM(true);
-            } else if ("swa".equalsIgnoreCase(method)) {
-                definition.setUseSwa(true);
-            }
-        }
-
-        if (encoding != null && encoding.getAttributeValue() != null) {
-            definition.setCharSetEncoding(encoding.getAttributeValue());
-        }
-
-        OMElement wsAddr = elem.getFirstChildWithName(
-                new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, "enableAddressing"));
-        if (wsAddr != null) {
-
-            definition.setAddressingOn(true);
-
-            OMAttribute version = wsAddr.getAttribute(new QName("version"));
-            if (version != null && version.getAttributeValue() != null) {
-                String versionValue = version.getAttributeValue().trim().toLowerCase();
-                if (SynapseConstants.ADDRESSING_VERSION_FINAL.equals(versionValue) ||
-                        SynapseConstants.ADDRESSING_VERSION_SUBMISSION.equals(versionValue)) {
-                    definition.setAddressingVersion(version.getAttributeValue());
-                } else {
-                    handleException("Unknown value for the addressing version. Possible values " +
-                            "for the addressing version are 'final' and 'submission' only.");
-                }
-            }
-
-            String useSepList = wsAddr.getAttributeValue(new QName("separateListener"));
-            if (useSepList != null) {
-                if ("true".equals(useSepList.trim().toLowerCase())) {
-                    definition.setUseSeparateListener(true);
-                }
-            }
-        }
-
-        OMElement wsSec = elem.getFirstChildWithName(
-                new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, "enableSec"));
-        if (wsSec != null) {
-
-            definition.setSecurityOn(true);
-
-            OMAttribute policyKey      = wsSec.getAttribute(
-                    new QName(XMLConfigConstants.NULL_NAMESPACE, "policy"));
-            OMAttribute inboundPolicyKey  = wsSec.getAttribute(
-                    new QName(XMLConfigConstants.NULL_NAMESPACE, "inboundPolicy"));
-            OMAttribute outboundPolicyKey = wsSec.getAttribute(
-                    new QName(XMLConfigConstants.NULL_NAMESPACE, "outboundPolicy"));
-            
-            if (policyKey != null && policyKey.getAttributeValue() != null) {
-                definition.setWsSecPolicyKey(policyKey.getAttributeValue());
-            } else {
-                if (inboundPolicyKey != null && inboundPolicyKey.getAttributeValue() != null) {
-                    definition.setInboundWsSecPolicyKey(inboundPolicyKey.getAttributeValue());
-                }
-                if (outboundPolicyKey != null && outboundPolicyKey.getAttributeValue() != null) {
-                    definition.setOutboundWsSecPolicyKey(outboundPolicyKey.getAttributeValue());
-                }
-            }
-        }
-
-        OMElement wsRm = elem.getFirstChildWithName(
-                new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, "enableRM"));
-        if (wsRm != null) {
-
-            definition.setReliableMessagingOn(true);
-
-            OMAttribute policy
-                    = wsRm.getAttribute(new QName(XMLConfigConstants.NULL_NAMESPACE, "policy"));
-            if (policy != null) {
-                definition.setWsRMPolicyKey(policy.getAttributeValue());
-            }
-        }
-
-        // set the timeout configuration
-        OMElement timeout = elem.getFirstChildWithName(
-                new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, "timeout"));
-        if (timeout != null) {
-            OMElement duration = timeout.getFirstChildWithName(
-                    new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, "duration"));
-
-            if (duration != null) {
-                String d = duration.getText();
-                if (d != null) {
-                    try {
-                        long timeoutMilliSeconds = Long.parseLong(d.trim());
-                        definition.setTimeoutDuration(timeoutMilliSeconds);
-                    } catch (NumberFormatException e) {
-                        handleException("Endpoint timeout duration expected as a " +
-                                "number but was not a number");
-                    }
-                }
-            }
-
-            OMElement action = timeout.getFirstChildWithName(
-                    new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, "responseAction"));
-            if (action != null && action.getText() != null) {
-                String actionString = action.getText();
-                if ("discard".equalsIgnoreCase(actionString.trim())) {
-
-                    definition.setTimeoutAction(SynapseConstants.DISCARD);
-
-                    // set timeout duration to 30 seconds, if it is not set explicitly
-                    if (definition.getTimeoutDuration() == 0) {
-                        definition.setTimeoutDuration(30000);
-                    }
-                } else if ("fault".equalsIgnoreCase(actionString.trim())) {
-
-                    definition.setTimeoutAction(SynapseConstants.DISCARD_AND_FAULT);
-
-                    // set timeout duration to 30 seconds, if it is not set explicitly
-                    if (definition.getTimeoutDuration() == 0) {
-                        definition.setTimeoutDuration(30000);
-                    }
-                } else {
-                    handleException("Invalid timeout action, action : "
-                            + actionString + " is not supported");
-                }
-            }
-        }
-
-        OMElement markAsTimedOut = elem.getFirstChildWithName(new QName(
-            SynapseConstants.SYNAPSE_NAMESPACE,
-            XMLConfigConstants.MARK_FOR_SUSPENSION));
-
-        if (markAsTimedOut != null) {
-
-            OMElement timeoutCodes = markAsTimedOut.getFirstChildWithName(new QName(
-                SynapseConstants.SYNAPSE_NAMESPACE,
-                XMLConfigConstants.ERROR_CODES));
-            if (timeoutCodes != null && timeoutCodes.getText() != null) {
-                StringTokenizer st = new StringTokenizer(timeoutCodes.getText().trim(), ", ");
-                while (st.hasMoreTokens()) {
-                    String s = st.nextToken();
-                    try {
-                        definition.addTimeoutErrorCode(Integer.parseInt(s));
-                    } catch (NumberFormatException e) {
-                        handleException("The timeout error codes should be specified " +
-                            "as valid numbers separated by commas : " + timeoutCodes.getText(), e);
-                    }
-                }
-            }
-
-            OMElement retriesBeforeSuspend = markAsTimedOut.getFirstChildWithName(new QName(
-                SynapseConstants.SYNAPSE_NAMESPACE,
-                XMLConfigConstants.RETRIES_BEFORE_SUSPENSION));
-            if (retriesBeforeSuspend != null && retriesBeforeSuspend.getText() != null) {
-                try {
-                    definition.setRetriesOnTimeoutBeforeSuspend(
-                        Integer.parseInt(retriesBeforeSuspend.getText().trim()));
-                } catch (NumberFormatException e) {
-                    handleException("The retries before suspend [for timeouts] should be " +
-                        "specified as a valid number : " + retriesBeforeSuspend.getText(), e);
-                }
-            }
-
-            OMElement retryDelay = markAsTimedOut.getFirstChildWithName(new QName(
-                SynapseConstants.SYNAPSE_NAMESPACE,
-                XMLConfigConstants.RETRY_DELAY));
-            if (retryDelay != null && retryDelay.getText() != null) {
-                try {
-                    definition.setRetryDurationOnTimeout(
-                        Integer.parseInt(retryDelay.getText().trim()));
-                } catch (NumberFormatException e) {
-                    handleException("The retry delay for timeouts should be specified " +
-                        "as a valid number : " + retryDelay.getText(), e);
-                }
-            }
-        }
-
-        // support backwards compatibility with Synapse 1.2 - for suspendDurationOnFailure
-        OMElement suspendDurationOnFailure = elem.getFirstChildWithName(new QName(
-            SynapseConstants.SYNAPSE_NAMESPACE, "suspendDurationOnFailure"));
-        if (suspendDurationOnFailure != null && suspendDurationOnFailure.getText() != null) {
-
-            log.warn("Configuration uses deprecated style for endpoint 'suspendDurationOnFailure'");
-            try {
-                definition.setInitialSuspendDuration(
-                        1000 * Long.parseLong(suspendDurationOnFailure.getText().trim()));
-                definition.setSuspendProgressionFactor((float) 1.0);
-            } catch (NumberFormatException e) {
-                handleException("The initial suspend duration should be specified " +
-                    "as a valid number : " + suspendDurationOnFailure.getText(), e);
-            }
-        }
-
-        OMElement suspendOnFailure = elem.getFirstChildWithName(new QName(
-            SynapseConstants.SYNAPSE_NAMESPACE,
-            XMLConfigConstants.SUSPEND_ON_FAILURE));
-
-        if (suspendOnFailure != null) {
-
-            OMElement suspendCodes = suspendOnFailure.getFirstChildWithName(new QName(
-                SynapseConstants.SYNAPSE_NAMESPACE,
-                XMLConfigConstants.ERROR_CODES));
-            if (suspendCodes != null && suspendCodes.getText() != null) {
-
-                StringTokenizer st = new StringTokenizer(suspendCodes.getText().trim(), ", ");
-                while (st.hasMoreTokens()) {
-                    String s = st.nextToken();
-                    try {
-                        definition.addSuspendErrorCode(Integer.parseInt(s));
-                    } catch (NumberFormatException e) {
-                        handleException("The suspend error codes should be specified " +
-                            "as valid numbers separated by commas : " + suspendCodes.getText(), e);
-                    }
-                }
-            }
-
-            OMElement initialDuration = suspendOnFailure.getFirstChildWithName(new QName(
-                SynapseConstants.SYNAPSE_NAMESPACE,
-                XMLConfigConstants.SUSPEND_INITIAL_DURATION));
-            if (initialDuration != null && initialDuration.getText() != null) {
-                try {
-                    definition.setInitialSuspendDuration(
-                        Integer.parseInt(initialDuration.getText().trim()));
-                } catch (NumberFormatException e) {
-                    handleException("The initial suspend duration should be specified " +
-                        "as a valid number : " + initialDuration.getText(), e);
-                }
-            }
-
-            OMElement progressionFactor = suspendOnFailure.getFirstChildWithName(new QName(
-                SynapseConstants.SYNAPSE_NAMESPACE,
-                XMLConfigConstants.SUSPEND_PROGRESSION_FACTOR));
-            if (progressionFactor != null && progressionFactor.getText() != null) {
-                try {
-                    definition.setSuspendProgressionFactor(
-                        Float.parseFloat(progressionFactor.getText().trim()));
-                } catch (NumberFormatException e) {
-                    handleException("The suspend duration progression factor should be specified " +
-                        "as a valid float : " + progressionFactor.getText(), e);
-                }
-            }
-
-            OMElement maximumDuration = suspendOnFailure.getFirstChildWithName(new QName(
-                SynapseConstants.SYNAPSE_NAMESPACE,
-                XMLConfigConstants.SUSPEND_MAXIMUM_DURATION));
-            if (maximumDuration != null && maximumDuration.getText() != null) {
-                try {
-                    definition.setSuspendMaximumDuration(
-                        Long.parseLong(maximumDuration.getText().trim()));
-                } catch (NumberFormatException e) {
-                    handleException("The maximum suspend duration should be specified " +
-                        "as a valid number : " + maximumDuration.getText(), e);
-                }
-            }
-        }
-
-        OMElement retryConfig = elem.getFirstChildWithName(new QName(
-            SynapseConstants.SYNAPSE_NAMESPACE, XMLConfigConstants.RETRY_CONFIG));
-
-        if (retryConfig != null) {
-
-            OMElement retryDisabledErrorCodes = retryConfig.getFirstChildWithName(new QName(
-                SynapseConstants.SYNAPSE_NAMESPACE, "disabledErrorCodes"));
-            if (retryDisabledErrorCodes != null && retryDisabledErrorCodes.getText() != null) {
-
-                StringTokenizer st = new StringTokenizer(
-                        retryDisabledErrorCodes.getText().trim(), ", ");
-                while (st.hasMoreTokens()) {
-                    String s = st.nextToken();
-                    try {
-                        definition.addRetryDisabledErrorCode(Integer.parseInt(s));
-                    } catch (NumberFormatException e) {
-                        handleException("The suspend error codes should be specified as valid " +
-                                "numbers separated by commas : "
-                                + retryDisabledErrorCodes.getText(), e);
-                    }
-                }
-            }
-        }
-    }
-
     protected void extractSpecificEndpointProperties(EndpointDefinition definition,
         OMElement elem) {
 
@@ -470,6 +166,10 @@ public abstract class EndpointFactory im
             return ResolvingEndpointFactory.getInstance();
         }
 
+        if (configElement.getAttribute(new QName("template")) != null) {
+            return new TemplateEndpointFactory();
+        }
+
         OMElement addressElement = configElement.getFirstChildWithName(
                 new QName(SynapseConstants.SYNAPSE_NAMESPACE, "address"));
         if (addressElement != null) {

Modified: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/EndpointSerializer.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/EndpointSerializer.java?rev=1080161&r1=1080160&r2=1080161&view=diff
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/EndpointSerializer.java (original)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/EndpointSerializer.java Thu Mar 10 09:16:32 2011
@@ -94,202 +94,6 @@ public abstract class EndpointSerializer
         }
     }
 
-    /**
-     * Serializes the QoS information of the endpoint to the XML element
-     *
-     * @param endpointDefinition specifies the QoS information of the endpoint
-     * @param element            to which the QoS information will be serialized
-     */
-    protected void serializeCommonEndpointProperties(
-            EndpointDefinition endpointDefinition, OMElement element) {
-
-        if (endpointDefinition.getTraceState() == SynapseConstants.TRACING_ON) {
-            element.addAttribute(fac.createOMAttribute(XMLConfigConstants.TRACE_ATTRIB_NAME,
-                    null, XMLConfigConstants.TRACE_ENABLE));
-        } else if (endpointDefinition.getTraceState() == SynapseConstants.TRACING_OFF) {
-            element.addAttribute(fac.createOMAttribute(XMLConfigConstants.TRACE_ATTRIB_NAME,
-                    null, XMLConfigConstants.TRACE_DISABLE));
-        }
-
-        StatisticsConfigurable statisticsConfigurable =
-                endpointDefinition.getAspectConfiguration();
-
-        if (statisticsConfigurable != null &&
-                statisticsConfigurable.isStatisticsEnable()) {
-
-            element.addAttribute(fac.createOMAttribute(
-                    XMLConfigConstants.STATISTICS_ATTRIB_NAME, null,
-                    XMLConfigConstants.STATISTICS_ENABLE));
-        }
-
-        if (endpointDefinition.isUseSwa()) {
-            element.addAttribute(fac.createOMAttribute("optimize", null, "swa"));
-        } else if (endpointDefinition.isUseMTOM()) {
-            element.addAttribute(fac.createOMAttribute("optimize", null, "mtom"));
-        }
-
-        if (endpointDefinition.getCharSetEncoding() != null) {
-            element.addAttribute(fac.createOMAttribute(
-                    "encoding", null, endpointDefinition.getCharSetEncoding()));
-        }
-
-        if (endpointDefinition.isAddressingOn()) {
-            OMElement addressing = fac.createOMElement(
-                    "enableAddressing", SynapseConstants.SYNAPSE_OMNAMESPACE);
-
-            if (endpointDefinition.getAddressingVersion() != null) {
-                addressing.addAttribute(fac.createOMAttribute(
-                        "version", null, endpointDefinition.getAddressingVersion()));
-            }
-
-            if (endpointDefinition.isUseSeparateListener()) {
-                addressing.addAttribute(fac.createOMAttribute("separateListener", null, "true"));
-            }
-            element.addChild(addressing);
-        }
-
-        if (endpointDefinition.isReliableMessagingOn()) {
-            OMElement rm = fac.createOMElement("enableRM", SynapseConstants.SYNAPSE_OMNAMESPACE);
-
-            if (endpointDefinition.getWsRMPolicyKey() != null) {
-                rm.addAttribute(fac.createOMAttribute(
-                        "policy", null, endpointDefinition.getWsRMPolicyKey()));
-            }
-            element.addChild(rm);
-        }
-
-        if (endpointDefinition.isSecurityOn()) {
-            OMElement sec = fac.createOMElement("enableSec", SynapseConstants.SYNAPSE_OMNAMESPACE);
-
-            if (endpointDefinition.getWsSecPolicyKey() != null) {
-                sec.addAttribute(fac.createOMAttribute(
-                        "policy", null, endpointDefinition.getWsSecPolicyKey()));
-            } else {
-                if (endpointDefinition.getInboundWsSecPolicyKey() != null) {
-                    sec.addAttribute(fac.createOMAttribute(
-                            "inboundPolicy", null, endpointDefinition.getInboundWsSecPolicyKey()));
-                }
-                if (endpointDefinition.getOutboundWsSecPolicyKey() != null) {
-                    sec.addAttribute(fac.createOMAttribute("outboundPolicy",
-                            null, endpointDefinition.getOutboundWsSecPolicyKey()));
-                }
-            }
-            element.addChild(sec);
-        }
-
-        if (endpointDefinition.getTimeoutAction() != SynapseConstants.NONE ||
-                endpointDefinition.getTimeoutDuration() > 0) {
-
-            OMElement timeout = fac.createOMElement(
-                    "timeout", SynapseConstants.SYNAPSE_OMNAMESPACE);
-            element.addChild(timeout);
-
-            OMElement duration = fac.createOMElement(
-                    "duration", SynapseConstants.SYNAPSE_OMNAMESPACE);
-            duration.setText(Long.toString(endpointDefinition.getTimeoutDuration()));
-            timeout.addChild(duration);
-
-            OMElement action = fac.createOMElement("responseAction", SynapseConstants.SYNAPSE_OMNAMESPACE);
-            if (endpointDefinition.getTimeoutAction() == SynapseConstants.DISCARD) {
-                action.setText("discard");
-            } else if (endpointDefinition.getTimeoutAction()
-                    == SynapseConstants.DISCARD_AND_FAULT) {
-                action.setText("fault");
-            }
-            timeout.addChild(action);
-        }
-
-        if (endpointDefinition.getInitialSuspendDuration() != -1 ||
-            !endpointDefinition.getSuspendErrorCodes().isEmpty()) {
-
-            OMElement suspendOnFailure = fac.createOMElement(
-                org.apache.synapse.config.xml.XMLConfigConstants.SUSPEND_ON_FAILURE,
-                SynapseConstants.SYNAPSE_OMNAMESPACE);
-
-            if (!endpointDefinition.getSuspendErrorCodes().isEmpty()) {
-                OMElement errorCodes = fac.createOMElement(
-                    org.apache.synapse.config.xml.XMLConfigConstants.ERROR_CODES,
-                    SynapseConstants.SYNAPSE_OMNAMESPACE);
-                errorCodes.setText(endpointDefinition.getSuspendErrorCodes().
-                    toString().replaceAll("[\\[\\] ]", ""));
-                suspendOnFailure.addChild(errorCodes);
-            }
-
-            if (endpointDefinition.getInitialSuspendDuration() != -1) {
-                OMElement initialDuration = fac.createOMElement(
-                    org.apache.synapse.config.xml.XMLConfigConstants.SUSPEND_INITIAL_DURATION,
-                    SynapseConstants.SYNAPSE_OMNAMESPACE);
-                initialDuration.setText(Long.toString(endpointDefinition.getInitialSuspendDuration()));
-                suspendOnFailure.addChild(initialDuration);
-            }
-
-            if (endpointDefinition.getSuspendProgressionFactor() != -1) {
-                OMElement progressionFactor = fac.createOMElement(
-                    org.apache.synapse.config.xml.XMLConfigConstants.SUSPEND_PROGRESSION_FACTOR,
-                    SynapseConstants.SYNAPSE_OMNAMESPACE);
-                progressionFactor.setText(Float.toString(endpointDefinition.getSuspendProgressionFactor()));
-                suspendOnFailure.addChild(progressionFactor);
-            }
-
-            if (endpointDefinition.getSuspendMaximumDuration() != -1 &&
-                    endpointDefinition.getSuspendMaximumDuration() != Long.MAX_VALUE) {
-                OMElement suspendMaximum = fac.createOMElement(
-                    org.apache.synapse.config.xml.XMLConfigConstants.SUSPEND_MAXIMUM_DURATION,
-                    SynapseConstants.SYNAPSE_OMNAMESPACE);
-                suspendMaximum.setText(Long.toString(endpointDefinition.getSuspendMaximumDuration()));
-                suspendOnFailure.addChild(suspendMaximum);
-            }
-
-            element.addChild(suspendOnFailure);
-        }
-
-        if (endpointDefinition.getRetryDurationOnTimeout() > 0 ||
-            !endpointDefinition.getTimeoutErrorCodes().isEmpty()) {
-
-            OMElement markAsTimedout = fac.createOMElement(
-                org.apache.synapse.config.xml.XMLConfigConstants.MARK_FOR_SUSPENSION,
-                SynapseConstants.SYNAPSE_OMNAMESPACE);
-
-            if (!endpointDefinition.getTimeoutErrorCodes().isEmpty()) {
-                OMElement errorCodes = fac.createOMElement(
-                    org.apache.synapse.config.xml.XMLConfigConstants.ERROR_CODES,
-                    SynapseConstants.SYNAPSE_OMNAMESPACE);
-                errorCodes.setText(endpointDefinition.getTimeoutErrorCodes().
-                    toString().replaceAll("[\\[\\] ]", ""));
-                markAsTimedout.addChild(errorCodes);
-            }
-
-            if (endpointDefinition.getRetriesOnTimeoutBeforeSuspend() > 0) {
-                OMElement retries = fac.createOMElement(
-                    org.apache.synapse.config.xml.XMLConfigConstants.RETRIES_BEFORE_SUSPENSION,
-                    SynapseConstants.SYNAPSE_OMNAMESPACE);
-                retries.setText(Long.toString(endpointDefinition.getRetriesOnTimeoutBeforeSuspend()));
-                markAsTimedout.addChild(retries);
-            }
-
-            if (endpointDefinition.getRetryDurationOnTimeout() > 0) {
-                OMElement retryDelay = fac.createOMElement(
-                    org.apache.synapse.config.xml.XMLConfigConstants.RETRY_DELAY,
-                    SynapseConstants.SYNAPSE_OMNAMESPACE);
-                retryDelay.setText(Long.toString(endpointDefinition.getRetryDurationOnTimeout()));
-                markAsTimedout.addChild(retryDelay);
-            }
-
-            element.addChild(markAsTimedout);
-        }
-
-         if (!endpointDefinition.getRetryDisabledErrorCodes().isEmpty()) {
-            OMElement retryConfig = fac.createOMElement(XMLConfigConstants.RETRY_CONFIG,
-                    SynapseConstants.SYNAPSE_OMNAMESPACE);
-            OMElement errorCodes = fac.createOMElement("disabledErrorCodes",
-                    SynapseConstants.SYNAPSE_OMNAMESPACE);
-                errorCodes.setText(endpointDefinition.getRetryDisabledErrorCodes().
-                        toString().replaceAll("[\\[\\] ]", ""));
-                retryConfig.addChild(errorCodes);
-            element.addChild(retryConfig);
-        }
-    }
-
     protected void serializeSpecificEndpointProperties(EndpointDefinition endpointDefinition,
         OMElement element) {
 
@@ -329,6 +133,8 @@ public abstract class EndpointSerializer
             return new LoadbalanceEndpointSerializer();
         } else if (endpoint instanceof FailoverEndpoint) {
             return new FailoverEndpointSerializer();
+        } else if (endpoint instanceof TemplateEndpoint) {
+            return new TemplateEndpointSerializer();
         }
 
         throw new SynapseException("Serializer for endpoint " +

Added: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/TemplateEndpointFactory.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/TemplateEndpointFactory.java?rev=1080161&view=auto
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/TemplateEndpointFactory.java (added)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/TemplateEndpointFactory.java Thu Mar 10 09:16:32 2011
@@ -0,0 +1,92 @@
+/*
+ *  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.config.xml.endpoints;
+
+import org.apache.axiom.om.OMAttribute;
+import org.apache.axiom.om.OMElement;
+import org.apache.synapse.SynapseConstants;
+import org.apache.synapse.config.xml.XMLConfigConstants;
+import org.apache.synapse.endpoints.Endpoint;
+import org.apache.synapse.endpoints.TemplateEndpoint;
+
+import javax.xml.namespace.QName;
+import java.util.Iterator;
+import java.util.Properties;
+
+public class TemplateEndpointFactory extends EndpointFactory {
+    public Endpoint createEndpoint(OMElement endpointElement, boolean a, Properties properties) {
+        TemplateEndpoint templateEndpoint = new TemplateEndpoint();
+
+        OMAttribute endpointNameAttribute = endpointElement.getAttribute(
+                new QName(XMLConfigConstants.NULL_NAMESPACE, "name"));
+        if (endpointNameAttribute != null) {
+            templateEndpoint.addParameter("name", endpointNameAttribute.getAttributeValue());
+            templateEndpoint.setName(endpointNameAttribute.getAttributeValue());
+        } else {
+            handleException("Error loading the configuration from Template " +
+                    "Endpoint, name attribute is missing");
+        }
+
+        OMAttribute endpointURIAttribute = endpointElement.getAttribute(
+                new QName(XMLConfigConstants.NULL_NAMESPACE, "uri"));
+        if (endpointURIAttribute != null) {
+            templateEndpoint.addParameter("uri", endpointURIAttribute.getAttributeValue());
+        } else {
+            handleException("Error loading the configuration from Template Endpoint, " +
+                    templateEndpoint.getName() + " uri attribute is missing");
+        }
+
+        OMAttribute endpointTemplateAttribute = endpointElement.getAttribute(
+                new QName(XMLConfigConstants.NULL_NAMESPACE, "template"));
+        if (endpointTemplateAttribute != null) {
+            templateEndpoint.setTemplate(endpointTemplateAttribute.getAttributeValue());
+        } else {
+            handleException("Error loading the configuration from endpoint group, " +
+                    templateEndpoint.getName() +
+                    " template attribute is missing");
+        }
+
+        Iterator paramItr = endpointElement.getChildrenWithName(
+                new QName(SynapseConstants.SYNAPSE_NAMESPACE, "parameter"));
+        while (paramItr.hasNext()) {
+            OMElement paramElement = (OMElement) paramItr.next();
+
+            OMAttribute paramName = paramElement.getAttribute(new QName("name"));
+            OMAttribute paramValue = paramElement.getAttribute(new QName("value"));
+
+            if (paramName == null) {
+                handleException("parameter name should be present");
+            }
+
+            if (paramValue == null) {
+                handleException("parameter value should be present");
+            }
+
+
+            assert paramName != null;
+            assert paramValue != null;
+
+            templateEndpoint.addParameter(paramName.getAttributeValue(),
+                    paramValue.getAttributeValue());
+        }
+
+        return templateEndpoint;
+    }
+}

Added: synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/TemplateEndpointSerializer.java
URL: http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/TemplateEndpointSerializer.java?rev=1080161&view=auto
==============================================================================
--- synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/TemplateEndpointSerializer.java (added)
+++ synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/TemplateEndpointSerializer.java Thu Mar 10 09:16:32 2011
@@ -0,0 +1,71 @@
+/*
+ *  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.config.xml.endpoints;
+
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMNamespace;
+import org.apache.synapse.SynapseConstants;
+import org.apache.synapse.config.xml.XMLConfigConstants;
+import org.apache.synapse.endpoints.Endpoint;
+import org.apache.synapse.endpoints.TemplateEndpoint;
+
+import javax.xml.namespace.QName;
+import java.util.Map;
+
+public class TemplateEndpointSerializer extends EndpointSerializer {
+    protected static OMFactory fac = OMAbstractFactory.getOMFactory();
+
+    protected static final OMNamespace nullNS
+            = fac.createOMNamespace(XMLConfigConstants.NULL_NAMESPACE, "");
+
+    public OMElement serializeEndpoint(Endpoint epr) {
+        TemplateEndpoint endpoints = (TemplateEndpoint) epr;
+
+        OMElement endpointElement = fac.createOMElement(
+                new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, "endpoint"));
+
+        if (endpoints.getName() != null) {
+            endpointElement.addAttribute(
+                    fac.createOMAttribute("name", nullNS, endpoints.getName()));
+        }
+
+        endpointElement.addAttribute(fac.createOMAttribute("template", nullNS, endpoints.getTemplate()));
+
+        Map<String, String> parameters = endpoints.getParameters();
+        for (Map.Entry<String, String> entry : parameters.entrySet()) {
+            if (entry.getKey().equals("name")) {
+                endpointElement.addAttribute(fac.createOMAttribute("name", nullNS, entry.getValue()));
+            } else if (entry.getKey().equals("uri")) {
+                endpointElement.addAttribute(fac.createOMAttribute("uri", nullNS, entry.getValue()));
+            } else {
+                OMElement paramElement = fac.createOMElement(
+                    new QName(SynapseConstants.SYNAPSE_NAMESPACE, "parameter"));
+
+                endpointElement.addChild(paramElement);
+                paramElement.addAttribute(fac.createOMAttribute("name", nullNS, entry.getKey()));
+                paramElement.addAttribute(fac.createOMAttribute("value", nullNS, entry.getValue()));
+            }
+        }
+
+        return endpointElement;
+    }
+}