Skip to content

Instantly share code, notes, and snippets.

View javaeeeee's full-sized avatar

Dmitry Noranovich javaeeeee

View GitHub Profile
@javaeeeee
javaeeeee / HAL representation with properties
Created February 28, 2015 11:39
HAL representation with properties
{
"Title":"RESTful Web APIs",
"Price":"$31.92",
"Paperback":"408 pages",
"Language":"English"
}
@javaeeeee
javaeeeee / Dropwizard Integration Test using HTTPS, TLS
Created February 10, 2015 04:07
Dropwizard Integration Test using HTTPS/TLS and Jersey 2.x Client
//Create SSL Configurator
SslConfigurator sslConfigurator = SslConfigurator.newInstance();
//Register a keystore
sslConfigurator.trustStoreFile("dwstart.keystore")
.trustStorePassword("crimson");
//Create SSL Context
SSLContext sSLContext = sslConfigurator.createSSLContext();
//Obtain client
Client client = ClientBuilder
.newBuilder()
@javaeeeee
javaeeeee / Dropwizard Integration Test
Created February 10, 2015 04:05
Dropwizard Integration Test
public class IntegrationTest {
@ClassRule
public static final DropwizardAppRule<DWGettingStartedConfiguration> RULE
= new DropwizardAppRule<>(DWGettingStartedApplication.class,
"config.yml");
@Test
public void testGetGreeting() {
String expected = "Hello world!";
@javaeeeee
javaeeeee / Dropwizard HTTPS Configuration
Created February 10, 2015 04:04
Dropwizard HTTPS Configuration
#Server configuration.
server:
applicationConnectors:
- type: http
port: 8080
- type: https
port: 8443
keyStorePath: dwstart.keystore
keyStorePassword: crimson
validateCerts: false
@javaeeeee
javaeeeee / Create keystore using Java 8 keytool
Created February 10, 2015 04:03
Create keystore using Java 8 keytool
keytool -genkeypair
-keyalg RSA
-dname "CN=localhost"
-keystore dwstart.keystore
-keypass crimson
-storepass crimson
@javaeeeee
javaeeeee / Dropwizard Custom Port Configuration
Created February 10, 2015 04:00
Dropwizard Custom Port Configuration
#Server configuration.
server:
applicationConnectors:
- type: http
port: 8085
@javaeeeee
javaeeeee / Register Dropwizard Authenticator
Created February 10, 2015 03:59
Register Dropwizard Authenticator
public void run(final DWGettingStartedConfiguration configuration,
final Environment environment) {
environment.jersey().register(AuthFactory.binder(
new BasicAuthFactory<>(
new GreetingAuthenticator(configuration.getLogin(),
configuration.getPassword()),
"SECURITY REALM",
User.class)));
// ...
}
@javaeeeee
javaeeeee / Dropwizard Authenticator with Configuration
Created February 10, 2015 03:58
Dropwizard Authenticator with Configuration
public class GreetingAuthenticator
implements Authenticator<BasicCredentials, User> {
private String login;
private String password;
public GreetingAuthenticator(String login, String password) {
this.login = login;
this.password = password;
@javaeeeee
javaeeeee / Dropwizard Configuration Subclass
Created February 10, 2015 03:56
Dropwizard Configuration Subclass
public class DWGettingStartedConfiguration extends Configuration {
@NotNull
private String login;
@NotNull
private String password;
@JsonProperty
public String getLogin() {
@javaeeeee
javaeeeee / Dropwizard Custom Configuration
Created February 10, 2015 03:55
Dropwizard Custom Configuration
## Configuration file for DWGettingStarted application.
---
# User login.
login: javaeeeee
# User password.
password: crimson