You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@synapse.apache.org by ch...@apache.org on 2007/03/06 06:48:13 UTC
svn commit: r514989 [2/2] - in
/webservices/synapse/trunk/java/modules/core/src:
main/java/org/apache/synapse/ main/java/org/apache/synapse/config/
main/java/org/apache/synapse/config/xml/
main/java/org/apache/synapse/config/xml/endpoints/ main/java/or...
Added: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/utils/WSDL11EndpointBuilder.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/utils/WSDL11EndpointBuilder.java?view=auto&rev=514989
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/utils/WSDL11EndpointBuilder.java (added)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/utils/WSDL11EndpointBuilder.java Mon Mar 5 21:48:09 2007
@@ -0,0 +1,94 @@
+/*
+ * 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.utils;
+
+import org.apache.synapse.config.EndpointDefinition;
+import org.apache.synapse.SynapseException;
+import org.apache.axiom.om.OMElement;
+
+import javax.wsdl.factory.WSDLFactory;
+import javax.wsdl.WSDLException;
+import javax.wsdl.Definition;
+import javax.wsdl.Service;
+import javax.wsdl.Port;
+import javax.wsdl.extensions.soap.SOAPAddress;
+import javax.wsdl.xml.WSDLReader;
+import javax.xml.namespace.QName;
+import java.util.List;
+
+public class WSDL11EndpointBuilder {
+
+ public EndpointDefinition createEndpointDefinitionFromWSDL(OMElement wsdlElement) {
+
+ EndpointDefinition endpointDefinition = null;
+ String serviceURL = null;
+
+ String wsdlURI = wsdlElement.getAttributeValue(new QName("uri"));
+ String serviceName = wsdlElement.getAttributeValue(new QName("service"));
+ String portName = wsdlElement.getAttributeValue(new QName("port"));
+
+ if (wsdlURI == null) {
+ throw new SynapseException("WSDL is not specified.");
+ }
+
+ if (serviceName == null) {
+ throw new SynapseException("Service is not specified.");
+ }
+
+ if (portName == null) {
+ throw new SynapseException("Port is not specified.");
+ }
+
+ try {
+ WSDLFactory fac = WSDLFactory.newInstance();
+ WSDLReader reader = fac.newWSDLReader();
+ Definition definition = reader.readWSDL(wsdlURI);
+ String tns = definition.getTargetNamespace();
+ Service service = definition.getService(new QName(tns, serviceName));
+ if (service != null) {
+ Port port = service.getPort(portName);
+ if (port != null) {
+ List ext = port.getExtensibilityElements();
+ for (int i = 0; i < ext.size(); i++) {
+ Object o = ext.get(i);
+ if (o instanceof SOAPAddress) {
+ SOAPAddress address = (SOAPAddress) o;
+ serviceURL = address.getLocationURI();
+ break;
+ }
+ }
+ }
+ }
+
+ } catch (WSDLException e) {
+ throw new SynapseException("Unable create endpoint definition from WSDL.");
+ }
+
+ if (serviceURL != null) {
+ endpointDefinition = new EndpointDefinition();
+ endpointDefinition.setAddress(serviceURL);
+
+ // todo: determine this using wsdl and policy
+ endpointDefinition.setAddressingOn(true);
+ }
+
+ return endpointDefinition;
+ }
+}
Added: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/utils/WSDL20EndpointBuilder.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/utils/WSDL20EndpointBuilder.java?view=auto&rev=514989
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/utils/WSDL20EndpointBuilder.java (added)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/endpoints/utils/WSDL20EndpointBuilder.java Mon Mar 5 21:48:09 2007
@@ -0,0 +1,80 @@
+/*
+ * 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.utils;
+
+import org.apache.synapse.config.EndpointDefinition;
+import org.apache.synapse.SynapseException;
+import org.apache.axiom.om.OMElement;
+import org.apache.woden.WSDLFactory;
+import org.apache.woden.WSDLReader;
+import org.apache.woden.WSDLException;
+import org.apache.woden.types.NCName;
+import org.apache.woden.wsdl20.xml.DescriptionElement;
+import org.apache.woden.wsdl20.Description;
+import org.apache.woden.wsdl20.Service;
+import org.apache.woden.wsdl20.Endpoint;
+
+import javax.xml.namespace.QName;
+
+public class WSDL20EndpointBuilder {
+
+ public EndpointDefinition createEndpointDefinitionFromWSDL(OMElement wsdlElement) {
+
+ EndpointDefinition endpointDefinition = null;
+
+ String wsdlURI = wsdlElement.getAttributeValue(new QName("uri"));
+ String serviceName = wsdlElement.getAttributeValue(new QName("service"));
+ String portName = wsdlElement.getAttributeValue(new QName("port"));
+
+ if (wsdlURI == null) {
+ throw new SynapseException("WSDL is not specified.");
+ }
+
+ if (serviceName == null) {
+ throw new SynapseException("Service is not specified.");
+ }
+
+ if (portName == null) {
+ throw new SynapseException("Port is not specified.");
+ }
+
+ try {
+ WSDLFactory fac = WSDLFactory.newInstance();
+ WSDLReader reader = fac.newWSDLReader();
+ reader.setFeature(WSDLReader.FEATURE_VALIDATION, true);
+
+ DescriptionElement descriptionElement = reader.readWSDL(wsdlURI);
+ Description description = descriptionElement.toComponent();
+ String tns = descriptionElement.getTargetNamespace().toString();
+ Service service = description.getService(new QName(tns, serviceName));
+ if (service != null) {
+ Endpoint wsdlEndpoint = service.getEndpoint(new NCName(portName));
+ String serviceURL = wsdlEndpoint.getAddress().toString();
+ endpointDefinition = new EndpointDefinition();
+ endpointDefinition.setAddress(serviceURL);
+ }
+
+ } catch (WSDLException e) {
+ e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
+ }
+
+ return endpointDefinition;
+ }
+}
Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/SynapseEnvironment.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/SynapseEnvironment.java?view=diff&rev=514989&r1=514988&r2=514989
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/SynapseEnvironment.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/SynapseEnvironment.java Mon Mar 5 21:48:09 2007
@@ -20,7 +20,7 @@
package org.apache.synapse.core;
import org.apache.synapse.MessageContext;
-import org.apache.synapse.config.Endpoint;
+import org.apache.synapse.config.EndpointDefinition;
import org.apache.synapse.statistics.StatisticsCollector;
/**
@@ -41,7 +41,7 @@
* <p/>
* This will send request messages on (forward), and send the response messages back to the client
*/
- public void send(Endpoint endpoint, MessageContext smc);
+ public void send(EndpointDefinition endpoint, MessageContext smc);
/**
* Creates a new Synapse <code>MessageContext</code> instance.
Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2FlexibleMEPClient.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2FlexibleMEPClient.java?view=diff&rev=514989&r1=514988&r2=514989
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2FlexibleMEPClient.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2FlexibleMEPClient.java Mon Mar 5 21:48:09 2007
@@ -42,15 +42,13 @@
import org.apache.axis2.description.AxisServiceGroup;
import org.apache.axis2.engine.AxisConfiguration;
import org.apache.axis2.util.UUIDGenerator;
-import org.apache.axis2.util.Utils;
-import org.apache.axis2.wsdl.WSDLConstants;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.neethi.Policy;
import org.apache.neethi.PolicyEngine;
import org.apache.synapse.Constants;
import org.apache.synapse.SynapseException;
-import org.apache.synapse.config.Endpoint;
+import org.apache.synapse.config.EndpointDefinition;
/**
* This is a simple client that handles both in only and in out
@@ -73,7 +71,7 @@
*/
public static void send(
- Endpoint endpoint,
+ EndpointDefinition endpoint,
org.apache.synapse.MessageContext synapseOutMessageContext) throws AxisFault {
boolean separateListener = false;
Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2Sender.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2Sender.java?view=diff&rev=514989&r1=514988&r2=514989
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2Sender.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2Sender.java Mon Mar 5 21:48:09 2007
@@ -21,16 +21,13 @@
import org.apache.axis2.AxisFault;
import org.apache.axis2.context.MessageContext;
-import org.apache.axis2.description.Parameter;
import org.apache.axis2.engine.AxisEngine;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.synapse.Constants;
import org.apache.synapse.SynapseException;
-import org.apache.synapse.config.Endpoint;
+import org.apache.synapse.config.EndpointDefinition;
import org.apache.synapse.statistics.StatisticsUtils;
-import org.apache.neethi.Policy;
-import org.apache.axiom.soap.SOAPFault;
import java.util.Iterator;
@@ -42,7 +39,7 @@
private static final Log log = LogFactory.getLog(Axis2Sender.class);
public static void sendOn(
- Endpoint endpoint,
+ EndpointDefinition endpoint,
org.apache.synapse.MessageContext synapseInMessageContext) {
try {
Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2SynapseEnvironment.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2SynapseEnvironment.java?view=diff&rev=514989&r1=514988&r2=514989
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2SynapseEnvironment.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2SynapseEnvironment.java Mon Mar 5 21:48:09 2007
@@ -20,14 +20,13 @@
package org.apache.synapse.core.axis2;
import org.apache.axis2.context.ConfigurationContext;
-import org.apache.axis2.util.threadpool.ThreadFactory;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.synapse.Constants;
import org.apache.synapse.Mediator;
import org.apache.synapse.MessageContext;
import org.apache.synapse.config.SynapseConfiguration;
-import org.apache.synapse.config.Endpoint;
+import org.apache.synapse.config.EndpointDefinition;
import org.apache.synapse.core.SynapseEnvironment;
import org.apache.synapse.statistics.StatisticsCollector;
import org.apache.synapse.statistics.StatisticsUtils;
@@ -101,7 +100,7 @@
}
}
- public void send(Endpoint endpoint, MessageContext synCtx) {
+ public void send(EndpointDefinition endpoint, MessageContext synCtx) {
if (synCtx.isResponse())
Axis2Sender.sendBack(synCtx);
else
Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/ProxyService.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/ProxyService.java?view=diff&rev=514989&r1=514988&r2=514989
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/ProxyService.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/ProxyService.java Mon Mar 5 21:48:09 2007
@@ -33,9 +33,10 @@
import org.apache.synapse.Constants;
import org.apache.synapse.SynapseException;
import org.apache.synapse.mediators.base.SequenceMediator;
+import org.apache.synapse.mediators.builtin.send.endpoints.Endpoint;
import org.apache.synapse.config.SynapseConfiguration;
import org.apache.synapse.config.Util;
-import org.apache.synapse.config.Endpoint;
+import org.apache.synapse.config.EndpointDefinition;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLStreamException;
Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/ProxyServiceMessageReceiver.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/ProxyServiceMessageReceiver.java?view=diff&rev=514989&r1=514988&r2=514989
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/ProxyServiceMessageReceiver.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/ProxyServiceMessageReceiver.java Mon Mar 5 21:48:09 2007
@@ -20,22 +20,17 @@
package org.apache.synapse.core.axis2;
import org.apache.axis2.AxisFault;
-import org.apache.axis2.Constants;
import org.apache.axis2.addressing.EndpointReference;
-import org.apache.axis2.engine.AxisEngine;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.synapse.Mediator;
import org.apache.synapse.MessageContext;
import org.apache.synapse.SynapseException;
import org.apache.synapse.FaultHandler;
-import org.apache.synapse.mediators.base.SequenceMediator;
import org.apache.synapse.mediators.MediatorFaultHandler;
-import org.apache.synapse.statistics.StatisticsUtils;
-import org.apache.synapse.statistics.impl.EndPointStatisticsStack;
+import org.apache.synapse.mediators.builtin.send.endpoints.Endpoint;
import org.apache.synapse.statistics.impl.ProxyServiceStatisticsStack;
-import org.apache.synapse.config.Endpoint;
-import org.apache.axiom.om.OMNode;
+import org.apache.synapse.config.EndpointDefinition;
/**
* This is the MessageReceiver set to act on behalf of Proxy services.
@@ -95,7 +90,7 @@
log.debug("Setting the anonymous fault sequence of the proxy to context");
synCtx.pushFault(new MediatorFaultHandler(proxy.getTargetInLineFaultSequence()));
}
-
+
// Using inSequence for the incoming message mediation
if (proxy.getTargetInSequence() != null) {
@@ -120,8 +115,9 @@
if (endpoint != null) {
log.debug("Forwarding message to the endpoint named "
+ proxy.getTargetEndpoint() + " after message mediation");
- synCtx.setTo(new EndpointReference(endpoint.getAddress()));
- Axis2FlexibleMEPClient.send(endpoint, synCtx);
+ endpoint.send(synCtx);
+ //synCtx.setTo(new EndpointReference(endpoint.getAddress()));
+ //Axis2FlexibleMEPClient.send(endpoint, synCtx);
} else {
log.error("Unable to find the endpoint for the proxy service " +
@@ -132,8 +128,9 @@
} else if (proxy.getTargetInLineEndpoint() != null) {
log.debug("Forwarding the message to the anonymous " +
"endpoint of the proxy service after message mediation");
- synCtx.setTo(new EndpointReference(proxy.getTargetInLineEndpoint().getAddress()));
- Axis2FlexibleMEPClient.send(proxy.getTargetInLineEndpoint(), synCtx);
+ proxy.getTargetInLineEndpoint().send(synCtx);
+ //synCtx.setTo(new EndpointReference(proxy.getTargetInLineEndpoint().getAddress()));
+ //Axis2FlexibleMEPClient.send(proxy.getTargetInLineEndpoint(), synCtx);
}
} else {
Added: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/send/FailureListener.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/send/FailureListener.java?view=auto&rev=514989
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/send/FailureListener.java (added)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/send/FailureListener.java Mon Mar 5 21:48:09 2007
@@ -0,0 +1,29 @@
+/*
+ * 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.mediators.builtin.send;
+
+import org.apache.synapse.MessageContext;
+
+
+// todo: move this interface to some common package. this should be gerenel failure listener for network failures.
+
+public interface FailureListener {
+ public void onFail(MessageContext synMessageContext);
+}
Added: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/send/SendConstants.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/send/SendConstants.java?view=auto&rev=514989
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/send/SendConstants.java (added)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/send/SendConstants.java Mon Mar 5 21:48:09 2007
@@ -0,0 +1,47 @@
+/*
+ * 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.mediators.builtin.send;
+
+import javax.xml.namespace.QName;
+
+/**
+ * Tempory class to hlod send mediator specific constants. Later decide on where to place these.
+ */
+public class SendConstants {
+
+ public static final String ESBSEND_ELEMENT = "send";
+ public static final String LOADBALANCE_ELEMENT = "loadbalance";
+ public static final String FAILOVER_ELEMENT = "failover"; // failover only element
+ public static final String RETRY_AFTER_FAILURE_TIME = "retryAfterFailure";
+ public static final String MAXIMUM_RETRIES = "maximumRetries";
+ public static final String RETRY_INTERVAL = "retryInterval";
+ public static final String FAILOVER = "failover"; // failover attribute in the loadbalance element
+ public static final String SESSION_AFFINITY = "sessionAffinity";
+ public static final String ALGORITHM_NAME = "algorithmName";
+ public static final String FAILOVER_GROUP_ELEMENT = "failover"; // failover group element inside the loadbalance element
+ public static final String DISPATCH_MANAGER = "DISPATCH_MANAGER";
+ public static final String DISPATCHERS_ELEMENT = "dispatchers";
+ public static final String DISPATCHER_ELEMENT = "dispatcher";
+
+ public static final QName ATT_REF_Q =
+ new QName(org.apache.synapse.config.xml.Constants.NULL_NAMESPACE, "ref");
+ public static final QName ATT_ADDRESS_Q =
+ new QName(org.apache.synapse.config.xml.Constants.NULL_NAMESPACE, "address");
+}
Added: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/send/SendMediator.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/send/SendMediator.java?view=auto&rev=514989
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/send/SendMediator.java (added)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/send/SendMediator.java Mon Mar 5 21:48:09 2007
@@ -0,0 +1,90 @@
+/*
+ * 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.mediators.builtin.send;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.synapse.Constants;
+import org.apache.synapse.MessageContext;
+import org.apache.synapse.mediators.builtin.send.endpoints.Endpoint;
+import org.apache.synapse.mediators.AbstractMediator;
+
+/**
+ * The Send mediator sends the message using the following semantics.
+ * <p/>
+ * This is a leaf mediator (i.e. further processing halts after this mediator completes)
+ * <p/>
+ * TODO support loadbalancing and failover
+ */
+public class SendMediator extends AbstractMediator {
+
+ private static final Log log = LogFactory.getLog(SendMediator.class);
+ private static final Log trace = LogFactory.getLog(Constants.TRACE_LOGGER);
+
+ private Endpoint endpoint = null;
+
+ /**
+ * This is a leaf mediator. i.e. processing stops once send is invoked,
+ * as it always returns false
+ *
+ * @param synCtx the current message to be sent
+ * @return false always as this is a leaf mediator
+ */
+ public boolean mediate(MessageContext synCtx) {
+ log.debug("Send mediator :: mediate()");
+
+ boolean shouldTrace = shouldTrace(synCtx.getTracingState());
+ try {
+ if (shouldTrace) {
+ trace.trace("Start : Send mediator");
+ trace.trace("Sending Message :: " + synCtx.getEnvelope());
+ }
+ // if no endpoints are defined, send where implicitly stated
+ if (endpoint == null) {
+ if (log.isDebugEnabled()) {
+ log.debug("Sending message using implicit message properties..");
+ log.debug("Sending To: " + (synCtx.getTo() != null ?
+ synCtx.getTo().getAddress() : "null"));
+ log.debug("SOAPAction: " + (synCtx.getWSAAction() != null ?
+ synCtx.getWSAAction() : "null"));
+ log.debug("Body : \n" + synCtx.getEnvelope());
+ }
+ synCtx.getEnvironment().send(null, synCtx);
+
+ } else {
+ endpoint.send(synCtx);
+ }
+
+ } finally {
+ if (shouldTrace) {
+ trace.trace("End : Send mediator");
+ }
+ }
+ return false;
+ }
+
+ public Endpoint getEndpoint() {
+ return endpoint;
+ }
+
+ public void setEndpoint(Endpoint endpoint) {
+ this.endpoint = endpoint;
+ }
+}
Added: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/send/algorithms/LoadbalanceAlgorithm.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/send/algorithms/LoadbalanceAlgorithm.java?view=auto&rev=514989
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/send/algorithms/LoadbalanceAlgorithm.java (added)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/send/algorithms/LoadbalanceAlgorithm.java Mon Mar 5 21:48:09 2007
@@ -0,0 +1,43 @@
+/*
+ * 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.mediators.builtin.send.algorithms;
+
+import org.apache.synapse.MessageContext;
+import org.apache.synapse.mediators.builtin.send.endpoints.Endpoint;
+
+/**
+ * All load balance algorithms must implement this interface. Implementations of this interface can
+ * be registered in LoadbalanceManagers.
+ */
+public interface LoadbalanceAlgorithm {
+
+ /**
+ * This method returns the next node according to the algorithm implementation.
+ *
+ * @param synapseMessageContext SynapseMessageContext of the current message
+ * @return Next node for directing the message
+ */
+ public Endpoint getNextEndpoint(MessageContext synapseMessageContext);
+
+ /**
+ * Resets the algorithm to its initial position. Initial position depends on the implementation.
+ */
+ public void reset();
+}
Added: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/send/algorithms/RoundRobin.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/send/algorithms/RoundRobin.java?view=auto&rev=514989
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/send/algorithms/RoundRobin.java (added)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/send/algorithms/RoundRobin.java Mon Mar 5 21:48:09 2007
@@ -0,0 +1,70 @@
+/*
+ * 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.mediators.builtin.send.algorithms;
+
+import org.apache.synapse.MessageContext;
+import org.apache.synapse.SynapseException;
+import org.apache.synapse.mediators.builtin.send.endpoints.Endpoint;
+
+import java.util.ArrayList;
+
+public class RoundRobin implements LoadbalanceAlgorithm {
+
+ private ArrayList endpoints = null;
+ private int currentEPR = 0;
+
+ public RoundRobin(ArrayList endpoints) {
+ this.endpoints = endpoints;
+ }
+
+ /**
+ * Choose an active endpoint using the round robin algorithm.
+ *
+ * @param synapseMessageContext
+ * @return endpoint to send the next message
+ */
+ public Endpoint getNextEndpoint(MessageContext synapseMessageContext) {
+
+ Endpoint nextEndpoint = null;
+ int attempts = 0;
+
+ do {
+ nextEndpoint = (Endpoint) endpoints.get(currentEPR);
+
+ if(currentEPR == endpoints.size() - 1) {
+ currentEPR = 0;
+ } else {
+ currentEPR++;
+ }
+
+ attempts++;
+ if (attempts > endpoints.size()) {
+ throw new SynapseException("All endpoints have failed.");
+ }
+
+ } while (!nextEndpoint.isActive());
+
+ return nextEndpoint;
+ }
+
+ public void reset() {
+ currentEPR = 0;
+ }
+}
Added: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/send/endpoints/AddressEndpoint.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/send/endpoints/AddressEndpoint.java?view=auto&rev=514989
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/send/endpoints/AddressEndpoint.java (added)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/send/endpoints/AddressEndpoint.java Mon Mar 5 21:48:09 2007
@@ -0,0 +1,159 @@
+/*
+ * 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.mediators.builtin.send.endpoints;
+
+import org.apache.synapse.MessageContext;
+import org.apache.synapse.Constants;
+import org.apache.synapse.FaultHandler;
+import org.apache.synapse.SynapseException;
+import org.apache.synapse.mediators.builtin.send.FailureListener;
+import org.apache.synapse.statistics.impl.EndPointStatisticsStack;
+import org.apache.synapse.config.EndpointDefinition;
+import org.apache.axis2.addressing.EndpointReference;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * This class represents an actual endpoint to send the message. It is resposible for sending the
+ * message, performing reries if a failure occured and informing the parent endpoint if a failure
+ * couldn't be recovered.
+ */
+public class AddressEndpoint implements Endpoint, FaultHandler {
+
+ private static final Log log = LogFactory.getLog(AddressEndpoint.class);
+
+ private String name;
+ private boolean active = true;
+ private EndpointDefinition endpoint = null;
+ private Endpoint parentEndpoint = null;
+
+ public EndpointDefinition getEndpoint() {
+ return endpoint;
+ }
+
+ public void setEndpoint(EndpointDefinition endpoint) {
+ this.endpoint = endpoint;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public boolean isActive() {
+ return active;
+ }
+
+ public void setActive(boolean active) {
+ this.active = active;
+ }
+
+ public void send(MessageContext synCtx) {
+
+ String eprAddress = null;
+ if (endpoint.getAddress() != null) {
+ eprAddress = endpoint.getAddress().toString();
+
+ if (endpoint.isForcePOX()) {
+ synCtx.setDoingPOX(true);
+ } else if (endpoint.isForceSOAP()) {
+ synCtx.setDoingPOX(false);
+ }
+
+ if (endpoint.isUseMTOM()) {
+ synCtx.setDoingMTOM(true);
+ } else if (endpoint.isUseSwa()) {
+ synCtx.setDoingSWA(true);
+ }
+
+ if (endpoint.isUseSeparateListener()) {
+ synCtx.setProperty(Constants.OUTFLOW_USE_SEPARATE_LISTENER, Boolean.TRUE);
+ }
+
+ String endPointName = endpoint.getName();
+
+ // Setting Required property to collect the End Point statistics
+ boolean statisticsEnable = (org.apache.synapse.Constants.STATISTICS_ON == endpoint.getStatisticsEnable());
+ if (endPointName != null && statisticsEnable) {
+ EndPointStatisticsStack endPointStatisticsStack = new EndPointStatisticsStack();
+ boolean isFault =synCtx.getEnvelope().getBody().hasFault();
+ endPointStatisticsStack.put(endPointName, System.currentTimeMillis(), !synCtx.isResponse(), statisticsEnable,isFault);
+ synCtx.setProperty(org.apache.synapse.Constants.ENDPOINT_STATISTICS_STACK, endPointStatisticsStack);
+ }
+ synCtx.setTo(new EndpointReference(eprAddress));
+
+ if (log.isDebugEnabled()) {
+ log.debug("Sending message to endpoint :: name = " +
+ endPointName + " resolved address = " + eprAddress);
+ log.debug("Sending To: " + (synCtx.getTo() != null ?
+ synCtx.getTo().getAddress() : "null"));
+ log.debug("SOAPAction: " + (synCtx.getWSAAction() != null ?
+ synCtx.getWSAAction() : "null"));
+ log.debug("Body : \n" + synCtx.getEnvelope());
+ }
+
+ // if RM is turned on
+ if (endpoint.isReliableMessagingOn()) {
+ synCtx.setProperty(Constants.OUTFLOW_ADDRESSING_ON, Boolean.TRUE);
+ synCtx.setProperty(Constants.OUTFLOW_RM_ON, Boolean.TRUE);
+ if (endpoint.getWsRMPolicyKey() != null) {
+ synCtx.setProperty(Constants.OUTFLOW_RM_POLICY,
+ endpoint.getWsRMPolicyKey());
+ }
+ }
+
+ // if WS Security is specified
+ if (endpoint.isSecurityOn()) {
+ synCtx.setProperty(Constants.OUTFLOW_ADDRESSING_ON, Boolean.TRUE);
+ synCtx.setProperty(Constants.OUTFLOW_SECURITY_ON, Boolean.TRUE);
+ if (endpoint.getWsSecPolicyKey() != null) {
+ synCtx.setProperty(Constants.OUTFLOW_SEC_POLICY,
+ endpoint.getWsSecPolicyKey());
+ }
+ }
+
+ // if WS Addressing is specified
+ if (endpoint.isAddressingOn()) {
+ synCtx.setProperty(Constants.OUTFLOW_ADDRESSING_ON, Boolean.TRUE);
+ }
+
+ synCtx.pushFault(this);
+ synCtx.getEnvironment().send(endpoint, synCtx);
+ }
+ }
+
+ public void onChildEndpointFail(Endpoint endpoint, MessageContext synMessageContext) {
+ // nothing to do as this is a leaf level endpoint
+ }
+
+ public void setParentEndpoint(Endpoint parentEndpoint) {
+ this.parentEndpoint = parentEndpoint;
+ }
+
+ public void handleFault(MessageContext synCtx) throws SynapseException {
+ // perform retries here
+
+ // if this endpoint has actually failed, inform the parent.
+ parentEndpoint.onChildEndpointFail(this, synCtx);
+ }
+}
Added: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/send/endpoints/Endpoint.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/send/endpoints/Endpoint.java?view=auto&rev=514989
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/send/endpoints/Endpoint.java (added)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/send/endpoints/Endpoint.java Mon Mar 5 21:48:09 2007
@@ -0,0 +1,39 @@
+/*
+ * 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.mediators.builtin.send.endpoints;
+
+import org.apache.synapse.MessageContext;
+
+public interface Endpoint {
+
+ public void send(MessageContext synMessageContext);
+
+ public void onChildEndpointFail(Endpoint endpoint, MessageContext synMessageContext);
+
+ public void setParentEndpoint(Endpoint parentEndpoint);
+
+ public String getName();
+
+ public void setName(String name);
+
+ public boolean isActive();
+
+ public void setActive(boolean active);
+}
Added: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/send/endpoints/FailoverEndpoint.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/send/endpoints/FailoverEndpoint.java?view=auto&rev=514989
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/send/endpoints/FailoverEndpoint.java (added)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/send/endpoints/FailoverEndpoint.java Mon Mar 5 21:48:09 2007
@@ -0,0 +1,95 @@
+/*
+ * 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.mediators.builtin.send.endpoints;
+
+import org.apache.synapse.MessageContext;
+
+import java.util.ArrayList;
+
+public class FailoverEndpoint implements Endpoint {
+
+ private String name = null;
+ private boolean active = true;
+ private ArrayList endpoints = null;
+ private Endpoint currentEndpoint = null;
+ private Endpoint parentEndpoint = null;
+
+ public void send(MessageContext synMessageContext) {
+
+ if (currentEndpoint.isActive()) {
+ currentEndpoint.send(synMessageContext);
+ } else {
+
+ Endpoint liveEndpoint = null;
+ boolean foundEndpoint = false;
+ for (int i = 0; i < endpoints.size(); i++) {
+ liveEndpoint = (Endpoint) endpoints.get(i);
+ if (liveEndpoint.isActive()) {
+ foundEndpoint = true;
+ currentEndpoint = liveEndpoint;
+ currentEndpoint.send(synMessageContext);
+ break;
+ }
+ }
+
+ if (!foundEndpoint) {
+ if (parentEndpoint != null) {
+ parentEndpoint.onChildEndpointFail(this, synMessageContext);
+ }
+ }
+ }
+ }
+
+ public String getName() {
+ return this.name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public boolean isActive() {
+ return this.active;
+ }
+
+ public void setActive(boolean active) {
+ this.active = active;
+ }
+
+ public ArrayList getEndpoints() {
+ return endpoints;
+ }
+
+ public void setEndpoints(ArrayList endpoints) {
+ this.endpoints = endpoints;
+ if (endpoints.size() > 0) {
+ currentEndpoint = (Endpoint) endpoints.get(0);
+ }
+ }
+
+ public void onChildEndpointFail(Endpoint endpoint, MessageContext synMessageContext) {
+ endpoint.setActive(false);
+ send(synMessageContext);
+ }
+
+ public void setParentEndpoint(Endpoint parentEndpoint) {
+ this.parentEndpoint = parentEndpoint;
+ }
+}
Added: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/send/endpoints/IndirectEndpoint.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/send/endpoints/IndirectEndpoint.java?view=auto&rev=514989
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/send/endpoints/IndirectEndpoint.java (added)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/send/endpoints/IndirectEndpoint.java Mon Mar 5 21:48:09 2007
@@ -0,0 +1,75 @@
+/*
+ * 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.mediators.builtin.send.endpoints;
+
+import org.apache.synapse.MessageContext;
+
+public class IndirectEndpoint implements Endpoint {
+
+ private String name = null;
+ private String ref = null;
+ private boolean active = true;
+ private Endpoint parentEndpoint = null;
+
+ public void send(MessageContext synMessageContext) {
+ // get the actual endpoint and send
+ Endpoint endpoint = synMessageContext.getConfiguration().
+ getNamedEndpoint(ref);
+
+ if (endpoint.isActive()) {
+ endpoint.send(synMessageContext);
+ } else {
+ parentEndpoint.onChildEndpointFail(this, synMessageContext);
+ }
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getRef() {
+ return ref;
+ }
+
+ public void setRef(String ref) {
+ this.ref = ref;
+ }
+
+ public boolean isActive() {
+ return active;
+ }
+
+ public void setActive(boolean active) {
+ this.active = active;
+ }
+
+ public void setParentEndpoint(Endpoint parentEndpoint) {
+ this.parentEndpoint = parentEndpoint;
+ }
+
+ public void onChildEndpointFail(Endpoint endpoint, MessageContext synMessageContext) {
+ endpoint.setActive(false);
+ parentEndpoint.onChildEndpointFail(this, synMessageContext);
+ }
+}
Added: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/send/endpoints/LoadbalanceEndpoint.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/send/endpoints/LoadbalanceEndpoint.java?view=auto&rev=514989
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/send/endpoints/LoadbalanceEndpoint.java (added)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/send/endpoints/LoadbalanceEndpoint.java Mon Mar 5 21:48:09 2007
@@ -0,0 +1,108 @@
+/*
+ * 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.mediators.builtin.send.endpoints;
+
+import org.apache.synapse.MessageContext;
+import org.apache.synapse.mediators.builtin.send.algorithms.LoadbalanceAlgorithm;
+
+import java.util.ArrayList;
+
+public class LoadbalanceEndpoint implements Endpoint {
+
+ private ArrayList endpoints = null;
+ private long abandonTime = 0;
+ private LoadbalanceAlgorithm algorithm = null;
+ private int maximumRetries = 1;
+ private long retryInterval = 30000;
+ private String name = null;
+ private boolean active = true;
+ private Endpoint parentEndpoint = null;
+
+ public void send(MessageContext synMessageContext) {
+
+ Endpoint endpoint = algorithm.getNextEndpoint(synMessageContext);
+ endpoint.send(synMessageContext);
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public LoadbalanceAlgorithm getAlgorithm() {
+ return algorithm;
+ }
+
+ public void setAlgorithm(LoadbalanceAlgorithm algorithm) {
+ this.algorithm = algorithm;
+ }
+
+ public int getMaximumRetries() {
+ return maximumRetries;
+ }
+
+ public void setMaximumRetries(int maximumRetries) {
+ this.maximumRetries = maximumRetries;
+ }
+
+ public long getRetryInterval() {
+ return retryInterval;
+ }
+
+ public void setRetryInterval(long retryInterval) {
+ this.retryInterval = retryInterval;
+ }
+
+ public boolean isActive() {
+ return active;
+ }
+
+ public void setActive(boolean active) {
+ this.active = active;
+ }
+
+ public ArrayList getEndpoints() {
+ return endpoints;
+ }
+
+ public void setEndpoints(ArrayList endpoints) {
+ this.endpoints = endpoints;
+ }
+
+ public long getAbandonTime() {
+ return abandonTime;
+ }
+
+ public void setAbandonTime(long abandonTime) {
+ this.abandonTime = abandonTime;
+ }
+
+ public void setParentEndpoint(Endpoint parentEndpoint) {
+ this.parentEndpoint = parentEndpoint;
+ }
+
+ public void onChildEndpointFail(Endpoint endpoint, MessageContext synMessageContext) {
+ endpoint.setActive(false);
+ send(synMessageContext);
+ }
+}
Added: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/send/endpoints/WSDLEndpoint.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/send/endpoints/WSDLEndpoint.java?view=auto&rev=514989
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/send/endpoints/WSDLEndpoint.java (added)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/send/endpoints/WSDLEndpoint.java Mon Mar 5 21:48:09 2007
@@ -0,0 +1,67 @@
+/*
+ * 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.mediators.builtin.send.endpoints;
+
+import org.apache.synapse.MessageContext;
+import org.apache.synapse.config.EndpointDefinition;
+
+public class WSDLEndpoint implements Endpoint {
+
+ private String name;
+ private boolean active = true;
+ private Endpoint parentEndpoint = null;
+ private EndpointDefinition endpointDefinition = null;
+
+ public void send(MessageContext synMessageContext) {
+
+ }
+
+ public void onChildEndpointFail(Endpoint endpoint, MessageContext synMessageContext) {
+
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public boolean isActive() {
+ return active;
+ }
+
+ public void setActive(boolean active) {
+ this.active = active;
+ }
+
+ public void setParentEndpoint(Endpoint parentEndpoint) {
+ this.parentEndpoint = parentEndpoint;
+ }
+
+ public EndpointDefinition getEndpointDefinition() {
+ return endpointDefinition;
+ }
+
+ public void setEndpointDefinition(EndpointDefinition endpointDefinition) {
+ this.endpointDefinition = endpointDefinition;
+ }
+}
Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/registry/AbstractRegistry.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/registry/AbstractRegistry.java?view=diff&rev=514989&r1=514988&r2=514989
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/registry/AbstractRegistry.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/registry/AbstractRegistry.java Mon Mar 5 21:48:09 2007
@@ -24,7 +24,7 @@
import org.apache.commons.logging.LogFactory;
import org.apache.synapse.config.XMLToObjectMapper;
import org.apache.synapse.config.Property;
-import org.apache.synapse.config.Endpoint;
+import org.apache.synapse.config.EndpointDefinition;
import org.apache.synapse.mediators.base.SequenceMediator;
import java.net.URI;
@@ -101,8 +101,8 @@
SequenceMediator seq = (SequenceMediator) dp.getValue();
seq.setDynamic(true);
seq.setRegistryKey(dp.getKey());
- } else if (dp.getValue() instanceof Endpoint) {
- Endpoint ep = (Endpoint) dp.getValue();
+ } else if (dp.getValue() instanceof EndpointDefinition) {
+ EndpointDefinition ep = (EndpointDefinition) dp.getValue();
ep.setDynamic(true);
ep.setRegistryKey(dp.getKey());
}
Modified: webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/ProxyServiceSerializationTest.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/ProxyServiceSerializationTest.java?view=diff&rev=514989&r1=514988&r2=514989
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/ProxyServiceSerializationTest.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/ProxyServiceSerializationTest.java Mon Mar 5 21:48:09 2007
@@ -59,7 +59,7 @@
// assertTrue(comparator.compare(resultOM, inputOM));
// }
public void testProxyServiceSerializationSenarioFive() throws Exception {
- String inputXml = "<proxy xmlns=\"http://ws.apache.org/ns/synapse\" startOnLoad=\"true\" name=\"name\" transports=\"http\"><description>description</description><target><endpoint address=\"http://www.example.com/testepr\" /></target><publishWSDL uri=\"http://uri\"></publishWSDL><policy key=\"key\"/><parameter name=\"para\">text</parameter></proxy>";
+ String inputXml = "<proxy xmlns=\"http://ws.apache.org/ns/synapse\" startOnLoad=\"true\" name=\"name\" transports=\"http\"><description>description</description><target><endpoint><address uri=\"http://www.example.com/testepr\"/></endpoint></target><publishWSDL uri=\"http://uri\"></publishWSDL><policy key=\"key\"/><parameter name=\"para\">text</parameter></proxy>";
OMElement inputOM = createOMElement(inputXml);
ProxyService proxy = ProxyServiceFactory.createProxy(inputOM);
OMElement resultOM = ProxyServiceSerializer.serializeProxy(null, proxy);
Modified: webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/SendMediatorSerializationTest.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/SendMediatorSerializationTest.java?view=diff&rev=514989&r1=514988&r2=514989
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/SendMediatorSerializationTest.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/SendMediatorSerializationTest.java Mon Mar 5 21:48:09 2007
@@ -20,79 +20,196 @@
package org.apache.synapse.config.xml;
import org.apache.axiom.om.impl.exception.XMLComparisonException;
+import org.apache.axiom.om.impl.builder.StAXOMBuilder;
+import org.apache.axiom.om.OMElement;
+import org.apache.synapse.mediators.builtin.send.SendMediator;
+import org.apache.synapse.mediators.builtin.send.endpoints.LoadbalanceEndpoint;
+import org.apache.synapse.mediators.builtin.send.endpoints.AddressEndpoint;
+import org.apache.synapse.mediators.builtin.send.endpoints.FailoverEndpoint;
+
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamException;
+import java.util.ArrayList;
+import java.io.StringReader;
public class SendMediatorSerializationTest extends AbstractTestCase {
- private SendMediatorFactory sendMediatorFactory = null;
- private SendMediatorSerializer sendMediatorSerializer = null;
+ private SendMediatorFactory factory = null;
+ private SendMediatorSerializer serializer = null;
public SendMediatorSerializationTest() {
- sendMediatorFactory = new SendMediatorFactory();
- sendMediatorSerializer = new SendMediatorSerializer();
+ factory = new SendMediatorFactory();
+ serializer = new SendMediatorSerializer();
}
- public void testSendMediatorWithNoEndpoints() {
+ public void testSimpleLoadbalanceSendSerialization() {
- String sendConfiguration = "<syn:send xmlns:syn=\"http://ws.apache.org/ns/synapse\"/>";
-
- try {
- assertTrue(serialization(sendConfiguration, sendMediatorFactory, sendMediatorSerializer));
- } catch (XMLComparisonException e) {
- fail("Exception in test.");
- }
+ String sendConfig = "<send xmlns=\"http://ws.apache.org/ns/synapse\">" +
+ "<endpoint>" +
+ "<loadbalance>" +
+ "<endpoint>" +
+ "<address uri=\"http://localhost:9001/axis2/services/Service1\">" +
+ "<enableAddressing/>" +
+ "</address>" +
+ "</endpoint>" +
+ "<endpoint>" +
+ "<address uri=\"http://localhost:9002/axis2/services/Service1\">" +
+ "<enableAddressing/>" +
+ "</address>" +
+ "</endpoint>" +
+ "<endpoint>" +
+ "<address uri=\"http://localhost:9003/axis2/services/Service1\">" +
+ "<enableAddressing/>" +
+ "</address>" +
+ "</endpoint>" +
+ "</loadbalance>" +
+ "</endpoint>" +
+ "</send>";
+
+ OMElement config1 = createOMElement(sendConfig);
+ SendMediator send1 = (SendMediator) factory.createMediator(config1);
+
+ OMElement config2 = serializer.serializeMediator(null, send1);
+ SendMediator send2 = (SendMediator) factory.createMediator(config2);
+
+ assertTrue("Top level endpoint should be a load balance endpoint.",
+ send2.getEndpoint() instanceof LoadbalanceEndpoint);
+
+ LoadbalanceEndpoint endpoint = (LoadbalanceEndpoint) send2.getEndpoint();
+ ArrayList addresses = endpoint.getEndpoints();
+ assertEquals("There should be 3 leaf level address endpoints", addresses.size(), 3);
+
+ assertTrue("Leaf level endpoints should be address endpoints",
+ addresses.get(0) instanceof AddressEndpoint);
+ assertTrue("Leaf level endpoints should be address endpoints",
+ addresses.get(1) instanceof AddressEndpoint);
+ assertTrue("Leaf level endpoints should be address endpoints",
+ addresses.get(2) instanceof AddressEndpoint);
+
+ AddressEndpoint addressEndpoint = (AddressEndpoint) addresses.get(0);
+ assertTrue("URI of address endpoint is not serialized properly",
+ "http://localhost:9001/axis2/services/Service1".equals(addressEndpoint.getEndpoint().getAddress()));
}
- public void testSendMediatorWithSingleEndpoint() {
-
- String sendConfiguration = "<syn:send xmlns:syn=\"http://ws.apache.org/ns/synapse\">" +
- "<syn:endpoint address=\"http://ws.apache.org/axis2/services/Service1\" />" +
- "</syn:send>";
+ public void testSimpleFailoverSendSerialization() {
- try {
- assertTrue(serialization(sendConfiguration, sendMediatorFactory, sendMediatorSerializer));
- } catch (XMLComparisonException e) {
- fail("Exception in test.");
- }
+ String sendConfig = "<send xmlns=\"http://ws.apache.org/ns/synapse\">" +
+ "<endpoint>" +
+ "<failover>" +
+ "<endpoint>" +
+ "<address uri=\"http://localhost:9001/axis2/services/Service1\">" +
+ "<enableAddressing/>" +
+ "</address>" +
+ "</endpoint>" +
+ "<endpoint>" +
+ "<address uri=\"http://localhost:9002/axis2/services/Service1\">" +
+ "<enableAddressing/>" +
+ "</address>" +
+ "</endpoint>" +
+ "<endpoint>" +
+ "<address uri=\"http://localhost:9003/axis2/services/Service1\">" +
+ "<enableAddressing/>" +
+ "</address>" +
+ "</endpoint>" +
+ "</failover>" +
+ "</endpoint>" +
+ "</send>";
+
+ OMElement config1 = createOMElement(sendConfig);
+ SendMediator send1 = (SendMediator) factory.createMediator(config1);
+
+ OMElement config2 = serializer.serializeMediator(null, send1);
+ SendMediator send2 = (SendMediator) factory.createMediator(config2);
+
+ assertTrue("Top level endpoint should be a failover endpoint.",
+ send2.getEndpoint() instanceof FailoverEndpoint);
+
+ FailoverEndpoint endpoint = (FailoverEndpoint) send2.getEndpoint();
+ ArrayList addresses = endpoint.getEndpoints();
+ assertEquals("There should be 3 leaf level address endpoints", addresses.size(), 3);
+
+ assertTrue("Leaf level endpoints should be address endpoints",
+ addresses.get(0) instanceof AddressEndpoint);
+ assertTrue("Leaf level endpoints should be address endpoints",
+ addresses.get(1) instanceof AddressEndpoint);
+ assertTrue("Leaf level endpoints should be address endpoints",
+ addresses.get(2) instanceof AddressEndpoint);
+
+ AddressEndpoint addressEndpoint = (AddressEndpoint) addresses.get(0);
+ assertTrue("URI of address endpoint is not serialized properly",
+ "http://localhost:9001/axis2/services/Service1".equals(addressEndpoint.getEndpoint().getAddress()));
}
- public void testSendMediatorWithMultipleEndpoints() {
+ public void testNestedLoadbalanceFailoverSendSerialization() {
- String sendConfiguration = "<syn:send xmlns:syn=\"http://ws.apache.org/ns/synapse\">" +
- "<syn:endpoint address=\"http://ws.apache.org/axis2/services/Service1\" />" +
- "<syn:endpoint address=\"http://ws.apache.org/axis2/services/Service2\" />" +
- "</syn:send>";
-
- try {
- assertTrue(serialization(sendConfiguration, sendMediatorFactory, sendMediatorSerializer));
- } catch (XMLComparisonException e) {
- fail("Exception in test.");
- }
+ String sendConfig = "<send xmlns=\"http://ws.apache.org/ns/synapse\">" +
+ "<endpoint>" +
+ "<loadbalance>" +
+ "<endpoint>" +
+ "<address uri=\"http://localhost:9001/axis2/services/Service1\">" +
+ "<enableAddressing/>" +
+ "</address>" +
+ "</endpoint>" +
+ "<endpoint>" +
+ "<failover>" +
+ "<endpoint>" +
+ "<address uri=\"http://localhost:9002/axis2/services/Service1\">" +
+ "<enableAddressing/>" +
+ "</address>" +
+ "</endpoint>" +
+ "<endpoint>" +
+ "<address uri=\"http://localhost:9003/axis2/services/Service1\">" +
+ "<enableAddressing/>" +
+ "</address>" +
+ "</endpoint>" +
+ "</failover>" +
+ "</endpoint>" +
+ "</loadbalance>" +
+ "</endpoint>" +
+ "</send>";
+
+ OMElement config1 = createOMElement(sendConfig);
+ SendMediator send1 = (SendMediator) factory.createMediator(config1);
+
+ OMElement config2 = serializer.serializeMediator(null, send1);
+ SendMediator send2 = (SendMediator) factory.createMediator(config2);
+
+ assertTrue("Top level endpoint should be a load balance endpoint.",
+ send2.getEndpoint() instanceof LoadbalanceEndpoint);
+
+ LoadbalanceEndpoint loadbalanceEndpoint = (LoadbalanceEndpoint) send2.getEndpoint();
+
+ ArrayList children = loadbalanceEndpoint.getEndpoints();
+ assertEquals("Top level endpoint should have 2 child endpoints.", children.size(), 2);
+
+ assertTrue("First child should be a address endpoint",
+ children.get(0) instanceof AddressEndpoint);
+
+ assertTrue("Second child should be a fail over endpoint",
+ children.get(1) instanceof FailoverEndpoint);
+
+ FailoverEndpoint failoverEndpoint = (FailoverEndpoint) children.get(1);
+ ArrayList children2 = failoverEndpoint.getEndpoints();
+
+ assertEquals("Fail over endpoint should have 2 children.", children2.size(), 2);
+ assertTrue("Children of the fail over endpoint should be address endpoints.",
+ children2.get(0) instanceof AddressEndpoint);
+ assertTrue("Children of the fail over endpoint should be address endpoints.",
+ children2.get(1) instanceof AddressEndpoint);
}
- public void testSendMediatorWithSingleEndpointReference() {
-
- String sendConfiguration = "<syn:send xmlns:syn=\"http://ws.apache.org/ns/synapse\">" +
- "<syn:endpoint ref=\"ep1\"/>" +
- "</syn:send>";
-
+ protected OMElement createOMElement(String xml) {
try {
- assertTrue(serialization(sendConfiguration, sendMediatorFactory, sendMediatorSerializer));
- } catch (XMLComparisonException e) {
- fail("Exception in test.");
- }
- }
-
- public void testSendMediatorWithMultipleEndpointReferences() {
- String sendConfiguration = "<syn:send xmlns:syn=\"http://ws.apache.org/ns/synapse\">" +
- "<syn:endpoint ref=\"ep1\"/>" +
- "<syn:endpoint ref=\"ep2\"/>" +
- "</syn:send>";
+ XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(new StringReader(xml));
+ StAXOMBuilder builder = new StAXOMBuilder(reader);
+ OMElement omElement = builder.getDocumentElement();
+ return omElement;
- try {
- assertTrue(serialization(sendConfiguration, sendMediatorFactory, sendMediatorSerializer));
- } catch (XMLComparisonException e) {
- fail("Exception in test.");
+ }
+ catch (XMLStreamException e) {
+ throw new RuntimeException(e);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: synapse-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: synapse-dev-help@ws.apache.org