equinox with slf4j can't find logback provider - osgi

So I have this OSGi project built with equinox with this gradle structure:
> Task :projects
------------------------------------------------------------
Root project 'project'
------------------------------------------------------------
Root project 'project'
No sub-projects
Included builds
+--- Included build ':callable-processor'
+--- Included build ':osgi-sun-misc'
+--- Included build ':path-collector'
+--- Included build ':robot-api'
+--- Included build ':robot-equinox'
+--- Included build ':robot-signal'
+--- Included build ':robot-instance'
+--- Included build ':utils'
\--- Included build ':reactive'
Main bundle is robot-equinox.
On the root (project), I have the following build.gradle configuration:
// project
ext.baseVersion = '2.0.0'
ext.buildTag = "SNAPSHOT"
group 'project'
version "${baseVersion}-${buildTag}"
project {
quality = ALFA
}
configurations {
bundleInstall
bundleStart
misc
}
dependencies {
bundleInstall 'ch.qos.logback:logback-classic:1.3.5'
bundleInstall 'ch.qos.logback:logback-core:1.3.5'
bundleInstall 'org.slf4j:slf4j-api:2.0.5'
bundleInstall 'org.apache.aries.spifly:org.apache.aries.spifly.dynamic.bundle:1.3.5'
bundleInstall 'prodist:callable-processor'
bundleInstall 'prodist:osgi-sun-misc'
bundleInstall 'prodist:path-collector'
bundleInstall 'prodist:reactive'
bundleInstall 'prodist:robot-api'
bundleStart 'ch.qos.logback:logback-classic:1.3.5'
bundleStart 'ch.qos.logback:logback-core:1.3.5'
bundleStart 'org.slf4j:slf4j-api:2.0.5'
bundleStart 'prodist:robot-equinox'
}
And under robot-equinox I have the following configuration:
dependencies {
implementation group: 'prodist', name: 'callable-processor'
implementation group: 'prodist', name: 'path-collector'
implementation group: 'prodist', name: 'robot-api'
implementation group: 'prodist', name: 'reactive'
implementation group: 'prodist', name: 'robot-instance'
implementation group: 'prodist', name: 'utils'
compileOnly group: 'org.osgi', name: 'osgi.core', version: '6.0.0'
testImplementation group: 'org.hamcrest', name: 'hamcrest', version: '2.2'
testImplementation group: 'org.mockito', name: 'mockito-core', version: '3.2.4'
testImplementation group: 'org.reactivestreams', name: 'reactive-streams-tck', version: '1.0.3'
testImplementation group: 'org.testng', name: 'testng', version: '7.1.0'
testCompileOnly group: 'org.osgi', name: 'osgi.core', version: '6.0.0'
}
I'll give a sample of my log implementation on the main class, which is present under 'project'.
Application.java
package project.robot.equinox;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.*;
import java.security.SecureRandom;
import java.util.*;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.IntStream;
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleException;
import org.reactivestreams.Subscriber;
import org.reactivestreams.Subscription;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MDC;
public class Application {
private static final Logger logger = LoggerFactory.getLogger(Application.class);
public Application ()
{
MDC.put("product.name", ProductInfo.getName());
MDC.put("product.version", ProductInfo.getVersion());
}
public void activate (BundleContext bundleContext)
{
logger.atTrace().log(_S("activate: enter"));
}
...
}
But when I start the Application, I'm getting this message on the osgi console:
osgi> SLF4J: No SLF4J providers were found.
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See https://www.slf4j.org/codes.html#noProviders for further details.
My expectation was that by installing both - slf4j and logback, slf4j would recognize logback implementation and would work.
How can I solve this problem?

