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
if(tlbMembershipHandler.isAValidHostName(targetHost)){
currentMember = tlbMembershipHandler.getNextApplicationMember(targetHost, tenantId);
if (currentMember == null) {
String msg = "No application members available";
log.error(msg);
throw new SynapseException(msg);
}
sendToApplicationMember(synCtx, currentMember, faultHandler, true);
} else {
if(domainMapping == null){
registryManager = new RegistryManager();
domainMapping = registryManager.getMapping(targetHost);
mappingCache.addValidMapping(targetHost, domainMapping);
}
if(domainMapping != null) {
actualHost = domainMapping.getActualHost();
log.debug("************* Actual Host: "+actualHost +" ****** Target Host: "+targetHost);
faultHandler.setHost(actualHost != null ? actualHost : targetHost);
if(containsPort){