Spring boot redis connection not working only during junit testing - java

Have a simple project with following config
#Configuration
#EnableRedisRepositories
public class RedisConfig {
#Bean
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory connectionFactory) {
RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
redisTemplate.setConnectionFactory(connectionFactory);
redisTemplate.setHashValueSerializer(new StringRedisSerializer());
redisTemplate.setKeySerializer(new StringRedisSerializer());
redisTemplate.setValueSerializer(new StringRedisSerializer());
redisTemplate.setHashKeySerializer(new StringRedisSerializer());
redisTemplate.afterPropertiesSet();
return redisTemplate;
}
}
application.properties
spring.data.redis.host=localhost
spring.data.redis.port=6379
build.gradle for ref
implementation 'org.springframework.boot:spring-boot-starter-data-redis'
implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation 'org.springframework.boot:spring-boot-starter-aop'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.12.0'
implementation group: 'com.google.guava', name: 'guava', version: '31.1-jre'
compileOnly 'org.projectlombok:lombok:1.18.20'
annotationProcessor 'org.projectlombok:lombok:1.18.20'
The application as such works totally fine, it's able to connect to redis, read/write data. But when I run my JUNITS with the same config, connection keeps failing.
Any idea what might be causing this issue?

ufff, after half a day of gruesome trial and error 😭 realized this in build.gradle was causing the issue.
testImplementation ('it.ozimov:embedded-redis:0.7.3') {
exclude module: 'commons-logging'
exclude module: 'slf4j-simple'
}
I had excluded for brevity sake when wrote the above question here. I would still thank SOF, thank you!

Related

Spring Boot 2.7.6: Java 8 date/time type `java.time.Instant` not supported by default

