SlideShare ist ein Scribd-Unternehmen logo
Dropwizard
12.05.14 2
Übersicht
Was ist Dropwizard?
Getting started
Konfiguration
RESTful Services
Persistenz
Templating
Metriken, Healthchecks
OSIAM
12.05.14 3
Was ist Dropwizard?
Java-Framework für RESTful Web
Services
Stabile Standard-Bibliotheken
Jetty für HTTP
Jersey für REST
Jackson für JSON
Metrics für Metriken
Hibernate für Persistenz
Logging
Konfiguration
12.05.14 4
Was ist Dropwizard?
Micro-Services !!!11
Anwendung als einzelnes JAR paketierbar
Startet in wenigen Sekunden
12.05.14 5
Getting started
Neues Maven-Projekt
Dropwizard-Dependencies eintragen
Maven-Shade Plugin konfigurieren
Konfigurationsdatei anlegen oder Template verwenden
Service-Klasse anlegen
Bundles hinzufügen (AssetBundles, Hibernate)
Resourcen hinzufügen
HealthChecks hinzufügen
12.05.14 6
Konfiguration
Zentrale Konfigurationsdatei für ALLESTM
Jetty
SSL
Datenbank
Logging
Eigene Konfiguration
Einfaches Mapping über Konfigurations-Klasse
12.05.14 7
RESTful Services
Jersey
@Path("/books")
@Produces(MediaType.APPLICATION_JSON)
public class BookResource {
@GET
@Path("/list")
public List<Book> getAllBooks() {
List<Book> books = ...
return books;
}
}
12.05.14 8
Persistenz
Konfiguration
database:
driverClass: org.hsqldb.jdbc.JDBCDriver
user: sa
url: jdbc:hsqldb:db/example
properties:
hibernate.hbm2ddl.auto: update
Hibernate-Bundle
private final HibernateBundle<Config> hibernate =
new HibernateBundle<Config>(Book.class) {
public DatabaseConfiguration getDatabaseConfiguration(Config cfg){
return configuration.getDatabase();
}
};
12.05.14 9
Persistenz
DAO-Klasse
public class BookDAO extends AbstractDAO<Book> {
public BookDAO(SessionFactory sessionFactory) {
super(sessionFactory);
}
public Book getBook(int id) {
return get(id);
}
}
new BookResource(hibernate.getSessionFactory());
Wichtig: @UnitOfWork Annotation an der REST-Resourcen Methode für DB-
Session Handling und Transaktionen
12.05.14 10
Templating
Mit Moustache oder FreeMarker
View Klasse ableiten
Template anlegen
12.05.14 11
Templating
ABER:
Dropwizard spielt auch wunderbar mit AngularJS
zusammen
Templating im Browser
Responsive Single-Page Apps
12.05.14 12
Metriken und Healthchecks
Healhchecks, Metriken, etc auf eigenem Port abrufbar
@Timed an REST-Resourcen zum Sammeln von Performance-Daten
HealthChecks
public class Health extends HealthCheck {
public Health() {
super("Jedi-Health");
}
protected Result check() {
if(getMidichlorianLevel()) < 2500) {
return Result.unhealthy("Not a Jedi!");
}
return Result.healthy();
}
12.05.14 13
Metriken und Healthchecks
Eigene Metrik
Histogram responseStats =
Metrics.newHistogram(Ping.class,
"ping_response_time");
…
responseStats.update(responseTime);
12.05.14 14
OSIAM-Integration (WIP)
Dropwizard Authentication/Authorization Provider für
REST-Resourcen
OAuth
Prüft AccessToken und Gruppen-Mitgliedschaft
@GET
@Path("/all")
public String secured(@RestrictedTo({“admin“}) OsiamContext oc) {
User user = oc.getCurrentUser();
…
12.05.14 15
Was noch?
Keine Dependency-Injection an Bord
Spring oder Guice
WebSockets gehen auch
Testing
JSON Serialisierung über Fixtures
In-Memory Jetty-Server
Integrationstests
12.05.14 16
Mehr Informationen
Demo-Projekt
https://schulungs-
evolvis.tarent.de/projects/dropwizarddemo/
Dropwizard Home
https://dropwizard.github.io/dropwizard/
OSIAM (Dropwizard-Modul kommt bald)
https://github.com/osiam/
Vielen Dank!

Weitere ähnliche Inhalte

PPT
Sig Middleware Weblogicserver Cluster
PPT
Tomcat as a service
PPTX
TechNet Conference 2013 Berlin-Office365 Einsatzszenarien by Martina Grom
PDF
Data Center Automation for the Cloud
PPTX
Web APIs auf dem Prüfstand - Volle Kontrolle oder fertig mit den Azure Mobile...
PDF
Eventzentrierte Architekturen (JUG Münster)
PDF
CF Korea Meetup - Spring Cloud Services
PDF
Microservices with Netflix OSS and Spring Cloud - Dev Day Orange
Sig Middleware Weblogicserver Cluster
Tomcat as a service
TechNet Conference 2013 Berlin-Office365 Einsatzszenarien by Martina Grom
Data Center Automation for the Cloud
Web APIs auf dem Prüfstand - Volle Kontrolle oder fertig mit den Azure Mobile...
Eventzentrierte Architekturen (JUG Münster)
CF Korea Meetup - Spring Cloud Services
Microservices with Netflix OSS and Spring Cloud - Dev Day Orange
Anzeige

Dropwizard Tech-Talk