Search in sources :

Example 31 with Axis2SynapseEnvironment

use of org.apache.synapse.core.axis2.Axis2SynapseEnvironment in project wso2-synapse by wso2.

the class DynamicLoadBalanceEndpointTest method createMessageContext.

/**
 * Create a empty message context
 *
 * @return A context with empty message
 * @throws AxisFault on an error creating a context
 */
private MessageContext createMessageContext() throws AxisFault {
    Axis2SynapseEnvironment synapseEnvironment = new Axis2SynapseEnvironment(new SynapseConfiguration());
    org.apache.axis2.context.MessageContext axis2MC = new org.apache.axis2.context.MessageContext();
    axis2MC.setConfigurationContext(new ConfigurationContext(new AxisConfiguration()));
    ServiceContext svcCtx = new ServiceContext();
    OperationContext opCtx = new OperationContext(new InOutAxisOperation(), svcCtx);
    axis2MC.setServiceContext(svcCtx);
    axis2MC.setOperationContext(opCtx);
    axis2MC.setTransportIn(new TransportInDescription("http"));
    axis2MC.setTo(new EndpointReference("http://localhost:9000/services/SimpleStockQuoteService"));
    MessageContext mc = new Axis2MessageContext(axis2MC, new SynapseConfiguration(), synapseEnvironment);
    mc.setMessageID(UIDGenerator.generateURNString());
    mc.setEnvelope(OMAbstractFactory.getSOAP12Factory().createSOAPEnvelope());
    mc.getEnvelope().addChild(OMAbstractFactory.getSOAP12Factory().createSOAPBody());
    return mc;
}
Also used : OperationContext(org.apache.axis2.context.OperationContext) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) ServiceContext(org.apache.axis2.context.ServiceContext) TransportInDescription(org.apache.axis2.description.TransportInDescription) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration) EndpointReference(org.apache.axis2.addressing.EndpointReference) Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) MessageContext(org.apache.synapse.MessageContext) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext) InOutAxisOperation(org.apache.axis2.description.InOutAxisOperation) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext)

Example 32 with Axis2SynapseEnvironment

use of org.apache.synapse.core.axis2.Axis2SynapseEnvironment in project wso2-synapse by wso2.

the class DynamicLoadBalanceEndpointTest method getMockedSynapseEnvironment.

/**
 * Create a mock SynapseEnvironment object
 *
 * @return Axis2SynapseEnvironment instance
 * @throws AxisFault on creating/mocking object
 */
private Axis2SynapseEnvironment getMockedSynapseEnvironment() throws AxisFault {
    Axis2SynapseEnvironment synapseEnvironment = PowerMockito.mock(Axis2SynapseEnvironment.class);
    ConfigurationContext axis2ConfigurationContext = new ConfigurationContext(new AxisConfiguration());
    axis2ConfigurationContext.getAxisConfiguration().addParameter(SynapseConstants.SYNAPSE_ENV, synapseEnvironment);
    Mockito.when(synapseEnvironment.getAxis2ConfigurationContext()).thenReturn(axis2ConfigurationContext);
    return synapseEnvironment;
}
Also used : Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) AxisConfiguration(org.apache.axis2.engine.AxisConfiguration)

Example 33 with Axis2SynapseEnvironment

use of org.apache.synapse.core.axis2.Axis2SynapseEnvironment in project wso2-synapse by wso2.

the class EndpointViewTest method createEndPointView.

/**
 * Creates a basic EndpointView with a given number of children added to the endpoint.
 *
 * @param numberOfChildren the child endpoints inside the endpoint attached to the end point view. If
 *                         specified as 0, the children list will be null
 * @return the created end point view
 */
private EndpointView createEndPointView(int numberOfChildren) {
    AbstractEndpoint endpoint = new AddressEndpoint();
    MessageContext synCtx = new TestMessageContext();
    synCtx.setConfiguration(new SynapseConfiguration());
    SynapseEnvironment environment = new Axis2SynapseEnvironment(new ConfigurationContext(new AxisConfiguration()), synCtx.getConfiguration());
    if (numberOfChildren > 0) {
        List<Endpoint> children = new ArrayList<>(numberOfChildren);
        for (int i = 0; i < numberOfChildren; i++) {
            AbstractEndpoint child = new AddressEndpoint();
            child.init(environment);
            child.setEnableMBeanStats(true);
            child.setName("endpoint" + i);
            children.add(child);
        }
        endpoint.setChildren(children);
    }
    endpoint.init(environment);
    return new EndpointView("endpoint", endpoint);
}
Also used : ConfigurationContext(org.apache.axis2.context.ConfigurationContext) AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) SynapseEnvironment(org.apache.synapse.core.SynapseEnvironment) Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) ArrayList(java.util.ArrayList) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration) Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) TestMessageContext(org.apache.synapse.TestMessageContext) TestMessageContext(org.apache.synapse.TestMessageContext) MessageContext(org.apache.synapse.MessageContext)

