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;
}
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;
}
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;
}
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);
}
Aggregations