Ok, so I found a solution and I'm going to post it here so it help someone else facing this same issue.
In order to help SLF4J find his provider, I create a new bundle osgi-log - a "log bundle" with this configuration:
group 'project'
version '2.0.0'
dependencies {
api group: 'org.slf4j', name: 'slf4j-api', version: '2.0.5'
implementation group: 'ch.qos.logback', name: 'logback-classic', version: '1.3.5'
implementation group: 'ch.qos.logback', name: 'logback-core', version: '1.3.5'
implementation group: 'org.ow2.asm', name: 'asm', version: '5.2'
implementation group: 'org.ow2.asm', name: 'asm-commons', version: '5.2'
implementation group: 'org.ow2.asm', name: 'asm-util', version: '5.2'
implementation group: 'org.apache.aries.spifly', name: 'org.apache.aries.spifly.dynamic.bundle', version: '1.3.5'
}
And then, in each bundle who uses log, I added the following dependency:
dependencies {
(...)
implementation group: 'project', name: 'osgi-log'
}
And when I started my application, the message about provider was gone and log was being registered as expected.
I came to conclusion that Apache Aries spifly offers a ServiceLoader to SLF4J and helps him find provider, which in my case is logback.

Related

Building app with spring-boot + Cassandra, getting "Unable to load class 'com.datastax.oss.driver.api.mapper.entity.naming.GetterStyle'"

Facing isssue while integration with datastax with cassandra
gradle file :
plugins {
id 'org.springframework.boot' version '2.3.12.RELEASE'
id 'io.spring.dependency-management' version '1.0.13.RELEASE'
id 'java'
id 'org.sonarqube' version '3.2.0'
}
group = 'in.demo'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '11'
def javaDriverVersion ='4.14.1'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
}
dependencies {
implementation ('org.springframework.boot:spring-boot-starter')
compileOnly 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
implementation('org.springframework.boot:spring-boot-starter-web') {
exclude module: 'spring-boot-starter-tomcat'
exclude group: 'com.fasterxml.jackson.core', module: 'jackson-core'
exclude group: 'com.fasterxml.jackson.core', module: 'jackson-databind'
exclude group: 'com.fasterxml.jackson.core', module: 'jackson-annotations'
}
implementation('org.springframework.boot:spring-boot-starter-jetty')
implementation('org.springframework.boot:spring-boot-starter-webflux')
runtimeOnly('org.springframework.boot:spring-boot-devtools')
// datastax driver
implementation group: 'com.datastax.oss', name: 'java-driver-core', version: javaDriverVersion
implementation group: 'com.datastax.oss', name: 'java-driver-query-builder', version: javaDriverVersion
//implementation group: 'com.datastax.oss', name: 'java-driver-mapper-runtime', version: javaDriverVersion
implementation group: 'com.datastax.oss', name: 'native-protocol', version: '1.5.0'
annotationProcessor group: 'com.datastax.oss', name: 'java-driver-mapper-processor', version: javaDriverVersion
//compileOnly group: 'com.datastax.oss', name: 'java-driver-mapper-processor', version: '4.14.1'
compileOnly group: 'com.datastax.oss', name: 'java-driver-mapper-runtime', version: javaDriverVersion
implementation 'org.mapstruct:mapstruct:1.3.1.Final'
annotationProcessor 'org.mapstruct:mapstruct-processor:1.3.1.Final'
}
tasks.named('test') {
useJUnitPlatform()
}
#Data
#AllArgsConstructor
#NoArgsConstructor
#Entity(defaultKeyspace = "quest_test")
public class TestTable {
private UUID id;
private String name;
}
import com.datastax.oss.driver.api.mapper.annotations.Dao;
import com.datastax.oss.driver.api.mapper.annotations.Select;
#Dao
public interface TestTableDao {
#Select
TestTable findById();
}
import com.datastax.oss.driver.api.mapper.annotations.DaoFactory;
import com.datastax.oss.driver.api.mapper.annotations.Mapper;
#Mapper
public interface TestTableMapper {
#DaoFactory
TestTableDao testTableDao();
}
getting error
Unable to load class 'com.datastax.oss.driver.api.mapper.entity.naming.GetterStyle'.
i tried to interaction with different project also but still not able to solve issue
. for testing part i added library mappstruct which is generation code on compile time
With drivers 4x+, you need to declare an annotation processor for the mappers code to be generated at build time.
Gradle file
dependencies {
annotationProcessor group: 'com.datastax.oss', name: 'java-driver-mapper-processor', version: javaDriverVersion
compile group: 'com.datastax.oss', name: 'java-driver-mapper-runtime', version: javaDriverVersion
}
Documentation
Here more code to work with Driver 4x
You might be interested in the full-fledged Spring PetClinic application running with your technical stack.

