public void send(MessageContext synCtx) {
/* setCookieHeader(synCtx); */
Member currentMember = null;
SessionInformation sessionInformation = null;
String actualHost = null;
//Gathering required information for domain mapping
org.apache.axis2.context.MessageContext axis2MessageContext =
((Axis2MessageContext) synCtx).getAxis2MessageContext();
Map<String, String> transportHeaders = (Map<String, String>) axis2MessageContext.
getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS);
String targetHost = transportHeaders.get(HTTP.TARGET_HOST);
String port = "";
boolean containsPort = false;
if (targetHost.contains(":")) {
containsPort = true;
port = targetHost.substring(targetHost.indexOf(':') + 1, targetHost.length());
targetHost = targetHost.substring(0, targetHost.indexOf(':'));
}
//Gathering required information for domain mapping done
boolean isValidHost = tlbMembershipHandler.isAValidHostName(targetHost);
DomainMapping domainMapping = null;
if(!isValidHost){
//check if the host is valid, if not valid, execute following code to check whether it is a mapped domain
domainMapping = mappingCache.getMapping(targetHost);
if(domainMapping == null){
registryManager = new RegistryManager();
domainMapping = registryManager.getMapping(targetHost);
mappingCache.addValidMapping(targetHost, domainMapping);
}
if (domainMapping != null) {
actualHost = domainMapping.getActualHost();
if(containsPort){
transportHeaders.put(HTTP.TARGET_HOST, actualHost + ":" + port);
} else {
transportHeaders.put(HTTP.TARGET_HOST, actualHost);
}
((Axis2MessageContext) synCtx).getAxis2MessageContext().setProperty("TRANSPORT_HEADERS" , transportHeaders);
} else {
String msg = "Invalid host name : " + targetHost;
log.error(msg);
throw new SynapseException(msg);
}
}
if (isSessionAffinityBasedLB()) {
// first check if this session is associated with a session. if so, get the endpoint
// associated for that session.
sessionInformation =
(SessionInformation) synCtx.getProperty(
SynapseConstants.PROP_SAL_CURRENT_SESSION_INFORMATION);
currentMember = (Member) synCtx.getProperty(
SynapseConstants.PROP_SAL_ENDPOINT_CURRENT_MEMBER);
if (sessionInformation == null && currentMember == null) {
sessionInformation = dispatcher.getSession(synCtx);
if (sessionInformation != null) {
if (log.isDebugEnabled()) {
log.debug("Current session id : " + sessionInformation.getId());
}
currentMember = sessionInformation.getMember();
synCtx.setProperty(
SynapseConstants.PROP_SAL_ENDPOINT_CURRENT_MEMBER, currentMember);
// This is for reliably recovery any session information if while response is getting ,
// session information has been removed by cleaner.
// This will not be a cost as session information a not heavy data structure
synCtx.setProperty(
SynapseConstants.PROP_SAL_CURRENT_SESSION_INFORMATION, sessionInformation);
}
}
}
// Dispatch request the relevant member
// String targetHost = getTargetHost(synCtx);
ConfigurationContext configCtx =
((Axis2MessageContext) synCtx).getAxis2MessageContext().getConfigurationContext();
if (tlbMembershipHandler.getConfigurationContext() == null) {
tlbMembershipHandler.setConfigurationContext(configCtx);
}
if(tlbMembershipHandler.getClusteringAgent() == null) {
tlbMembershipHandler.setConfigurationContext(configCtx);
}
TenantDynamicLoadBalanceFaultHandlerImpl faultHandler = new TenantDynamicLoadBalanceFaultHandlerImpl();
log.debug("************* Actual Host: "+actualHost +" ****** Target Host: "+targetHost);
faultHandler.setHost(actualHost != null ? actualHost : targetHost);
if (sessionInformation != null && currentMember != null) {
//send message on current session
sessionInformation.updateExpiryTime();
sendToApplicationMember(synCtx, currentMember, faultHandler, false);
} else {
// prepare for a new session
int tenantId = getTenantId(synCtx);
//check if this is a valid host name registered in ELB