use of org.apache.synapse.core.axis2.Axis2MessageContext 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());
}
use of org.apache.synapse.core.axis2.Axis2MessageContext 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);
}
use of org.apache.synapse.core.axis2.Axis2MessageContext in project wso2-synapse by wso2.
the class PropertyMediatorTest method testSpecialPropertiesHandling.
public void testSpecialPropertiesHandling() throws Exception {
MessageContext synCtx = TestUtils.createLightweightSynapseMessageContext("<empty/>");
PropertyMediator propMediatorEight = new PropertyMediator();
propMediatorEight.setName(HTTP.CONTENT_TYPE);
propMediatorEight.setValue("application/xml");
propMediatorEight.setScope(XMLConfigConstants.SCOPE_TRANSPORT);
PropertyMediator propMediatorNine = new PropertyMediator();
propMediatorNine.setName(org.apache.axis2.Constants.Configuration.MESSAGE_TYPE);
propMediatorNine.setValue("application/json");
propMediatorNine.setScope(XMLConfigConstants.SCOPE_AXIS2);
propMediatorEight.mediate(synCtx);
propMediatorNine.mediate(synCtx);
org.apache.axis2.context.MessageContext axisCtx = ((Axis2MessageContext) synCtx).getAxis2MessageContext();
Map transportHeaders = (Map) axisCtx.getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS);
assertNotNull(transportHeaders);
assertTrue("application/json".equals(transportHeaders.get(HTTP.CONTENT_TYPE)));
}
use of org.apache.synapse.core.axis2.Axis2MessageContext in project wso2-synapse by wso2.
the class AbstractSplitMediatorTestCase 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();
envelope.getBody().addChild(createOMElement("<original>test-split-context</original>"));
testCtx.setEnvelope(envelope);
testCtx.setSoapAction("urn:test");
SequenceMediator seqMed = new SequenceMediator();
helperMediator = new SplitTestHelperMediator();
helperMediator.init(testCtx.getEnvironment());
seqMed.addChild(helperMediator);
testCtx.getConfiguration().addSequence("seqRef", seqMed);
testCtx.getConfiguration().addSequence("main", new SequenceMediator());
testCtx.getConfiguration().addSequence("fault", new SequenceMediator());
}
use of org.apache.synapse.core.axis2.Axis2MessageContext in project wso2-synapse by wso2.
the class HttpEndpointTest 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;
}
Aggregations