[jboss-jira] [JBoss JIRA] (WFLY-1325) Install custom default socket factories to avoid bind restrictions
David Lloyd (JIRA)
jira-events at lists.jboss.org
Thu May 9 11:35:53 EDT 2013
David Lloyd created WFLY-1325:
---------------------------------
Summary: Install custom default socket factories to avoid bind restrictions
Key: WFLY-1325
URL: https://issues.jboss.org/browse/WFLY-1325
Project: WildFly
Issue Type: Enhancement
Reporter: David Lloyd
Priority: Minor
It would be nice if we could install a custom default socket factory to work around restrictions imposed by OpenShift and other cloud providers, regarding binding to an interface before establishing an outbound connection.
What happens is, if you use a SocketFactory to create a socket and you call the bind variant *even if you pass null* it will try to bind the socket before connecting out, and the address it passes to the bind call is restricted.
So the workaround is to install a socket factory like this one:
{code}
static final class OpenShiftSocketFactory extends SocketFactory {
private final SocketFactory original;
OpenShiftSocketFactory(final SocketFactory original) {
this.original = original;
}
public Socket createSocket(final String host, final int port) throws IOException {
return original.createSocket(host, port);
}
public Socket createSocket(final String host, final int port, final InetAddress localHost, final int localPort) throws IOException {
if (localPort == 0) {
return original.createSocket(host, port);
} else {
return original.createSocket(host, port, localHost, localPort);
}
}
public Socket createSocket(final InetAddress host, final int port) throws IOException {
return original.createSocket(host, port);
}
public Socket createSocket(final InetAddress host, final int port, final InetAddress localHost, final int localPort) throws IOException {
if (localPort == 0) {
return original.createSocket(host, port);
} else {
return original.createSocket(host, port, localHost, localPort);
}
}
}
{code}
...with probably more checking to ensure that localHost is 0.0.0.0 or ::0 or whatever.
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the jboss-jira
mailing list