Author: ruwan
Date: Thu Oct 1 05:55:11 2009
New Revision: 820540
URL: http://svn.apache.org/viewvc?rev=820540&view=rev
Log:
Adding a resolving endpoint to the Synapse-1.3 branch
Added:
synapse/branches/1.3/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/ResolvingEndpointFactory.java
synapse/branches/1.3/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/ResolvingEndpointSerializer.java
synapse/branches/1.3/modules/core/src/main/java/org/apache/synapse/endpoints/ResolvingEndpoint.java
Modified:
synapse/branches/1.3/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/EndpointFactory.java
synapse/branches/1.3/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/EndpointSerializer.java
Modified:
synapse/branches/1.3/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/EndpointFactory.java
URL:
http://svn.apache.org/viewvc/synapse/branches/1.3/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/EndpointFactory.java?rev=820540&r1=820539&r2=820540&view=diff
==============================================================================
---
synapse/branches/1.3/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/EndpointFactory.java
(original)
+++
synapse/branches/1.3/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/EndpointFactory.java
Thu Oct 1 05:55:11 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/branches/1.3/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/EndpointSerializer.java
URL:
http://svn.apache.org/viewvc/synapse/branches/1.3/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/EndpointSerializer.java?rev=820540&r1=820539&r2=820540&view=diff
==============================================================================
---
synapse/branches/1.3/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/EndpointSerializer.java
(original)
+++
synapse/branches/1.3/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/EndpointSerializer.java
Thu Oct 1 05:55:11 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/branches/1.3/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/ResolvingEndpointFactory.java
URL:
http://svn.apache.org/viewvc/synapse/branches/1.3/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/ResolvingEndpointFactory.java?rev=820540&view=auto
==============================================================================
---
synapse/branches/1.3/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/ResolvingEndpointFactory.java
(added)
+++
synapse/branches/1.3/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/ResolvingEndpointFactory.java
Thu Oct 1 05:55:11 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/branches/1.3/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/ResolvingEndpointSerializer.java
URL:
http://svn.apache.org/viewvc/synapse/branches/1.3/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/ResolvingEndpointSerializer.java?rev=820540&view=auto
==============================================================================
---
synapse/branches/1.3/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/ResolvingEndpointSerializer.java
(added)
+++
synapse/branches/1.3/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/ResolvingEndpointSerializer.java
Thu Oct 1 05:55:11 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/branches/1.3/modules/core/src/main/java/org/apache/synapse/endpoints/ResolvingEndpoint.java
URL:
http://svn.apache.org/viewvc/synapse/branches/1.3/modules/core/src/main/java/org/apache/synapse/endpoints/ResolvingEndpoint.java?rev=820540&view=auto
==============================================================================
---
synapse/branches/1.3/modules/core/src/main/java/org/apache/synapse/endpoints/ResolvingEndpoint.java
(added)
+++
synapse/branches/1.3/modules/core/src/main/java/org/apache/synapse/endpoints/ResolvingEndpoint.java
Thu Oct 1 05:55:11 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;
+ }
+}