Search in sources :

Example 6 with CallMediator

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);
}
Also used : EventPublisherMediator(org.apache.synapse.mediators.eventing.EventPublisherMediator) Mediator(org.apache.synapse.Mediator) CallMediator(org.apache.synapse.mediators.builtin.CallMediator) CallMediator(org.apache.synapse.mediators.builtin.CallMediator) Test(org.junit.Test)

Example 7 with CallMediator

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;
}
Also used : Endpoint(org.apache.synapse.endpoints.Endpoint) OMElement(org.apache.axiom.om.OMElement) CallMediator(org.apache.synapse.mediators.builtin.CallMediator)

Example 8 with CallMediator

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;
}
Also used : Target(org.apache.synapse.mediators.elementary.Target) Endpoint(org.apache.synapse.endpoints.Endpoint) OMElement(org.apache.axiom.om.OMElement) CallMediator(org.apache.synapse.mediators.builtin.CallMediator) OMAttribute(org.apache.axiom.om.OMAttribute) File(java.io.File) Source(org.apache.synapse.mediators.elementary.Source)

Example 9 with 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());
}
Also used : AddressEndpoint(org.apache.synapse.endpoints.AddressEndpoint) OMElement(org.apache.axiom.om.OMElement) CallMediator(org.apache.synapse.mediators.builtin.CallMediator) Properties(java.util.Properties)

Aggregations

CallMediator (org.apache.synapse.mediators.builtin.CallMediator)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 File (java.io.File)1 OMAttribute (org.apache.axiom.om.OMAttribute)1 Mediator (org.apache.synapse.Mediator)1 WSDLEndpoint (org.apache.synapse.endpoints.WSDLEndpoint)1 Source (org.apache.synapse.mediators.elementary.Source)1 Target (org.apache.synapse.mediators.elementary.Target)1 EventPublisherMediator (org.apache.synapse.mediators.eventing.EventPublisherMediator)1 Test (org.junit.Test)1