Search in sources :

Example 16 with AddressEndpoint

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

the class SynapseObserverTest method testSimpleObserver.

public void testSimpleObserver() {
    SynapseConfiguration synapseConfig = new SynapseConfiguration();
    synapseConfig.setAxisConfiguration(new AxisConfiguration());
    synapseConfig.registerObserver(observer);
    Endpoint epr = new AddressEndpoint();
    epr.setName("endpoint1");
    synapseConfig.addEndpoint(epr.getName(), epr);
    assertItemAdded(epr.getName(), ENDPOINT);
    synapseConfig.removeEndpoint(epr.getName());
    assertItemRemoved(epr.getName(), ENDPOINT);
    SequenceMediator seq = new SequenceMediator();
    seq.setName("sequence1");
    synapseConfig.addSequence(seq.getName(), seq);
    assertItemAdded(seq.getName(), SEQUENCE);
    synapseConfig.removeSequence(seq.getName());
    assertItemRemoved(seq.getName(), SEQUENCE);
    TemplateMediator template = new TemplateMediator();
    template.setName("template1");
    synapseConfig.addSequenceTemplate(template.getName(), template);
    assertItemAdded(template.getName(), SEQUENCE_TEMPLATE);
    synapseConfig.removeSequenceTemplate(template.getName());
    assertItemRemoved(template.getName(), SEQUENCE_TEMPLATE);
    Entry entry = new Entry();
    entry.setKey("entry1");
    synapseConfig.addEntry(entry.getKey(), entry);
    assertItemAdded(entry.getKey(), ENTRY);
    synapseConfig.removeEntry(entry.getKey());
    assertItemRemoved(entry.getKey(), ENTRY);
    ProxyService proxy = new ProxyService("proxy1");
    synapseConfig.addProxyService(proxy.getName(), proxy);
    assertItemAdded(proxy.getName(), PROXY);
    synapseConfig.removeProxyService(proxy.getName());
    assertItemRemoved(proxy.getName(), PROXY);
    Startup startup = new StartUpController();
    startup.setName("startup1");
    synapseConfig.addStartup(startup);
    assertItemAdded(startup.getName(), STARTUP);
    synapseConfig.removeStartup(startup.getName());
    assertItemRemoved(startup.getName(), STARTUP);
    SynapseEventSource eventSrc = new SynapseEventSource("eventSrc1");
    synapseConfig.addEventSource(eventSrc.getName(), eventSrc);
    assertItemAdded(eventSrc.getName(), EVENT_SRC);
    synapseConfig.removeEventSource(eventSrc.getName());
    assertItemRemoved(eventSrc.getName(), EVENT_SRC);
    PriorityExecutor exec = new PriorityExecutor();
    exec.setName("exec1");
    synapseConfig.addPriorityExecutor(exec.getName(), exec);
    assertItemAdded(exec.getName(), EXECUTOR);
    synapseConfig.removeExecutor(exec.getName());
    assertItemRemoved(exec.getName(), EXECUTOR);
}
Also used : AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) StartUpController(org.apache.synapse.startup.quartz.StartUpController) AddressEndpoint(org.apache.synapse.endpoints.AddressEndpoint) AddressEndpoint(org.apache.synapse.endpoints.AddressEndpoint) Endpoint(org.apache.synapse.endpoints.Endpoint) InboundEndpoint(org.apache.synapse.inbound.InboundEndpoint) TemplateMediator(org.apache.synapse.mediators.template.TemplateMediator) SynapseEventSource(org.apache.synapse.eventing.SynapseEventSource) ProxyService(org.apache.synapse.core.axis2.ProxyService) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator) PriorityExecutor(org.apache.synapse.commons.executors.PriorityExecutor) Startup(org.apache.synapse.Startup)

Example 17 with AddressEndpoint

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

the class CallMediatorSerializationTest method testSimpleFailoverCallSerialization.

public void testSimpleFailoverCallSerialization() {
    String callConfig = "<call xmlns=\"http://ws.apache.org/ns/synapse\">" + "<endpoint>" + "<failover>" + "<endpoint>" + "<address uri=\"http://localhost:9001/services/Service1\">" + "<enableAddressing/>" + "</address>" + "</endpoint>" + "<endpoint>" + "<address uri=\"http://localhost:9002/services/Service1\">" + "<enableAddressing/>" + "</address>" + "</endpoint>" + "<endpoint>" + "<address uri=\"http://localhost:9003/services/Service1\">" + "<enableAddressing/>" + "</address>" + "</endpoint>" + "</failover>" + "</endpoint>" + "</call>";
    OMElement config1 = createOMElement(callConfig);
    CallMediator call1 = (CallMediator) factory.createMediator(config1, new Properties());
    OMElement config2 = serializer.serializeMediator(null, call1);
    CallMediator call2 = (CallMediator) factory.createMediator(config2, new Properties());
    assertTrue("Top level endpoint should be a failover endpoint.", call2.getEndpoint() instanceof FailoverEndpoint);
    FailoverEndpoint endpoint = (FailoverEndpoint) call2.getEndpoint();
    List addresses = endpoint.getChildren();
    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/services/Service1".equals(addressEndpoint.getDefinition().getAddress()));
}
Also used : AddressEndpoint(org.apache.synapse.endpoints.AddressEndpoint) OMElement(org.apache.axiom.om.OMElement) List(java.util.List) CallMediator(org.apache.synapse.mediators.builtin.CallMediator) Properties(java.util.Properties) FailoverEndpoint(org.apache.synapse.endpoints.FailoverEndpoint)