running app as jar gives fileNotFoundException

Im attempting to run my spring app as a jar, but i get the below error
java.io.FileNotFoundException: class path resource [org/springframework/web/socket/config/annotation/AbstractWebSocketMessageBrokerConfigurer.class] cannot be opened because it does not exist
It runs fine from intelij(as in my main class can runs using the play button). I find the file under project structure --> Libraries and under external libraries (albeit depracted)
Ive tried to look into it, but everywhere (list of examples below) seem to talk about xml files instead of a class
Spring ClassPathResource - cannot be opened because it does not exist
Class path resource cannot be opened because it does not existHow to avoid "class path resource [...] cannot be opened because it does not exist" in a spring boot application?
java.io.FileNotFoundException: class path resource can't be opened
java.io.FileNotFoundException: class path resource cannot be opened because it does not exist
My gradle file:
plugins {
id 'org.springframework.boot' version '2.2.4.RELEASE'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
id 'war'
id 'groovy'
// id 'java'
}
war {
enabled = true
}
jar {
manifest {
attributes 'Main-Class': 'co.za.ebucks.HandlingRewardsFormSubmission'
}
}
group = 'co.za.ebucks'
version = '1.0.0'
sourceCompatibility = '1.8'
repositories {
mavenCentral()
}
ext {
seleniumVersion = '3.141.59'
}
configurations {
developmentOnly
runtimeClasspath {
extendsFrom developmentOnly
}
}
test {
useTestNG()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-tomcat'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-webflux'
// implementation 'org.springframework.session:spring-session-core'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-integration'
implementation 'org.springframework.boot:spring-boot-starter-websocket'
implementation 'org.springframework:spring-messaging'
implementation 'org.springframework.integration:spring-integration-file'
implementation group: 'org.webjars.bower', name: 'angular-ui-router', version: '0.2.8'
implementation group: 'org.webjars', name:'angularjs', version: '1.3.0-beta.11'
implementation group: 'org.webjars', name: 'bootstrap', version: '3.1.1-1'
// implementation 'org.webjars.bower:angular-ui-router'//, version: '1.0.20'
implementation 'commons-io:commons-io'//, version: '2.4'
implementation 'org.apache.commons:commons-dbcp2'//, version: '2.7.0'
implementation 'org.hibernate.validator:hibernate-validator'//, version: '6.1.2.Final'
// implementation 'nz.net.ultraq.thymeleaf:thymeleaf-layout-dialect'//, version: '2.4.1'
implementation 'javax.servlet:javax.servlet-api'//, version: '4.0.1'
// compile group: 'org.apache.tomcat', name: 'tomcat-jni', version: '9.0.33'
implementation group: 'de.codecentric', name: 'spring-boot-admin-starter-client', version: '2.2.2'
implementation group: 'de.codecentric', name: 'spring-boot-admin-server', version: '2.2.2'
implementation group: 'org.testng', name: 'testng', version: '7.1.0'
implementation group: 'org.codehaus.groovy', name: 'groovy-all', version: '3.0.0'
implementation group: 'com.google.inject', name: 'guice', version: '4.2.2'
implementation group: 'com.google.guava', name: 'guava', version: '28.1-jre'
implementation group: 'cglib', name: 'cglib', version: '3.3.0'
implementation group: 'org.postgresql', name: 'postgresql', version: '42.2.10'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
testImplementation 'io.projectreactor:reactor-test'
implementation "org.seleniumhq.selenium:selenium-support:${seleniumVersion}"
implementation group: 'io.appium', name: 'java-client', version: '7.3.0'
implementation group: 'org.seleniumhq.selenium', name: 'selenium-java', version: "${seleniumVersion}"
implementation group: 'org.seleniumhq.selenium', name: 'selenium-server', version: "${seleniumVersion}"
implementation group: 'org.seleniumhq.selenium', name: 'selenium-chrome-driver', version: "${seleniumVersion}"
testImplementation group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.13.0'
testImplementation group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.13.0'
testImplementation group: 'org.testng', name: 'testng', version: '7.1.0'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
}
And what Im sure is the class in question:
import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.web.socket.config.annotation.AbstractWebSocketMessageBrokerConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry
import org.springframework.web.socket.server.support.DefaultHandshakeHandler;
#Configuration
#EnableWebSocketMessageBroker
class WebSocketDefaultConfig extends AbstractWebSocketMessageBrokerConfigurer {
#Override
void configureMessageBroker(MessageBrokerRegistry config) {
// config.enableStompBrokerRelay("/topic/", "/queue/");
config.enableSimpleBroker("/topic/", "/queue/");
config.setApplicationDestinationPrefixes("/app");
}
#Override
void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/tailfilesep")
// .setAllowedOrigins("*")
// .setHandshakeHandler(new DefaultHandshakeHandler())
.withSockJS()
}
}
Kindly assist me, this has passed frustration. Why is that class not in the jar?
The only thing that worked was creating a new project - copy and pasted all the code, build files everything... lol and its fine.
Intelij corruption somewhere along the line

