use of org.apache.synapse.mediators.builtin.CallMediator in project wso2-synapse by wso2.
the class EventPublisherMediatorSerializerTest method testCreateEventSource.
/**
* Passing unsupported mediator.
*/
@Test(expected = SynapseException.class)
public void testCreateEventSource() {
EventPublisherMediatorSerializer mediatorSerializer = new EventPublisherMediatorSerializer();
Mediator mediator = new CallMediator();
mediatorSerializer.serializeSpecificMediator(mediator);
}
use of org.apache.synapse.mediators.builtin.CallMediator in project wso2-synapse by wso2.
the class CallMediatorSerializer method serializeSpecificMediator.
public OMElement serializeSpecificMediator(Mediator m) {
if (!(m instanceof CallMediator)) {
handleException("Unsupported mediator passed in for serialization : " + m.getType());
}
CallMediator mediator = (CallMediator) m;
OMElement call = fac.createOMElement("call", synNS);
saveTracingState(call, mediator);
Endpoint activeEndpoint = mediator.getEndpoint();
if (activeEndpoint != null) {
call.addChild(EndpointSerializer.getElementFromEndpoint(activeEndpoint));
}
if (mediator.isBlocking()) {
call.addAttribute(fac.createOMAttribute("blocking", nullNS, "true"));
if (!mediator.getInitClientOptions()) {
call.addAttribute(fac.createOMAttribute("initAxis2ClientOptions", nullNS, "false"));
}
if (mediator.getClientRepository() != null) {
call.addAttribute(fac.createOMAttribute("repository", nullNS, mediator.getClientRepository()));
}
if (mediator.getAxis2xml() != null) {
call.addAttribute(fac.createOMAttribute("axis2xml", nullNS, mediator.getAxis2xml()));
}
}
if (mediator.isSourceAvailable()) {
OMElement sourceEle = serializeSource(mediator);
call.addChild(sourceEle);
}
if (mediator.isTargetAvailable()) {
OMElement targetEle = serializeTarget(mediator.getTargetForInboundPayload());
call.addChild(targetEle);
}
serializeComments(call, mediator.getCommentsList());
return call;
}
use of org.apache.synapse.mediators.builtin.CallMediator in project wso2-synapse by wso2.
the class CallMediatorFactory method createSpecificMediator.
public Mediator createSpecificMediator(OMElement elem, Properties properties) {
CallMediator callMediator = new CallMediator();
// after successfully creating the mediator
// set its common attributes such as tracing etc
processAuditStatus(callMediator, elem);
OMElement sourceEle = elem.getFirstChildWithName(SOURCE_Q);
if (sourceEle != null) {
Source source = new Source();
populateSource(callMediator, source, sourceEle);
callMediator.setSourceForOutboundPayload(source);
}
OMElement targetEle = elem.getFirstChildWithName(TARGET_Q);
if (targetEle != null) {
Target target = new Target();
populateTarget(callMediator, target, targetEle);
callMediator.setTargetForInboundPayload(target);
}
OMElement epElement = elem.getFirstChildWithName(ENDPOINT_Q);
if (epElement != null) {
// create the endpoint and set it in the call mediator
Endpoint endpoint = EndpointFactory.getEndpointFromElement(epElement, true, properties);
if (endpoint != null) {
callMediator.setEndpoint(endpoint);
}
}
OMAttribute blockingAtt = elem.getAttribute(BLOCKING_Q);
if (blockingAtt != null) {
callMediator.setBlocking(Boolean.parseBoolean(blockingAtt.getAttributeValue()));
if (callMediator.isBlocking()) {
OMAttribute initAxis2ClientOptions = elem.getAttribute(ATT_INIT_AXIS2_CLIENT_OPTIONS);
OMAttribute axis2xmlAttr = elem.getAttribute(ATT_AXIS2XML);
OMAttribute repoAttr = elem.getAttribute(ATT_REPOSITORY);
if (initAxis2ClientOptions != null) {
callMediator.setInitClientOptions(Boolean.parseBoolean(initAxis2ClientOptions.getAttributeValue()));
}
if (axis2xmlAttr != null && axis2xmlAttr.getAttributeValue() != null) {
File axis2xml = new File(axis2xmlAttr.getAttributeValue());
if (axis2xml.exists() && axis2xml.isFile()) {
callMediator.setAxis2xml(axis2xmlAttr.getAttributeValue());
} else {
handleException("Invalid axis2.xml path: " + axis2xmlAttr.getAttributeValue());
}
}
if (repoAttr != null && repoAttr.getAttributeValue() != null) {
File repo = new File(repoAttr.getAttributeValue());
if (repo.exists() && repo.isDirectory()) {
callMediator.setClientRepository(repoAttr.getAttributeValue());
} else {
handleException("Invalid repository path: " + repoAttr.getAttributeValue());
}
}
}
}
addAllCommentChildrenToList(elem, callMediator.getCommentsList());
return callMediator;
}
use of org.apache.synapse.mediators.builtin.CallMediator in project wso2-synapse by wso2.
the class CallMediatorSerializationTest method testAddressEndpointSerialization.
public void testAddressEndpointSerialization() {
String callConfig = "<call xmlns=\"http://ws.apache.org/ns/synapse\">" + "<endpoint>" + "<address uri='http://localhost:9000/services/MyService1'>" + "<enableAddressing/>" + "<timeout>" + "<duration>60</duration>" + "<responseAction>discard</responseAction>" + "</timeout>" + "</address>" + "</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 address endpoint.", call1.getEndpoint() instanceof AddressEndpoint);
AddressEndpoint ep1 = (AddressEndpoint) call1.getEndpoint();
assertTrue("Top level endpoint should be a address endpoint.", call2.getEndpoint() instanceof AddressEndpoint);
AddressEndpoint ep2 = (AddressEndpoint) call2.getEndpoint();
assertEquals("Address URI is not serialized properly", ep1.getDefinition().getAddress(), ep2.getDefinition().getAddress());
assertEquals("Addressing information is not serialized properly", ep1.getDefinition().isAddressingOn(), ep2.getDefinition().isAddressingOn());
}
Aggregations