Search in sources :

Example 6 with FailoverEndpoint

use of org.apache.synapse.endpoints.FailoverEndpoint in project wso2-synapse by wso2.

the class FailoverEndpointSerializer method serializeEndpoint.

protected OMElement serializeEndpoint(Endpoint endpoint) {
    if (!(endpoint instanceof FailoverEndpoint)) {
        handleException("Invalid endpoint type.");
    }
    FailoverEndpoint failoverEndpoint = (FailoverEndpoint) endpoint;
    fac = OMAbstractFactory.getOMFactory();
    OMElement endpointElement = fac.createOMElement("endpoint", SynapseConstants.SYNAPSE_OMNAMESPACE);
    OMElement failoverElement = fac.createOMElement("failover", SynapseConstants.SYNAPSE_OMNAMESPACE);
    endpointElement.addChild(failoverElement);
    serializeCommonAttributes(endpoint, endpointElement);
    if (failoverEndpoint.isBuildMessageAtt()) {
        failoverElement.addAttribute(XMLConfigConstants.BUILD_MESSAGE, Boolean.toString(failoverEndpoint.isBuildMessageAtt()), null);
    }
    for (Endpoint childEndpoint : failoverEndpoint.getChildren()) {
        failoverElement.addChild(EndpointSerializer.getElementFromEndpoint(childEndpoint));
    }
    if (!failoverEndpoint.isDynamic()) {
        failoverElement.addAttribute("dynamic", "false", null);
    }
    // serialize the parameters
    serializeProperties(failoverEndpoint, endpointElement);
    return endpointElement;
}
Also used : Endpoint(org.apache.synapse.endpoints.Endpoint) FailoverEndpoint(org.apache.synapse.endpoints.FailoverEndpoint) OMElement(org.apache.axiom.om.OMElement) FailoverEndpoint(org.apache.synapse.endpoints.FailoverEndpoint)

Example 7 with FailoverEndpoint

use of org.apache.synapse.endpoints.FailoverEndpoint in project wso2-synapse by wso2.

the class SendMediatorSerializationTest method testNestedLoadbalanceFailoverSendSerialization.

public void testNestedLoadbalanceFailoverSendSerialization() {
    String sendConfig = "<send xmlns=\"http://ws.apache.org/ns/synapse\">" + "<endpoint>" + "<loadbalance>" + "<endpoint>" + "<address uri=\"http://localhost:9001/services/Service1\">" + "<enableAddressing/>" + "</address>" + "</endpoint>" + "<endpoint>" + "<failover>" + "<endpoint>" + "<address uri=\"http://localhost:9002/services/Service1\">" + "<enableAddressing/>" + "</address>" + "</endpoint>" + "<endpoint>" + "<address uri=\"http://localhost:9003/services/Service1\">" + "<enableAddressing/>" + "</address>" + "</endpoint>" + "</failover>" + "</endpoint>" + "</loadbalance>" + "</endpoint>" + "</send>";
    OMElement config1 = createOMElement(sendConfig);
    SendMediator send1 = (SendMediator) factory.createMediator(config1, new Properties());
    OMElement config2 = serializer.serializeMediator(null, send1);
    SendMediator send2 = (SendMediator) factory.createMediator(config2, new Properties());
    assertTrue("Top level endpoint should be a load balance endpoint.", send2.getEndpoint() instanceof LoadbalanceEndpoint);
    LoadbalanceEndpoint loadbalanceEndpoint = (LoadbalanceEndpoint) send2.getEndpoint();
    List children = loadbalanceEndpoint.getChildren();
    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);
    List children2 = failoverEndpoint.getChildren();
    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);
}
Also used : LoadbalanceEndpoint(org.apache.synapse.endpoints.LoadbalanceEndpoint) AddressEndpoint(org.apache.synapse.endpoints.AddressEndpoint) OMElement(org.apache.axiom.om.OMElement) List(java.util.List) SendMediator(org.apache.synapse.mediators.builtin.SendMediator) Properties(java.util.Properties) FailoverEndpoint(org.apache.synapse.endpoints.FailoverEndpoint)

Aggregations

FailoverEndpoint (org.apache.synapse.endpoints.FailoverEndpoint)7 OMElement (org.apache.axiom.om.OMElement)6 List (java.util.List)4 Properties (java.util.Properties)4 AddressEndpoint (org.apache.synapse.endpoints.AddressEndpoint)4 Endpoint (org.apache.synapse.endpoints.Endpoint)3 LoadbalanceEndpoint (org.apache.synapse.endpoints.LoadbalanceEndpoint)2 CallMediator (org.apache.synapse.mediators.builtin.CallMediator)2 SendMediator (org.apache.synapse.mediators.builtin.SendMediator)2 Stack (java.util.Stack)1 QName (javax.xml.namespace.QName)1 EndpointReference (org.apache.axis2.addressing.EndpointReference)1 RelatesTo (org.apache.axis2.addressing.RelatesTo)1 MessageContext (org.apache.axis2.context.MessageContext)1 NHttpServerConnection (org.apache.http.nio.NHttpServerConnection)1 ContinuationState (org.apache.synapse.ContinuationState)1 FaultHandler (org.apache.synapse.FaultHandler)1 SynapseException (org.apache.synapse.SynapseException)1 TenantInfoConfigurator (org.apache.synapse.carbonext.TenantInfoConfigurator)1 ConcurrentAccessController (org.apache.synapse.commons.throttle.core.ConcurrentAccessController)1