Skip to content

Instantly share code, notes, and snippets.

View mrserverless's full-sized avatar
🌆
Building a Metaverse

Yun Zhi Lin mrserverless

🌆
Building a Metaverse
View GitHub Profile
@mrserverless
mrserverless / build.gradle
Last active February 5, 2017 03:39
Dropwizard build.gradle with ShadowJar
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.github.jengelman.gradle.plugins:shadow:1.1.2'
}
}
apply plugin: 'maven'
@mrserverless
mrserverless / JdbiIntegrationTest.java
Last active August 29, 2015 14:08 — forked from thody/JdbiIntegrationTest.java
Dropwizard JDBI Integration Test slightly more simplified and upgraded to Dropwizard version 0.7.1
public abstract class JdbiIntegrationTest {
protected DBI dbi;
private Handle handle;
private Liquibase liquibase;
protected abstract DataSourceFactory getDataSourceFactory();
@mrserverless
mrserverless / JdbiUnitTest.java
Last active April 8, 2019 10:17
Dropwizard JDBI Unit Test abstract class using H2 by default.
public abstract class JdbiUnitTest {
protected DBI dbi;
private Handle handle;
private Liquibase liquibase;
protected abstract void setUpDataAccessObjects();
// Bridge all Guice injection from AppServletContextListener
GuiceBridge.getGuiceBridge().initializeGuiceBridge( serviceLocator );
GuiceIntoHK2Bridge guiceBridge = serviceLocator.getService( GuiceIntoHK2Bridge.class );
guiceBridge.bridgeGuiceInjector( injector );
@mrserverless
mrserverless / DropwizardGovernatorApplication.java
Last active February 17, 2017 09:53
Using Governator with Dropwizard-Guice, pending pull request https://github.com/HubSpot/dropwizard-guice/pull/39/
@Override
public void initialize( final Bootstrap<PlatformConfiguration> bootstrap ) {
final GuiceBundle<PlatformConfiguration> guiceBundle = GuiceBundle.<PlatformConfiguration>newBuilder()
.addModule( new PlatformModule() )
.enableAutoConfig( "com.apmasphere.platform.resources", "com.apmasphere.platform.health" )
.setConfigClass( PlatformConfiguration.class )
.setInjectorFactory( new GovernatorInjectorFactory() )
.build();
bootstrap.addBundle( guiceBundle );
}
@mrserverless
mrserverless / Configuration.java
Last active March 14, 2019 12:08
Dropwizard serving Static Assets on Root URL "/" and APIs on "/api/"
public class ApplicationConfiguration extends Configuration implements AssetsBundleConfiguration {
@Valid
@NotNull
@JsonProperty
private AssetsConfiguration assets;
@Override
public AssetsConfiguration getAssets() {
return assets;
}
@mrserverless
mrserverless / build.gradle
Created December 22, 2014 00:15
Gradle maven publish replace default runtime scope with compile scope. See: http://forums.gradle.org/gradle/topics/using_the_maven_publish_plugin_no_dependencies_in_pom_xml
publishing {
publications {
mavenJava(MavenPublication) {
pom.withXml {
asNode().dependencies.'*'.findAll() {
it.scope.text() == 'runtime' && project.configurations.compile.allDependencies.find { dep ->
dep.name == it.artifactId.text()
}
}.each() {
it.scope*.value = 'compile'
@mrserverless
mrserverless / MultiTenantDataSource
Last active February 17, 2017 09:52
Dropwizard MultiTenant DataSource using RequestScope injected Schema object
public class MultiTenantDataSource implements ManagedDataSource {
private final ManagedDataSource managedDataSource;
private final SchemaResolver schemaResolver;
public MultiTenantDataSource( final ManagedDataSource managedDataSource, final SchemaResolver schemaResolver )
{
this.managedDataSource = managedDataSource;
this.schemaResolver = schemaResolver;
}
@Singleton
@javax.ws.rs.ext.Provider
public class NewRelicTimedApplicationListener implements ApplicationEventListener {
private Map<Method,String> methodMap = new HashMap<>();
@Override
public void onEvent(ApplicationEvent event) {
if (event.getType() == ApplicationEvent.Type.INITIALIZATION_APP_FINISHED) {
for (Resource resource : event.getResourceModel().getResources()) {
@mrserverless
mrserverless / Dropwizard DockerFile minimal
Created February 6, 2015 09:06
Dropwizard DockerFile minimal, less than 200mb
errordeveloper/oracle-jre
WORKDIR /app/
ADD app-config.yml /app/
ADD build/app.jar /app/
# port and run
EXPOSE 9090
ENTRYPOINT [ "java" ]
CMD [ "-jar", "app.jar", "server", "app-config.yml" ]