FINERACT-730: Fixed dependencies, SSL config and main class etc to get bootRun to work. Migrated from Gradle Tomcat plugin to Cargo plugin to fix integration test

This commit is contained in:
Petri Tuomola
2020-05-05 22:04:04 +02:00
committed by Michael Vorburger ⛑️
parent cb690f6d5b
commit b05162f60b
9 changed files with 94 additions and 142 deletions
+38 -48
View File
@@ -18,8 +18,7 @@
*/
description = '''\
Run as:
gradle clean tomcatrunwar
'''
gradle clean bootRun'''
project.ext.jerseyVersion = '1.19.4'
@@ -35,7 +34,7 @@ buildscript {
dependencies {
classpath 'io.spring.gradle:dependency-management-plugin:1.0.9.RELEASE'
classpath 'com.bmuschko:gradle-tomcat-plugin:2.5',
classpath 'com.bmuschko:gradle-cargo-plugin:2.7.1',
'nl.javadude.gradle.plugins:license-gradle-plugin:0.11.0',
'org.zeroturnaround:gradle-jrebel-plugin:1.1.2',
'org.springframework.boot:spring-boot-gradle-plugin:2.2.4.RELEASE'
@@ -60,7 +59,7 @@ apply plugin: 'war'
apply plugin: 'org.springframework.boot'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'com.bmuschko.tomcat'
apply plugin: 'com.bmuschko.cargo'
apply plugin: 'project-report'
apply plugin: 'java-library'
apply plugin: 'openjpa'
@@ -88,6 +87,7 @@ dependencyManagement {
dependency 'com.google.code.gson:gson:+'
dependency 'com.google.guava:guava:28.1-jre'
dependency 'org.apache.commons:commons-email:1.5'
dependency 'org.apache.commons:commons-io:+'
dependency 'org.drizzle.jdbc:drizzle-jdbc:1.4'
dependency 'com.lowagie:itext:2.1.7'
dependency 'com.lowagie:itext-rtf:2.1.7'
@@ -124,13 +124,7 @@ dependencyManagement {
entry 'poi'
entry 'poi-ooxml'
entry 'poi-ooxml-schemas'
}
dependencySet(group: 'org.apache.tomcat.embed', version: '7.0.94') {
entry 'tomcat-embed-core'
entry 'tomcat-embed-jasper'
entry 'tomcat-embed-logging-log4j'
}
}
}
}
@@ -274,7 +268,6 @@ configurations {
exclude module: 'classworlds'
}
runtime
all*.exclude group: 'commons-logging'
all*.exclude module: 'jul-to-slf4j' // see FINERACT-700 re. ClassCircularityError: java/util/logging/LogRecord
}
/* Pick up dependencies based on the environemnt, defaults to production */
@@ -419,52 +412,51 @@ task licenseFormatBuildScripts (type:nl.javadude.gradle.plugins.license.License)
}
licenseFormat.dependsOn licenseFormatBuildScripts
tomcatRun {
httpPort = 8080
httpsPort = 8443
stopPort = 8081
stopKey= 'stopKey'
enableSSL = true
configurations
{
tomcat
}
tomcatRunWar {
httpPort = 8080
httpsPort = 8443
stopPort = 8081
stopKey= 'stopKey'
enableSSL = true
keystoreFile = file('src/main/resources/keystore.jks')
keystorePass = 'openmf'
dependencies {
tomcat "org.apache.tomcat:tomcat:9.0.34@zip"
}
task tomcatRunWarAsDaemonForIntegrationTest(type: com.bmuschko.gradle.tomcat.tasks.TomcatRunWar) {
httpPort = 8080
httpsPort = 8443
stopPort = 8081
stopKey= 'stopKey'
enableSSL = true
keystoreFile = file('src/main/resources/keystore.jks')
keystorePass = 'openmf'
daemon = true
cargo {
containerId "tomcat9x"
local {
installer {
installConfiguration = configurations.tomcat
downloadDir = file("$buildDir/download")
extractDir = file("$buildDir/tomcat")
}
containerProperties {
property 'cargo.tomcat.connector.keystoreFile', file('src/main/resources/keystore.jks')
property 'cargo.tomcat.connector.keystorePass', 'openmf'
property 'cargo.tomcat.httpSecure', true
property 'cargo.tomcat.connector.sslProtocol', 'TLS'
property 'cargo.tomcat.connector.clientAuth', false
property 'cargo.protocol', 'https'
property 'cargo.servlet.port', 8443
}
}
}
task tomcatStopAfterIntegrationTest(type: com.bmuschko.gradle.tomcat.tasks.TomcatStop) {
stopPort = 8081
stopKey = 'stopKey'
}
cargoRunLocal.dependsOn bootWar
cargoStartLocal.dependsOn bootWar
/* http://stackoverflow.com/questions/19653311/jpa-repository-works-in-idea-and-production-but-not-in-gradle */
sourceSets.main.output.resourcesDir = sourceSets.main.java.outputDir
sourceSets.test.output.resourcesDir = sourceSets.test.java.outputDir
/* Exclude maria db and embedded tomcat related files for non dev builds */
/* Exclude maria db related files for non dev builds */
if (!(project.hasProperty('env') && project.getProperty('env') == 'dev')) {
sourceSets {
main {
java {
exclude '**/Server*'
exclude '**/ServerWithMariaDB*'
exclude '**/MariaDB4j*'
exclude '**/EmbeddedTomcatWithSSLConfiguration.java'
}
}
test {
@@ -489,10 +481,8 @@ configurations {
task integrationTest(type:Test) {
description = "Run integration tests (located in src/integrationTest/java). Starts Tomcat in daemon mode before executing the tests (and stops it after)."
dependsOn war
dependsOn tomcatRunWarAsDaemonForIntegrationTest
tasks.findByName('tomcatRunWarAsDaemonForIntegrationTest').mustRunAfter 'war'
finalizedBy tomcatStopAfterIntegrationTest
dependsOn cargoStartLocal
finalizedBy cargoStopLocal
testClassesDirs = project.sourceSets.integrationTest.output.classesDirs
classpath = project.sourceSets.integrationTest.runtimeClasspath
@@ -576,11 +566,11 @@ def qualifyVersionIfNecessary(version) {
}
springBoot {
mainClassName = 'org.apache.fineract.ServerWithMariaDB4jApplication'
mainClassName = 'org.apache.fineract.ServerApplication'
}
bootWar {
mainClassName = 'org.apache.fineract.ServerWithMariaDB4jApplication'
mainClassName = 'org.apache.fineract.ServerApplication'
}
// To generate an HTML report instead of XML
+21 -15
View File
@@ -17,25 +17,26 @@
* under the License.
*/
dependencies {
tomcat "org.apache.tomcat.embed:tomcat-embed-core",
"org.apache.tomcat.embed:tomcat-embed-logging-log4j" // NOT tomcat-embed-logging-juli (http://stackoverflow.com/questions/23963049/classcircularityerror-java-util-logging-logrecord-running-gradle-webapp-with-ja)
tomcat("org.apache.tomcat.embed:tomcat-embed-jasper") {
exclude group: 'org.eclipse.jdt.core.compiler', module: 'ecj'
}
providedRuntime('org.springframework.boot:spring-boot-starter-tomcat')
spotbugsPlugins 'jp.skypencil.findbugs.slf4j:bug-pattern:1.4.2@jar'
providedRuntime("org.springframework.boot:spring-boot-starter-tomcat")
spotbugsPlugins "jp.skypencil.findbugs.slf4j:bug-pattern:1.4.2@jar"
compile ('org.springframework.boot:spring-boot-starter-data-jpa') {
exclude group: 'org.hibernate'
}
compile ('com.amazonaws:aws-java-sdk-s3') {
exclude group: 'commons-logging'
}
compile ('org.mnode.ical4j:ical4j') {
exclude group: 'commons-logging'
}
api(
'com.google.code.gson:gson',
'org.springframework:spring-jms',
'joda-time:joda-time',
'org.mnode.ical4j:ical4j',
'com.google.guava:guava',
'org.springframework:spring-context-support',
'org.springframework.security.oauth:spring-security-oauth2',
@@ -44,13 +45,15 @@ dependencies {
'jakarta.jms:jakarta.jms-api',
'jakarta.management.j2ee:jakarta.management.j2ee-api'
)
api ('org.apache.openjpa:openjpa') {
exclude group: 'org.eclipse.persistence'
exclude group: 'org.apache.geronimo.specs'
}
api('org.quartz-scheduler:quartz') {
exclude group: 'com.zaxxer', module: 'HikariCP-java7'
}
api('org.quartz-scheduler:quartz') {
exclude group: 'com.zaxxer', module: 'HikariCP-java7'
}
implementation(
//'ch.vorburger.mariaDB4j:mariaDB4j:2.4.0',
@@ -73,6 +76,7 @@ dependencies {
'org.apache.commons:commons-email',
'org.apache.commons:commons-lang3',
'org.apache.commons:commons-io',
'org.drizzle.jdbc:drizzle-jdbc',
@@ -84,7 +88,6 @@ dependencies {
'com.googlecode.flyway:flyway-core',
'com.amazonaws:aws-java-sdk-s3',
'net.sf.ehcache:ehcache',
'com.github.spullara.mustache.java:compiler',
'com.jayway.jsonpath:json-path',
@@ -108,7 +111,6 @@ dependencies {
'com.google.code.gson:gson',
'org.springframework:spring-jms',
'joda-time:joda-time',
'org.mnode.ical4j:ical4j',
'com.google.guava:guava',
'org.apache.poi:poi-ooxml',
'org.springframework:spring-context-support',
@@ -117,9 +119,13 @@ dependencies {
exclude group: 'regexp'
}
testCompile ('io.rest-assured:rest-assured') {
exclude group: 'commons-logging'
exclude group: 'org.apache.sling'
}
testCompile ('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'com.jayway.jsonpath', module: 'json-path'
}
testCompile ('org.mnode.ical4j:ical4j') {
exclude group: 'commons-logging'
}
}
@@ -161,4 +161,4 @@ public class SchedulerJobHelper {
}
}
}
}
}
@@ -18,14 +18,15 @@
*/
package org.apache.fineract;
import java.io.IOException;
import org.apache.fineract.infrastructure.core.boot.AbstractApplicationConfiguration;
import org.apache.fineract.infrastructure.core.boot.ApplicationExitUtil;
import org.apache.fineract.infrastructure.core.boot.EmbeddedTomcatWithSSLConfiguration;
import org.apache.fineract.infrastructure.core.boot.db.DataSourceConfiguration;
import org.apache.fineract.infrastructure.core.boot.db.DataSourceProperties;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.ImportResource;
/**
* Fineract main() application which launches Fineract in an embedded Tomcat HTTP
@@ -40,17 +41,26 @@ import org.springframework.context.annotation.Import;
*
* It's the old/classic Mifos (non-X) Workspace 2.0 reborn for Fineract! ;-)
*
* @see DataSourceProperties about how to configure the DataSource used
* @see ServerWithMariaDB4jApplication for an alternative with an embedded DB
*/
public class ServerApplication {
@Import({ DataSourceConfiguration.class, EmbeddedTomcatWithSSLConfiguration.class })
public class ServerApplication extends SpringBootServletInitializer {
@Import({ EmbeddedTomcatWithSSLConfiguration.class })
@ImportResource({ "classpath*:META-INF/spring/hikariDataSource.xml" })
private static class Configuration extends AbstractApplicationConfiguration { }
public static void main(String[] args) throws Exception {
ConfigurableApplicationContext ctx = SpringApplication.run(Configuration.class, args);
ApplicationExitUtil.waitForKeyPressToCleanlyExit(ctx);
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(Configuration.class);
}
}
private static SpringApplicationBuilder configureApplication(SpringApplicationBuilder builder) {
return builder.sources(Configuration.class);
}
public static void main(String[] args) throws IOException {
ConfigurableApplicationContext ctx = configureApplication(new SpringApplicationBuilder(ServerApplication.class)).run(args);
//ApplicationExitUtil.waitForKeyPressToCleanlyExit(ctx);
}
}
@@ -21,11 +21,11 @@ package org.apache.fineract.infrastructure.core.boot;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import org.apache.catalina.connector.Connector;
import org.apache.commons.io.FileUtils;
import org.apache.coyote.http11.Http11NioProtocol;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
import org.springframework.boot.web.servlet.server.ServletWebServerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
@@ -34,10 +34,10 @@ import org.springframework.core.io.Resource;
@Configuration
public class EmbeddedTomcatWithSSLConfiguration {
// http://docs.spring.io/spring-boot/docs/1.1.5.RELEASE/reference/htmlsingle/#howto-enable-multiple-connectors-in-tomcat
// https://docs.spring.io/spring-boot/docs/2.2.6.RELEASE/reference/html/howto.html#howto-enable-multiple-connectors-in-tomcat
@Bean
public TomcatServletWebServerFactory servletContainer() {
public ServletWebServerFactory servletContainer() {
TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory();
tomcat.setContextPath(getContextPath());
tomcat.addAdditionalTomcatConnectors(createSslConnector());
@@ -53,16 +53,12 @@ public class EmbeddedTomcatWithSSLConfiguration {
Http11NioProtocol protocol = (Http11NioProtocol) connector.getProtocolHandler();
try {
File keystore = getFile(getKeystore());
File truststore = keystore;
connector.setScheme("https");
connector.setSecure(true);
connector.setPort(getHTTPSPort());
protocol.setSSLEnabled(true);
protocol.setKeystoreFile(keystore.getAbsolutePath());
protocol.setKeystorePass(getKeystorePass());
protocol.setTruststoreFile(truststore.getAbsolutePath());
protocol.setTruststorePass(getKeystorePass());
// ? protocol.setKeyAlias("apitester");
return connector;
} catch (IOException ex) {
throw new IllegalStateException("can't access keystore: [" + "keystore" + "] or truststore: [" + "keystore" + "]", ex);
@@ -1,53 +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.fineract.infrastructure.core.boot;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.annotation.ImportResource;
/**
* Required to still have a working legacy "classic" WAR.
*
* Configuration just adds the JNDI-based DataSource lookup to its
* AbstractApplicationConfiguration.
*
* This (intentionally) only configures the original (pre-Spring Boot &
* MariaDB4j) fineract Spring Beans, and does NOT include the embedded Tomcat
* (incl. TomcatSSLConfiguration) nor the MariaDB4jSetupService or
* MariaDB4jDataSourceConfiguration, and not even the DataSourceConfiguration
* (as it uses "classic" JNDI) - we want the WAR to "work like before".
*
* @see <a
* href="http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#howto-convert-an-existing-application-to-spring-boot">#howto-convert-an-existing-application-to-spring-boot</a>
*/
public class WarWebApplicationInitializer extends SpringBootServletInitializer {
@ImportResource({ "classpath*:META-INF/spring/hikariDataSource.xml" })
private static class Configuration extends AbstractApplicationConfiguration {
}
@Override
protected SpringApplicationBuilder configure(
SpringApplicationBuilder application) {
// let's share Spring Boot Love, so no showBanner(false)
return application.sources(Configuration.class);
}
}