String targetHost = extractTargetHost(synCtx);
if (!requestDelegator.isTargetHostValid(targetHost)) {
throwSynapseException(synCtx, 404, String.format("Unknown host name %s", targetHost));
}
Member member = null;
if (LoadBalancerConfiguration.getInstance().isMultiTenancyEnabled()) {
// Try to find next member from multi-tenant cluster map
if (log.isDebugEnabled()) {
log.debug("Multi-tenancy enabled, scanning URL for tenant...");
}
String url = extractUrl(synCtx);
int tenantId = scanUrlForTenantId(url);
if (tenantExists(tenantId)) {
member = requestDelegator.findNextMemberFromTenantId(targetHost, tenantId);
} else {
// Multi-tenant cluster not found, try single tenant
member = requestDelegator.findNextMemberFromHostName(targetHost);
}
} else {
// Find next member from single tenant cluster map
member = requestDelegator.findNextMemberFromHostName(targetHost);
}
if (member == null)
return null;
// Create Axi2 member object
String transport = extractTransport(synCtx);
Port transportPort = member.getPort(transport);
if (transportPort == null) {
if (log.isErrorEnabled()) {
log.error(String.format("Port not found for transport %s in member %s", transport, member.getMemberId()));
}
throwSynapseException(synCtx, 500, "Internal server error");
}
int memberPort = transportPort.getValue();
org.apache.axis2.clustering.Member axis2Member = new org.apache.axis2.clustering.Member(getMemberIp(synCtx, member), memberPort);
axis2Member.setDomain(member.getClusterId());
Port httpPort = member.getPort("http");
if (httpPort != null)
axis2Member.setHttpPort(httpPort.getValue());
Port httpsPort = member.getPort("https");
if (httpsPort != null)
axis2Member.setHttpsPort(httpsPort.getValue());
axis2Member.setActive(member.isActive());
// Set cluster id and partition id in message context
axis2Member.getProperties().setProperty(Constants.CLUSTER_ID, member.getClusterId());
return axis2Member;
}