Example 34 with Axis2SynapseEnvironment

use of org.apache.synapse.core.axis2.Axis2SynapseEnvironment in project wso2-synapse by wso2.

the class RecipientListEndpointTest method testRecipientListEndpointInit.

/**
 * Test on init of RecipientListEndpoint
 */
@Test
public void testRecipientListEndpointInit() throws Exception {
    Axis2SynapseEnvironment synapseEnvironment = getMockedSynapseEnvironment();
    RecipientListEndpoint recipientListEndpoint = new RecipientListEndpoint();
    recipientListEndpoint.init(synapseEnvironment);
}
Also used : Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) Test(org.junit.Test)

Example 35 with Axis2SynapseEnvironment

use of org.apache.synapse.core.axis2.Axis2SynapseEnvironment in project wso2-synapse by wso2.

the class RecipientListEndpointTest method testSendToEndpointList.

/**
 * Create a RecipientListEndpoint by config and test sending a message
 * @throws Exception on an issue sending out the message
 */
@Test
public void testSendToEndpointList() throws Exception {
    OMElement omBody = AXIOMUtil.stringToOM("<endpoint><recipientlist xmlns=\"http://ws.apache.org/ns/synapse\">\n" + "    <endpoint xmlns=\"http://ws.apache.org/ns/synapse\">\n" + "            <address uri=\"http://localhost:9000/services/SimpleStockQuoteService\"/>\n" + "    </endpoint>\n" + "    <endpoint xmlns=\"http://ws.apache.org/ns/synapse\">\n" + "            <address uri=\"http://localhost:9001/services/SimpleStockQuoteService\"/>\n" + "    </endpoint>\n" + "</recipientlist></endpoint>");
    RecipientListEndpoint recipientListEndpoint = (RecipientListEndpoint) EndpointFactory.getEndpointFromElement(omBody, true, null);
    Axis2SynapseEnvironment synapseEnvironment = getMockedSynapseEnvironment();
    Mockito.when(synapseEnvironment.createMessageContext()).thenReturn(createMessageContext());
    // test send message
    String samplePayload = "<test><a>WSO2</a></test>";
    Axis2MessageContext messageContext = getMessageContext(samplePayload);
    // message will be sent to EP using this env (which is mocked and do nothing)
    messageContext.setEnvironment(synapseEnvironment);
    recipientListEndpoint.init(synapseEnvironment);
    recipientListEndpoint.sendMessage(messageContext);
}
Also used : Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) OMElement(org.apache.axiom.om.OMElement) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext) Test(org.junit.Test)

Aggregations

Axis2SynapseEnvironment (org.apache.synapse.core.axis2.Axis2SynapseEnvironment)81 SynapseConfiguration (org.apache.synapse.config.SynapseConfiguration)64 ConfigurationContext (org.apache.axis2.context.ConfigurationContext)57 AxisConfiguration (org.apache.axis2.engine.AxisConfiguration)49 SynapseEnvironment (org.apache.synapse.core.SynapseEnvironment)43 Test (org.junit.Test)38 OMElement (org.apache.axiom.om.OMElement)30 Parameter (org.apache.axis2.description.Parameter)26 MessageContext (org.apache.synapse.MessageContext)23 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)21 Properties (java.util.Properties)14 TestMessageContext (org.apache.synapse.TestMessageContext)13 Mediator (org.apache.synapse.Mediator)12 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)10 ArrayList (java.util.ArrayList)8 AddressEndpoint (org.apache.synapse.endpoints.AddressEndpoint)7 Endpoint (org.apache.synapse.endpoints.Endpoint)7 HashMap (java.util.HashMap)5 OMDocument (org.apache.axiom.om.OMDocument)4 EndpointReference (org.apache.axis2.addressing.EndpointReference)4