Search in sources :

Example 56 with Axis2SynapseEnvironment

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

the class SALSessionsTest method testUpdateCookieWithOldSession.

/**
 * Test updating session with cookie and old session
 * @throws Exception
 */
@Test
public void testUpdateCookieWithOldSession() throws Exception {
    BasicConfigurator.configure();
    SynapseConfiguration synapseConfiguration = new SynapseConfiguration();
    AxisConfiguration axisConfiguration = synapseConfiguration.getAxisConfiguration();
    ConfigurationContext cfgCtx = new ConfigurationContext(axisConfiguration);
    SynapseEnvironment synapseEnvironment = new Axis2SynapseEnvironment(cfgCtx, synapseConfiguration);
    Axis2MessageContext axis2MessageContext = new Axis2MessageContext(new org.apache.axis2.context.MessageContext(), synapseConfiguration, synapseEnvironment);
    MessageContext messageContext = axis2MessageContext;
    Endpoint endpoint = new AddressEndpoint();
    List<Endpoint> endpoints = new ArrayList<>();
    endpoints.add(endpoint);
    SALSessions salSessions = SALSessions.getInstance();
    salSessions.initialize(false, cfgCtx);
    SessionInformation oldSessionInfo = new SessionInformation("oldTestSession", endpoints, 30000);
    List<String> path = new ArrayList<>();
    path.add("samplePath");
    oldSessionInfo.setPath(path);
    messageContext.setProperty(SynapseConstants.PROP_SAL_CURRENT_SESSION_INFORMATION, oldSessionInfo);
    SessionCookie sessionCookie = new SessionCookie();
    sessionCookie.setSessionId("testCookie2");
    sessionCookie.setPath("samplePath");
    salSessions.updateSession(messageContext, sessionCookie);
    SessionInformation sessionInformation = salSessions.getSession("testCookie2");
    Assert.assertEquals("Session not updated!", "testCookie2", sessionInformation.getId());
}
Also used : AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) SynapseEnvironment(org.apache.synapse.core.SynapseEnvironment) ArrayList(java.util.ArrayList) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration) Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) AddressEndpoint(org.apache.synapse.endpoints.AddressEndpoint) AddressEndpoint(org.apache.synapse.endpoints.AddressEndpoint) Endpoint(org.apache.synapse.endpoints.Endpoint) MessageContext(org.apache.synapse.MessageContext) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext) Test(org.junit.Test)

Example 57 with Axis2SynapseEnvironment

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

the class SALSessionsTest method testUpdateCookieWithOldSessionSameName.

/**
 * Test updating session with cookie and old session where the old session id is same as current session id
 * @throws Exception
 */
@Test
public void testUpdateCookieWithOldSessionSameName() throws Exception {
    BasicConfigurator.configure();
    SynapseConfiguration synapseConfiguration = new SynapseConfiguration();
    AxisConfiguration axisConfiguration = synapseConfiguration.getAxisConfiguration();
    ConfigurationContext cfgCtx = new ConfigurationContext(axisConfiguration);
    SynapseEnvironment synapseEnvironment = new Axis2SynapseEnvironment(cfgCtx, synapseConfiguration);
    Axis2MessageContext axis2MessageContext = new Axis2MessageContext(new org.apache.axis2.context.MessageContext(), synapseConfiguration, synapseEnvironment);
    MessageContext messageContext = axis2MessageContext;
    Endpoint endpoint = new AddressEndpoint();
    List<Endpoint> endpoints = new ArrayList<>();
    endpoints.add(endpoint);
    messageContext.setProperty(SynapseConstants.PROP_SAL_ENDPOINT_ENDPOINT_LIST, endpoints);
    SALSessions salSessions = SALSessions.getInstance();
    salSessions.initialize(false, cfgCtx);
    SessionInformation oldSessionInfo = new SessionInformation("testCookie3", endpoints, 30000);
    List<String> path = new ArrayList<>();
    path.add("samplePath");
    oldSessionInfo.setPath(path);
    messageContext.setProperty(SynapseConstants.PROP_SAL_CURRENT_SESSION_INFORMATION, oldSessionInfo);
    SessionCookie sessionCookie = new SessionCookie();
    sessionCookie.setSessionId("testCookie3");
    sessionCookie.setPath("samplePath");
    salSessions.updateSession(messageContext, sessionCookie);
    SessionInformation sessionInformation = salSessions.getSession("testCookie3");
    Assert.assertEquals("Session not updated!", "testCookie3", sessionInformation.getId());
}
Also used : AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) SynapseEnvironment(org.apache.synapse.core.SynapseEnvironment) ArrayList(java.util.ArrayList) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration) Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) AddressEndpoint(org.apache.synapse.endpoints.AddressEndpoint) AddressEndpoint(org.apache.synapse.endpoints.AddressEndpoint) Endpoint(org.apache.synapse.endpoints.Endpoint) MessageContext(org.apache.synapse.MessageContext) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext) Test(org.junit.Test)

Example 58 with Axis2SynapseEnvironment

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

the class SALSessionsTest method testUpdateWithCookie.

/**
 * Test updating session with cookie
 * @throws Exception
 */