The import cucumber cannot be resolved in Runner Class for Gradle Project

I don't whats wrong with my Gradle Dependencies but when I try to import import cucumber.api.junit.Cucumber; then I get error The import cucumber cannot be resolved
Below is my Gradle file:
apply plugin: 'java'
version = '1.0-SNAPSHOT'
dependencies {
compile group: 'info.cukes', name: 'cucumber-java', version: '1.2.5'
testCompile group: 'info.cukes', name: 'cucumber-junit', version: '1.2.5'
compile group: 'info.cukes', name: 'cucumber-core', version: '1.2.5'
testCompile group: 'info.cukes', name: 'cucumber-picocontainer', version: '1.2.5'
compile group: 'info.cukes', name: 'cucumber-guice', version: '1.2.5'
testCompile group: 'junit', name: 'junit', version: '4.12'
}
repositories {
mavenCentral()
}
My Runner Class is:
package Runner;
import org.junit.runner.RunWith;
import cucumber.api.junit.CucumberOptions;
import cucumber.api.junit.Cucumber;
#RunWith(Cucumber.class)
Cucumber.options(
features = "\\src\\test\\java\\Feature",
glue = {"\\src\\main\\java\\Steps\\"},
tags = {"#ignored"},
format = {"json:target/cucumber/wikipedia.json","html:target/cucumber/wikipedia.html","pretty"}
)
public class RunnerMain {
}
When I comment #RunWith, CucumberOptions and remove the imports, then run command gradle build then I don't see any error and all goes well.
I don't know what wrong I am doing here.
Replace Cucumber.options with #CucumberOptions and try once

Karate Gatling with gradle build is not working [duplicate]

