Search in sources :

Example 6 with SendMediator

use of org.apache.synapse.mediators.builtin.SendMediator in project wso2-synapse by wso2.

the class SynapseConfigurationBuilder method getDefaultConfiguration.

/**
 * Return the default Synapse Configuration
 * @return the default configuration to be used
 */
public static SynapseConfiguration getDefaultConfiguration() {
    // programatically create an empty configuration which just log and drop the messages
    SynapseConfiguration config = SynapseConfigUtils.newConfiguration();
    SequenceMediator mainMediator = new SequenceMediator();
    InMediator inMediator = new InMediator();
    inMediator.addChild(new LogMediator());
    mainMediator.addChild(inMediator);
    OutMediator outMediator = new OutMediator();
    outMediator.addChild(new SendMediator());
    mainMediator.addChild(outMediator);
    mainMediator.setName(SynapseConstants.MAIN_SEQUENCE_KEY);
    config.addSequence(SynapseConstants.MAIN_SEQUENCE_KEY, mainMediator);
    SequenceMediator faultMediator = new SequenceMediator();
    LogMediator fault = new LogMediator();
    fault.setLogLevel(LogMediator.FULL);
    faultMediator.addChild(fault);
    faultMediator.setName(SynapseConstants.FAULT_SEQUENCE_KEY);
    config.addSequence(SynapseConstants.FAULT_SEQUENCE_KEY, faultMediator);
    config.setDescription("The default configuration of the ESB, that is created " + "programatically at the startup");
    return config;
}
Also used : OutMediator(org.apache.synapse.mediators.filters.OutMediator) LogMediator(org.apache.synapse.mediators.builtin.LogMediator) InMediator(org.apache.synapse.mediators.filters.InMediator) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator) SendMediator(org.apache.synapse.mediators.builtin.SendMediator)

Example 7 with SendMediator

use of org.apache.synapse.mediators.builtin.SendMediator in project wso2-synapse by wso2.

the class SendMediatorFactory method createSpecificMediator.

public Mediator createSpecificMediator(OMElement elem, Properties properties) {
    SendMediator sm = new SendMediator();
    // after successfully creating the mediator
    // set its common attributes such as tracing etc
    processAuditStatus(sm, elem);
    OMElement epElement = elem.getFirstChildWithName(ENDPOINT_Q);
    if (epElement != null) {
        // create the endpoint and set it in the send mediator
        Endpoint endpoint = EndpointFactory.getEndpointFromElement(epElement, true, properties);
        if (endpoint != null) {
            sm.setEndpoint(endpoint);
        }
    }
    String receivingSequence = elem.getAttributeValue(RECEIVING_SEQUENCE);
    if (receivingSequence != null) {
        ValueFactory valueFactory = new ValueFactory();
        Value value = valueFactory.createValue(XMLConfigConstants.RECEIVE, elem);
        sm.setReceivingSequence(value);
    }
    String buildMessage = elem.getAttributeValue(BUILD_MESSAGE);
    if ("true".equals(buildMessage)) {
        sm.setBuildMessage(true);
    }
    return sm;
}
Also used : Endpoint(org.apache.synapse.endpoints.Endpoint) Value(org.apache.synapse.mediators.Value) OMElement(org.apache.axiom.om.OMElement) SendMediator(org.apache.synapse.mediators.builtin.SendMediator)

Example 8 with SendMediator

use of org.apache.synapse.mediators.builtin.SendMediator in project wso2-synapse by wso2.

the class SendMediatorSerializer method serializeSpecificMediator.

public OMElement serializeSpecificMediator(Mediator m) {
    if (!(m instanceof SendMediator)) {
        handleException("Unsupported mediator passed in for serialization : " + m.getType());
    }
    SendMediator mediator = (SendMediator) m;
    OMElement send = fac.createOMElement("send", synNS);
    saveTracingState(send, mediator);
    Endpoint activeEndpoint = mediator.getEndpoint();
    if (activeEndpoint != null) {
        send.addChild(EndpointSerializer.getElementFromEndpoint(activeEndpoint));
    }
    Value receive = mediator.getReceivingSequence();
    if (receive != null) {
        ValueSerializer serializer = new ValueSerializer();
        serializer.serializeValue(receive, XMLConfigConstants.RECEIVE, send);
    }
    if (mediator.isBuildMessage()) {
        send.addAttribute(fac.createOMAttribute("buildmessage", nullNS, "true"));
    }
    return send;
}
Also used : Endpoint(org.apache.synapse.endpoints.Endpoint) Value(org.apache.synapse.mediators.Value) OMElement(org.apache.axiom.om.OMElement) SendMediator(org.apache.synapse.mediators.builtin.SendMediator)

Example 9 with SendMediator

use of org.apache.synapse.mediators.builtin.SendMediator 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

SendMediator (org.apache.synapse.mediators.builtin.SendMediator)9 OMElement (org.apache.axiom.om.OMElement)8 Properties (java.util.Properties)6 AddressEndpoint (org.apache.synapse.endpoints.AddressEndpoint)4 List (java.util.List)3 Endpoint (org.apache.synapse.endpoints.Endpoint)2 FailoverEndpoint (org.apache.synapse.endpoints.FailoverEndpoint)2 LoadbalanceEndpoint (org.apache.synapse.endpoints.LoadbalanceEndpoint)2 Value (org.apache.synapse.mediators.Value)2 WSDLEndpoint (org.apache.synapse.endpoints.WSDLEndpoint)1 SequenceMediator (org.apache.synapse.mediators.base.SequenceMediator)1 LogMediator (org.apache.synapse.mediators.builtin.LogMediator)1 InMediator (org.apache.synapse.mediators.filters.InMediator)1 OutMediator (org.apache.synapse.mediators.filters.OutMediator)1