Differences
This shows you the differences between two versions of the page.
dropwizard [2015/02/12 17:04] |
dropwizard [2021/04/05 11:23] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Dropwizard ====== | ||
+ | ===== HTTP ===== | ||
+ | The port settings of the Jetty server can also be done via the configuration file. | ||
+ | |||
+ | <code yaml> | ||
+ | server: | ||
+ | applicationConnectors: | ||
+ | - type: http | ||
+ | port: 18080 | ||
+ | |||
+ | adminConnectors: | ||
+ | - type: http | ||
+ | port: 18081 | ||
+ | |||
+ | </ | ||
+ | |||
+ | |||
+ | ===== Logging ===== | ||
+ | The logging of the server and services is also done via the configuration file. | ||
+ | |||
+ | <code yaml> | ||
+ | server: | ||
+ | requestLog: | ||
+ | timeZone: UTC | ||
+ | appenders: | ||
+ | - type: file | ||
+ | currentLogFilename: | ||
+ | threshold: ALL | ||
+ | archive: true | ||
+ | archivedLogFilenamePattern: | ||
+ | archivedFileCount: | ||
+ | |||
+ | |||
+ | logging: | ||
+ | level: INFO | ||
+ | |||
+ | appenders: | ||
+ | - type: console | ||
+ | threshold: WARN | ||
+ | target: stderr | ||
+ | |||
+ | - type: file | ||
+ | currentLogFilename: | ||
+ | archivedLogFilenamePattern: | ||
+ | archivedFileCount: | ||
+ | timeZone: UTC | ||
+ | </ | ||
+ | |||
+ | ===== Metrics ===== | ||
+ | The [[http:// | ||
+ | |||
+ | ==== Adding additional metrics ==== | ||
+ | To add additional metrics a '' | ||
+ | |||
+ | <code java> | ||
+ | @Override | ||
+ | public void initialize(Bootstrap< | ||
+ | metricRegistry = bootstrap.getMetricRegistry(); | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ===== Jetty ===== | ||
+ | |||
+ | ==== Adding additional HTML pages ==== | ||
+ | If you want to add additional HTML pages (like a welcome page) then you can do this in the '' | ||
+ | |||
+ | |||
+ | Found on Stackoverlow [[http:// | ||
+ | |||
+ | < | ||
+ | |||
+ | bootstrap.addBundle(new AssetsBundle("/ | ||
+ | |||
+ | Which basically says to serve anything under /app inside my JAR file under the URL pattern /, with index.html as the default file. This bundle will be named static, but you could pick whatever name you like. | ||
+ | |||
+ | Note that I'm using version 0.7.0-rc2 of Dropwizard, I'm not sure whether it works for earlier versions as well.</ | ||
+ | |||
+ | |||
+ | ===== Serialization ===== | ||
+ | [[http:// | ||
+ | |||
+ | '' | ||
+ | |||
+ | If a field should be ignored during the serialization process the annotation '' | ||
+ | |||
+ | |||
+ | ===== Swagger ===== | ||
+ | Swagger can be used to document the REST services registered the dropwizard instance. | ||
+ | |||
+ | ==== Add Maven Dependency ==== | ||
+ | <sxh xml> | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | ==== Register Swagger UI ==== | ||
+ | <sxh java; title = In Application class> | ||
+ | private final SwaggerDropwizard swaggerDropwizard = new SwaggerDropwizard(); | ||
+ | |||
+ | @Override | ||
+ | public void initialize(Bootstrap< | ||
+ | ... | ||
+ | swaggerDropwizard.onInitialize(bootstrap); | ||
+ | } | ||
+ | |||
+ | @Override | ||
+ | public void run(TestConfiguration configuration, | ||
+ | ... | ||
+ | swaggerDropwizard.onRun(configuration, | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ==== Annotate Resources ==== | ||
+ | Swagger only scans resources which have an @Api annotation on them. Resources need to be annotated to be listed by swagger. | ||
+ | |||
+ | ==== Annotate Methods ==== | ||
+ | At least one method must be annotated for the resource to be visible for swagger. | ||
+ | |||
+ | |||
+ | ==== Links ==== | ||
+ | * https:// | ||
+ | * https:// | ||
+ | |||
+ | |||
+ | {{tag> |