I know there have been a few duplicates of my question but none have resolved my issue so I'm creating a new question.
I have a spring boot app (v 2.7.6) with JDK17 which queries an ElasticSearch object. This object contains an Instant field which when being mapped to an Java object is causing the following error:
2022-12-07 00:43:14.442 ERROR 59384 --- [nio-8080-exec-2] o.a.c.c.C.[.[.[.[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [/api/v1] threw exception [Request processing failed; nested exception is co.elastic.clients.json.JsonpMappingException: Error deserializing co.elastic.clients.elasticsearch.core.GetResponse: jakarta.json.JsonException: Jackson exception (JSON path: _source) (line no=1, column no=280, offset=-1)] with root cause
com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Java 8 date/time type `java.time.Instant` not supported by default: add Module "com.fasterxml.jackson.datatype:jackson-datatype-jsr310" to enable handling
at [Source: (org.apache.http.nio.entity.ContentInputStream); line: 1, column: 279] (through reference chain: test.com.model.Project["createdDate"])
at com.fasterxml.jackson.databind.exc.InvalidDefinitionException.from(InvalidDefinitionException.java:67) ~[jackson-databind-2.14.1.jar:2.14.1]
at com.fasterxml.jackson.databind.DeserializationContext.reportBadDefinition(DeserializationContext.java:1909) ~[jackson-databind-2.14.1.jar:2.14.1]
at com.fasterxml.jackson.databind.deser.impl.UnsupportedTypeDeserializer.deserialize(UnsupportedTypeDeserializer.java:48) ~[jackson-databind-2.14.1.jar:2.14.1]
at com.fasterxml.jackson.databind.deser.impl.MethodProperty.deserializeAndSet(MethodProperty.java:129) ~[jackson-databind-2.14.1.jar:2.14.1]
at com.fasterxml.jackson.databind.deser.BeanDeserializer.vanillaDeserialize(BeanDeserializer.java:314) ~[jackson-databind-2.14.1.jar:2.14.1]
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:177) ~[jackson-databind-2.14.1.jar:2.14.1]
at com.fasterxml.jackson.databind.deser.DefaultDeserializationContext.readRootValue(DefaultDeserializationContext.java:323) ~[jackson-databind-2.14.1.jar:2.14.1]
at com.fasterxml.jackson.databind.ObjectMapper._readValue(ObjectMapper.java:4706) ~[jackson-databind-2.14.1.jar:2.14.1]
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2879) ~[jackson-databind-2.14.1.jar:2.14.1]
at co.elastic.clients.json.jackson.JacksonJsonpMapper$JacksonValueParser.deserialize(JacksonJsonpMapper.java:123) ~[elasticsearch-java-8.5.1.jar:na]
at co.elastic.clients.json.JsonpDeserializer.deserialize(JsonpDeserializer.java:76) ~[elasticsearch-java-8.5.1.jar:na]
at co.elastic.clients.json.JsonpMapperBase.deserialize(JsonpMapperBase.java:70) ~[elasticsearch-java-8.5.1.jar:na]
at co.elastic.clients.json.JsonpDeserializer$1.deserialize(JsonpDeserializer.java:99) ~[elasticsearch-java-8.5.1.jar:na]
at co.elastic.clients.json.NamedDeserializer.deserialize(NamedDeserializer.java:64) ~[elasticsearch-java-8.5.1.jar:na]
at co.elastic.clients.json.ObjectDeserializer$FieldObjectDeserializer.deserialize(ObjectDeserializer.java:78) ~[elasticsearch-java-8.5.1.jar:na]
at co.elastic.clients.json.ObjectDeserializer.deserialize(ObjectDeserializer.java:192) ~[elasticsearch-java-8.5.1.jar:na]
at co.elastic.clients.json.ObjectDeserializer.deserialize(ObjectDeserializer.java:148) ~[elasticsearch-java-8.5.1.jar:na]
at co.elastic.clients.json.JsonpDeserializer.deserialize(JsonpDeserializer.java:76) ~[elasticsearch-java-8.5.1.jar:na]
at co.elastic.clients.json.ObjectBuilderDeserializer.deserialize(ObjectBuilderDeserializer.java:79) ~[elasticsearch-java-8.5.1.jar:na]
at co.elastic.clients.json.DelegatingDeserializer$SameType.deserialize(DelegatingDeserializer.java:43) ~[elasticsearch-java-8.5.1.jar:na]
at co.elastic.clients.json.DelegatingDeserializer$SameType.deserialize(DelegatingDeserializer.java:43) ~[elasticsearch-java-8.5.1.jar:na]
at co.elastic.clients.transport.endpoints.EndpointWithResponseMapperAttr$1.deserialize(EndpointWithResponseMapperAttr.java:56) ~[elasticsearch-java-8.5.1.jar:na]
at co.elastic.clients.transport.rest_client.RestClientTransport.decodeResponse(RestClientTransport.java:325) ~[elasticsearch-java-8.5.1.jar:na]
at co.elastic.clients.transport.rest_client.RestClientTransport.getHighLevelResponse(RestClientTransport.java:295) ~[elasticsearch-java-8.5.1.jar:na]
at co.elastic.clients.transport.rest_client.RestClientTransport.performRequest(RestClientTransport.java:148) ~[elasticsearch-java-8.5.1.jar:na]
at co.elastic.clients.elasticsearch.ElasticsearchClient.get(ElasticsearchClient.java:831) ~[elasticsearch-java-8.5.1.jar:na]
at co.elastic.clients.elasticsearch.ElasticsearchClient.get(ElasticsearchClient.java:847) ~[elasticsearch-java-8.5.1.jar:na]
...
.....
Originally I had no JacksonConfiguration so I would have thought the default jackson would have just worked.
After reading other stackoverflow posts I have tried creating a configuration class like so, but it has not resolved the issue:
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import org.openapitools.jackson.nullable.JsonNullableModule;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import javax.annotation.PostConstruct;
#Configuration
public class JacksonConfiguration {
private final ObjectMapper objectMapper;
public JacksonConfiguration(ObjectMapper objectMapper) {
this.objectMapper = objectMapper;
}
#Bean
public JavaTimeModule dateTimeModule(){
return new JavaTimeModule();
}
#PostConstruct
ObjectMapper jacksonObjectMapper() {
objectMapper.registerModule(new JavaTimeModule());
objectMapper.registerModule(new JsonNullableModule());
return objectMapper;
}
}
Here are also my dependancies:
dependencies {
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-data-mongodb'
implementation group: 'org.springframework.data', name: 'spring-data-elasticsearch', version: '5.0.0'
implementation 'org.elasticsearch.client:elasticsearch-rest-client:8.5.2'
implementation 'co.elastic.clients:elasticsearch-java:8.5.1'
implementation 'org.elasticsearch.client:elasticsearch-rest-high-level-client:7.17.6'
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-security'
implementation group: 'org.springframework.security', name: 'spring-security-oauth2-client'
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-validation'
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-oauth2-resource-server'
// implementation("org.springframework.boot:spring-boot-starter-actuator")
implementation 'org.apache.httpcomponents.client5:httpclient5:5.0.3'
implementation 'org.springdoc:springdoc-openapi-ui:1.6.13'
implementation 'org.springdoc:springdoc-openapi-security:1.6.13'
implementation 'org.springdoc:springdoc-openapi-webmvc-core:1.6.13'
implementation 'org.springdoc:springdoc-openapi-webflux-core:1.6.13'
implementation 'org.springdoc:springdoc-openapi-webflux-ui:1.6.13'
implementation("org.springframework.cloud:spring-cloud-gcp-starter-pubsub:1.2.8.RELEASE")
implementation("org.springframework.integration:spring-integration-core")
implementation group: 'org.springframework.cloud', name: 'spring-cloud-gcp-starter-logging'
implementation group: 'org.springframework.cloud', name: 'spring-cloud-gcp-starter-logging', version: '1.2.8.RELEASE'
implementation group: 'co.elastic.logging', name: 'logback-ecs-encoder', version: '1.3.2'
implementation group: 'com.amazonaws', name: 'aws-java-sdk', version: '1.12.142'
implementation group: 'javax.validation', name: 'validation-api', version: '2.0.1.Final'
// implementation group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-jsr310', version: '2.13.1'
implementation group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-jsr310', version: '2.14.1'
implementation group: 'io.jsonwebtoken', name: 'jjwt', version: '0.9.1'
implementation group: 'org.json', name: 'json', version: '20201115'
implementation group: 'org.openapitools', name: 'jackson-databind-nullable', version: '0.2.2'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.14.1'
implementation 'jakarta.json:jakarta.json-api:2.0.1'
implementation group: 'org.apache.commons', name: 'commons-collections4', version: '4.4'
implementation 'commons-io:commons-io:2.11.0'
implementation 'org.apache.commons:commons-lang3:3.12.0'
implementation 'com.google.guava:guava:31.0.1-jre'
implementation group: 'com.auth0', name: 'java-jwt', version: '3.12.0'
implementation group: 'com.auth0', name: 'auth0', version: '1.34.1'
annotationProcessor "org.springframework.boot:spring-boot-configuration-processor"
implementation group: 'commons-codec', name: 'commons-codec', version: '1.15'
compileOnly 'org.projectlombok:lombok:1.18.24'
annotationProcessor 'org.projectlombok:lombok:1.18.22'
implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation group: 'junit', name: 'junit', version: '4.13.2'
testImplementation 'org.projectlombok:lombok:1.18.20'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.20'
testImplementation 'org.junit.jupiter:junit-jupiter-api'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
}
Two things, add the dependency the error log talks about (which I see you did) and then create a objectmapper bean in your spring configs for your service to use. Please remove what you have in the config class above and simply it to just this one bean method:
#Bean
ObjectMapper jacksonObjectMapper() {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.registerModule(new JavaTimeModule());
return objectMapper;
}

java.lang.IllegalArgumentException: LoggerFactory is not a Logback LoggerContext but Logback is on the classpath

I am getting the following error when I build my project, I tried various other StackOverflow answers but all in vain.
Also tried to exclude logback from all the dependencies,
configurations {
implementation {
exclude group: 'ch.qos.logback', module: 'logback-classic'
}
}
And the above does solve the problem but gives another error java.lang.NoClassDefFoundError: ch/qos/logback/classic/turbo/TurboFilter, seems like it is using logback some place else and hence logback cannot be excluded from all the dependencies. Any suggestion on how to get rid of the issue would be really valuable. Thanks.
Error log
Caused by: java.lang.IllegalArgumentException: LoggerFactory is not a
Logback LoggerContext but Logback is on the classpath. Either remove
Logback or the competing implementation (class
org.jboss.slf4j.JBossLoggerFactory loaded from
file:/C:/Users/idnpga/.gradle/caches/modules-2/files-2.1/org.infinispan/infinispan-embedded/9.1.7.Final/6b94fd0e5872b8ce90ab35531afe90d1efaf36f0/infinispan-embedded-9.1.7.Final.jar).
If you are using WebLogic you will need to add 'org.slf4j' to
prefer-application-packages in WEB-INF/weblogic.xml:
org.jboss.slf4j.JBossLoggerFactory at
org.springframework.util.Assert.instanceCheckFailed(Assert.java:696)
at org.springframework.util.Assert.isInstanceOf(Assert.java:596) at
org.springframework.boot.logging.logback.LogbackLoggingSystem.getLoggerContext(LogbackLoggingSystem.java:284)
at
org.springframework.boot.logging.logback.LogbackLoggingSystem.beforeInitialize(LogbackLoggingSystem.java:104)
at
org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationStartingEvent(LoggingApplicationListener.java:232)
at
org.springframework.boot.context.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:213)
at
org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
at
org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
at
org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
at
org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127)
at
org.springframework.boot.context.event.EventPublishingRunListener.starting(EventPublishingRunListener.java:74)
at
org.springframework.boot.SpringApplicationRunListeners.starting(SpringApplicationRunListeners.java:47)
at
org.springframework.boot.SpringApplication.run(SpringApplication.java:305)
at
org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:120)
at
org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:99)
at
org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124)
... 81 more
build.gradle
dependencies {
implementation('org.springframework.boot:spring-boot-starter-actuator')
implementation('org.springframework.boot:spring-boot-starter-amqp')
implementation('org.springframework.boot:spring-boot-starter-data-mongodb')
implementation('org.springframework.boot:spring-boot-starter-data-rest')
implementation('org.springframework.boot:spring-boot-starter-integration')
implementation('org.springframework.boot:spring-boot-starter-security')
implementation('org.springframework.boot:spring-boot-starter-thymeleaf') {
exclude group: 'org.codehaus.groovy', module: 'groovy'
}
implementation('org.springframework.boot:spring-boot-starter-web')
implementation('org.springframework.boot:spring-boot-starter-web-services')
implementation group: 'org.springframework.cloud', name: 'spring-cloud-starter-config', version: '2.0.5.RELEASE'
implementation('org.springframework.data:spring-data-rest-hal-explorer')
implementation('org.springframework.integration:spring-integration-amqp')
implementation('org.springframework.integration:spring-integration-mongodb')
implementation('org.springframework.integration:spring-integration-file')
implementation('org.springframework.integration:spring-integration-http')
implementation('org.springframework.integration:spring-integration-ip')
implementation('org.springframework.integration:spring-integration-sftp')
implementation('org.springframework.integration:spring-integration-stream')
implementation('org.springframework.integration:spring-integration-xml')
implementation('org.springframework.ws:spring-ws-security') {
exclude group: 'org.opensaml:opensaml-saml-impl'
}
implementation ('org.springframework.security:spring-security-oauth2-core') {
exclude group: 'org.codehaus.jackson'
}
implementation group: 'org.springframework.data', name: 'spring-data-mongodb', version: '3.0.4.RELEASE'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation group: 'org.springframework.cloud', name: 'spring-cloud-starter-netflix-hystrix', version: '2.1.5.RELEASE'
implementation 'org.infinispan:infinispan-spring-boot-starter-parent:14.0.0.Dev01'
implementation 'org.infinispan:spring-boot-starter-infinispan-autoconfigure:1.0.0'
implementation('org.infinispan:infinispan-embedded:9.1.7.Final')
implementation group: 'ch.qos.logback', name: 'logback-core', version: '1.2.9'
testImplementation group: 'ch.qos.logback', name: 'logback-core', version: '1.2.9'
implementation group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.9'
testImplementation group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.9'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module : 'junit-vintage-engine'
}
testImplementation('org.springframework.ws:spring-ws-test')
testImplementation("org.springframework.cloud:spring-cloud-contract-wiremock:3.1.1")
testImplementation("org.springframework.cloud:spring-cloud-starter-contract-verifier") {
exclude group: 'org.springframework.boot', module : 'spring-boot-starter-test'
}
}

