use of org.apache.synapse.core.axis2.Axis2MessageContext in project wso2-synapse by wso2.
the class HttpSessionDispatcher method getSession.
/**
* Check if "Cookie" HTTP header is available. If so, check if that cookie is in the session
* map. If cookie is available, there is a session for this cookie. return the (server)
* endpoint for that session.
*
* @param synCtx MessageContext possibly containing a "Cookie" HTTP header.
* @return Endpoint Server endpoint for the given HTTP session.
*/
public SessionInformation getSession(MessageContext synCtx) {
String hostName = extractHost(synCtx);
if (log.isDebugEnabled()) {
log.debug("Extracted Host Name : " + hostName);
}
// print TO
org.apache.axis2.context.MessageContext axis2MessageContext = ((Axis2MessageContext) synCtx).getAxis2MessageContext();
if (log.isDebugEnabled()) {
log.debug("Endpoint Address : " + axis2MessageContext.getTo().getAddress());
}
Map headerMap = getTransportHeaderMap(synCtx);
String contentType = (String) headerMap.get("Content-Type");
if (log.isDebugEnabled()) {
log.debug("Content Type : " + contentType);
}
if (hostName == null) {
return SALSessions.getInstance().getSession(extractSessionID(synCtx, COOKIE));
} else {
List<String> sessionList = extractSessionIDs(synCtx, COOKIE);
if (sessionList != null) {
for (String sessionID : sessionList) {
SessionInformation sessionInfoObj = SALSessions.getInstance().getSession(sessionID);
if (sessionInfoObj != null && sessionInfoObj.getMember() != null) {
Map<String, String> subDomainNames = (Map<String, String>) sessionInfoObj.getMember().getProperties().get(HOSTS);
if (log.isDebugEnabled()) {
log.debug("Member Domain : " + (subDomainNames != null ? subDomainNames.get(hostName) : null) + " : Session ID " + sessionID);
}
if (subDomainNames != null && subDomainNames.get(hostName) != null) {
if (log.isDebugEnabled()) {
log.debug("Found a matching sessionInfo Object for the " + hostName);
}
return sessionInfoObj;
}
} else if (sessionInfoObj != null && sessionInfoObj.getMember() == null) {
// looks like a session attached to a failed member.Just return the session in this case
if (log.isDebugEnabled()) {
log.debug("sessionInfo object[" + sessionInfoObj.getId() + "] found with a null member. " + "Looks like this is attached to a failed member.");
}
return sessionInfoObj;
}
}
}
}
if (log.isDebugEnabled()) {
log.debug("Did not find a session info obj.");
}
return null;
}
use of org.apache.synapse.core.axis2.Axis2MessageContext in project wso2-synapse by wso2.
the class SynapseEventSource method receive.
/**
* Override the Message receiver method to accept subscriptions and events
*
* @param mc message context
* @throws AxisFault
*/
public void receive(MessageContext mc) throws AxisFault {
// Create synapse message context from the axis2 message context
SynapseConfiguration synCfg = (SynapseConfiguration) mc.getConfigurationContext().getAxisConfiguration().getParameter(SynapseConstants.SYNAPSE_CONFIG).getValue();
SynapseEnvironment synEnv = (SynapseEnvironment) mc.getConfigurationContext().getAxisConfiguration().getParameter(SynapseConstants.SYNAPSE_ENV).getValue();
org.apache.synapse.MessageContext smc = new Axis2MessageContext(mc, synCfg, synEnv);
// initialize the response message builder using the message context
ResponseMessageBuilder messageBuilder = new ResponseMessageBuilder(mc);
try {
if (EventingConstants.WSE_SUBSCRIBE.equals(mc.getWSAAction())) {
// add new subscription to the SynapseSubscription store through subscription manager
processSubscriptionRequest(mc, messageBuilder);
} else if (EventingConstants.WSE_UNSUBSCRIBE.equals(mc.getWSAAction())) {
// Unsubscribe the matching subscription
processUnSubscribeRequest(mc, messageBuilder);
} else if (EventingConstants.WSE_GET_STATUS.equals(mc.getWSAAction())) {
// Response with the status of the subscription
processGetStatusRequest(mc, messageBuilder);
} else if (EventingConstants.WSE_RENEW.equals(mc.getWSAAction())) {
// Renew subscription
processReNewRequest(mc, messageBuilder);
} else {
// Treat as an Event
if (log.isDebugEnabled()) {
log.debug("Event received");
}
dispatchEvents(smc);
}
} catch (EventException e) {
handleException("Subscription manager processing error", e);
}
}
use of org.apache.synapse.core.axis2.Axis2MessageContext in project wso2-synapse by wso2.
the class FailoverForwardingServiceTest method test.
/**
* Testing whether the failover forwarding service is successfully storing
* the message in the queue
*
* @throws Exception
*/
@Test
public void test() throws Exception {
JmsStore jmsStore = new JmsStore();
Map<String, Object> parameters = new HashMap<>();
parameters.put("java.naming.factory.initial", "org.apache.activemq.jndi.ActiveMQInitialContextFactory");
parameters.put("java.naming.provider.url", "tcp://127.0.0.1:61616");
jmsStore.setParameters(parameters);
jmsStore.setName("JMSStore");
MessageProcessor messageProcessor = new FailoverScheduledMessageForwardingProcessor();
Map<String, Object> parametersPro = new HashMap<>();
parametersPro.put("message.target.store.name", jmsStore.getName());
parametersPro.put("interval", "5000");
messageProcessor.setName("FailoverProcessor");
messageProcessor.setParameters(parametersPro);
messageProcessor.setMessageStoreName("JMSStore");
SynapseConfiguration synapseConfiguration = new SynapseConfiguration();
ConfigurationContext cfgCtx = new ConfigurationContext(synapseConfiguration.getAxisConfiguration());
SynapseEnvironment synapseEnvironment = new Axis2SynapseEnvironment(cfgCtx, synapseConfiguration);
synapseConfiguration.addMessageStore("JMSStore", jmsStore);
synapseConfiguration.addMessageProcessor("FailoverProcessor", messageProcessor);
jmsStore.init(synapseEnvironment);
FailoverForwardingService failoverForwardingService = new FailoverForwardingService(messageProcessor, synapseEnvironment, 5000, false);
failoverForwardingService.init(synapseEnvironment);
Axis2MessageContext axis2MessageContext = new Axis2MessageContext(new org.apache.axis2.context.MessageContext(), synapseConfiguration, synapseEnvironment);
MessageContext messageContext = axis2MessageContext;
SOAP11Factory factory = new SOAP11Factory();
SOAPEnvelope envelope = factory.getDefaultEnvelope();
OMElement element = AXIOMUtil.stringToOM("<name><value>Test</value></name>");
envelope.getBody().addChild(element);
messageContext.setEnvelope(envelope);
Assert.assertEquals("Queue is not empty!", 0, broker.getAdminView().getTotalMessageCount());
failoverForwardingService.dispatch(messageContext);
Assert.assertEquals("Message not forwarded!", 1, broker.getAdminView().getTotalMessageCount());
}
use of org.apache.synapse.core.axis2.Axis2MessageContext in project wso2-synapse by wso2.
the class JmsMessageStoreTest method testProducer.
/**
* Testing whether jms producer is storing the message to the store
* @throws Exception
*/
@Test
public void testProducer() throws Exception {
JmsStore jmsStore = new JmsStore();
Map<String, Object> parameters = new HashMap<>();
parameters.put("java.naming.factory.initial", "org.apache.activemq.jndi.ActiveMQInitialContextFactory");
parameters.put("java.naming.provider.url", "tcp://127.0.0.1:61616");
jmsStore.setParameters(parameters);
jmsStore.setName("TestJmsStore");
SynapseConfiguration synapseConfiguration = new SynapseConfiguration();
synapseConfiguration.addMessageStore("JMSStore", jmsStore);
SynapseEnvironment synapseEnvironment = new Axis2SynapseEnvironment(synapseConfiguration);
Axis2MessageContext axis2MessageContext = new Axis2MessageContext(new org.apache.axis2.context.MessageContext(), synapseConfiguration, synapseEnvironment);
MessageContext messageContext = axis2MessageContext;
SOAP11Factory factory = new SOAP11Factory();
SOAPEnvelope envelope = factory.createSOAPEnvelope();
messageContext.setEnvelope(envelope);
jmsStore.init(synapseEnvironment);
JmsProducer jmsProducer = (JmsProducer) jmsStore.getProducer();
boolean response = jmsProducer.storeMessage(messageContext);
Assert.assertTrue("Message not stored!", response);
}
use of org.apache.synapse.core.axis2.Axis2MessageContext in project wso2-synapse by wso2.
the class PropertyMediatorTest method testTypeAwarePropertyHandling.
public void testTypeAwarePropertyHandling() throws Exception {
PropertyMediator propMediatorOne = new PropertyMediator();
propMediatorOne.setName("nameOne");
propMediatorOne.setValue("valueOne", XMLConfigConstants.DATA_TYPES.STRING.name());
PropertyMediator propMediatorTwo = new PropertyMediator();
propMediatorTwo.setName("nameTwo");
propMediatorTwo.setValue("25000", XMLConfigConstants.DATA_TYPES.INTEGER.name());
propMediatorTwo.setScope(XMLConfigConstants.SCOPE_AXIS2);
PropertyMediator propMediatorThree = new PropertyMediator();
propMediatorThree.setName("nameThree");
propMediatorThree.setValue("123.456", XMLConfigConstants.DATA_TYPES.DOUBLE.name());
propMediatorThree.setScope(XMLConfigConstants.SCOPE_TRANSPORT);
PropertyMediator propMediatorFour = new PropertyMediator();
propMediatorFour.setName("nameFour");
propMediatorFour.setValue("true", XMLConfigConstants.DATA_TYPES.BOOLEAN.name());
PropertyMediator propMediatorFive = new PropertyMediator();
propMediatorFive.setName("nameFive");
propMediatorFive.setValue("123456", XMLConfigConstants.DATA_TYPES.LONG.name());
propMediatorFive.setScope(XMLConfigConstants.SCOPE_AXIS2);
PropertyMediator propMediatorSix = new PropertyMediator();
propMediatorSix.setName("nameSix");
propMediatorSix.setValue("12345", XMLConfigConstants.DATA_TYPES.SHORT.name());
propMediatorSix.setScope(XMLConfigConstants.SCOPE_TRANSPORT);
PropertyMediator propMediatorSeven = new PropertyMediator();
propMediatorSeven.setName("nameSeven");
propMediatorSeven.setValue("123.456", XMLConfigConstants.DATA_TYPES.FLOAT.name());
MessageContext synCtx = TestUtils.createLightweightSynapseMessageContext("<empty/>");
propMediatorOne.mediate(synCtx);
propMediatorTwo.mediate(synCtx);
propMediatorThree.mediate(synCtx);
propMediatorFour.mediate(synCtx);
propMediatorFive.mediate(synCtx);
propMediatorSix.mediate(synCtx);
propMediatorSeven.mediate(synCtx);
org.apache.axis2.context.MessageContext axisCtx = ((Axis2MessageContext) synCtx).getAxis2MessageContext();
Map transportHeaders = (Map) axisCtx.getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS);
Object valueOne = synCtx.getProperty("nameOne");
Object valueTwo = axisCtx.getProperty("nameTwo");
Object valueThree = transportHeaders.get("nameThree");
Object valueFour = synCtx.getProperty("nameFour");
Object valueFive = axisCtx.getProperty("nameFive");
Object valueSix = transportHeaders.get("nameSix");
Object valueSeven = synCtx.getProperty("nameSeven");
assertEquals("valueOne", valueOne);
assertEquals(new Integer(25000), valueTwo);
assertEquals(new Double(123.456), valueThree);
assertEquals(Boolean.TRUE, valueFour);
assertEquals(new Long(123456), valueFive);
assertEquals(new Short("12345"), valueSix);
assertEquals(new Float(123.456), valueSeven);
}
Aggregations