SyslogUtils { public static String getIP(SocketAddress socketAddress) { try { InetSocketAddress inetSocketAddress = (InetSocketAddress) socketAddress; String ip = inetSocketAddress.getAddress().getHostAddress(); if (ip != null) { return ip; } else { throw new NullPointerException("The returned IP is null"); } } catch (Exception e) { logger.warn("Unable to retrieve client IP address", e); } return ""; } SyslogUtils();  SyslogUtils(boolean isUdp);  SyslogUtils(Integer defaultSize, Set<String> keepFields, boolean isUdp);  SyslogUtils(Integer eventSize, Set<String> keepFields, boolean isUdp, Clock clock); static boolean keepAllFields(Set<String> keepFields); static Set<String> chooseFieldsToKeep(String keepFields); static String addFieldsToBody(Set<String> keepFields,
                                       String body,
                                       String priority,
                                       String version,
                                       String timestamp,
                                       String hostname); static String getIP(SocketAddress socketAddress); static String getHostname(SocketAddress socketAddress); void addFormats(Map<String, String> formatProp); Event extractEvent(ChannelBuffer in); Integer getEventSize(); void setEventSize(Integer eventSize); void setKeepFields(Set<String> keepFields); static final String SYSLOG_TIMESTAMP_FORMAT_RFC5424_2; static final String SYSLOG_TIMESTAMP_FORMAT_RFC5424_1; static final String SYSLOG_TIMESTAMP_FORMAT_RFC5424_3; static final String SYSLOG_TIMESTAMP_FORMAT_RFC5424_4; static final String SYSLOG_TIMESTAMP_FORMAT_RFC3164_1; static final String SYSLOG_MSG_RFC5424_0; static final String SYSLOG_MSG_RFC3164_0; static final int SYSLOG_PRIORITY_POS; static final int SYSLOG_VERSION_POS; static final int SYSLOG_TIMESTAMP_POS; static final int SYSLOG_HOSTNAME_POS; static final int SYSLOG_BODY_POS; static final String SYSLOG_FACILITY; static final String SYSLOG_SEVERITY; static final String SYSLOG_PRIORITY; static final String SYSLOG_VERSION; static final String EVENT_STATUS; static final Integer MIN_SIZE; static final Integer DEFAULT_SIZE; static final String KEEP_FIELDS_ALL; }
@Test public void testGetIPWhenSuccessful() { SocketAddress socketAddress = new InetSocketAddress("localhost", 2000); String ip = SyslogUtils.getIP(socketAddress); assertEquals("127.0.0.1", ip); }
@Test public void testGetIPWhenInputIsNull() { SocketAddress socketAddress = null; String ip = SyslogUtils.getIP(socketAddress); assertEquals("", ip); }
@Test public void testGetIPWhenInputIsNotInetSocketAddress() { SocketAddress socketAddress = new SocketAddress() {}; String ip = SyslogUtils.getIP(socketAddress); assertEquals("", ip); }