User Tools

Site Tools


dropwizard

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
dropwizard [2014/07/18 09:44]
mihael
dropwizard [2017/07/12 14:51] (current)
mihael [Links]
Line 1: Line 1:
 ====== Dropwizard ====== ====== 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
 +
 +</​code>​
 +
 +
 +===== 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:​ /​var/​log/​areacodes/​access.log
 +        threshold: ALL
 +        archive: true
 +        archivedLogFilenamePattern:​ /​var/​log/​areacodes/​access.%d.log.gz
 +        archivedFileCount:​ 14
 +
 +
 +logging:
 +  level: INFO
 +
 +  appenders:
 +    - type: console
 +      threshold: WARN
 +      target: stderr
 +
 +    - type: file
 +      currentLogFilename:​ /​var/​log/​areacodes/​broker.log
 +      archivedLogFilenamePattern:​ /​var/​log/​areacodes/​broker.%d.log.gz
 +      archivedFileCount:​ 14
 +      timeZone: UTC
 +</​code>​
  
 ===== Metrics ===== ===== Metrics =====
Line 7: Line 54:
 To add additional metrics a ''​MetricRegistry''​ is needed. It can be obtained during the bootstrap phase. To add additional metrics a ''​MetricRegistry''​ is needed. It can be obtained during the bootstrap phase.
  
-<sxh java>+<code java>
 @Override @Override
 public void initialize(Bootstrap<​PostalCodeConfiguration>​ bootstrap) { public void initialize(Bootstrap<​PostalCodeConfiguration>​ bootstrap) {
     metricRegistry = bootstrap.getMetricRegistry();​     metricRegistry = bootstrap.getMetricRegistry();​
 } }
-</sxh>+</code>
  
 ===== Jetty ===== ===== Jetty =====
Line 24: Line 71:
 <​blockquote>​I'​ve done this without changing my configuration. In fact, it only took me one line of code, to be put in the initialize method of my Application class: <​blockquote>​I'​ve done this without changing my configuration. In fact, it only took me one line of code, to be put in the initialize method of my Application class:
  
-bootstrap.addBundle(new AssetsBundle("/​app",​ "/",​ "​index.html",​ "​static"​));​+  ​bootstrap.addBundle(new AssetsBundle("/​app",​ "/",​ "​index.html",​ "​static"​));​ 
 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. 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.
  
Line 30: Line 78:
  
  
-{{tag>​devel java}}+===== Serialization ===== 
 +[[http://​wiki.fasterxml.com/​JacksonHome | Jackson]] is used for de-/​serialization of the data. 
 + 
 +''​@JsonProperty''​ is used to annotate field or method for serialization. 
 + 
 +If a field should be ignored during the serialization process the annotation ''​@JsonIgnore''​ can be used or the field can be marked as ''​transient''​. 
 + 
 + 
 +===== Swagger ===== 
 +Swagger can be used to document the REST services registered the dropwizard instance. 
 + 
 +==== Add Maven Dependency ==== 
 +<sxh xml> 
 +<​dependency>​ 
 +    <​groupId>​io.federecio</​groupId>​ 
 +    <​artifactId>​dropwizard-swagger</​artifactId>​ 
 +    <​version>​0.5.2</​version>​ 
 +</​dependency>​ 
 +</​sxh>​ 
 + 
 +==== Register Swagger UI ==== 
 +<sxh java; title = In Application class> 
 +private final SwaggerDropwizard swaggerDropwizard = new SwaggerDropwizard();​ 
 + 
 +@Override 
 +public void initialize(Bootstrap<​TestConfiguration>​ bootstrap) { 
 +    ... 
 +    swaggerDropwizard.onInitialize(bootstrap);​ 
 +
 + 
 +@Override 
 +public void run(TestConfiguration configuration,​ Environment environment) throws Exception { 
 +    ... 
 +    swaggerDropwizard.onRun(configuration,​ environment);​ 
 +
 +</​sxh>​ 
 + 
 +==== 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://​github.com/​federecio/​dropwizard-swagger 
 +  * https://​github.com/​swagger-api/​swagger-core/​wiki/​JavaDropwizard-Quickstart 
 + 
 + 
 +{{tag>​devel java dropwizard}}
dropwizard.1405676645.txt.gz · Last modified: 2014/07/18 09:44 by mihael