protected Object getRemoteRef(ImmutableEndpoint endpoint)
throws IOException, NotBoundException, NamingException, InitialisationException
{
EndpointURI endpointUri = endpoint.getEndpointURI();
String serviceName = endpointUri.getPath();
try
{
// Test if we can find the object locally
return getJndiContext().lookup(serviceName);
}
catch (NamingException e)
{
// Strip path seperator
}
try
{
serviceName = serviceName.substring(1);
return getJndiContext().lookup(serviceName);
}
catch (NamingException e)
{
// Try with full host and path
}
int port = endpointUri.getPort();
if (port < 1)
{
if (logger.isWarnEnabled())
{
logger.warn("RMI port not set on URI: " + endpointUri + ". Using default port: "
+ RmiConnector.DEFAULT_RMI_muleRegistry_PORT);
}
port = RmiConnector.DEFAULT_RMI_muleRegistry_PORT;
}
InetAddress inetAddress = InetAddress.getByName(endpointUri.getHost());
return getJndiContext(inetAddress.getHostAddress() + ":" + port).lookup(serviceName);
}