Skip to content

Commit

Permalink
Add Dropwizard module (#2236)
Browse files Browse the repository at this point in the history
Motivation:

Dropwizard is another popular framework we'd like to integrate Armeria into.

Modifications:

- Add `armeria-dropwizard` which provides a Dropwizard bundle and SPI implementations.
- Add documentation about Dropwizard integration
- Add an example

Result:

Closes #2165
  • Loading branch information
OneCricketeer authored and trustin committed Dec 23, 2019
1 parent 626a341 commit db47ad3
Show file tree
Hide file tree
Showing 56 changed files with 2,681 additions and 71 deletions.
34 changes: 34 additions & 0 deletions dependencies.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,40 @@ com.squareup.retrofit2:
gradle.plugin.net.davidecavestro:
gradle-jxr-plugin: { version: '0.2.1' }

io.dropwizard:
dropwizard-core:
version: &DROPWIZARD_VERSION '1.3.17'
javadocs:
- https://static.javadoc.io/io.dropwizard/dropwizard-core/1.3.17/
dropwizard-jackson:
version: *DROPWIZARD_VERSION
javadocs:
- https://static.javadoc.io/io.dropwizard/dropwizard-jackson/1.3.17/
dropwizard-lifecycle:
version: *DROPWIZARD_VERSION
javadocs:
- https://static.javadoc.io/io.dropwizard/dropwizard-lifecycle/1.3.17/
dropwizard-jersey:
version: *DROPWIZARD_VERSION
javadocs:
- https://static.javadoc.io/io.dropwizard/dropwizard-jersey/1.3.17/
dropwizard-jetty:
version: *DROPWIZARD_VERSION
javadocs:
- https://static.javadoc.io/io.dropwizard/dropwizard-jetty/1.3.17/
dropwizard-testing:
version: *DROPWIZARD_VERSION
javadocs:
- https://static.javadoc.io/io.dropwizard/dropwizard-testing/1.3.17/
dropwizard-util:
version: *DROPWIZARD_VERSION
javadocs:
- https://static.javadoc.io/io.dropwizard/dropwizard-util/1.3.17/
dropwizard-validation:
version: *DROPWIZARD_VERSION
javadocs:
- https://static.javadoc.io/io.dropwizard/dropwizard-validation/1.3.17/

io.dropwizard.metrics:
metrics-core:
javadocs:
Expand Down
33 changes: 33 additions & 0 deletions dropwizard/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
buildscript {
repositories {
gradlePluginPortal()
}
dependencies {
classpath "com.github.jengelman.gradle.plugins:shadow:${managedVersions['com.github.jengelman.gradle.plugins:shadow']}"
}
}

dependencies {
compile project(':jetty')
// Dropwizard
['core', 'util', 'lifecycle', 'jackson', 'validation', 'jetty', 'jersey'].each {
compile "io.dropwizard:dropwizard-$it"
}
// Dropwizard Metrics
compile 'io.dropwizard.metrics:metrics-core'

testCompile 'io.dropwizard:dropwizard-testing'
}

// Do not relocate Guava because it's part of Dropwizard's public API.
[tasks.shadedJar, tasks.shadedTestJar].each { task ->
task.relocators.clear()
project.ext.relocations.each { Map<String, String> props ->
def from = props['from']
def to = props['to']
if (from in ['com.google.common', 'com.google.thirdparty.publicsuffix']) {
return
}
task.relocate from, to
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright 2019 LINE Corporation
*
* LINE Corporation licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at:
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package com.linecorp.armeria.dropwizard;

import com.linecorp.armeria.server.Server;
import com.linecorp.armeria.server.ServerBuilder;

import io.dropwizard.Configuration;
import io.dropwizard.ConfiguredBundle;
import io.dropwizard.setup.Bootstrap;
import io.dropwizard.setup.Environment;

/**
* A Dropwizard {@link ConfiguredBundle} that routes requests through an
* Armeria {@link Server} rather than the default Jetty server.
*
* @param <C> The Dropwizard {@link Configuration} type.
*/
public abstract class ArmeriaBundle<C extends Configuration>
implements ConfiguredBundle<C>, ArmeriaServerConfigurator {

@Override
public void initialize(Bootstrap<?> bootstrap) {
}

@Override
public void run(C configuration, Environment environment) throws Exception {
final ManagedArmeriaServer<C> managedArmeriaServer = new ManagedArmeriaServer<>(configuration, this);
environment.lifecycle().manage(managedArmeriaServer);
}

@Override
public abstract void configure(ServerBuilder builder);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright 2019 LINE Corporation
*
* LINE Corporation licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at:
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package com.linecorp.armeria.dropwizard;

import com.linecorp.armeria.server.ServerBuilder;

/**
* Interface used to configure a service on the default armeria server. Can be
* used to register arbitrary services.
*/
@FunctionalInterface
interface ArmeriaServerConfigurator {
/**
* Configures the server using the specified {@link ServerBuilder}.
*/
void configure(ServerBuilder builder);
}
Loading

0 comments on commit db47ad3

Please sign in to comment.