Skip to content

Commit d12604b

Browse files
author
Simon MacMullen
committed
Make the SocketFrameHandler know about which hostname was provided in the first place, rather than doing a reverse DNS lookup and possibly breaking things.
1 parent 68b66d9 commit d12604b

File tree

7 files changed

+18
-14
lines changed

7 files changed

+18
-14
lines changed

src/com/rabbitmq/client/ConnectionFactory.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -360,13 +360,13 @@ protected FrameHandler createFrameHandler(Address addr)
360360
Socket socket = factory.createSocket();
361361
configureSocket(socket);
362362
socket.connect(new InetSocketAddress(hostName, portNumber), connectionTimeout);
363-
return createFrameHandler(socket);
363+
return createFrameHandler(socket, hostName);
364364
}
365365

366-
protected FrameHandler createFrameHandler(Socket sock)
366+
protected FrameHandler createFrameHandler(Socket sock, String host)
367367
throws IOException
368368
{
369-
return new SocketFrameHandler(sock);
369+
return new SocketFrameHandler(sock, host);
370370
}
371371

372372
/**

src/com/rabbitmq/client/impl/SocketFrameHandler.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
*/
3434

3535
public class SocketFrameHandler implements FrameHandler {
36+
/** Host we connect to */
37+
public final String _host;
38+
3639
/** The underlying socket */
3740
public final Socket _socket;
3841

@@ -48,15 +51,16 @@ public class SocketFrameHandler implements FrameHandler {
4851
/**
4952
* @param socket the socket to use
5053
*/
51-
public SocketFrameHandler(Socket socket) throws IOException {
54+
public SocketFrameHandler(Socket socket, String host) throws IOException {
5255
_socket = socket;
56+
_host = host;
5357

5458
_inputStream = new DataInputStream(new BufferedInputStream(_socket.getInputStream()));
5559
_outputStream = new DataOutputStream(new BufferedOutputStream(_socket.getOutputStream()));
5660
}
5761

5862
public String getHost() {
59-
return _socket.getInetAddress().getHostName();
63+
return _host;
6064
}
6165

6266
public int getPort() {

test/src/com/rabbitmq/client/test/CloseInMainLoop.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public boolean hadValidShutdown(){
3636
public SpecialConnection() throws Exception{
3737
super(
3838
new ConnectionFactory(),
39-
new SocketFrameHandler(SocketFactory.getDefault().createSocket("localhost", 5672)),
39+
new SocketFrameHandler(SocketFactory.getDefault().createSocket("localhost", 5672), "localhost"),
4040
new DefaultExceptionHandler(){
4141
@Override public void handleConsumerException(Channel channel,
4242
Throwable exception,

test/src/com/rabbitmq/client/test/functional/ConnectionOpen.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
public class ConnectionOpen extends TestCase {
3737
public void testCorrectProtocolHeader() throws IOException {
3838
ConnectionFactory factory = new ConnectionFactory();
39-
SocketFrameHandler fh = new SocketFrameHandler(factory.getSocketFactory().createSocket("localhost", AMQP.PROTOCOL.PORT));
39+
SocketFrameHandler fh = new SocketFrameHandler(factory.getSocketFactory().createSocket("localhost", AMQP.PROTOCOL.PORT), "localhost");
4040
fh.sendHeader();
4141
AMQCommand.Assembler a = AMQCommand.newAssembler();
4242
AMQCommand command = null;
@@ -56,7 +56,7 @@ public void testCorrectProtocolHeader() throws IOException {
5656

5757
public void testCrazyProtocolHeader() throws IOException {
5858
ConnectionFactory factory = new ConnectionFactory();
59-
SocketFrameHandler fh = new SocketFrameHandler(factory.getSocketFactory().createSocket("localhost", AMQP.PROTOCOL.PORT));
59+
SocketFrameHandler fh = new SocketFrameHandler(factory.getSocketFactory().createSocket("localhost", AMQP.PROTOCOL.PORT), "localhost");
6060
fh.sendHeader(100, 3); // major, minor
6161
DataInputStream in = fh._inputStream;
6262
// we should get a valid protocol header back

test/src/com/rabbitmq/client/test/functional/FrameMax.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ private static class MyFrameHandler extends SocketFrameHandler {
8383
public MyFrameHandler(Socket socket)
8484
throws IOException
8585
{
86-
super(socket);
86+
super(socket, "localhost");
8787
}
8888

8989
public Frame readFrame() throws IOException {

test/src/com/rabbitmq/client/test/functional/UnexpectedFrames.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ private static class ConfusedFrameHandler extends SocketFrameHandler {
3838

3939
private boolean confusedOnce = false;
4040

41-
public ConfusedFrameHandler(Socket socket) throws IOException {
42-
super(socket);
41+
public ConfusedFrameHandler(Socket socket, String host) throws IOException {
42+
super(socket, host);
4343
}
4444

4545
@Override
@@ -66,9 +66,9 @@ public Frame confuse(Frame frame) {
6666

6767
private static class ConfusedConnectionFactory extends ConnectionFactory {
6868

69-
@Override protected FrameHandler createFrameHandler(Socket sock)
69+
@Override protected FrameHandler createFrameHandler(Socket sock, String host)
7070
throws IOException {
71-
return new ConfusedFrameHandler(sock);
71+
return new ConfusedFrameHandler(sock, host);
7272
}
7373
}
7474

test/src/com/rabbitmq/examples/TestMain.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ protected FrameHandler createFrameHandler(Address addr)
8888
String hostName = addr.getHost();
8989
int portNumber = addr.getPort();
9090
if (portNumber == -1) portNumber = AMQP.PROTOCOL.PORT;
91-
return new SocketFrameHandler(getSocketFactory().createSocket(hostName, portNumber)) {
91+
return new SocketFrameHandler(getSocketFactory().createSocket(hostName, portNumber), hostName) {
9292
public void sendHeader() throws IOException {
9393
sendHeader(protocolMajor, protocolMinor);
9494
}

0 commit comments

Comments
 (0)