Skip to content

Instantly share code, notes, and snippets.

View javaeeeee's full-sized avatar

Dmitry Noranovich javaeeeee

View GitHub Profile
@javaeeeee
javaeeeee / ConverterResource.java
Created December 4, 2015 06:58
A resource class to perform currency conversion
@Path("/converter")
public class ConverterResource {
/**
* The name of the path parameter for the API key.
*/
public static final String APP_ID = "app_id";
/**
* A part of an error message.
*/
@javaeeeee
javaeeeee / CurrencyData.java
Created December 4, 2015 06:56
A representation class to communicate to Open Exchange Rates API
public class CurrencyData {
/**
* A string with a disclaimer.
*/
private String disclaimer;
/**
* A string with a license.
*/
private String license;
@javaeeeee
javaeeeee / DWGettingStartedConfiguration.java
Last active December 4, 2015 07:38
Additions to Dropwizard Configuration file to configure Jersey client
public class DWGettingStartedConfiguration extends Configuration {
...
/**
* The URL to access exchange rate API.
*/
@NotEmpty
private String apiURL;
/**
* The key to access exchange rate API.
*/
@javaeeeee
javaeeeee / config.yml
Created December 4, 2015 06:50
Jersey client settings in a Dropwizard application
#API settings
#API URL
apiURL: https://openexchangerates.org/api/latest.json
#API key
apiKey: <Your API key>
#Jersey client settings
jerseyClient:
#The maximum idle time for a connection, once established.
timeout: 512ms
@javaeeeee
javaeeeee / pom.xml
Created December 4, 2015 06:48
Maven dependency for Jersey client in Dropwizard application
<dependency>
<groupId>io.dropwizard</groupId>
<artifactId>dropwizard-client</artifactId>
<version>${dropwizard.version}</version>
</dependency>
@javaeeeee
javaeeeee / User.java
Created November 17, 2015 10:45
User class
/*
* The MIT License
*
* Copyright 2015 Dmitry Noranovich.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
@javaeeeee
javaeeeee / DWGettingStartedApplication.java
Created November 6, 2015 13:11
Registering a database-backed resource class in the Application class of a Dropwizard project
public class DWGettingStartedApplication
extends Application<DWGettingStartedConfiguration> {
...
@Override
public void run(final DWGettingStartedConfiguration configuration,
final Environment environment) {
final EmployeeDAO employeeDAO
= new EmployeeDAO(hibernateBundle.getSessionFactory());
@javaeeeee
javaeeeee / DWGettingStartedApplication.java
Created November 6, 2015 13:08
Adding Hibernate bundle to the Dropwizard Application class
public class DWGettingStartedApplication
extends Application<DWGettingStartedConfiguration> {
/**
* Hibernate bundle.
*/
private final HibernateBundle<DWGettingStartedConfiguration> hibernateBundle
= new HibernateBundle<DWGettingStartedConfiguration>(
Employee.class
) {
@javaeeeee
javaeeeee / EmployeesResource.java
Created November 6, 2015 13:06
A database-backed resource class for a Dropwizard application
@Path("/employees")
@Produces(MediaType.APPLICATION_JSON)
public class EmployeesResource {
/**
* The DAO object to manipulate employees.
*/
private EmployeeDAO employeeDAO;
/**
@javaeeeee
javaeeeee / EmployeeDAO.java
Created November 6, 2015 13:04
A Hibernate DAO class for a Dropwizard project
public class EmployeeDAO extends AbstractDAO<Employee> {
/**
* Constructor.
*
* @param sessionFactory Hibernate session factory.
*/
public EmployeeDAO(SessionFactory sessionFactory) {
super(sessionFactory);
}