Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions src/main/java/org/logstash/beats/BeatsHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import org.apache.logging.log4j.Logger;

import java.net.InetSocketAddress;
import java.net.SocketAddress;

import javax.net.ssl.SSLHandshakeException;

public class BeatsHandler extends SimpleChannelInboundHandler<Batch> {
Expand Down Expand Up @@ -114,23 +116,21 @@ private void writeAck(ChannelHandlerContext ctx, byte protocol, int sequence) {
* we will use similar logic than Netty's LoggingHandler
*/
private String format(String message) {
InetSocketAddress local = (InetSocketAddress) context.channel().localAddress();
InetSocketAddress remote = (InetSocketAddress) context.channel().remoteAddress();

String localhost;
if(local != null) {
localhost = local.getAddress().getHostAddress() + ":" + local.getPort();
} else{
localhost = "undefined";
}
SocketAddress local = context.channel().localAddress();
SocketAddress remote = context.channel().remoteAddress();

String remotehost;
if(remote != null) {
remotehost = remote.getAddress().getHostAddress() + ":" + remote.getPort();
} else{
remotehost = "undefined";
}
String localhost = addressToString(local);
String remotehost = addressToString(remote);

return "[local: " + localhost + ", remote: " + remotehost + "] " + message;
}

private String addressToString(SocketAddress saddr) {
if (saddr instanceof InetSocketAddress) {
InetSocketAddress inetaddr = (InetSocketAddress) saddr;
return inetaddr.getAddress().getHostAddress() + ":" + inetaddr.getPort();
} else {
return "undefined";
}
}
}