dropwizard-swagger
dropwizard-swagger copied to clipboard
Setting the hostname/port from dropwizard config file?
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.
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.
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());
}
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 As of dropwizard-swagger 0.7.0 this no longer works, as swagger now uses relative URLs
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