Rupert Anderson's Blog

Mainly SoapUI, API, Open Source stuff and Elite Dangerous!

Issue/Fix: SLF4J: Failed to load class “org.slf4j.impl.StaticLoggerBinder”

Introduction

This probably a minor issue for most, but the error message isn’t great and it inhibits (sometimes helpful) log messages in certain situations e.g. when running SoapUI from the shell, testrunner scripts and Maven.

Issue

You run SoapUI from the shell / terminal and you see something like:

tests-MacBook-Pro:app test$ ./bin/soapui.sh 
================================
=
= SOAPUI_HOME = /Applications/SoapUI-5.2.1.app/Contents/java/app
=
================================
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Configuring log4j from [/Applications/SoapUI-5.2.1.app/Contents/java/app/bin/soapui-log4j.xml]

Fix

The error just means that no suitable slf4j logger implementation can be found, as per http://www.slf4j.org/codes.html#StaticLoggerBinder – the slf4j-api-1.6.1.jar is there in <SoapUI Home>/app/java/lib already. If no suitable logger implementation is added, then the documentation explains that as of version 1.6, the nop logger implementation will be used – but this doesn’t log anything and you get the warning every time.

There are two main options here depending on how you install/use SoapUI. Taking either option should result in no error and potentially extra logging:


tests-MacBook-Pro:app test$ ./bin/soapui.sh
================================
=
= SOAPUI_HOME = /Applications/SoapUI-5.2.1.app/Contents/java/app
=
================================
Configuring log4j from [/Applications/SoapUI-5.2.1.app/Contents/java/app/bin/soapui-log4j.xml]

Option 1 – SoapUI Was Installed Using The Installer

  1. Pick an slf4j logger implementation from http://mvnrepository.com/artifact/org.slf4j  e.g. download slf4j-simple-1.6.1.jar
  2. Add it to <SoapUI Home>/java/app/lib
  3. Try to run SoapUI again and the error message should be gone and logging may be seen.

Option 2 – SoapUI Built & Run From Source Code (Using Maven)

When building and running SoapUI from source code using maven just add the dependency for the chosen logger implementation (see option 1 – step 1) to the pom.xml for the SoapUI project soapui-project/soapui/pom.xml – for example:

<!-- Logging -->
<dependency>
    <groupId>log4j</groupId>
    <artifactId>log4j</artifactId>
    <version>1.2.14</version>
</dependency>
<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-simple</artifactId>
    <version>1.6.1</version>
</dependency>
<dependency>
    <groupId>commons-logging</groupId>
    <artifactId>commons-logging</artifactId>
    <version>1.1.1</version>
</dependency>
<!-- In-app analytics -->

SoapUI Google Analytics NullPointerException On Ubuntu

Hi,

This is just a quick post to consolidate my findings when investigating why a Null Pointer Exception occurs in SoapUI when running on Ubuntu. The error occurs in the analytics code when it tries to obtain the machine’s MAC address. For now, I have hopefully found a quick work around explained below.

I tested this when running SoapUI 5.2.1 (built & run from source code) on a clean install of Ubuntu 14.04.4, Java 1.7u79 and running on VirtualBox.

Problem Description

When starting you may see:

ubuntu-nullpointer-on-startup

Aside from com.eviware.soapui.analytics.AnalyticsManager, a similar error can also be seen in com.eviware.soapui.analytics.providers.GoogleAnalyticsProvider.getMacAddressString when using different areas of functionality.

Looking at either of those classes where the NPE occurs we can see route cause is the same piece of code:


NetworkInterface network = NetworkInterface.getByInetAddress(InetAddress.getLocalHost());
byte mac[] = network.getHardwareAddress();
MessageDigest hasher = MessageDigest.getInstance("SHA-1");
return createHexBinary(hasher.digest(mac));

You can probably see that network is coming back as null.

Investigation

To understand why, and work around the problem, try running a snippet of the same code with logging added e.g. something like:


package com.company;

import java.net.InetAddress;
import java.net.NetworkInterface;
import java.security.MessageDigest;

public class Main {

   public static void main(String[] args) {

      try {
         NetworkInterface network = NetworkInterface.getByInetAddress(InetAddress.getLocalHost());
         System.out.println("Machine Name="+ InetAddress.getLocalHost());
         System.out.println("Network Interface="+network);
         byte mac[] = network.getHardwareAddress();
         System.out.println("Mac Address="+mac);
         MessageDigest hasher = MessageDigest.getInstance("SHA-1");
         System.out.println("Hashed Mac"+hasher.digest(mac));
      } 
      catch(Exception e){
         System.out.println("Error generating Analytics session ID - returning empty String"+ e);
      }
   }
}

Depending on how your hosts file / network settings are, you may see something like:


Machine Name=ubuntutest-VirtualBox/127.0.1.1
Network Interface=null
Error generating Analytics session ID - returning empty Stringjava.lang.NullPointerException

The Machine Name will vary on your machine, but the Network Interface can be seen as null and a NullPointerException is caught. The problem seems to be that NetworkInterface.getByInetAddress cannot match the Machine Name to any of the Network Interface values. Running ifconfg shows that there is indeed no match available:


ubuntutest@ubuntutest-VirtualBox:~$ ifconfig
eth0 Link encap:Ethernet HWaddr 07:07:27:79:d2:07
inet addr:10.0.2.30 Bcast:10.0.2.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fe79:d101/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:21 errors:0 dropped:0 overruns:0 frame:0
TX packets:73 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:3086 (3.0 KB) TX bytes:10810 (10.8 KB)

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:46 errors:0 dropped:0 overruns:0 frame:0
TX packets:46 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:3559 (3.5 KB) TX bytes:3559 (3.5 KB)

Work-Around

So without fixing the code, one quick solution is to change the /etc/hosts entry for your machine name to use the same IP address as eth0. So in my case, I did something like:


sudo nano /etc/hosts

And added:


10.0.2.30 &nbsp; &nbsp; &nbsp;ubuntutest-VirtualBox

Running the above snippet should then show the Network Interface correctly matched and the Mac Address found e.g.


Machine Name=ubuntutest-VirtualBox/10.0.2.30
Network Interface=name:eth0 (eth0)
Mac Address=[B@520b368f
Hashed Mac[B@4a5e88f7

Note – adding a host entry pointing to lo (127.0.0.1) solves the first problem of matching the Network Interface, but then fails when the code tries to obtain the MAC address with network.getHardwareAddress() – unlike eth0, the interface lo doesn’t have one!

Starting up SoapUI should now occur without the Analytics NPE.

Code Fix

Aside from having / changing your network settings to help the code work, it would probably be better to fix the code in SoapUI to iterate over the possible Network Interfaces until it finds one with a MAC address. I’ll maybe take more of a look at this later.

Comments

There are probably more or even better options for solving this problem, but I just wanted to get some options down in response to various SoapUI Community posts featuring this error for users running on Ubuntu. Hopefully this will help somewhat, please come in with any suggestions / corrections / comments!

Thanks,

Rup