dropwizard-swagger icon indicating copy to clipboard operation
dropwizard-swagger copied to clipboard

Setting the hostname/port from dropwizard config file?

Open MattMacGillivray opened this issue 9 years ago • 5 comments

I can see there are a few ways of setting the hostname/port, one involves hardcoding into java, the other relates to a hosted provider. Wondering if there is a way to just set it in the dropwizard config (yaml) file?

That would be so much easier!

Thanks!

Matt.

MattMacGillivray avatar Apr 19 '15 05:04 MattMacGillivray

To be more specific, my VM has the /var/lib/cloud directory, but won't resolve the "http://169.254.169.254/latest/meta-data/public-hostname/" url. Based on the code, it doesn't do any further checking and resolves to localhost.

Matt.

MattMacGillivray avatar Apr 19 '15 22:04 MattMacGillivray

I'm not sure if this is the preferred way, but this is how I've gotten it to work.

If you use the older way of initializing swagger-dropwizard (instead of using SwaggerBundle), you can specify the host/port. Simply put some fields in to your config.yml, reference them your Configuration class, and plop them into the SwaggerDropwizard.onRun() method:

config.yml

host: site.dev
# You can specify a port as well, just add the relevant field/getter/setter in MyConfiguration.java
# port: 8080

MyConfiguration.java

/**
 * the host of this server (ex: localhost, site.dev, example.com), minus the http://
 */
@NotEmpty
@JsonProperty("host")
private String host;

@JsonProperty
 public String getHost() {
    return host;
}

@JsonProperty
public void setHost(String host) {
    this.host = host;
}

MyApplication.java

private final SwaggerDropwizard<MyConfiguration> swaggerDropwizard = new SwaggerDropwizard<>();

public void initialize(Bootstrap<AppConfiguration> bootstrap) {
    swaggerDropwizard.onInitialize(bootstrap);
}

public void run(AppConfiguration configuration, Environment environment) throws Exception {
    swaggerDropwizard.onRun(configuration, environment, configuration.getHost());
}

MarkyC avatar Apr 21 '15 15:04 MarkyC

I have an instance on digital ocean and this fails as "http://169.254.169.254/latest/meta-data/public-hostname/" does not exist. How do i resolve this @qmnonic @MarkyC

sheldon-sminq avatar Jun 04 '15 07:06 sheldon-sminq

@sheldon-sminq As of dropwizard-swagger 0.7.0 this no longer works, as swagger now uses relative URLs

MarkyC avatar Jun 08 '15 19:06 MarkyC

So there is no way to get this working with dropwizard 0.8.1? @qmnonic @MarkyC . I got version 0.6 to work but 0.7 fails

sheldon-sminq avatar Jun 29 '15 18:06 sheldon-sminq