Repository: incubator-freemarker-online-tester Updated Branches: refs/heads/master 808bd5365 -> 5291fabbd
initial commit for dropwizard integration, removed fallwizard dependency Project: http://git-wip-us.apache.org/repos/asf/incubator-freemarker-online-tester/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-freemarker-online-tester/commit/c67cf04d Tree: http://git-wip-us.apache.org/repos/asf/incubator-freemarker-online-tester/tree/c67cf04d Diff: http://git-wip-us.apache.org/repos/asf/incubator-freemarker-online-tester/diff/c67cf04d Branch: refs/heads/master Commit: c67cf04d662fa40f92bfdbf41797f818d8533f20 Parents: 808bd53 Author: Pradeep Murugesan <[email protected]> Authored: Fri Apr 28 15:28:34 2017 +0200 Committer: Pradeep Murugesan <[email protected]> Committed: Fri Apr 28 15:28:34 2017 +0200 ---------------------------------------------------------------------- .gitignore | 1 + build.gradle | 10 ++-- dependencies.gradle | 18 +++--- intellij.gradle | 2 +- .../dropwizard/ApplicationStartup.java | 42 -------------- .../dropwizard/FreeMarkerOnlineTester.java | 58 ++++++++++++++++++++ .../FreeMarkerOnlineTesterConfiguration.java | 8 +++ .../healthchecks/MyProjectHealthCheck.java | 7 +-- .../onlinetester/resources/TestResource.java | 18 ++++++ .../spring/SpringConfiguration.java | 8 +++ .../onlinetester/view/FreeMarkerOnlineView.java | 2 +- src/main/resources/freemarker-online.yml | 36 +++++------- src/main/resources/view/freemarker-online.ftl | 4 +- .../platform/DropWizardServiceTest.java | 10 ++-- 14 files changed, 134 insertions(+), 90 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-freemarker-online-tester/blob/c67cf04d/.gitignore ---------------------------------------------------------------------- diff --git a/.gitignore b/.gitignore index 3d6b9a5..7fd4b48 100644 --- a/.gitignore +++ b/.gitignore @@ -27,3 +27,4 @@ freemarker-online.ipr freemarker-online.iws **/.DS_Store +/out/ http://git-wip-us.apache.org/repos/asf/incubator-freemarker-online-tester/blob/c67cf04d/build.gradle ---------------------------------------------------------------------- diff --git a/build.gradle b/build.gradle index 3e0405f..5151008 100644 --- a/build.gradle +++ b/build.gradle @@ -51,13 +51,13 @@ buildscript { repositories { mavenCentral() - // For com.berico:fallwizard:1.1.1 that must be locally installed; see README.md! - mavenLocal() } dependencies { compile libraries.dropwizard - compile libraries.dropwizrd_views + compile libraries.dropwizard_views + compile libraries.dropwizard_views_freemarker + compile libraries.dropwizard_assets compile libraries.springCore compile libraries.springContext compile libraries.springContextSupport @@ -65,7 +65,7 @@ dependencies { compile libraries.springSecurityCore compile libraries.springTransaction compile libraries.springBeans - compile libraries.fallwizard + compile libraries.springWeb testCompile libraries.dropwizard_testing testCompile libraries.springTest @@ -100,7 +100,7 @@ fatJar { exclude "META-INF/*.DSA" exclude "META-INF/*.RSA" manifest { - attributes 'Main-Class': 'org.apache.freemarker.onlinetester.dropwizard.ApplicationStartup' + attributes 'Main-Class': 'org.apache.freemarker.onlinetester.dropwizard.FreeMarkerOnlineTester' attributes 'Implementation-Version': "$version" } } http://git-wip-us.apache.org/repos/asf/incubator-freemarker-online-tester/blob/c67cf04d/dependencies.gradle ---------------------------------------------------------------------- diff --git a/dependencies.gradle b/dependencies.gradle index 80ff8ce..73d9088 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -18,14 +18,16 @@ */ project.ext.set("libraries", "") -ext.dw_version = "0.6.2"; -ext.spring_version = "3.2.2.RELEASE"; +ext.dw_version = "0.7.1"; +ext.spring_version = "3.2.18.RELEASE"; ext.jackson_version = "2.5.1"; project.libraries = [ - dropwizard: "com.yammer.dropwizard:dropwizard-core:$dw_version", - dropwizard_client: "com.yammer.dropwizard:dropwizard-client:$dw_version", - dropwizrd_views: "com.yammer.dropwizard:dropwizard-views:$dw_version", + dropwizard: "io.dropwizard:dropwizard-core:$dw_version", + dropwizard_client: "io.dropwizard:dropwizard-client:$dw_version", + dropwizard_views: "io.dropwizard:dropwizard-views:$dw_version", + dropwizard_views_freemarker: "io.dropwizard:dropwizard-views-freemarker:$dw_version", + dropwizard_assets: "io.dropwizard:dropwizard-assets:$dw_version", guava: 'com.google.guava:guava:13.0.1', jersey_core: 'com.sun.jersey:jersey-core:1.1.4.1', @@ -37,19 +39,19 @@ project.libraries = [ springTransaction: "org.springframework:spring-tx:$spring_version", springBeans: "org.springframework:spring-beans:$spring_version", springJersey: "com.sun.jersey.contribs:jersey-spring:1.7", + springWeb: "org.springframework:spring-web:$spring_version", // Security // Spring and Spring Security support for dropwizard - fallwizard: "com.berico:fallwizard:1.1.1", // adheres to fallwizard version of spring security springSecurityCore: "org.springframework.security:spring-security-core:3.1.4.RELEASE", - dropwizardAuth: "com.yammer.dropwizard:dropwizard-auth:$dw_version", + dropwizardAuth: "io.dropwizard:dropwizard-auth:$dw_version", // Spring test springTest: "org.springframework:spring-test:$spring_version", //Test libs - dropwizard_testing: "com.yammer.dropwizard:dropwizard-testing:$dw_version", + dropwizard_testing: "io.dropwizard:dropwizard-testing:$dw_version", junit: 'junit:junit-dep:4.11', mockito: 'org.mockito:mockito-core:1.9.0', hamcrest: 'org.hamcrest:hamcrest-library:1.3', http://git-wip-us.apache.org/repos/asf/incubator-freemarker-online-tester/blob/c67cf04d/intellij.gradle ---------------------------------------------------------------------- diff --git a/intellij.gradle b/intellij.gradle index 0853356..72fdc24 100644 --- a/intellij.gradle +++ b/intellij.gradle @@ -39,7 +39,7 @@ idea.workspace.iws.withXml { provider -> list.appendNode('item', [index: '0', class: 'java.lang.String', itemvalue: 'MyProjectStartup']) def Application = runManager.appendNode('configuration', [default: 'false', name: "${projectName}", type: 'Application', factoryName: 'Application']) Application.appendNode('extension', [name: 'coverage', enabled: 'false', merge: 'false', runner: 'idea']) - Application.appendNode('option', [name: 'MAIN_CLASS_NAME', value: "org.apache.freemarker.onlinetester.dropwizard.ApplicationStartup"]) + Application.appendNode('option', [name: 'MAIN_CLASS_NAME', value: "org.apache.freemarker.onlinetester.dropwizard.FreeMarkerOnlineTester"]) Application.appendNode('option', [name: 'VM_PARAMETERS', value: ""]) Application.appendNode('option', [name: 'PROGRAM_PARAMETERS', value: "server src/main/resources/${projectName}.yml"]) Application.appendNode('option', [name: 'WORKING_DIRECTORY', value: "$projectDir"]) http://git-wip-us.apache.org/repos/asf/incubator-freemarker-online-tester/blob/c67cf04d/src/main/java/org/apache/freemarker/onlinetester/dropwizard/ApplicationStartup.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/onlinetester/dropwizard/ApplicationStartup.java b/src/main/java/org/apache/freemarker/onlinetester/dropwizard/ApplicationStartup.java deleted file mode 100644 index 4caf07c..0000000 --- a/src/main/java/org/apache/freemarker/onlinetester/dropwizard/ApplicationStartup.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF 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.apache.freemarker.onlinetester.dropwizard; - -import com.berico.fallwizard.SpringConfiguration; -import com.berico.fallwizard.SpringService; -import com.yammer.dropwizard.assets.AssetsBundle; -import com.yammer.dropwizard.config.Bootstrap; -import com.yammer.dropwizard.views.ViewBundle; - -public class ApplicationStartup extends SpringService<SpringConfiguration> { - - public static void main(String[] args) throws Exception { - new ApplicationStartup().run(args); - } - - @Override - public void initialize(Bootstrap<SpringConfiguration> bootstrap) { - bootstrap.setName("freemarker-online"); - bootstrap.addBundle(new ViewBundle()); - bootstrap.addBundle(new AssetsBundle("/assets/css", "/css")); - bootstrap.addBundle(new AssetsBundle("/assets/js", "/js")); - } - -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-freemarker-online-tester/blob/c67cf04d/src/main/java/org/apache/freemarker/onlinetester/dropwizard/FreeMarkerOnlineTester.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/onlinetester/dropwizard/FreeMarkerOnlineTester.java b/src/main/java/org/apache/freemarker/onlinetester/dropwizard/FreeMarkerOnlineTester.java new file mode 100644 index 0000000..3c48efd --- /dev/null +++ b/src/main/java/org/apache/freemarker/onlinetester/dropwizard/FreeMarkerOnlineTester.java @@ -0,0 +1,58 @@ +package org.apache.freemarker.onlinetester.dropwizard; + + +import com.codahale.metrics.health.HealthCheck; + +import io.dropwizard.Application; +import io.dropwizard.assets.AssetsBundle; +import io.dropwizard.setup.Bootstrap; +import io.dropwizard.setup.Environment; +import io.dropwizard.views.ViewBundle; +import org.apache.freemarker.onlinetester.spring.SpringConfiguration; +import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; + + +import javax.ws.rs.Path; +import java.util.Map; + +public class FreeMarkerOnlineTester extends Application<FreeMarkerOnlineTesterConfiguration> { + + public static void main(String[] args) throws Exception { + new FreeMarkerOnlineTester().run(args); + } + + @Override + public String getName() { + return "freemarker-online"; + } + + @Override + public void run(FreeMarkerOnlineTesterConfiguration configuration, Environment environment) throws Exception { + AnnotationConfigWebApplicationContext context = initializeSpringContext(); + + + Map<String, Object> resources = context.getBeansWithAnnotation(Path.class); + for(Map.Entry<String,Object> entry : resources.entrySet()) { + environment.jersey().register(entry.getValue()); + } + + Map<String, HealthCheck> healthChecks = context.getBeansOfType(HealthCheck.class); + for(Map.Entry<String,HealthCheck> entry : healthChecks.entrySet()) { + environment.healthChecks().register("", entry.getValue()); + } + } + + private AnnotationConfigWebApplicationContext initializeSpringContext() { + AnnotationConfigWebApplicationContext springContext = new AnnotationConfigWebApplicationContext(); + springContext.register(SpringConfiguration.class); + springContext.refresh(); + springContext.start(); + return springContext; + } + + @Override + public void initialize(Bootstrap<FreeMarkerOnlineTesterConfiguration> bootstrap) { + bootstrap.addBundle(new ViewBundle()); + bootstrap.addBundle(new AssetsBundle()); + } +} http://git-wip-us.apache.org/repos/asf/incubator-freemarker-online-tester/blob/c67cf04d/src/main/java/org/apache/freemarker/onlinetester/dropwizard/FreeMarkerOnlineTesterConfiguration.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/onlinetester/dropwizard/FreeMarkerOnlineTesterConfiguration.java b/src/main/java/org/apache/freemarker/onlinetester/dropwizard/FreeMarkerOnlineTesterConfiguration.java new file mode 100644 index 0000000..355192c --- /dev/null +++ b/src/main/java/org/apache/freemarker/onlinetester/dropwizard/FreeMarkerOnlineTesterConfiguration.java @@ -0,0 +1,8 @@ +package org.apache.freemarker.onlinetester.dropwizard; + + +import io.dropwizard.Configuration; + +public class FreeMarkerOnlineTesterConfiguration extends Configuration { + +} http://git-wip-us.apache.org/repos/asf/incubator-freemarker-online-tester/blob/c67cf04d/src/main/java/org/apache/freemarker/onlinetester/healthchecks/MyProjectHealthCheck.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/onlinetester/healthchecks/MyProjectHealthCheck.java b/src/main/java/org/apache/freemarker/onlinetester/healthchecks/MyProjectHealthCheck.java index 192fa46..6322100 100644 --- a/src/main/java/org/apache/freemarker/onlinetester/healthchecks/MyProjectHealthCheck.java +++ b/src/main/java/org/apache/freemarker/onlinetester/healthchecks/MyProjectHealthCheck.java @@ -19,17 +19,12 @@ package org.apache.freemarker.onlinetester.healthchecks; -import com.yammer.metrics.core.HealthCheck; +import com.codahale.metrics.health.HealthCheck; import org.springframework.stereotype.Component; @Component public class MyProjectHealthCheck extends HealthCheck { - // note that this is due to the default spring CTR - public MyProjectHealthCheck() { - super("MyProjectHealthCheck"); - } - @Override protected Result check() throws Exception { return Result.healthy(); // we're always healthy! http://git-wip-us.apache.org/repos/asf/incubator-freemarker-online-tester/blob/c67cf04d/src/main/java/org/apache/freemarker/onlinetester/resources/TestResource.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/onlinetester/resources/TestResource.java b/src/main/java/org/apache/freemarker/onlinetester/resources/TestResource.java new file mode 100644 index 0000000..df790bf --- /dev/null +++ b/src/main/java/org/apache/freemarker/onlinetester/resources/TestResource.java @@ -0,0 +1,18 @@ +package org.apache.freemarker.onlinetester.resources; + +import org.springframework.stereotype.Component; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +@Path("/test") +@Component +public class TestResource { + @GET + @Produces(MediaType.TEXT_HTML) + public String blankForm() { + return "Hello"; + } +} http://git-wip-us.apache.org/repos/asf/incubator-freemarker-online-tester/blob/c67cf04d/src/main/java/org/apache/freemarker/onlinetester/spring/SpringConfiguration.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/onlinetester/spring/SpringConfiguration.java b/src/main/java/org/apache/freemarker/onlinetester/spring/SpringConfiguration.java new file mode 100644 index 0000000..a4fe003 --- /dev/null +++ b/src/main/java/org/apache/freemarker/onlinetester/spring/SpringConfiguration.java @@ -0,0 +1,8 @@ +package org.apache.freemarker.onlinetester.spring; + +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; + +@Configuration +@ComponentScan(basePackages = {"org.apache.freemarker.onlinetester"}) +public class SpringConfiguration {} http://git-wip-us.apache.org/repos/asf/incubator-freemarker-online-tester/blob/c67cf04d/src/main/java/org/apache/freemarker/onlinetester/view/FreeMarkerOnlineView.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/freemarker/onlinetester/view/FreeMarkerOnlineView.java b/src/main/java/org/apache/freemarker/onlinetester/view/FreeMarkerOnlineView.java index 3aecbb5..c90e2a5 100644 --- a/src/main/java/org/apache/freemarker/onlinetester/view/FreeMarkerOnlineView.java +++ b/src/main/java/org/apache/freemarker/onlinetester/view/FreeMarkerOnlineView.java @@ -26,11 +26,11 @@ import java.util.List; import java.util.Locale; import java.util.Map; +import io.dropwizard.views.View; import org.apache.commons.lang3.StringUtils; import org.apache.freemarker.onlinetester.model.SelectionOption; import org.apache.freemarker.onlinetester.services.AllowedSettingValuesMaps; -import com.yammer.dropwizard.views.View; import freemarker.template.Configuration; http://git-wip-us.apache.org/repos/asf/incubator-freemarker-online-tester/blob/c67cf04d/src/main/resources/freemarker-online.yml ---------------------------------------------------------------------- diff --git a/src/main/resources/freemarker-online.yml b/src/main/resources/freemarker-online.yml index 2b50ba5..f67fc2d 100644 --- a/src/main/resources/freemarker-online.yml +++ b/src/main/resources/freemarker-online.yml @@ -15,25 +15,19 @@ # specific language governing permissions and limitations # under the License. -# Spring configuration -# Application Contexts to Load. -applicationContext: ['classpath*:/spring/*-context.xml'] - logging: - # Settings for logging to a file. - file: - # If true, write log statements to a file. - enabled: true - threshold: ALL - # The file to which current statements will be logged. - currentLogFilename: /var/log/freemarker-online/freemarker-online.log - - # When the log file rotates, the archived log will be renamed to this and gzipped. The - # %d is replaced with the previous day (yyyy-MM-dd). Custom rolling windows can be created - # by passing a SimpleDateFormat-compatible format as an argument: "%d{yyyy-MM-dd-hh}". - archivedLogFilenamePattern: /var/log/freemarker-online/freemarker-online-%d.log.gz - # The number of archived files to keep. - archivedFileCount: 5 - - # The timezone used to format dates. HINT: USE THE DEFAULT, UTC. - timeZone: UTC + level: INFO + appenders: + - type: file + currentLogFilename: /var/log/freemarker-online/freemarker-online.log + threshold: ALL + archive: true + archivedLogFilenamePattern: /var/log/freemarker-online/freemarker-online-%d.log.gz + archivedFileCount: 5 + timeZone: UTC + logFormat: + - type: console + threshold: ALL + timeZone: UTC + target: stdout + logFormat: \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-freemarker-online-tester/blob/c67cf04d/src/main/resources/view/freemarker-online.ftl ---------------------------------------------------------------------- diff --git a/src/main/resources/view/freemarker-online.ftl b/src/main/resources/view/freemarker-online.ftl index 57194f0..7c57f3e 100644 --- a/src/main/resources/view/freemarker-online.ftl +++ b/src/main/resources/view/freemarker-online.ftl @@ -28,13 +28,13 @@ <html> <head> <meta charset="utf-8"> - <link rel="stylesheet" href="css/main.css"> + <link rel="stylesheet" href="assets/css/main.css"> <link rel="stylesheet" href="http://yui.yahooapis.com/pure/0.5.0/pure-min.css"> <script src="https://code.jquery.com/jquery-1.11.2.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.blockUI/2.70/jquery.blockUI.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/autosize.js/3.0.8/autosize.min.js"></script> - <script src="js/script.js"></script> + <script src="assets/js/script.js"></script> <script> $(function() { // Auto-focus on first form input: http://git-wip-us.apache.org/repos/asf/incubator-freemarker-online-tester/blob/c67cf04d/src/test/java/org/apache/freemarker/onlinetester/platform/DropWizardServiceTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/freemarker/onlinetester/platform/DropWizardServiceTest.java b/src/test/java/org/apache/freemarker/onlinetester/platform/DropWizardServiceTest.java index f23672c..c467a04 100644 --- a/src/test/java/org/apache/freemarker/onlinetester/platform/DropWizardServiceTest.java +++ b/src/test/java/org/apache/freemarker/onlinetester/platform/DropWizardServiceTest.java @@ -20,20 +20,22 @@ package org.apache.freemarker.onlinetester.platform; import com.google.common.io.Resources; -import org.apache.freemarker.onlinetester.dropwizard.ApplicationStartup; -import com.yammer.dropwizard.testing.junit.DropwizardServiceRule; +import io.dropwizard.testing.junit.DropwizardAppRule; + +import org.apache.freemarker.onlinetester.dropwizard.FreeMarkerOnlineTester; +import org.apache.freemarker.onlinetester.dropwizard.FreeMarkerOnlineTesterConfiguration; import org.junit.ClassRule; import org.junit.Test; import org.junit.rules.TestRule; public class DropWizardServiceTest { @ClassRule - public static TestRule testRule = new DropwizardServiceRule<>(ApplicationStartup.class, + public static TestRule testRule = new DropwizardAppRule<FreeMarkerOnlineTesterConfiguration>(FreeMarkerOnlineTester.class, Resources.getResource("freemarker-online.yml").getPath()); @Test public void testServerIsUp() throws Exception { - ((DropwizardServiceRule) testRule).getService(); + ((DropwizardAppRule) testRule).getApplication(); } }
