support defining local address and port for a socket - e.g:

ssl://localhost:5666/localhost:60606
where the path (localhost:60606) - defines the local address and local port

For jira issue: AMQ-529

git-svn-id: https://svn.apache.org/repos/asf/incubator/activemq/trunk@375922 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Davies 2006-02-08 11:02:36 +00:00
parent f367df5b28
commit c195dd3052
1 changed files with 20 additions and 1 deletions

View File

@ -61,7 +61,26 @@ public class SocketStreamChannelFactory implements StreamChannelFactory {
*/
public StreamChannel openStreamChannel(URI location) throws IOException {
Socket socket=null;
socket = socketFactory.createSocket(location.getHost(), location.getPort());
String path=location.getPath();
// see if the path is a local URI location
if(path!=null&&path.length()>0){
if (path.indexOf('/')==0){
//strip leading slash
path = path.substring(1,path.length());
}
int localPortIndex=path.indexOf(':');
try{
int localPort = Integer.parseInt(path.substring((localPortIndex+1),path.length()));
InetAddress localAddress = InetAddress.getByName(path);
socket = socketFactory.createSocket(location.getHost(), location.getPort(),localAddress,localPort);
}catch(Exception e){
System.err.println("Could not define local address and port from path: " + path);
e.printStackTrace();
}
}
if (socket==null){
socket = socketFactory.createSocket(location.getHost(), location.getPort());
}
return createStreamChannel(socket);
}