Permalink
Browse files

resources: add support for servlets backed by jooby

This library will now require JDK 1.8+.

Signed-off-by: Pierre-Alexandre Meyer <pierre@mouraf.org>
  • Loading branch information...
pierre committed Jul 19, 2017
1 parent e2522e0 commit 57c1db9f7a8279f1f9183fcdbe6d21fda36e7b7a
View
@@ -20,10 +20,10 @@
</profile>
</annotationProcessing>
<bytecodeTargetLevel>
<module name="killbill-base-plugin" target="1.6" />
<module name="killbill-base-plugin" target="1.8" />
</bytecodeTargetLevel>
</component>
<component name="JavacSettings">
<option name="ADDITIONAL_OPTIONS_STRING" value="-Xlint:unchecked " />
</component>
</project>
</project>
View
6 NEWS
@@ -1,3 +1,9 @@
1.2.0
jdk1.8+ only
Support for servlets backed by jooby
Support for plugin healthchecks
Support for multi-regions configuration
1.1.2
Update to killbill-oss-parent 0.140.24
View
@@ -14,8 +14,8 @@ Kill Bill compatibility
| Framework version | Kill Bill version |
| ----------------: | ----------------: |
| 0.3.y | 0.16.z |
| 1.1.y | 0.18.z |
| 1.2.y | 0.19.z |
| 1.x.y | 0.18.z |
| 2.x.y | 0.19.z |
Usage
-----
View
69 pom.xml
@@ -24,7 +24,7 @@
</parent>
<groupId>org.kill-bill.billing.plugin.java</groupId>
<artifactId>killbill-base-plugin</artifactId>
<version>1.1.3-SNAPSHOT</version>
<version>1.2.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Kill Bill base OSGI plugin</name>
<description>Kill Bill base OSGI plugin</description>
@@ -38,18 +38,31 @@
<system>Github</system>
<url>https://github.com/killbill/killbill-plugin-framework-java/issues</url>
</issueManagement>
<properties>
<!-- More recent versions than the core (JDK1.8+) -->
<guava.version>21.0</guava.version>
<jackson.version>2.8.3</jackson.version>
</properties>
<dependencies>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-joda</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
@@ -59,6 +72,7 @@
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
@@ -82,6 +96,18 @@
<groupId>org.joda</groupId>
<artifactId>joda-money</artifactId>
</dependency>
<dependency>
<groupId>org.jooby</groupId>
<artifactId>jooby</artifactId>
</dependency>
<dependency>
<groupId>org.jooby</groupId>
<artifactId>jooby-jackson</artifactId>
</dependency>
<dependency>
<groupId>org.jooby</groupId>
<artifactId>jooby-servlet</artifactId>
</dependency>
<dependency>
<groupId>org.jooq</groupId>
<artifactId>jooq</artifactId>
@@ -167,4 +193,45 @@
<scope>test</scope>
</dependency>
</dependencies>
<profiles>
<profile>
<id>jdk18</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<showDeprecation>true</showDeprecation>
<showWarnings>true</showWarnings>
<fork>true</fork>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>jar</goal>
<goal>test-jar</goal>
</goals>
<configuration>
<classifier>jdk18</classifier>
</configuration>
</execution>
</executions>
<configuration>
<skipIfEmpty>true</skipIfEmpty>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
@@ -0,0 +1,63 @@
/*
* Copyright 2014-2017 Groupon, Inc
* Copyright 2014-2017 The Billing Project, LLC
*
* The Billing Project 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:
*
* http://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 org.killbill.billing.plugin.core;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.jooby.servlet.ServletServletRequest;
import org.jooby.servlet.ServletServletResponse;
import org.jooby.spi.HttpHandler;
import org.killbill.billing.plugin.core.resources.jooby.PluginApp;
import com.typesafe.config.Config;
public class JoobyServlet extends PluginServlet {
private final PluginApp app;
private final HttpHandler dispatcher;
private final String tmpdir;
public JoobyServlet(final PluginApp app) {
this.app = app;
this.app.start();
dispatcher = app.require(HttpHandler.class);
tmpdir = app.require(Config.class).getString("application.tmpdir");
}
@Override
protected void service(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {
try {
dispatcher.handle(new ServletServletRequest(req, tmpdir),
new ServletServletResponse(req, resp));
} catch (final Exception e) {
throw new ServletException(e);
}
}
@Override
public void destroy() {
super.destroy();
app.stop();
}
}
@@ -0,0 +1,50 @@
/*
* Copyright 2014-2017 Groupon, Inc
* Copyright 2014-2017 The Billing Project, LLC
*
* The Billing Project 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:
*
* http://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 org.killbill.billing.plugin.core.resources;
import java.util.Dictionary;
import javax.annotation.Nullable;
import org.jooby.MediaType;
import org.jooby.Result;
import org.jooby.Results;
import org.jooby.Status;
import org.killbill.billing.plugin.service.Healthcheck;
import org.killbill.billing.plugin.service.Healthcheck.HealthStatus;
import org.killbill.billing.tenant.api.Tenant;
// Specified in the concrete class
//@Singleton
//@Path("/healthcheck")
public abstract class PluginHealthcheck {
private static final String CACHE_CONTROL = "Cache-Control";
private static final String DEFAULT_CACHE_CONTROL = "private, no-cache, no-store, no-transform, must-revalidate";
protected Result check(final Healthcheck healthcheck, @Nullable final Tenant tenant, @Nullable final Dictionary properties) {
final HealthStatus healthStatus = healthcheck.getHealthStatus(tenant, properties);
return buildHealthcheckResponse(healthStatus);
}
protected Result buildHealthcheckResponse(final HealthStatus healthStatus) {
return Results.with(healthStatus.getDetails(), healthStatus.isHealthy() ? Status.OK : Status.SERVICE_UNAVAILABLE)
.header(CACHE_CONTROL, DEFAULT_CACHE_CONTROL)
.type(MediaType.json);
}
}
@@ -0,0 +1,48 @@
/*
* Copyright 2014-2017 Groupon, Inc
* Copyright 2014-2017 The Billing Project, LLC
*
* The Billing Project 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:
*
* http://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 org.killbill.billing.plugin.core.resources.jooby;
import javax.servlet.http.HttpServlet;
import org.jooby.Jooby;
import org.jooby.json.Jackson;
import org.killbill.billing.plugin.core.JoobyServlet;
import com.fasterxml.jackson.databind.ObjectMapper;
public class PluginApp extends Jooby {
public PluginApp(final ObjectMapper objectMapper,
final Iterable<Object> services,
final Iterable<Class> routeClasses) {
use(new Jackson(objectMapper));
for (final Object service : services) {
bind(service);
}
for (final Class<?> routeClass : routeClasses) {
use(routeClass);
}
}
// To be registered in your Activator
public static HttpServlet createServlet(final PluginApp pluginApp) {
return new JoobyServlet(pluginApp);
}
}
Oops, something went wrong.

0 comments on commit 57c1db9

Please sign in to comment.