This question already has answers here:
How to run Karate and Gatling with Gradle build system
(2 answers)
Closed 1 year ago.
I am trying to run gatling with karate in gradle build and getting below error,
/smoketests/SmokeTestRunner.java:19: error: package org.junit.runner does not exist
import org.junit.runner.RunWith;
^
/smoketests/SmokeTestRunner.java:21: error: package com.intuit.karate.junit4 does not exist
import com.intuit.karate.junit4.Karate;
^
/smoketests/SmokeTestRunner.java:30: error: cannot find symbol
#RunWith(Karate.class)
^
symbol: class RunWith
/wskadmin/WskAdminRunner.java:19: error: package org.junit does not exist
import org.junit.Test;
^
/wskadmin/WskAdminRunner.java:20: error: package org.junit.runner does not exist
import org.junit.runner.RunWith;
^
/wskadmin/WskAdminRunner.java:22: error: package com.intuit.karate.junit4 does not exist
import com.intuit.karate.junit4.Karate;
and exception as
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':compileGatlingScala'.
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:100)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:70)
at org.gradle.api.internal.tasks.execution.OutputDirectoryCreatingTaskExecuter.execute(OutputDirectoryCreatingTaskExecuter.java:51)
at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:62)
at org.gradle.api.internal.tasks.execution.ResolveTaskOutputCachingStateExecuter.execute(ResolveTaskOutputCachingStateExecuter.java:54)
at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:60)
For more information,
below is my build.gradle file,
plugins {
id "com.github.lkishalmi.gatling" version "0.7.3"
}
apply plugin: 'java'
apply plugin: 'maven'
group = 'karate-gatling'
version = '1.0-SNAPSHOT'
sourceCompatibility = 1.8
targetCompatibility = 1.8
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
repositories {
mavenCentral()
maven { url "http://repo.maven.apache.org/maven2" }
}
sourceSets {
gatling {
scala.srcDirs = ['src/test/java']
}
test {
java
{
srcDir file('src/test/java')
// exclude '**/*.java'
}
resources
{
srcDir file('src/test/java')
// exclude '**/*.java'
}
}
}
dependencies {
compile group: 'com.jcraft', name: 'jsch', version:'0.1.53'
compile group: 'org.apache.logging.log4j', name: 'log4j-api', version:'2.10.0'
compile group: 'org.apache.logging.log4j', name: 'log4j-core', version:'2.10.0'
compile group: 'com.intuit.karate', name: 'karate-netty', version:'0.8.0.1'
testCompile group: 'net.masterthought', name: 'cucumber-reporting', version:'3.8.0'
testCompile group: 'com.intuit.karate', name: 'karate-apache', version:'0.8.0.1'
testCompile group: 'com.intuit.karate', name: 'karate-junit4', version:'0.8.0.1'
testCompile group: 'com.intuit.karate', name: 'karate-gatling', version:'0.8.0.1'
gatling 'com.intuit.karate:karate-gatling:0.8.0.1'
gatling 'com.google.code.gson:gson:2.8.0'
gatling 'org.apache.httpcomponents:httpclient:4.3.2'
gatlingCompile 'org.apache.commons:commons-lang3:3.4'
gatlingRuntime 'cglib:cglib-nodep:3.2.0'
}
gatling {
sourceRoot = 'src/test/java'
toolVersion = '2.3.1'
}
to run my simulation class i am using below command,
./gradlew clean gatlingRun-mypackage.LoadTest
Below is my LoadTest.scala file
class LoadTest extends Simulation {
before{
println("Simulation is about to start!")
}
val createActionTest = scenario("smoke").exec(karateFeature("classpath:path/myfeature.feature"))
setUp(createActionTest.inject(rampUsers(5) over (5 seconds))
).maxDuration(1 minutes).assertions(global.responseTime.mean.lt(1100))
after {
println("Simulation is finished!")
}
}
And below is my runner file
import org.junit.runner.RunWith;
import com.intuit.karate.junit4.Karate;
import cucumber.api.CucumberOptions;
#RunWith(Karate.class)
#CucumberOptions(tags = {"~#ignore","~#driver","~#reliability","~#resiliency","~#concurrent","~#wskfunctions"})
public class SmokeTestRunner {
}
Any help on this is really appriciated
You need to add a testCompile dependency on JUnit, such as:
testCompile 'junit:junit:4.12'
gradle karate karate-gatling junit gradle-gatling-plugin