@Test
public void testUpdateWithCookie() throws Exception {
    BasicConfigurator.configure();
    SynapseConfiguration synapseConfiguration = new SynapseConfiguration();
    AxisConfiguration axisConfiguration = synapseConfiguration.getAxisConfiguration();
    ConfigurationContext cfgCtx = new ConfigurationContext(axisConfiguration);
    SynapseEnvironment synapseEnvironment = new Axis2SynapseEnvironment(cfgCtx, synapseConfiguration);
    Axis2MessageContext axis2MessageContext = new Axis2MessageContext(new org.apache.axis2.context.MessageContext(), synapseConfiguration, synapseEnvironment);
    MessageContext messageContext = axis2MessageContext;
    Endpoint endpoint = new AddressEndpoint();
    List<Endpoint> endpoints = new ArrayList<>();
    endpoints.add(endpoint);
    messageContext.setProperty(SynapseConstants.PROP_SAL_ENDPOINT_ENDPOINT_LIST, endpoints);
    SALSessions salSessions = SALSessions.getInstance();
    salSessions.initialize(false, cfgCtx);
    SessionCookie sessionCookie = new SessionCookie();
    sessionCookie.setSessionId("testCookie");
    salSessions.updateSession(messageContext, sessionCookie);
    SessionInformation sessionInformation = salSessions.getSession("testCookie");
    Assert.assertEquals("Session not updated!", "testCookie", sessionInformation.getId());
}
Also used : AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) SynapseEnvironment(org.apache.synapse.core.SynapseEnvironment) ArrayList(java.util.ArrayList) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration) Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) AddressEndpoint(org.apache.synapse.endpoints.AddressEndpoint) AddressEndpoint(org.apache.synapse.endpoints.AddressEndpoint) Endpoint(org.apache.synapse.endpoints.Endpoint) MessageContext(org.apache.synapse.MessageContext) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext) Test(org.junit.Test)

Example 59 with Axis2SynapseEnvironment

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

the class SynapseEventSourceTest method createMessageContext.

private MessageContext createMessageContext(String payload, String action) {
    try {
        SynapseConfiguration synapseConfig = new SynapseConfiguration();
        AxisConfiguration axisConfig = new AxisConfiguration();
        synapseConfig.setAxisConfiguration(axisConfig);
        ConfigurationContext cfgCtx = new ConfigurationContext(axisConfig);
        SynapseEnvironment env = new Axis2SynapseEnvironment(cfgCtx, synapseConfig);
        axisConfig.addParameter(SynapseConstants.SYNAPSE_CONFIG, synapseConfig);
        axisConfig.addParameter(SynapseConstants.SYNAPSE_ENV, env);
        MessageContext msgCtx = TestUtils.getAxis2MessageContext(payload, null).getAxis2MessageContext();
        msgCtx.setConfigurationContext(cfgCtx);
        msgCtx.setTo(new EndpointReference(SUB_MAN_URL));
        msgCtx.setWSAAction(action);
        return msgCtx;
    } catch (Exception e) {
        fail();
    }
    return null;
}
Also used : AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) SynapseEnvironment(org.apache.synapse.core.SynapseEnvironment) MessageContext(org.apache.axis2.context.MessageContext) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration) EventException(org.wso2.eventing.exceptions.EventException) EndpointReference(org.apache.axis2.addressing.EndpointReference)

Example 60 with Axis2SynapseEnvironment

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

the class ForEachMediatorTest method setUp.

protected void setUp() throws Exception {
    super.setUp();
    SynapseConfiguration synCfg = new SynapseConfiguration();
    AxisConfiguration config = new AxisConfiguration();
    testCtx = new Axis2MessageContext(new org.apache.axis2.context.MessageContext(), synCfg, new Axis2SynapseEnvironment(new ConfigurationContext(config), synCfg));
    ((Axis2MessageContext) testCtx).getAxis2MessageContext().setConfigurationContext(new ConfigurationContext(config));
    SOAPEnvelope envelope = OMAbstractFactory.getSOAP11Factory().getDefaultEnvelope();
    testCtx.setEnvelope(envelope);
    testCtx.setSoapAction("urn:test");
    SequenceMediator seqMed = new SequenceMediator();
    helperMediator = new ForEachHelperMediator();
    helperMediator.init(testCtx.getEnvironment());
    seqMed.addChild(helperMediator);
    SequenceMediator seqMedInvalid = new SequenceMediator();
    SendMediator sendMediator = new SendMediator();
    sendMediator.init(testCtx.getEnvironment());
    seqMedInvalid.addChild(sendMediator);
    testCtx.getConfiguration().addSequence("seqRef", seqMed);
    testCtx.getConfiguration().addSequence("seqRefInvalid", seqMedInvalid);
    testCtx.getConfiguration().addSequence("main", new SequenceMediator());
    testCtx.getConfiguration().addSequence("fault", new SequenceMediator());
    testCtx.setEnvelope(envelope);
}
Also used : AxisConfiguration(org.apache.axis2.engine.AxisConfiguration) Axis2SynapseEnvironment(org.apache.synapse.core.axis2.Axis2SynapseEnvironment) ConfigurationContext(org.apache.axis2.context.ConfigurationContext) MessageContext(org.apache.synapse.MessageContext) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext) SOAPEnvelope(org.apache.axiom.soap.SOAPEnvelope) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration) Axis2MessageContext(org.apache.synapse.core.axis2.Axis2MessageContext)

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