Author: ruwan
Date: Thu Oct  1 05:54:15 2009
New Revision: 820539

URL: http://svn.apache.org/viewvc?rev=820539&view=rev
Log:
Adding the Resolving Endpoint to the synapse

Added:
    
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/ResolvingEndpointFactory.java
    
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/ResolvingEndpointSerializer.java
    
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/ResolvingEndpoint.java
Modified:
    
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

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=820539&r1=820538&r2=820539&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 Oct  1 05:54:15 2009
@@ -393,6 +393,10 @@
             return IndirectEndpointFactory.getInstance();
         }
 
+        if (configElement.getAttribute(new QName("key-expression")) != null) {
+            return ResolvingEndpointFactory.getInstance();
+        }
+
         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=820539&r1=820538&r2=820539&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 Oct  1 05:54:15 2009
@@ -279,6 +279,8 @@
             return new WSDLEndpointSerializer();
         } else if (endpoint instanceof IndirectEndpoint) {
             return new IndirectEndpointSerializer();
+        } else if (endpoint instanceof ResolvingEndpoint) {
+            return new ResolvingEndpointSerializer();
         } else if (endpoint instanceof SALoadbalanceEndpoint) {
             return new SALoadbalanceEndpointSerializer();
         } else if (endpoint instanceof DynamicLoadbalanceEndpoint){

Added: 
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/ResolvingEndpointFactory.java
URL: 
http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/ResolvingEndpointFactory.java?rev=820539&view=auto
==============================================================================
--- 
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/ResolvingEndpointFactory.java
 (added)
+++ 
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/ResolvingEndpointFactory.java
 Thu Oct  1 05:54:15 2009
@@ -0,0 +1,63 @@
+/*
+ *  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.synapse.endpoints.Endpoint;
+import org.apache.synapse.endpoints.IndirectEndpoint;
+import org.apache.synapse.endpoints.ResolvingEndpoint;
+import org.apache.synapse.config.xml.SynapseXPathFactory;
+import org.apache.axiom.om.OMElement;
+import org.jaxen.JaxenException;
+
+import javax.xml.namespace.QName;
+
+/**
+ * 
+ */
+public class ResolvingEndpointFactory extends EndpointFactory {
+
+    private static ResolvingEndpointFactory instance = new 
ResolvingEndpointFactory();
+
+    private static final QName ATTR_KEY_EXPRESSION = new 
QName("key-expression");
+
+    private ResolvingEndpointFactory() {}
+
+    public static ResolvingEndpointFactory getInstance() {
+        return instance;
+    }
+
+    protected Endpoint createEndpoint(OMElement epConfig, boolean 
anonymousEndpoint) {
+
+        ResolvingEndpoint resolvingEndpoint = new ResolvingEndpoint();
+        String ref = epConfig.getAttributeValue(ATTR_KEY_EXPRESSION);
+        String name = epConfig.getAttributeValue(new QName("name"));
+        if (name != null) {
+            resolvingEndpoint.setName(name);
+        }
+        try {
+            resolvingEndpoint.setKeyExpression(
+                    SynapseXPathFactory.getSynapseXPath(epConfig, 
ATTR_KEY_EXPRESSION));
+        } catch (JaxenException e) {
+            handleException("Couldn't build the ResolvingEndpoint, unable to 
set " +
+                    "the key-expression XPath", e);
+        }
+        return resolvingEndpoint;
+    }
+}

Added: 
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/ResolvingEndpointSerializer.java
URL: 
http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/ResolvingEndpointSerializer.java?rev=820539&view=auto
==============================================================================
--- 
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/ResolvingEndpointSerializer.java
 (added)
+++ 
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/ResolvingEndpointSerializer.java
 Thu Oct  1 05:54:15 2009
@@ -0,0 +1,53 @@
+/*
+ *  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.OMElement;
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.synapse.endpoints.Endpoint;
+import org.apache.synapse.endpoints.IndirectEndpoint;
+import org.apache.synapse.endpoints.ResolvingEndpoint;
+import org.apache.synapse.SynapseConstants;
+import org.apache.synapse.config.xml.SynapseXPathSerializer;
+
+/**
+ * 
+ */
+public class ResolvingEndpointSerializer extends EndpointSerializer {
+
+    protected OMElement serializeEndpoint(Endpoint endpoint) {
+
+        if (!(endpoint instanceof ResolvingEndpoint)) {
+            handleException("Invalid endpoint type.");
+        }
+
+        fac = OMAbstractFactory.getOMFactory();
+        OMElement endpointElement = fac.createOMElement("endpoint", 
SynapseConstants.SYNAPSE_OMNAMESPACE);
+
+        ResolvingEndpoint resolvingEndpoint = (ResolvingEndpoint) endpoint;
+        
SynapseXPathSerializer.serializeXPath(resolvingEndpoint.getKeyExpression(),
+                endpointElement, "key-expression");
+        if (resolvingEndpoint.getName() != null) {
+            endpointElement.addAttribute("name", resolvingEndpoint.getName(), 
null);
+        }
+
+        return endpointElement;
+    }
+}

Added: 
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/ResolvingEndpoint.java
URL: 
http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/ResolvingEndpoint.java?rev=820539&view=auto
==============================================================================
--- 
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/ResolvingEndpoint.java
 (added)
+++ 
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/endpoints/ResolvingEndpoint.java
 Thu Oct  1 05:54:15 2009
@@ -0,0 +1,88 @@
+/*
+ *  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.endpoints;
+
+import org.apache.synapse.MessageContext;
+import org.apache.synapse.SynapseConstants;
+import org.apache.synapse.util.xpath.SynapseXPath;
+import org.apache.synapse.config.SynapseConfiguration;
+import org.apache.synapse.core.axis2.Axis2MessageContext;
+import org.apache.synapse.core.SynapseEnvironment;
+import org.apache.axis2.description.Parameter;
+import org.apache.axis2.context.ConfigurationContext;
+
+/**
+ * 
+ */
+public class ResolvingEndpoint extends AbstractEndpoint {
+
+    private SynapseXPath keyExpression = null;
+
+    /**
+     * Send by calling to the real endpoint
+     * @param synCtx the message to send
+     */
+    public void send(MessageContext synCtx) {
+
+        String key = keyExpression.stringValueOf(synCtx);
+        Endpoint ep = loadAndInitEndpoint(((Axis2MessageContext) synCtx).
+                getAxis2MessageContext().getConfigurationContext(), key);
+
+        if (ep != null) {
+            ep.send(synCtx);
+        } else {
+            informFailure(synCtx, 
SynapseConstants.ENDPOINT_IN_DIRECT_NOT_READY,
+                    "Couldn't find the endpoint with the key : " + key);
+        }
+    }
+
+    private Endpoint loadAndInitEndpoint(ConfigurationContext cc, String key) {
+        Parameter parameter = cc.getAxisConfiguration().getParameter(
+                SynapseConstants.SYNAPSE_CONFIG);
+        Parameter synEnvParameter = cc.getAxisConfiguration().getParameter(
+                SynapseConstants.SYNAPSE_ENV);
+        if (parameter.getValue() instanceof SynapseConfiguration &&
+                synEnvParameter.getValue() instanceof SynapseEnvironment) {
+
+            SynapseConfiguration synCfg = (SynapseConfiguration) 
parameter.getValue();
+            SynapseEnvironment synapseEnvironment = (SynapseEnvironment) 
synEnvParameter.getValue();
+
+            if (log.isDebugEnabled()) {
+                log.debug("Loading real endpoint with key : " + key);
+            }
+
+            Endpoint ep = synCfg.getEndpoint(key);
+            if (ep != null && !ep.isInitialized()) {
+                ep.init(synapseEnvironment);
+            }
+            return ep;
+        }
+
+        return null;
+    }
+
+    public SynapseXPath getKeyExpression() {
+        return keyExpression;
+    }
+
+    public void setKeyExpression(SynapseXPath keyExpression) {
+        this.keyExpression = keyExpression;
+    }
+}


Reply via email to