WebApplicationInitializer is not launched on jetty+selenium

i am trying to run selenium test on jetty using gradle and my gradle configuration is as follows:
gradle.build:
apply plugin: 'java'
apply plugin: 'eclipse-wtp'
apply plugin: 'war'
apply plugin: 'findbugs'
//apply from:'http://github.com/breskeby/gradleplugins/raw/master/emmaPlugin/emma.gradle'
apply from: 'emma.gradle'
apply plugin: 'jetty'
sourceCompatibility = 1.7
version = ''
sourceSets {
selenium
}
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'org.gradle.api.plugins:gradle-cargo-plugin:0.6'
}
}
repositories {
mavenCentral()
mavenRepo url: 'http://repository.primefaces.org'
mavenRepo url: 'http://repository.jboss.org/nexus/content/groups/public'
mavenRepo url: 'http://repository.jboss.org/maven2'
mavenRepo url: 'http://maven.springframework.org/release'
mavenRepo url: 'http://repo1.maven.org/maven2'
mavenRepo url: 'http://git.solutionstream.com/nexus/content/repositories/thirdparty'
}
dependencies {
//JSF
compile group: 'com.sun.faces', name: 'jsf-api', version: '2.1.22'
compile group: 'com.sun.faces', name: 'jsf-impl', version: '2.1.22'
compile 'org.ocpsoft.rewrite:rewrite-servlet:2.0.3.Final'
compile 'org.ocpsoft.rewrite:rewrite-config-prettyfaces:2.0.3.Final'
compile 'javax.el:el-api:2.2'
runtime 'org.glassfish.web:el-impl:2.2'
//Servlet
compile group: 'javax.servlet', name: 'jstl', version: '1.2'
providedCompile group: 'org.jboss.spec', name: 'jboss-javaee-6.0', version: '1.0.0.Final'
compile 'taglibs:standard:1.1.2'
compile group: 'org.springframework', name: 'spring-web', version: '3.2.2.RELEASE'
//Omnifaces
compile 'org.omnifaces:omnifaces:1.5'
//Prime Faces
compile group: 'org.primefaces', name: 'primefaces', version: '4.0-SNAPSHOT'
compile 'org.primefaces.themes:bootstrap:1.0.10'
// DB
compile group: 'org.springframework.data', name: 'spring-data-jpa', version: '1.3.1.RELEASE'
compile group: 'org.springframework', name: 'spring-aspects', version: '3.2.2.RELEASE'
compile group: 'mysql', name: 'mysql-connector-java', version: '5.1.9'
compile group: 'javax.inject', name: 'javax.inject', version: '1'
compile group: 'javax.enterprise', name: 'cdi-api', version: '1.0-SP4'
compile 'cglib:cglib-nodep:2.2.2'
//Hibernate / JPA
compile 'org.hibernate:hibernate-core:4.1.0.Final'
compile 'org.hibernate:hibernate-entitymanager:4.1.0.Final'
compile 'org.hibernate.javax.persistence:hibernate-jpa-2.0-api:1.0.1.Final'
//JSR-303
compile 'org.hibernate:hibernate-validator:4.3.1.Final'
// Spring Security
compile 'org.springframework.security:spring-security-core:3.1.4.RELEASE'
compile 'org.springframework.security:spring-security-web:3.1.4.RELEASE'
compile 'org.springframework.security:spring-security-config:3.1.4.RELEASE'
//Utility
compile 'com.google.guava:guava:14.0.1'
compile 'commons-lang:commons-lang:2.6'
compile 'org.apache.commons:commons-email:1.3.1'
compile 'com.typesafe:config:1.0.0'
compile 'joda-time:joda-time:2.2'
compile 'org.apache.geronimo.javamail:geronimo-javamail_1.4_mail:1.8.3'
compile 'org.slf4j:slf4j-api:1.7.2'
compile 'org.slf4j:jcl-over-slf4j:1.7.2'
compile 'org.slf4j:slf4j-log4j12:1.7.2'
//Mustache Templates
compile 'com.github.jknack:handlebars:1.0.0'
//Projects
//compile project(":ExtraValidators")
////TESTING DEPENDENCIES
testCompile 'com.googlecode.jmockit:jmockit:1.2'
testCompile group: 'junit', name: 'junit', version: '4.11'
testCompile 'com.h2database:h2:1.3.172'
//Spring Testing
testCompile 'org.springframework:spring-test:3.2.3.RELEASE'
/* Selenium */
seleniumCompile 'org.seleniumhq.selenium:selenium-java:2.33.0'
seleniumCompile 'junit:junit:4.11'
}
task wrapper(type: Wrapper){
gradleVersion = '1.5'
}
eclipse {
classpath {
downloadSources=true
plusConfigurations += configurations.seleniumCompile
}
}
task jettyDaemon(type: org.gradle.api.plugins.jetty.JettyRun) {
daemon = true
}
task selenium(type: Test, dependsOn: jettyDaemon) {
testClassesDir = sourceSets.selenium.output.classesDir
classpath = sourceSets.selenium.runtimeClasspath
}
WebApplicationInitializer:
package com.myapp.web.config;
import javax.faces.application.ProjectStage;
import javax.servlet.FilterRegistration;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.context.ContextLoader;
import org.springframework.web.context.request.RequestContextListener;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.filter.DelegatingFilterProxy;
import com.myapp.data.config.SpringConfig;
import com.myapp.data.config.SpringJNDIDataConfig;
import com.myapp.data.config.SpringJNDIJPAConfig;
import com.myapp.data.config.SpringSecurityConfig;
import com.myapp.data.config.SpringWebConfig;
import com.myapp.utils.configuration.ConfigurationUtil;
public class WebappConfig implements WebApplicationInitializer {
protected final Logger logger = LoggerFactory.getLogger(getClass());
#Override
public void onStartup(final ServletContext servletContext) throws ServletException {
if(logger.isDebugEnabled()) {
logger.debug("Starting web context configuration");
}
AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
// rootContext.getEnvironment().setActiveProfiles("production");
rootContext.register(SpringConfig.class, SpringSecurityConfig.class, SpringWebConfig.class, SpringJNDIDataConfig.class, SpringJNDIJPAConfig.class);
servletContext.addListener(RequestContextListener.class);
new ContextLoader(rootContext).initWebApplicationContext(servletContext);
addFilters(servletContext, rootContext.getEnvironment());
servletContext.setInitParameter(ProjectStage.PROJECT_STAGE_PARAM_NAME, ConfigurationUtil.config().getString("jsf.stage"));
servletContext.setInitParameter("javax.faces.FACELETS_REFRESH_PERIOD", ConfigurationUtil.config().getString("jsf.refreshPeriod"));
}
private void addFilters(final ServletContext servletContext, final ConfigurableEnvironment configurableEnvironment) {
FilterRegistration.Dynamic securityFilter = servletContext.addFilter("springSecurityFilterChain", new DelegatingFilterProxy("springSecurityFilterChain"));
securityFilter.addMappingForUrlPatterns(null, false, "/*");
}
}
please advise how to make WebApplicationInitializer runs when running the selenium test on jetty.
WebApplicationInitializer requires a Servlet 3 container. However, Gradle's Jetty plugin is based on Jetty 6 which supports only Servlet 2.5.
You have a few options:
Configure your application with the web.xml file instead of WebApplicationInitializer
Use a newer Jetty version with Gradle. There are some workarounds in the comments of GRADLE-1956
Use an alternative container like Tomcat (gradle-tomcat-plugin)
Use an alternative plugin like gradle-cargo-plugin or arquillian-gradle-plugin. AFAIK there's a new gradle deployment plugin in the works that should be base on Arquillian.

Resources