Spring Boot: Logback Issue with Owasp ESAPI version 2.2.3.1

I've recently started looking at how to sanitise any user inputs to my test api and I came across this tutorial
Before attempting the tutorial I had logging to console with GCP cloud as thats where I want to run my API.
Now after adding owasp esapi my application will not start when using version 2.2.3.1 of esapi. I just by sure luck attempted using a previous version and it works as in the application will start.
Below is the error I get from logback on application start up
SLF4J: Actual binding is of type [org.slf4j.impl.SimpleLoggerFactory]
Exception in thread "main" java.lang.IllegalArgumentException: LoggerFactory is not a Logback LoggerContext but Logback is on the classpath. Either remove Logback or the competing implementation (class org.slf4j.impl.SimpleLoggerFactory loaded from file:/Users/xxx/.gradle/caches/modules-2/files-2.1/org.slf4j/slf4j-simple/1.7.30/e606eac955f55ecf1d8edcccba04eb8ac98088dd/slf4j-simple-1.7.30.jar). If you are using WebLogic you will need to add 'org.slf4j' to prefer-application-packages in WEB-INF/weblogic.xml: org.slf4j.impl.SimpleLoggerFactory
Again, If I use version 2.2.2.0 I have no issues at all on startup. Can anyone with experience shed some light here. (PLEASE SEE EDIT)
Below is my gradle build file (note I'm also using GCP logging)
plugins {
id "org.springframework.boot" version "2.5.0"
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java'
id "idea"
id 'com.google.cloud.tools.jib' version '3.0.0'
}
group 'network.thefullstack.search-service'
version '1.0'
java {
sourceCompatibility = JavaVersion.VERSION_14
targetCompatibility = JavaVersion.VERSION_14
}
jib.from.image = 'openjdk:15-jdk-buster'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-security'
testImplementation group: 'org.springframework.security', name: 'spring-security-test'
implementation group: 'org.springframework.security', name: 'spring-security-oauth2-client'
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-webflux'
implementation('org.springframework.boot:spring-boot-starter-data-elasticsearch')
implementation group: 'org.springframework.data', name: 'spring-data-elasticsearch'
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-validation'
compile group: 'org.springframework.cloud', name: 'spring-cloud-gcp-starter-logging'
implementation group: 'org.springframework.cloud', name: 'spring-cloud-gcp-starter-logging', version: '1.2.8.RELEASE'
implementation group: 'io.springfox', name: 'springfox-swagger-ui', version: '3.0.0'
implementation group: 'io.springfox', name: 'springfox-boot-starter', version: '3.0.0'
implementation group: 'javax.validation', name: 'validation-api', version: '2.0.1.Final'
implementation group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-jsr310', version: '2.11.2'
implementation group: 'org.openapitools', name: 'jackson-databind-nullable', version: '0.2.1'
implementation group: 'commons-io', name: 'commons-io', version: '2.6'
implementation group: 'org.json', name: 'json', version: '20210307'
implementation group: 'org.apache.commons', name: 'commons-collections4', version: '4.4'
implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.11'
implementation 'org.jsoup:jsoup:1.13.1'
implementation 'org.apache.commons:commons-lang3:3.12.0'
implementation 'org.owasp:dependency-check-gradle:6.1.6'
compile (group: 'org.owasp.esapi', name: 'esapi', version: '2.2.2.0')
compileOnly 'org.projectlombok:lombok:1.18.12'
annotationProcessor 'org.projectlombok:lombok:1.18.12'
testCompile group: 'junit', name: 'junit', version: '4.12'
testCompileOnly 'org.projectlombok:lombok:1.18.12'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.12'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
jar {
manifest {
attributes(
'Main-Class': 'org.test.SearchServiceApplication'
)
}
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
}
}
Here is my ESAPI.properties file:
ESAPI.Logger=org.owasp.esapi.logging.slf4j.Slf4JLogFactory
Here is an example of where I am logging:
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.convert.converter.Converter;
import java.util.Arrays;
public class StringToEnumConverter implements Converter<String, Filters> {
private static Logger logger = LoggerFactory.getLogger(StringToEnumConverter.class);
#Override
public Filters convert(String source) {
try {
logger.info("Attempting to convert ENUM param to uppercase {}", source);
return Filters.valueOf(source.toUpperCase());
} catch (IllegalArgumentException e) {
logger.error("Failed to convert ENUM param to uppercase {}", source);
throw new BadFilterRequestException("Error: Filter provide must be one of: " + Arrays.asList(Filters.values()), "Search");
}
}
}
EDIT: Using the older version while it will allow the API to start, it will fire this error message when its envoked:
Caused by: java.lang.NoClassDefFoundError: Could not initialize class org.owasp.esapi.logging.slf4j.Slf4JLogFactory
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:340)
at org.owasp.esapi.util.ObjFactory.loadClassByStringName(ObjFactory.java:158)
at org.owasp.esapi.util.ObjFactory.make(ObjFactory.java:81)
at org.owasp.esapi.ESAPI.logFactory(ESAPI.java:139)
at org.owasp.esapi.ESAPI.getLogger(ESAPI.java:155)
at org.owasp.esapi.reference.DefaultEncoder.<init>(DefaultEncoder.java:83)
at org.owasp.esapi.reference.DefaultEncoder.getInstance(DefaultEncoder.java:67)
... 46 common frames omitted
Thank you for your time