Example 18 with AddressEndpoint

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

the class CallMediatorSerializationTest method testNestedLoadbalanceFailoverCallSerialization.

public void testNestedLoadbalanceFailoverCallSerialization() {
    String callConfig = "<call 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>" + "</call>";
    OMElement config1 = createOMElement(callConfig);
    CallMediator call1 = (CallMediator) factory.createMediator(config1, new Properties());
    OMElement config2 = serializer.serializeMediator(null, call1);
    CallMediator call2 = (CallMediator) factory.createMediator(config2, new Properties());
    assertTrue("Top level endpoint should be a load balance endpoint.", call2.getEndpoint() instanceof LoadbalanceEndpoint);
    LoadbalanceEndpoint loadbalanceEndpoint = (LoadbalanceEndpoint) call2.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) CallMediator(org.apache.synapse.mediators.builtin.CallMediator) Properties(java.util.Properties) FailoverEndpoint(org.apache.synapse.endpoints.FailoverEndpoint)

Example 19 with AddressEndpoint

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

the class CallMediatorSerializationTest method testSimpleLoadbalanceCallSerialization.

public void testSimpleLoadbalanceCallSerialization() {
    String callConfig = "<call xmlns=\"http://ws.apache.org/ns/synapse\">" + "<endpoint>" + "<loadbalance>" + "<endpoint>" + "<address uri=\"http://localhost:9001/services/Service1\">" + "<enableAddressing/>" + "</address>" + "</endpoint>" + "<endpoint>" + "<address uri=\"http://localhost:9002/services/Service1\">" + "<enableAddressing/>" + "</address>" + "</endpoint>" + "<endpoint>" + "<address uri=\"http://localhost:9003/services/Service1\">" + "<enableAddressing/>" + "</address>" + "</endpoint>" + "</loadbalance>" + "</endpoint>" + "</call>";
    OMElement config1 = createOMElement(callConfig);
    CallMediator call1 = (CallMediator) factory.createMediator(config1, new Properties());
    OMElement config2 = serializer.serializeMediator(null, call1);
    CallMediator call2 = (CallMediator) factory.createMediator(config2, new Properties());
    assertTrue("Top level endpoint should be a load balance endpoint.", call2.getEndpoint() instanceof LoadbalanceEndpoint);
    LoadbalanceEndpoint endpoint = (LoadbalanceEndpoint) call2.getEndpoint();
    List addresses = endpoint.getChildren();
    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/services/Service1".equals(addressEndpoint.getDefinition().getAddress()));
}
Also used : LoadbalanceEndpoint(org.apache.synapse.endpoints.LoadbalanceEndpoint) AddressEndpoint(org.apache.synapse.endpoints.AddressEndpoint) OMElement(org.apache.axiom.om.OMElement) List(java.util.List) CallMediator(org.apache.synapse.mediators.builtin.CallMediator) Properties(java.util.Properties)

Example 20 with AddressEndpoint

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

the class AddressEndpointFactory method createEndpoint.

@Override
protected Endpoint createEndpoint(OMElement epConfig, boolean anonymousEndpoint, Properties properties) {
    AddressEndpoint addressEndpoint = new AddressEndpoint();
    OMAttribute name = epConfig.getAttribute(new QName(XMLConfigConstants.NULL_NAMESPACE, "name"));
    if (name != null) {
        addressEndpoint.setName(name.getAttributeValue());
    }
    OMElement addressElement = epConfig.getFirstChildWithName(new QName(SynapseConstants.SYNAPSE_NAMESPACE, "address"));
    if (addressElement != null) {
        EndpointDefinition definition = createEndpointDefinition(addressElement);
        addressEndpoint.setDefinition(definition);
        processAuditStatus(definition, addressEndpoint.getName(), addressElement);
    }
    processProperties(addressEndpoint, epConfig);
    return addressEndpoint;
}
Also used : AddressEndpoint(org.apache.synapse.endpoints.AddressEndpoint) QName(javax.xml.namespace.QName) EndpointDefinition(org.apache.synapse.endpoints.EndpointDefinition) OMElement(org.apache.axiom.om.OMElement) OMAttribute(org.apache.axiom.om.OMAttribute)

Aggregations

AddressEndpoint (org.apache.synapse.endpoints.AddressEndpoint)34 OMElement (org.apache.axiom.om.OMElement)17 Endpoint (org.apache.synapse.endpoints.Endpoint)12 AxisConfiguration (org.apache.axis2.engine.AxisConfiguration)10 MessageContext (org.apache.synapse.MessageContext)10 SynapseConfiguration (org.apache.synapse.config.SynapseConfiguration)10 EndpointDefinition (org.apache.synapse.endpoints.EndpointDefinition)10 Properties (java.util.Properties)8 ArrayList (java.util.ArrayList)7 SynapseEnvironment (org.apache.synapse.core.SynapseEnvironment)7 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)7 Test (org.junit.Test)7 List (java.util.List)6 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)6 Axis2SynapseEnvironment (org.apache.synapse.core.axis2.Axis2SynapseEnvironment)6 LoadbalanceEndpoint (org.apache.synapse.endpoints.LoadbalanceEndpoint)6 SynapseException (org.apache.synapse.SynapseException)5 FailoverEndpoint (org.apache.synapse.endpoints.FailoverEndpoint)4 CallMediator (org.apache.synapse.mediators.builtin.CallMediator)4 SendMediator (org.apache.synapse.mediators.builtin.SendMediator)4