Search code examples
javawebspheredropwizardwebsphere-liberty

CodeSource on Liberty Profile 8.5.5.5


I'm trying to deploy a dropwizard (dw) application using wizard-in-a-box (wiab) on IBM Liberty Profile 8.5.5.5, but I'm encountering som issues with the io.dropwizard.util.JarLocation class. wiab will try to get the location of the Listener class wrapping the dw application but fails to do so since the CodeSource object in the class' ProtectionDomain is null.

klass.getProtectionDomain().getCodeSource().getLocation()

However, I've tried to deploy on Tomcat 8 and the latest Liberty Profile v9 beta, and they both work fine.

Both server.xml files on the Liberty servers look exaktly the same in terms of features.

<?xml version="1.0" encoding="UTF-8"?>
<server description="new server">
  <!-- Enable features -->
  <featureManager>
    <feature>servlet-3.1</feature>
    <feature>jsp-2.3</feature>
    <feature>el-3.0</feature>
    <feature>websocket-1.1</feature>
    <feature>localConnector-1.0</feature>
  </featureManager>
  <!-- To access this server from a remote client add a host attribute to the following element, e.g. host="*" -->
  <httpEndpoint id="defaultHttpEndpoint" httpPort="9080" httpsPort="9443" />
  <applicationMonitor updateTrigger="mbean" />
  <application id="moshpit_war_war_exploded" location="D:\code\moshpit\moshpit-war\target\moshpit" name="moshpit_war_war_exploded" type="war" context-root="/" />
</server>

I've tried deploying both the ordinary war and the exploded war from inside IntelliJ, as well as using the dropin folder with a pre-built war. The v9 beta version will play nice, but not 8.5.5.5.

This is the Listener class wrapping the dw app:

@WebListener
public class MoshpitWebApplication extends WebApplication<MoshpitConfiguration> {
    private static final Logger LOGGER = LoggerFactory.getLogger(MoshpitWebApplication.class);

    public MoshpitWebApplication() {
        super(new MoshpitApplication(), "/configuration/moshpit.yml");
    }
}

and this is my dw Application class

public class MoshpitApplication extends Application<MoshpitConfiguration> {

    public MoshpitApplication() {
    }

    public static void main(String[] args) throws Exception {
        new MoshpitApplication().run(args);
    }

    @Override
    public String getName() {
        return "moshpit";
    }

    @Override
    public void initialize(Bootstrap<MoshpitConfiguration> bootstrap) {
        bootstrap.setConfigurationSourceProvider(new FileConfigurationSourceProvider());
        // nothing to do yet
    }

    @Override
    public void run(MoshpitConfiguration configuration, Environment environment) throws Exception {
        final Template template = configuration.buildTemplate();
        environment.healthChecks().register("template", new TemplateHealthCheck(template));
        environment.jersey().register(new HelloWorldResource(template));
    }
}

Update:

This seems to be a general problem with Liberty 8.5.5.5. Tried deploying a completely different application and I observed the same behaviour. The CodeSource is null for application classes.


Solution

  • The Liberty profile doesn't currently set the CodeSource for application classes. As you note this is addressed in the current beta and will be addressed when 8.5.5.6 is released on June 26th.