Unable to start spring-boot in jetty and it always defaults to tomcat

Unable to start spring-boot in jetty even with the following configuration, what is not being configured properly
implementation ('org.springframework.boot:spring-boot-starter-web') {
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-tomcat'
}
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-jetty'
You need to add below code in your build.gradle to exclude Tomcat.
configurations {
compile.exclude module: "spring-boot-starter-tomcat"
}
and then to add Jetty dependecy:
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-jetty'
And this will start your Spring Boot app with Jetty.

gradle configuration for powermock 1.7.4 and mockito 1.10.19

I'm trying to run Java tests with PowerMock version 1.7.4 and Mockito version 1.10.19, using Gradle.
PowerMock 1.7.4 has transitive dependencies on both
org.mockito » mockito-core 1.10.19
and on
org.mockito » mockito-core 2.8.9
(See https://mvnrepository.com/artifact/org.powermock/powermock-api-mockito-common/1.7.4)
In order to NOT bring in Mockito 2.8.9, but instead have tests compile and run against Mockito 1.10.19, I have to do the following (because of various transitive dependencies within the powermock jars):
testCompile ("org.mockito:mockito-core:${versions.mockito}") {
exclude group: 'org.hamcrest', module: 'hamcrest-core'
}
testCompile ("org.powermock:powermock-api-mockito-common:${versions.powermock}") {
exclude group: 'org.mockito', module: 'mockito-core'
}
testCompile ("org.powermock:powermock-api-mockito:${versions.powermock}") {
exclude group: 'org.mockito', module: 'mockito-core'
}
testCompile ("org.powermock:powermock-core:${versions.powermock}") {
exclude group: 'org.mockito', module: 'mockito-core'
}
testCompile ("org.powermock:powermock-module-junit4:${versions.powermock}") {
exclude group: 'org.powermock', module: 'powermock-module-junit4-common'
}
testCompile ("org.powermock:powermock-module-junit4-common:${versions.powermock}") {
exclude group: 'org.powermock', module: 'powermock-core'
}
testCompile ("org.powermock:powermock-api-support:${versions.powermock}") {
exclude group: 'org.powermock', module: 'powermock-core'
}
testCompile ("org.powermock:powermock-api-easymock:${versions.powermock}") {
exclude group: 'org.powermock', module: 'powermock-api-support'
}
testCompile ("org.powermock:powermock-module-javaagent:${versions.powermock}") {
exclude group: 'org.powermock', module: 'powermock-core'
}
testCompile ("org.powermock:powermock-module-junit4-rule-agent:${versions.powermock}") {
exclude group: 'org.powermock', module: 'powermock-core'
}
testRuntime("org.mockito:mockito-core:${versions.mockito}") {
exclude group: 'org.hamcrest', module: 'hamcrest-core'
}
Where versions is:
versions = [
'mockito': '1.10.19',
'powermock': '1.7.4'
]
Surely there is a better, more concise way of doing this in Gradle, right?
One way to compact it, excluding only mockito-core :
testCompile ("org.mockito:mockito-core:${versions.mockito}") {
exclude group: 'org.hamcrest', module: 'hamcrest-core'
}
['powermock-api-mockito-common',
'powermock-api-mockito',
'powermock-core',
'powermock-module-junit4',
'powermock-module-junit4-common',
'powermock-api-support',
'powermock-api-easymock',
'powermock-module-javaagent',
'powermock-module-junit4-rule-agent'].each {
testCompile ("org.powermock:${it}:${versions.powermock}") {
exclude group: 'org.mockito', module: 'mockito-core'
}
}
Moreover the testRuntime mockito-core is useless as testRuntime extends testCompile

Categories