Escolar Documentos
Profissional Documentos
Cultura Documentos
Alexandros Dallas
Chapter 5, Representations RESTful Entities, deals with the modeling of representations to actual Java classes and how the POJOs are automatically transformed to JSON representations by Jackson. Chapter 6, Using a Database, demonstrates the integration and usage of jDBI, how to create data access objects from interfaces, and using jDBI's SQL Object API in order to interact with the database. The additional configuration modifications needed are also presented in this chapter. Chapter 7, Validating Web Service Requests, presents the usage of Hibernate Validator in order to validate requests from a web service client prior to fulfilling them. Chapter 8, The Web Service Client, demonstrates how to create a managed Jersey HTTP client to be used by a Dropwizard application in order to interact with web services through WebResource objects. Chapter 9, Authentication, goes through the basics of web service authentication and guides you through the implementation of a basic HTTP authenticator and how to adapt it to the resource class as well as the HTTP client of your application. Chapter 10, The User Interface Views, shows the usage of the Dropwizard views bundle and the Mustache template engine in order to create an HTML interface for the web service client. Appendix A, Testing a Dropwizard Application, demonstrates the usage of Dropwizard's testing module for the creation of automated integration tests. This appendix also deals with the implementation of runtime tests for our application, which are known as health checks. You will be guided through the implementation of a health check that ensures that your HTTP client can indeed interact with a web service. Appendix B, Deploying a Dropwizard Application, explains the necessary steps you need to take in order to deploy a Dropwizard application to a web server by using a separate configuration file and securing the access to you application's admin port.
Getting Started with Dropwizard Our application is going to use a database in order to store data. For our database interaction needs, we'll use JDBI. JDBI is a library that will allow us to easily create DAO interfaces. Data Access Objects would allow us to perform database operations by mapping Java methods to SQL queries and statements. JDBI comes as a Dropwizard module, allowing us to build Data Access Objects easily and fast. Dropwizard includes validation, monitoring, and testing modules, which we'll use to ensure that our services will behave correctly in production environments. We are going to integrate Dropwizard's validation mechanisms, ensuring that each and every request to our web services is valid, before trying to serve it.
Getting ready
Maven is a build manager for Java projects. We will use it to create and build our project. Our application's dependencies (on Dropwizard's modules) will be managed by Maven; we just need to add the appropriate entries in our project conguration le. We need a database, so we will use MySQL for the needs of this book. MySQL is the most popular open source relational database management systema common choice for web applications. Throughout the installation process, you will be prompted to create or congure the values of environment variables. This procedure varies from one operating system to another, and is something out of the scope of this book.
How to do it
We will take a look at all the components that you will need to download and install.
Chapter 1
4. Following the successful installation, set the JAVA_HOME environment variable with its value set to the path where you installed Java. In Windows, this may be something like C:\Program Files\Java\jdk1.7.0_40\.
Getting Started with Dropwizard 3. At some point, you will be prompted to provide the MySQL Root Password. This is the password of the root user, which has full access rights. Enter a password of your choice, and proceed by clicking on the Next > button. The installation will be completed shortly.
4. Please choose a password that you will remember easily, as you will need to provide it at a later stage.
How it works
We just completed the installation of the software packages required to build Dropwizard applications. We will use Maven to create the structure of our application, which will use MySQL as a persistent store for its data. We are going to create a Maven project, and in its Project Object Model (POM) le, we will include the references (dependencies) to the Dropwizard components our application will use. Maven will automatically download and make them available for use throughout our project.
10
Alternatively, you can buy the book from Amazon, BN.com, Computer Manuals and most internet book retailers.
www.PacktPub.com