use of org.apache.axis2.context.MessageContext in project wso2-synapse by wso2.
the class AbstractEndpoint method prepareForEndpointStatistics.
/**
* Process statistics for this message
* @param synCtx the current message
*/
protected void prepareForEndpointStatistics(MessageContext synCtx) {
// Setting Required property to reportForComponent the End Point aspects
if (definition != null && definition.isStatisticsEnable()) {
String opName = null;
if (synCtx.getProperty(SynapseConstants.ENDPOINT_OPERATION) != null) {
opName = synCtx.getProperty(SynapseConstants.ENDPOINT_OPERATION).toString();
} else if (synCtx instanceof Axis2MessageContext) {
AxisOperation operation = ((Axis2MessageContext) synCtx).getAxis2MessageContext().getAxisOperation();
if (operation != null) {
opName = operation.getName().getLocalPart();
}
if (opName == null || SynapseConstants.SYNAPSE_OPERATION_NAME.getLocalPart().equals(opName)) {
String soapAction = synCtx.getSoapAction();
opName = null;
if (soapAction != null) {
int index = soapAction.indexOf("urn:");
if (index >= 0) {
opName = soapAction.substring("urn:".length());
} else {
opName = soapAction;
}
}
}
}
AspectConfiguration oldConfiguration = definition.getAspectConfiguration();
if (opName != null) {
AspectConfiguration newConfiguration = new AspectConfiguration(oldConfiguration.getId() + SynapseConstants.STATISTICS_KEY_SEPARATOR + opName);
if (oldConfiguration.isStatisticsEnable()) {
newConfiguration.enableStatistics();
}
if (oldConfiguration.isTracingEnabled()) {
newConfiguration.enableTracing();
}
}
}
}
use of org.apache.axis2.context.MessageContext in project wso2-synapse by wso2.
the class SALSessions method updateSession.
/**
* Update or establish a session
*
* @param synCtx
* Synapse MessageContext
* @param sessionID
* session id
*/
public void updateSession(MessageContext synCtx, SessionCookie cookie) {
if (cookie == null || "".equals(cookie.getSessionId())) {
if (log.isDebugEnabled()) {
log.debug("Cannot find Session ID from the cookie.");
}
return;
}
String sessionId = cookie.getSessionId();
String path = cookie.getPath();
boolean createSession = false;
if (log.isDebugEnabled()) {
log.debug("Starting to update the session for : " + cookie);
}
// if this is related to the already established session
SessionInformation oldSession = (SessionInformation) synCtx.getProperty(SynapseConstants.PROP_SAL_CURRENT_SESSION_INFORMATION);
List<Endpoint> endpoints = null;
Member currentMember = null;
if (oldSession == null) {
if (log.isDebugEnabled()) {
log.debug("Going to create a New session with corresponds to: " + cookie);
}
endpoints = (List<Endpoint>) synCtx.getProperty(SynapseConstants.PROP_SAL_ENDPOINT_ENDPOINT_LIST);
currentMember = (Member) synCtx.getProperty(SynapseConstants.PROP_SAL_ENDPOINT_CURRENT_MEMBER);
createSession = true;
} else {
String oldSessionID = oldSession.getId();
// This assumes that there can only be one path
if (!sessionId.equals(oldSessionID) && pathMatches(path, oldSession.getPath())) {
if (log.isDebugEnabled()) {
log.debug("Renew the session : previous session id :" + oldSessionID + " new session :" + cookie);
}
removeSession(oldSessionID);
endpoints = oldSession.getEndpointList();
currentMember = oldSession.getMember();
createSession = true;
} else {
SessionInformation information = getSessionInformation(oldSessionID);
if (information == null) {
// the message context
if (log.isDebugEnabled()) {
log.debug("Recovering lost session information for session id " + sessionId);
}
endpoints = oldSession.getEndpointList();
currentMember = oldSession.getMember();
createSession = true;
} else {
if (log.isDebugEnabled()) {
log.debug("Session with id : " + sessionId + " is still live.");
}
}
}
}
if (createSession) {
SessionInformation newInformation;
List<String> paths = new ArrayList<String>();
// add the new path
paths.add(path);
if (currentMember == null) {
newInformation = createSessionInformation(synCtx, sessionId, endpoints, paths);
} else {
newInformation = createSessionInformation(synCtx, sessionId, currentMember, paths);
}
if (log.isDebugEnabled()) {
log.debug("Establishing a session for :" + cookie + " and it's endpoint sequence : " + endpoints);
}
if (isClustered) {
Replicator.setAndReplicateState(SESSION_IDS + sessionId, newInformation, configCtx);
} else {
establishedSessions.put(sessionId, newInformation);
}
}
}
use of org.apache.axis2.context.MessageContext in project wso2-synapse by wso2.
the class URLRewriteMediatorTest method testUnconditionalRewriteScenario3.
public void testUnconditionalRewriteScenario3() throws Exception {
URLRewriteMediator mediator = new URLRewriteMediator();
mediator.setOutputProperty("outURL");
RewriteAction action1 = new RewriteAction();
action1.setValue(targetURL);
RewriteRule rule1 = new RewriteRule();
rule1.addRewriteAction(action1);
mediator.addRule(rule1);
RewriteAction action2 = new RewriteAction();
action2.setValue("/services/SimpleStockQuoteService");
action2.setFragmentIndex(URIFragments.PATH);
RewriteAction action3 = new RewriteAction();
action3.setXpath(new SynapseXPath("get-property('port')"));
action3.setFragmentIndex(URIFragments.PORT);
RewriteRule rule2 = new RewriteRule();
rule2.addRewriteAction(action2);
rule2.addRewriteAction(action3);
mediator.addRule(rule2);
MessageContext msgCtx = TestUtils.createLightweightSynapseMessageContext("<empty/>");
msgCtx.setTo(new EndpointReference("http://localhost:8280"));
msgCtx.setProperty("port", 9000);
mediator.mediate(msgCtx);
assertEquals(targetURL, msgCtx.getProperty("outURL"));
}
use of org.apache.axis2.context.MessageContext in project wso2-synapse by wso2.
the class URLRewriteMediatorTest method testConditionalRewriteScenario4.
public void testConditionalRewriteScenario4() throws Exception {
URLRewriteMediator mediator = new URLRewriteMediator();
mediator.setOutputProperty("outURL");
RewriteAction action1 = new RewriteAction();
action1.setRegex("MyService");
action1.setValue("SimpleStockQuoteService");
action1.setFragmentIndex(URIFragments.PATH);
action1.setActionType(RewriteAction.ACTION_REPLACE);
RewriteRule rule1 = new RewriteRule();
rule1.addRewriteAction(action1);
EqualEvaluator eval1 = new EqualEvaluator();
SOAPEnvelopeTextRetriever txtRtvr1 = new SOAPEnvelopeTextRetriever("//symbol");
eval1.setTextRetriever(txtRtvr1);
eval1.setValue("IBM");
rule1.setCondition(eval1);
mediator.addRule(rule1);
MessageContext msgCtx = TestUtils.createLightweightSynapseMessageContext("<getQuote><symbol>IBM</symbol></getQuote>");
msgCtx.setTo(new EndpointReference("http://localhost:9000/services/MyService"));
mediator.mediate(msgCtx);
assertEquals(targetURL, msgCtx.getProperty("outURL"));
}
use of org.apache.axis2.context.MessageContext in project wso2-synapse by wso2.
the class URLRewriteMediatorTest method testConditionalRewriteScenario1.
public void testConditionalRewriteScenario1() throws Exception {
URLRewriteMediator mediator = new URLRewriteMediator();
RewriteAction action = new RewriteAction();
action.setValue(targetURL);
RewriteRule rule = new RewriteRule();
EqualEvaluator eval = new EqualEvaluator();
URLTextRetriever txtRtvr = new URLTextRetriever();
txtRtvr.setSource(EvaluatorConstants.URI_FRAGMENTS.port.name());
eval.setTextRetriever(txtRtvr);
eval.setValue("8280");
rule.setCondition(eval);
rule.addRewriteAction(action);
mediator.addRule(rule);
MessageContext msgCtx = TestUtils.createLightweightSynapseMessageContext("<empty/>");
msgCtx.setTo(new EndpointReference("http://localhost:8280"));
mediator.mediate(msgCtx);
assertEquals(targetURL, msgCtx.getTo().getAddress());
}
Aggregations