Spring Boot Transaction Proxy Error When I call two transactional method as nested - spring

I have a service class like below. i call this "addPlayerToTeam" method from my controller class. This method has 3 operations:
1.control parameters and check data valid on my db (without transaction)
2.insert player to new team and create a history record (with transaction)
3.send notify to player for 'say hello' (without transaction)
But transactional method has a problem.
package com.thecodemakerz.transaction.service;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.thecodemakerz.transaction.domain.PlayerHistoryDto;
import com.thecodemakerz.transaction.domain.TeamPlayerDto;
import com.thecodemakerz.transaction.entity.Player;
#Service
#Slf4j
public class TeamPlayerServiceBestCase implements ITeamPlayerServiceBestCase {
#Autowired
private ITeamService teamService;
#Autowired
private IPlayerService playerService;
#Autowired
private IPlayerHistoryService historyService;
#Autowired
private IBildirimService bildirimService;
#Override
public Player addPlayerToTeam(TeamPlayerDto teamPlayerDto) {
Player player = addPlayerToTeamControl(teamPlayerDto);
player.setFkTeamId(teamPlayerDto.getFkTeamId());
player = addPlayerToTeamInsert(player);
sendNotifyAfterAddPlayerToTeam(player.getName());
return player;
}
#Override
public Player addPlayerToTeamControl(TeamPlayerDto teamPlayerDto) {
log.info("addPlayerToTeamControl start");
if (!teamService.existsById(teamPlayerDto.getFkTeamId())) {
throw new RuntimeException("Team not found");
}
Player player = playerService.findById(teamPlayerDto.getFkPlayerId());
if (player == null) {
throw new RuntimeException("Player not found");
}
log.info("addPlayerToTeamControl end");
return player;
}
#Override
#Transactional
public Player addPlayerToTeamInsert(Player player) {
log.info("addPlayerToTeamInsert start");
player = playerService.update(player);
PlayerHistoryDto historyDto = new PlayerHistoryDto();
historyDto.setFkPlayerId(player.getId());
historyDto.setFkTeamId(player.getFkTeamId());
historyService.addPlayerHistoryToNew(historyDto);
log.info("addPlayerToTeamInsert end");
return player;
}
#Override
public void sendNotifyAfterAddPlayerToTeam(String playerName) {
log.info("sendNotifyAfterAddPlayerToTeam start");
bildirimService.sendMail();
bildirimService.sendSms();
bildirimService.sendPush();
log.info("sendNotifyAfterAddPlayerToTeam end");
}
}
playerService.update method is below and not contains class level or method level transaction
#Override
public Player update(Player player) {
log.info("Player update işlemi yapılıyor");
if (player == null || !existsById(player.getId())) {
throw new RuntimeException("Player bulunamadı");
}
return playerRepo.save(player);
}
historyService.addPlayerHistoryToNew method is below and not contains class level but has method level transaction as #Transactional(propagation = Propagation.MANDATORY)
#Override
#Transactional(propagation = Propagation.MANDATORY)
public void addPlayerHistoryToNew(PlayerHistoryDto historyDto) {
log.info("addPlayerHistoryToNew işlemi yapılıyor");
update(historyDto);
insert(historyDto);
}
Following is the error result after running the method
2021-10-20 11:14:16.466 DEBUG 16016 --- [nio-8080-exec-5] o.j.s.OpenEntityManagerInViewInterceptor : Opening JPA EntityManager in OpenEntityManagerInViewInterceptor
2021-10-20 11:14:16.467 INFO 16016 --- [nio-8080-exec-5] c.t.t.service.TeamPlayerServiceBestCase : addPlayerToTeamControl start
2021-10-20 11:14:16.468 DEBUG 16016 --- [nio-8080-exec-5] o.s.orm.jpa.JpaTransactionManager : Found thread-bound EntityManager [SessionImpl(1505155637<open>)] for JPA transaction
2021-10-20 11:14:16.468 INFO 16016 --- [nio-8080-exec-5] c.t.transaction.service.TeamService : team existsById kontrolü
2021-10-20 11:14:16.468 DEBUG 16016 --- [nio-8080-exec-5] o.s.orm.jpa.JpaTransactionManager : Found thread-bound EntityManager [SessionImpl(1505155637<open>)] for JPA transaction
2021-10-20 11:14:16.468 DEBUG 16016 --- [nio-8080-exec-5] o.s.orm.jpa.JpaTransactionManager : Creating new transaction with name [org.springframework.data.jpa.repository.support.SimpleJpaRepository.existsById]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT,readOnly
2021-10-20 11:14:16.468 DEBUG 16016 --- [nio-8080-exec-5] o.s.orm.jpa.JpaTransactionManager : Exposing JPA transaction as JDBC [org.springframework.orm.jpa.vendor.HibernateJpaDialect$HibernateConnectionHandle#2d62109e]
2021-10-20 11:14:16.469 DEBUG 16016 --- [nio-8080-exec-5] o.s.orm.jpa.JpaTransactionManager : Initiating transaction commit
2021-10-20 11:14:16.469 DEBUG 16016 --- [nio-8080-exec-5] o.s.orm.jpa.JpaTransactionManager : Committing JPA transaction on EntityManager [SessionImpl(1505155637<open>)]
2021-10-20 11:14:16.469 DEBUG 16016 --- [nio-8080-exec-5] o.s.orm.jpa.JpaTransactionManager : Not closing pre-bound JPA EntityManager after transaction
2021-10-20 11:14:16.469 DEBUG 16016 --- [nio-8080-exec-5] o.s.orm.jpa.JpaTransactionManager : Resuming suspended transaction after completion of inner transaction
2021-10-20 11:14:16.469 INFO 16016 --- [nio-8080-exec-5] c.t.transaction.service.PlayerService : player findById yapılıyor
2021-10-20 11:14:16.470 DEBUG 16016 --- [nio-8080-exec-5] o.s.orm.jpa.JpaTransactionManager : Found thread-bound EntityManager [SessionImpl(1505155637<open>)] for JPA transaction
2021-10-20 11:14:16.470 DEBUG 16016 --- [nio-8080-exec-5] o.s.orm.jpa.JpaTransactionManager : Creating new transaction with name [org.springframework.data.jpa.repository.support.SimpleJpaRepository.findById]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT,readOnly
2021-10-20 11:14:16.470 DEBUG 16016 --- [nio-8080-exec-5] o.s.orm.jpa.JpaTransactionManager : Exposing JPA transaction as JDBC [org.springframework.orm.jpa.vendor.HibernateJpaDialect$HibernateConnectionHandle#78d5a812]
2021-10-20 11:14:16.471 DEBUG 16016 --- [nio-8080-exec-5] o.s.orm.jpa.JpaTransactionManager : Initiating transaction commit
2021-10-20 11:14:16.471 DEBUG 16016 --- [nio-8080-exec-5] o.s.orm.jpa.JpaTransactionManager : Committing JPA transaction on EntityManager [SessionImpl(1505155637<open>)]
2021-10-20 11:14:16.471 DEBUG 16016 --- [nio-8080-exec-5] o.s.orm.jpa.JpaTransactionManager : Not closing pre-bound JPA EntityManager after transaction
2021-10-20 11:14:16.471 INFO 16016 --- [nio-8080-exec-5] c.t.t.service.TeamPlayerServiceBestCase : addPlayerToTeamControl end
2021-10-20 11:14:16.471 INFO 16016 --- [nio-8080-exec-5] c.t.t.service.TeamPlayerServiceBestCase : addPlayerToTeamInsert start
2021-10-20 11:14:16.471 INFO 16016 --- [nio-8080-exec-5] c.t.transaction.service.PlayerService : Player update işlemi yapılıyor
2021-10-20 11:14:16.471 DEBUG 16016 --- [nio-8080-exec-5] o.s.orm.jpa.JpaTransactionManager : Found thread-bound EntityManager [SessionImpl(1505155637<open>)] for JPA transaction
2021-10-20 11:14:16.471 DEBUG 16016 --- [nio-8080-exec-5] o.s.orm.jpa.JpaTransactionManager : Creating new transaction with name [org.springframework.data.jpa.repository.support.SimpleJpaRepository.existsById]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT,readOnly
2021-10-20 11:14:16.471 DEBUG 16016 --- [nio-8080-exec-5] o.s.orm.jpa.JpaTransactionManager : Exposing JPA transaction as JDBC [org.springframework.orm.jpa.vendor.HibernateJpaDialect$HibernateConnectionHandle#2b46ef95]
2021-10-20 11:14:16.473 DEBUG 16016 --- [nio-8080-exec-5] o.s.orm.jpa.JpaTransactionManager : Initiating transaction commit
2021-10-20 11:14:16.473 DEBUG 16016 --- [nio-8080-exec-5] o.s.orm.jpa.JpaTransactionManager : Committing JPA transaction on EntityManager [SessionImpl(1505155637<open>)]
2021-10-20 11:14:16.473 DEBUG 16016 --- [nio-8080-exec-5] o.s.orm.jpa.JpaTransactionManager : Not closing pre-bound JPA EntityManager after transaction
2021-10-20 11:14:16.473 DEBUG 16016 --- [nio-8080-exec-5] o.s.orm.jpa.JpaTransactionManager : Found thread-bound EntityManager [SessionImpl(1505155637<open>)] for JPA transaction
2021-10-20 11:14:16.473 DEBUG 16016 --- [nio-8080-exec-5] o.s.orm.jpa.JpaTransactionManager : Creating new transaction with name [org.springframework.data.jpa.repository.support.SimpleJpaRepository.save]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT
2021-10-20 11:14:16.473 DEBUG 16016 --- [nio-8080-exec-5] o.s.orm.jpa.JpaTransactionManager : Exposing JPA transaction as JDBC [org.springframework.orm.jpa.vendor.HibernateJpaDialect$HibernateConnectionHandle#a5a65bd]
2021-10-20 11:14:16.474 DEBUG 16016 --- [nio-8080-exec-5] o.s.orm.jpa.JpaTransactionManager : Initiating transaction commit
2021-10-20 11:14:16.474 DEBUG 16016 --- [nio-8080-exec-5] o.s.orm.jpa.JpaTransactionManager : Committing JPA transaction on EntityManager [SessionImpl(1505155637<open>)]
2021-10-20 11:14:16.483 DEBUG 16016 --- [nio-8080-exec-5] o.s.orm.jpa.JpaTransactionManager : Not closing pre-bound JPA EntityManager after transaction
2021-10-20 11:14:16.483 DEBUG 16016 --- [nio-8080-exec-5] o.s.orm.jpa.JpaTransactionManager : Found thread-bound EntityManager [SessionImpl(1505155637<open>)] for JPA transaction
2021-10-20 11:14:16.483 DEBUG 16016 --- [nio-8080-exec-5] o.j.s.OpenEntityManagerInViewInterceptor : Closing JPA EntityManager in OpenEntityManagerInViewInterceptor
2021-10-20 11:14:16.484 ERROR 16016 --- [nio-8080-exec-5] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.transaction.IllegalTransactionStateException: No existing transaction found for transaction marked with propagation 'mandatory'] with root cause
org.springframework.transaction.IllegalTransactionStateException: No existing transaction found for transaction marked with propagation 'mandatory'
at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:362) ~[spring-tx-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:574) ~[spring-tx-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:361) ~[spring-tx-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:118) ~[spring-tx-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:749) ~[spring-aop-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:691) ~[spring-aop-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at com.thecodemakerz.transaction.service.PlayerHistoryService$$EnhancerBySpringCGLIB$$a78b3f88.addPlayerHistoryToNew(<generated>) ~[classes/:na]
at com.thecodemakerz.transaction.service.TeamPlayerServiceBestCase.addPlayerToTeamInsert(TeamPlayerServiceBestCase.java:64) ~[classes/:na]
at com.thecodemakerz.transaction.service.TeamPlayerServiceBestCase.addPlayerToTeam(TeamPlayerServiceBestCase.java:35) ~[classes/:na]
at com.thecodemakerz.transaction.service.TeamPlayerServiceBestCase$$FastClassBySpringCGLIB$$c8ddf51b.invoke(<generated>) ~[classes/:na]
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) ~[spring-core-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:687) ~[spring-aop-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at com.thecodemakerz.transaction.service.TeamPlayerServiceBestCase$$EnhancerBySpringCGLIB$$7e6a92e3.addPlayerToTeam(<generated>) ~[classes/:na]
at com.thecodemakerz.transaction.controller.PlayerTeamController.addPlayerToTeamBestCase2(PlayerTeamController.java:55) ~[classes/:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:190) ~[spring-web-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138) ~[spring-web-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:105) ~[spring-webmvc-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:878) ~[spring-webmvc-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:792) ~[spring-webmvc-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) ~[spring-webmvc-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1040) ~[spring-webmvc-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943) ~[spring-webmvc-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) ~[spring-webmvc-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909) ~[spring-webmvc-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:652) ~[tomcat-embed-core-9.0.38.jar:4.0.FR]
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883) ~[spring-webmvc-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:733) ~[tomcat-embed-core-9.0.38.jar:4.0.FR]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) ~[tomcat-embed-core-9.0.38.jar:9.0.38]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.38.jar:9.0.38]
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) ~[tomcat-embed-websocket-9.0.38.jar:9.0.38]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.38.jar:9.0.38]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.38.jar:9.0.38]
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100) ~[spring-web-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[spring-web-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.38.jar:9.0.38]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.38.jar:9.0.38]
at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93) ~[spring-web-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[spring-web-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.38.jar:9.0.38]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.38.jar:9.0.38]
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201) ~[spring-web-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[spring-web-5.2.9.RELEASE.jar:5.2.9.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) ~[tomcat-embed-core-9.0.38.jar:9.0.38]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) ~[tomcat-embed-core-9.0.38.jar:9.0.38]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202) ~[tomcat-embed-core-9.0.38.jar:9.0.38]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97) ~[tomcat-embed-core-9.0.38.jar:9.0.38]
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:541) ~[tomcat-embed-core-9.0.38.jar:9.0.38]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:143) ~[tomcat-embed-core-9.0.38.jar:9.0.38]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) ~[tomcat-embed-core-9.0.38.jar:9.0.38]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78) ~[tomcat-embed-core-9.0.38.jar:9.0.38]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) ~[tomcat-embed-core-9.0.38.jar:9.0.38]
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:374) ~[tomcat-embed-core-9.0.38.jar:9.0.38]
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) ~[tomcat-embed-core-9.0.38.jar:9.0.38]
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868) ~[tomcat-embed-core-9.0.38.jar:9.0.38]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1590) ~[tomcat-embed-core-9.0.38.jar:9.0.38]
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) ~[tomcat-embed-core-9.0.38.jar:9.0.38]
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) ~[na:na]
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) ~[na:na]
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) ~[tomcat-embed-core-9.0.38.jar:9.0.38]
at java.base/java.lang.Thread.run(Thread.java:834) ~[na:na]
2021-10-20 11:14:16.485 DEBUG 16016 --- [nio-8080-exec-5] o.j.s.OpenEntityManagerInViewInterceptor : Opening JPA EntityManager in OpenEntityManagerInViewInterceptor
2021-10-20 11:14:16.486 DEBUG 16016 --- [nio-8080-exec-5] o.j.s.OpenEntityManagerInViewInterceptor : Closing JPA EntityManager in OpenEntityManagerInViewInterceptor
BUT when I run the method as below, it works fine
#Override
#Transactional
public Player addPlayerToTeam(TeamPlayerDto teamPlayerDto) {
if (!teamService.existsById(teamPlayerDto.getFkTeamId())) {
throw new RuntimeException("İşlem yapılmak istenen Team bulunamadır");
}
Player player = playerService.findById(teamPlayerDto.getFkPlayerId());
if (player == null) {
throw new RuntimeException("İşlem yapılmak istenen Player bulunamadır");
}
player.setFkTeamId(teamPlayerDto.getFkTeamId());
Player savedPlayer = playerService.update(player);
PlayerHistoryDto historyDto = new PlayerHistoryDto();
historyDto.setFkPlayerId(teamPlayerDto.getFkPlayerId());
historyDto.setFkTeamId(teamPlayerDto.getFkTeamId());
historyService.addPlayerHistoryToNew(historyDto);
bildirimService.sendMail();
bildirimService.sendSms();
bildirimService.sendPush();
return savedPlayer;
}
Why am I getting an error in the proxy in the first example use? Does anyone know this? Can you help?

When calling #Transactional methods from within the same component the proxy is not involved, and no transaction is started therefore. The #Transactional method has to be invoked from outside. (IMHO it's bad style to have several public methods that call each other.)

Related

Randomly getting java.util.concurrent.TimeoutException at com.rabbitmq.utility.BlockingCell.get(BlockingCell.java:77) sending message on RabbitMQ

While sending message on RabbitMQ, I am getting following exception randomly
2021-05-26 11:31:03.274 INFO 6728 --- [nio-8080-exec-1] o.s.a.r.c.CachingConnectionFactory : Attempting to connect to: [<<My Server IP>>:5672]
2021-05-26 11:31:09.653 WARN 6728 --- [0.3.52.168:5672] c.r.c.impl.ForgivingExceptionHandler : An unexpected connection driver error occured (Exception message: Socket closed)
2021-05-26 11:31:09.660 ERROR 6728 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.amqp.AmqpTimeoutException: java.util.concurrent.TimeoutException] with root cause
java.util.concurrent.TimeoutException: null
at com.rabbitmq.utility.BlockingCell.get(BlockingCell.java:77) ~[amqp-client-5.10.0.jar:5.10.0]
at com.rabbitmq.utility.BlockingCell.uninterruptibleGet(BlockingCell.java:120) ~[amqp-client-5.10.0.jar:5.10.0]
at com.rabbitmq.utility.BlockingValueOrException.uninterruptibleGetValue(BlockingValueOrException.java:36) ~[amqp-client-5.10.0.jar:5.10.0]
at com.rabbitmq.client.impl.AMQChannel$BlockingRpcContinuation.getReply(AMQChannel.java:502) ~[amqp-client-5.10.0.jar:5.10.0]
at com.rabbitmq.client.impl.AMQChannel.privateRpc(AMQChannel.java:330) ~[amqp-client-5.10.0.jar:5.10.0]
at com.rabbitmq.client.impl.AMQChannel.rpc(AMQChannel.java:275) ~[amqp-client-5.10.0.jar:5.10.0]
at com.rabbitmq.client.impl.AMQConnection.start(AMQConnection.java:373) ~[amqp-client-5.10.0.jar:5.10.0]
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:1139) ~[amqp-client-5.10.0.jar:5.10.0]
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:1087) ~[amqp-client-5.10.0.jar:5.10.0]
at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.connectAddresses(AbstractConnectionFactory.java:638) ~[spring-rabbit-2.3.5.jar:2.3.5]
at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.connect(AbstractConnectionFactory.java:613) ~[spring-rabbit-2.3.5.jar:2.3.5]
at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.createBareConnection(AbstractConnectionFactory.java:565) ~[spring-rabbit-2.3.5.jar:2.3.5]
at org.springframework.amqp.rabbit.connection.CachingConnectionFactory.createConnection(CachingConnectionFactory.java:724) ~[spring-rabbit-2.3.5.jar:2.3.5]
at org.springframework.amqp.rabbit.connection.ConnectionFactoryUtils.createConnection(ConnectionFactoryUtils.java:214) ~[spring-rabbit-2.3.5.jar:2.3.5]
at org.springframework.amqp.rabbit.core.RabbitTemplate.doExecute(RabbitTemplate.java:2132) ~[spring-rabbit-2.3.5.jar:2.3.5]
at org.springframework.amqp.rabbit.core.RabbitTemplate.execute(RabbitTemplate.java:2105) ~[spring-rabbit-2.3.5.jar:2.3.5]
at org.springframework.amqp.rabbit.core.RabbitTemplate.send(RabbitTemplate.java:1049) ~[spring-rabbit-2.3.5.jar:2.3.5]
at org.springframework.amqp.rabbit.core.RabbitTemplate.convertAndSend(RabbitTemplate.java:1114) ~[spring-rabbit-2.3.5.jar:2.3.5]
at org.springframework.amqp.rabbit.core.RabbitTemplate.convertAndSend(RabbitTemplate.java:1107) ~[spring-rabbit-2.3.5.jar:2.3.5]
at com.ukg.testbed.service.impl.RabbitMQSender.send(RabbitMQSender.java:23) ~[main/:na]
at com.ukg.testbed.service.impl.EmployeeServiceImpl.createEmployee(EmployeeServiceImpl.java:42) ~[main/:na]
at com.ukg.testbed.service.impl.EmployeeServiceImpl$$FastClassBySpringCGLIB$$77b5167b.invoke(<generated>) ~[main/:na]
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) ~[spring-core-5.3.4.jar:5.3.4]
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:688) ~[spring-aop-5.3.4.jar:5.3.4]
at com.ukg.testbed.service.impl.EmployeeServiceImpl$$EnhancerBySpringCGLIB$$70140a97.createEmployee(<generated>) ~[main/:na]
at com.ukg.testbed.controller.EmployeeController.registerNewEmployee(EmployeeController.java:36) ~[main/:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:197) ~[spring-web-5.3.4.jar:5.3.4]
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:141) ~[spring-web-5.3.4.jar:5.3.4]
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:106) ~[spring-webmvc-5.3.4.jar:5.3.4]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:894) ~[spring-webmvc-5.3.4.jar:5.3.4]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:808) ~[spring-webmvc-5.3.4.jar:5.3.4]
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) ~[spring-webmvc-5.3.4.jar:5.3.4]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1060) ~[spring-webmvc-5.3.4.jar:5.3.4]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:962) ~[spring-webmvc-5.3.4.jar:5.3.4]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) ~[spring-webmvc-5.3.4.jar:5.3.4]
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909) ~[spring-webmvc-5.3.4.jar:5.3.4]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:652) ~[tomcat-embed-core-9.0.43.jar:4.0.FR]
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883) ~[spring-webmvc-5.3.4.jar:5.3.4]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:733) ~[tomcat-embed-core-9.0.43.jar:4.0.FR]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:227) ~[tomcat-embed-core-9.0.43.jar:9.0.43]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[tomcat-embed-core-9.0.43.jar:9.0.43]
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) ~[tomcat-embed-websocket-9.0.43.jar:9.0.43]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) ~[tomcat-embed-core-9.0.43.jar:9.0.43]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[tomcat-embed-core-9.0.43.jar:9.0.43]
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100) ~[spring-web-5.3.4.jar:5.3.4]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[spring-web-5.3.4.jar:5.3.4]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) ~[tomcat-embed-core-9.0.43.jar:9.0.43]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[tomcat-embed-core-9.0.43.jar:9.0.43]
at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93) ~[spring-web-5.3.4.jar:5.3.4]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[spring-web-5.3.4.jar:5.3.4]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) ~[tomcat-embed-core-9.0.43.jar:9.0.43]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[tomcat-embed-core-9.0.43.jar:9.0.43]
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201) ~[spring-web-5.3.4.jar:5.3.4]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) ~[spring-web-5.3.4.jar:5.3.4]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:189) ~[tomcat-embed-core-9.0.43.jar:9.0.43]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:162) ~[tomcat-embed-core-9.0.43.jar:9.0.43]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202) ~[tomcat-embed-core-9.0.43.jar:9.0.43]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97) ~[tomcat-embed-core-9.0.43.jar:9.0.43]
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:542) ~[tomcat-embed-core-9.0.43.jar:9.0.43]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:143) ~[tomcat-embed-core-9.0.43.jar:9.0.43]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) ~[tomcat-embed-core-9.0.43.jar:9.0.43]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78) ~[tomcat-embed-core-9.0.43.jar:9.0.43]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:346) ~[tomcat-embed-core-9.0.43.jar:9.0.43]
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:374) ~[tomcat-embed-core-9.0.43.jar:9.0.43]
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) ~[tomcat-embed-core-9.0.43.jar:9.0.43]
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:887) ~[tomcat-embed-core-9.0.43.jar:9.0.43]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1684) ~[tomcat-embed-core-9.0.43.jar:9.0.43]
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) ~[tomcat-embed-core-9.0.43.jar:9.0.43]
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) ~[na:na]
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) ~[na:na]
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) ~[tomcat-embed-core-9.0.43.jar:9.0.43]
at java.base/java.lang.Thread.run(Thread.java:834) ~[na:na]
My code for sending
#Service
public class RabbitMQSender {
#Autowired
private AmqpTemplate kRabbitTemplate;
#Value("${rmq.test.exchange}")
private String exchange;
#Value("${rmq.test.routingkey}")
private String routingkey;
public void send(EmpDTO empDTO) {
System.out.println("Sending msg = " + empDTO);
kRabbitTemplate.convertAndSend(exchange, routingkey, empDTO);
System.out.println("Sent msg = " + empDTO);
}
}
And this is the config :
#Configuration
public class RabbitMQConfig {
#Value("${rmq.test.queue}")
String queueName;
#Value("${rmq.test.exchange}")
String exchange;
#Value("${rmq.test.routingkey}")
private String routingkey;
#Bean
Queue kQueue() {
return new Queue(queueName, false);
}
#Bean
DirectExchange kExchange() {
return new DirectExchange(exchange);
}
#Bean
Binding kBinding(Queue queue, DirectExchange exchange) {
return BindingBuilder.bind(queue).to(exchange).with(routingkey);
}
#Bean
public MessageConverter kJsonMessageConverter() {
return new Jackson2JsonMessageConverter();
}
#Bean
public AmqpTemplate kRabbitTemplate(ConnectionFactory connectionFactory) {
final RabbitTemplate kRabbitTemplate = new RabbitTemplate(connectionFactory);
kRabbitTemplate.setMessageConverter(kJsonMessageConverter());
return kRabbitTemplate;
}
}
I have checked following
Disk / CPU / Memory Utilization are ok on server
Maximum time connection is established so ruling out config issues.
This has been very frequent for multiple queues in Production env.
This is also happening for flows where we send message in Transaction.
"Caused By": {
"com.rabbitmq.client.ChannelContinuationTimeoutException: Continuation call for method #method<tx.commit>() on channel AMQChannel(amqp://myvhost#<RMQHOST>:5672/myvhost,1) (#1) timed out": ["AMQChannel.java", 313, "com.rabbitmq.client.impl.AMQChannel.wrapTimeoutException", "AMQChannel.java", 295, "com.rabbitmq.client.impl.AMQChannel.privateRpc", "AMQChannel.java", 141, "com.rabbitmq.client.impl.AMQChannel.exnWrappingRpc", "ChannelN.java", 1540, "com.rabbitmq.client.impl.ChannelN.txCommit", "ChannelN.java", 52, "com.rabbitmq.client.impl.ChannelN.txCommit", "", -1, "sun.reflect.GeneratedMethodAccessor435.invoke", "DelegatingMethodAccessorImpl.java", 43, "sun.reflect.DelegatingMethodAccessorImpl.invoke", "Method.java", 498, "java.lang.reflect.Method.invoke", "CachingConnectionFactory.java", 1190, "org.springframework.amqp.rabbit.connection.CachingConnectionFactory$CachedChannelInvocationHandler.invoke", "", -1, "com.sun.proxy.$Proxy941.txCommit", "RabbitResourceHolder.java", 153, "org.springframework.amqp.rabbit.connection.RabbitResourceHolder.commitAll"],
"Caused By": {
"java.util.concurrent.TimeoutException": ["BlockingCell.java", 77, "com.rabbitmq.utility.BlockingCell.get", "BlockingCell.java", 120, "com.rabbitmq.utility.BlockingCell.uninterruptibleGet", "BlockingValueOrException.java", 36, "com.rabbitmq.utility.BlockingValueOrException.uninterruptibleGetValue", "AMQChannel.java", 502, "com.rabbitmq.client.impl.AMQChannel$BlockingRpcContinuation.getReply", "AMQChannel.java", 293, "com.rabbitmq.client.impl.AMQChannel.privateRpc"]
}
}
You can add a RetryTemplate to the RabbitTemplate to retry sends when there are connection problems.
As I commented, you should check the server logs to see if there are clues for the failure.
EDIT
This test shows it works as expected:
#Test
public void testRetryOnCommitException() throws Exception {
ConnectionFactory mockConnectionFactory = mock(ConnectionFactory.class);
final AtomicInteger count = new AtomicInteger();
Connection mockConnection = mock(Connection.class);
Channel mockChannel = mock(Channel.class);
given(mockConnectionFactory.newConnection(any(ExecutorService.class), anyString())).willReturn(mockConnection);
given(mockConnection.isOpen()).willReturn(true);
given(mockConnection.createChannel()).willReturn(mockChannel);
willAnswer(invocation -> {
count.incrementAndGet();
throw new IOException("commitFailed");
}).given(mockChannel).txCommit();
SingleConnectionFactory connectionFactory = new SingleConnectionFactory(mockConnectionFactory);
connectionFactory.setExecutor(mock(ExecutorService.class));
RabbitTemplate template = new RabbitTemplate(connectionFactory);
template.setChannelTransacted(true);
template.setRetryTemplate(new RetryTemplate());
try {
template.convertAndSend("foo", "bar", "baz");
}
catch (Exception e) {
assertThat(e.getMessage()).contains("commitFailed");
}
assertThat(count.get()).isEqualTo(3);
}
EDIT2
This test simulates your ChannelContinuationTimeoutException problem:
#Test
public void testRetryOnCommitException() throws Exception {
CachingConnectionFactory connectionFactory = new CachingConnectionFactory("localhost");
connectionFactory.getRabbitConnectionFactory().setChannelRpcTimeout(1);
RabbitTemplate template = new RabbitTemplate(connectionFactory);
template.setChannelTransacted(true);
template.setRetryTemplate(new RetryTemplate());
assertThatExceptionOfType(AmqpIOException.class).isThrownBy(() -> template.convertAndSend(ROUTE, "commitError"))
.withCauseExactlyInstanceOf(ChannelContinuationTimeoutException.class);
}
And in the debugger, I see the send being tried 3 times, as expected.
And here are debug logs...
2021-06-10 09:23:20,135 INFO org.springframework.amqp.rabbit.junit.LogLevelsCondition [main] : +++++++++++++++++++++++++++++ Begin testRetryOnCommitException
2021-06-10 09:23:20,169 DEBUG org.springframework.retry.support.RetryTemplate [main] : Retry: count=0
2021-06-10 09:23:20,175 INFO org.springframework.amqp.rabbit.connection.CachingConnectionFactory [main] : Attempting to connect to: localhost:5672
2021-06-10 09:23:20,185 INFO org.springframework.amqp.rabbit.connection.CachingConnectionFactory [main] : Created new connection: SpringAMQP#706ddbc8:0/SimpleConnection#6397248c [delegate=amqp://guest#127.0.0.1:5672/, localPort= 53720]
2021-06-10 09:23:20,199 DEBUG org.springframework.amqp.rabbit.core.RabbitTemplate [main] : Executing callback RabbitTemplate$$Lambda$548/0x0000000800cffdb8 on RabbitMQ Channel: Cached Rabbit Channel: AMQChannel(amqp://guest#127.0.0.1:5672/,1), conn: Proxy#2d2b6960 Shared Rabbit Connection: SimpleConnection#6397248c [delegate=amqp://guest#127.0.0.1:5672/, localPort= 53720]
2021-06-10 09:23:20,199 DEBUG org.springframework.amqp.rabbit.core.RabbitTemplate [main] : Publishing message [(Body:'commitError' MessageProperties [headers={}, contentType=text/plain, contentEncoding=UTF-8, contentLength=11, deliveryMode=PERSISTENT, priority=0, deliveryTag=0])] on exchange [], routingKey = [test.queue.RabbitTemplateIntegrationTests]
2021-06-10 09:23:20,204 INFO org.springframework.amqp.rabbit.connection.CachingConnectionFactory [main] : Attempting to connect to: localhost:5672
09:23:20.206 [AMQP Connection 127.0.0.1:5672] WARN c.r.c.impl.ForgivingExceptionHandler - An unexpected connection driver error occured (Exception message: Connection reset)
2021-06-10 09:23:20,211 INFO org.springframework.amqp.rabbit.connection.CachingConnectionFactory [main] : Created new connection: SpringAMQP#706ddbc8:1/SimpleConnection#76ff68c5 [delegate=amqp://guest#127.0.0.1:5672/, localPort= 53721]
2021-06-10 09:23:20,213 DEBUG org.springframework.retry.support.RetryTemplate [main] : Checking for rethrow: count=1
2021-06-10 09:23:20,213 DEBUG org.springframework.retry.support.RetryTemplate [main] : Retry: count=1
2021-06-10 09:23:20,213 DEBUG org.springframework.amqp.rabbit.core.RabbitTemplate [main] : Executing callback RabbitTemplate$$Lambda$548/0x0000000800cffdb8 on RabbitMQ Channel: Cached Rabbit Channel: AMQChannel(amqp://guest#127.0.0.1:5672/,1), conn: Proxy#2d2b6960 Shared Rabbit Connection: SimpleConnection#76ff68c5 [delegate=amqp://guest#127.0.0.1:5672/, localPort= 53721]
2021-06-10 09:23:20,213 DEBUG org.springframework.amqp.rabbit.core.RabbitTemplate [main] : Publishing message [(Body:'commitError' MessageProperties [headers={}, contentType=text/plain, contentEncoding=UTF-8, contentLength=11, deliveryMode=PERSISTENT, priority=0, deliveryTag=0])] on exchange [], routingKey = [test.queue.RabbitTemplateIntegrationTests]
2021-06-10 09:23:20,216 INFO org.springframework.amqp.rabbit.connection.CachingConnectionFactory [main] : Attempting to connect to: localhost:5672
09:23:20.216 [AMQP Connection 127.0.0.1:5672] WARN c.r.c.impl.ForgivingExceptionHandler - An unexpected connection driver error occured (Exception message: Connection reset)
2021-06-10 09:23:20,226 INFO org.springframework.amqp.rabbit.connection.CachingConnectionFactory [main] : Created new connection: SpringAMQP#706ddbc8:2/SimpleConnection#1da1380b [delegate=amqp://guest#127.0.0.1:5672/, localPort= 53722]
2021-06-10 09:23:20,228 DEBUG org.springframework.retry.support.RetryTemplate [main] : Checking for rethrow: count=2
2021-06-10 09:23:20,228 DEBUG org.springframework.retry.support.RetryTemplate [main] : Retry: count=2
2021-06-10 09:23:20,228 DEBUG org.springframework.amqp.rabbit.core.RabbitTemplate [main] : Executing callback RabbitTemplate$$Lambda$548/0x0000000800cffdb8 on RabbitMQ Channel: Cached Rabbit Channel: AMQChannel(amqp://guest#127.0.0.1:5672/,1), conn: Proxy#2d2b6960 Shared Rabbit Connection: SimpleConnection#1da1380b [delegate=amqp://guest#127.0.0.1:5672/, localPort= 53722]
2021-06-10 09:23:20,228 DEBUG org.springframework.amqp.rabbit.core.RabbitTemplate [main] : Publishing message [(Body:'commitError' MessageProperties [headers={}, contentType=text/plain, contentEncoding=UTF-8, contentLength=11, deliveryMode=PERSISTENT, priority=0, deliveryTag=0])] on exchange [], routingKey = [test.queue.RabbitTemplateIntegrationTests]
2021-06-10 09:23:20,231 INFO org.springframework.amqp.rabbit.connection.CachingConnectionFactory [main] : Attempting to connect to: localhost:5672
09:23:20.232 [AMQP Connection 127.0.0.1:5672] WARN c.r.c.impl.ForgivingExceptionHandler - An unexpected connection driver error occured (Exception message: Connection reset)
2021-06-10 09:23:20,239 INFO org.springframework.amqp.rabbit.connection.CachingConnectionFactory [main] : Created new connection: SpringAMQP#706ddbc8:3/SimpleConnection#2accaec2 [delegate=amqp://guest#127.0.0.1:5672/, localPort= 53723]
2021-06-10 09:23:20,240 DEBUG org.springframework.retry.support.RetryTemplate [main] : Checking for rethrow: count=3
2021-06-10 09:23:20,240 DEBUG org.springframework.retry.support.RetryTemplate [main] : Retry failed last attempt: count=3

Keycloak server authentication wrong behaviour from a Docker app

I have two Docker containers:
RedHat Keycloak Server (https://keycloak.some.domain.com)
Springboot app (http://localhost:8081)
In my Springboot app, I have defined a secure page at: http://localhost:8081/api/sample.json
Now, when I hit that endpoint, I am redirected to the correct login page and, if I submit the correct login/password credentials, I get the following 403 error (forbidden) page:
However, if I run the Springboot app directly, without a docker wrapper, like this:
java -jar app.jar
then, when I hit the same protected endpoint, I am redirected to the correct login page and, if I submit the correct login/password credentials, in this case, I get the CORRECT, expected page/response !!! (it is the same app !!!)
Given this scenario, I have started the dockerized Springboot app, went inside of the container with:
docker exec -it app bash
and then intalled lynx like this:
apt-get install lynx
from there, I did hit the protected endpoint locally:
lynx http://localhost:8081/api/sample.json
But I got exactly the same error page (403) error. So, I believe the problem is the docker wrapper, not the app. That is critical, because it means that this kind of behavior between keycloak and ANY dockerized app will be similar. :(
As a conclusion, if I execute "docker run -d -p 8081:8081 springboot-app-image", everything works perfectly except authentication process against keycloak (outside and inside the container).
From the Springboot app logs I can see this error trace when I hit the dockerized endpoint:
2020-03-17 15:29:19.503 INFO 1 --- [ main] com.example.app.MainApp : Started MainApp in 13.257 seconds (JVM running for 14.845)
2020-03-17 15:29:30.139 DEBUG 1 --- [nio-8081-exec-1] o.k.adapters.PreAuthActionsHandler : adminRequest http://localhost:8081/api/sample2.json
2020-03-17 15:29:30.169 DEBUG 1 --- [nio-8081-exec-1] o.k.a.a.ClientCredentialsProviderUtils : Using provider 'secret' for authentication of client 'login-app'
2020-03-17 15:29:30.176 DEBUG 1 --- [nio-8081-exec-1] o.k.a.a.ClientCredentialsProviderUtils : Loaded clientCredentialsProvider secret
2020-03-17 15:29:30.179 DEBUG 1 --- [nio-8081-exec-1] o.k.a.a.ClientCredentialsProviderUtils : Loaded clientCredentialsProvider jwt
2020-03-17 15:29:30.182 DEBUG 1 --- [nio-8081-exec-1] o.k.a.a.ClientCredentialsProviderUtils : Loaded clientCredentialsProvider secret-jwt
2020-03-17 15:29:30.184 DEBUG 1 --- [nio-8081-exec-1] o.k.a.a.ClientCredentialsProviderUtils : Loaded clientCredentialsProvider secret
2020-03-17 15:29:30.185 DEBUG 1 --- [nio-8081-exec-1] o.k.a.a.ClientCredentialsProviderUtils : Loaded clientCredentialsProvider jwt
2020-03-17 15:29:30.188 DEBUG 1 --- [nio-8081-exec-1] o.k.a.a.ClientCredentialsProviderUtils : Loaded clientCredentialsProvider secret-jwt
2020-03-17 15:29:30.457 DEBUG 1 --- [nio-8081-exec-1] o.keycloak.adapters.KeycloakDeployment : resolveUrls
2020-03-17 15:29:30.461 DEBUG 1 --- [nio-8081-exec-1] o.k.adapters.KeycloakDeploymentBuilder : Use authServerUrl: https://keycloak.some.domain.com/auth, tokenUrl: https://keycloak.ci.ultrasist.net/auth/realms/SpringBootKeycloak/protocol/openid-connect/token, relativeUrls: NEVER
2020-03-17 15:29:30.479 DEBUG 1 --- [nio-8081-exec-1] .k.a.t.AbstractAuthenticatedActionsValve : AuthenticatedActionsValve.invoke /api/sample2.json
2020-03-17 15:29:30.481 DEBUG 1 --- [nio-8081-exec-1] o.k.a.AuthenticatedActionsHandler : AuthenticatedActionsValve.invoke http://localhost:8081/api/sample2.json
2020-03-17 15:29:30.483 DEBUG 1 --- [nio-8081-exec-1] o.k.a.AuthenticatedActionsHandler : Policy enforcement is disabled.
2020-03-17 15:29:30.494 INFO 1 --- [nio-8081-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'
2020-03-17 15:29:30.495 INFO 1 --- [nio-8081-exec-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2020-03-17 15:29:30.526 INFO 1 --- [nio-8081-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 29 ms
2020-03-17 15:29:30.592 DEBUG 1 --- [nio-8081-exec-1] o.k.adapters.PreAuthActionsHandler : adminRequest http://localhost:8081/api/sample2.json
2020-03-17 15:29:30.694 DEBUG 1 --- [nio-8081-exec-1] o.k.a.s.management.HttpSessionManager : Session created: E9F1974D7E734867356A0366CC0AC52A
2020-03-17 15:29:30.705 DEBUG 1 --- [nio-8081-exec-1] k.a.s.a.KeycloakAuthenticationEntryPoint : Redirecting to login URI /sso/login
2020-03-17 15:29:30.731 DEBUG 1 --- [nio-8081-exec-3] o.k.adapters.PreAuthActionsHandler : adminRequest http://localhost:8081/sso/login
2020-03-17 15:29:30.735 DEBUG 1 --- [nio-8081-exec-3] .k.a.t.AbstractAuthenticatedActionsValve : AuthenticatedActionsValve.invoke /sso/login
2020-03-17 15:29:30.737 DEBUG 1 --- [nio-8081-exec-3] o.k.a.AuthenticatedActionsHandler : AuthenticatedActionsValve.invoke http://localhost:8081/sso/login
2020-03-17 15:29:30.739 DEBUG 1 --- [nio-8081-exec-3] o.k.a.AuthenticatedActionsHandler : Policy enforcement is disabled.
2020-03-17 15:29:30.757 DEBUG 1 --- [nio-8081-exec-3] o.k.adapters.PreAuthActionsHandler : adminRequest http://localhost:8081/sso/login
2020-03-17 15:29:30.764 DEBUG 1 --- [nio-8081-exec-3] f.KeycloakAuthenticationProcessingFilter : Request is to process authentication
2020-03-17 15:29:30.766 DEBUG 1 --- [nio-8081-exec-3] f.KeycloakAuthenticationProcessingFilter : Attempting Keycloak authentication
2020-03-17 15:29:30.795 DEBUG 1 --- [nio-8081-exec-3] o.k.a.s.token.SpringSecurityTokenStore : Checking if org.keycloak.adapters.springsecurity.authentication.SpringSecurityRequestAuthenticator#1273c136 is cached
2020-03-17 15:29:30.800 DEBUG 1 --- [nio-8081-exec-3] o.k.adapters.OAuthRequestAuthenticator : there was no code
2020-03-17 15:29:30.805 DEBUG 1 --- [nio-8081-exec-3] o.k.adapters.OAuthRequestAuthenticator : redirecting to auth server
2020-03-17 15:29:30.809 DEBUG 1 --- [nio-8081-exec-3] o.k.adapters.OAuthRequestAuthenticator : callback uri: http://localhost:8081/sso/login
2020-03-17 15:29:30.822 DEBUG 1 --- [nio-8081-exec-3] f.KeycloakAuthenticationProcessingFilter : Auth outcome: NOT_ATTEMPTED
2020-03-17 15:29:30.824 DEBUG 1 --- [nio-8081-exec-3] o.k.adapters.OAuthRequestAuthenticator : Sending redirect to login page: https://keycloak.some.domain.com/auth/realms/SpringBootKeycloak/protocol/openid-connect/auth?response_type=code&client_id=login-app&redirect_uri=http%3A%2F%2Flocalhost%3A8081%2Fsso%2Flogin&state=412c7a6f-720f-4eea-b825-209c76d3a3db&login=true&scope=openid
2020-03-17 15:29:34.680 DEBUG 1 --- [nio-8081-exec-4] o.k.adapters.PreAuthActionsHandler : adminRequest http://localhost:8081/sso/login?state=412c7a6f-720f-4eea-b825-209c76d3a3db&session_state=802e466d-7b1e-4180-8870-cdae07b2fbae&code=7d93b2cf-d72b-4e83-b219-19d48897c9b7.802e466d-7b1e-4180-8870-cdae07b2fbae.35bc9442-2e19-485a-afad-adc1e62b4c52
2020-03-17 15:29:34.687 DEBUG 1 --- [nio-8081-exec-4] .k.a.t.AbstractAuthenticatedActionsValve : AuthenticatedActionsValve.invoke /sso/login
2020-03-17 15:29:34.688 DEBUG 1 --- [nio-8081-exec-4] o.k.a.AuthenticatedActionsHandler : AuthenticatedActionsValve.invoke http://localhost:8081/sso/login?state=412c7a6f-720f-4eea-b825-209c76d3a3db&session_state=802e466d-7b1e-4180-8870-cdae07b2fbae&code=7d93b2cf-d72b-4e83-b219-19d48897c9b7.802e466d-7b1e-4180-8870-cdae07b2fbae.35bc9442-2e19-485a-afad-adc1e62b4c52
2020-03-17 15:29:34.691 DEBUG 1 --- [nio-8081-exec-4] o.k.a.AuthenticatedActionsHandler : Policy enforcement is disabled.
2020-03-17 15:29:34.694 DEBUG 1 --- [nio-8081-exec-4] o.k.adapters.PreAuthActionsHandler : adminRequest http://localhost:8081/sso/login?state=412c7a6f-720f-4eea-b825-209c76d3a3db&session_state=802e466d-7b1e-4180-8870-cdae07b2fbae&code=7d93b2cf-d72b-4e83-b219-19d48897c9b7.802e466d-7b1e-4180-8870-cdae07b2fbae.35bc9442-2e19-485a-afad-adc1e62b4c52
2020-03-17 15:29:34.701 DEBUG 1 --- [nio-8081-exec-4] f.KeycloakAuthenticationProcessingFilter : Request is to process authentication
2020-03-17 15:29:34.703 DEBUG 1 --- [nio-8081-exec-4] f.KeycloakAuthenticationProcessingFilter : Attempting Keycloak authentication
2020-03-17 15:29:34.711 DEBUG 1 --- [nio-8081-exec-4] o.k.a.s.token.SpringSecurityTokenStore : Checking if org.keycloak.adapters.springsecurity.authentication.SpringSecurityRequestAuthenticator#4c5ab508 is cached
2020-03-17 15:29:34.712 DEBUG 1 --- [nio-8081-exec-4] o.k.adapters.OAuthRequestAuthenticator : there was a code, resolving
2020-03-17 15:29:34.712 DEBUG 1 --- [nio-8081-exec-4] o.k.adapters.OAuthRequestAuthenticator : checking state cookie for after code
2020-03-17 15:29:34.715 DEBUG 1 --- [nio-8081-exec-4] o.k.adapters.OAuthRequestAuthenticator : ** reseting application state cookie
2020-03-17 15:29:35.365 ERROR 1 --- [nio-8081-exec-4] o.k.adapters.OAuthRequestAuthenticator : failed to turn code into token
javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at sun.security.ssl.Alerts.getSSLException(Alerts.java:192) ~[na:1.8.0_65]
at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1949) ~[na:1.8.0_65]
at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:302) ~[na:1.8.0_65]
at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:296) ~[na:1.8.0_65]
at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1509) ~[na:1.8.0_65]
at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:216) ~[na:1.8.0_65]
at sun.security.ssl.Handshaker.processLoop(Handshaker.java:979) ~[na:1.8.0_65]
at sun.security.ssl.Handshaker.process_record(Handshaker.java:914) ~[na:1.8.0_65]
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1062) ~[na:1.8.0_65]
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1375) ~[na:1.8.0_65]
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1403) ~[na:1.8.0_65]
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1387) ~[na:1.8.0_65]
at org.apache.http.conn.ssl.SSLSocketFactory.createLayeredSocket(SSLSocketFactory.java:570) ~[httpclient-4.5.8.jar!/:4.5.8]
at org.keycloak.adapters.SniSSLSocketFactory.createLayeredSocket(SniSSLSocketFactory.java:114) ~[keycloak-adapter-core-4.8.3.Final.jar!/:4.8.3.Final]
at org.apache.http.conn.ssl.SSLSocketFactory.connectSocket(SSLSocketFactory.java:554) ~[httpclient-4.5.8.jar!/:4.5.8]
at org.keycloak.adapters.SniSSLSocketFactory.connectSocket(SniSSLSocketFactory.java:109) ~[keycloak-adapter-core-4.8.3.Final.jar!/:4.8.3.Final]
at org.apache.http.conn.ssl.SSLSocketFactory.connectSocket(SSLSocketFactory.java:415) ~[httpclient-4.5.8.jar!/:4.5.8]
at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:180) ~[httpclient-4.5.8.jar!/:4.5.8]
at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:144) ~[httpclient-4.5.8.jar!/:4.5.8]
at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:134) ~[httpclient-4.5.8.jar!/:4.5.8]
at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:605) ~[httpclient-4.5.8.jar!/:4.5.8]
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:440) ~[httpclient-4.5.8.jar!/:4.5.8]
at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:835) ~[httpclient-4.5.8.jar!/:4.5.8]
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83) ~[httpclient-4.5.8.jar!/:4.5.8]
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:108) ~[httpclient-4.5.8.jar!/:4.5.8]
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:56) ~[httpclient-4.5.8.jar!/:4.5.8]
at org.keycloak.adapters.ServerRequest.invokeAccessCodeToToken(ServerRequest.java:111) ~[keycloak-adapter-core-4.8.3.Final.jar!/:4.8.3.Final]
at org.keycloak.adapters.OAuthRequestAuthenticator.resolveCode(OAuthRequestAuthenticator.java:335) [keycloak-adapter-core-4.8.3.Final.jar!/:4.8.3.Final]
at org.keycloak.adapters.OAuthRequestAuthenticator.authenticate(OAuthRequestAuthenticator.java:280) [keycloak-adapter-core-4.8.3.Final.jar!/:4.8.3.Final]
at org.keycloak.adapters.RequestAuthenticator.authenticate(RequestAuthenticator.java:139) [keycloak-adapter-core-4.8.3.Final.jar!/:4.8.3.Final]
at org.keycloak.adapters.springsecurity.filter.KeycloakAuthenticationProcessingFilter.attemptAuthentication(KeycloakAuthenticationProcessingFilter.java:149) [keycloak-spring-security-adapter-4.8.3.Final.jar!/:4.8.3.Final]
at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:212) [spring-security-web-5.1.5.RELEASE.jar!/:5.1.5.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334) [spring-security-web-5.1.5.RELEASE.jar!/:5.1.5.RELEASE]
at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:116) [spring-security-web-5.1.5.RELEASE.jar!/:5.1.5.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334) [spring-security-web-5.1.5.RELEASE.jar!/:5.1.5.RELEASE]
at org.keycloak.adapters.springsecurity.filter.KeycloakPreAuthActionsFilter.doFilter(KeycloakPreAuthActionsFilter.java:86) [keycloak-spring-security-adapter-4.8.3.Final.jar!/:4.8.3.Final]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334) [spring-security-web-5.1.5.RELEASE.jar!/:5.1.5.RELEASE]
at org.springframework.security.web.csrf.CsrfFilter.doFilterInternal(CsrfFilter.java:100) [spring-security-web-5.1.5.RELEASE.jar!/:5.1.5.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-5.1.6.RELEASE.jar!/:5.1.6.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334) [spring-security-web-5.1.5.RELEASE.jar!/:5.1.5.RELEASE]
at org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:74) [spring-security-web-5.1.5.RELEASE.jar!/:5.1.5.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-5.1.6.RELEASE.jar!/:5.1.6.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334) [spring-security-web-5.1.5.RELEASE.jar!/:5.1.5.RELEASE]
at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:105) [spring-security-web-5.1.5.RELEASE.jar!/:5.1.5.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334) [spring-security-web-5.1.5.RELEASE.jar!/:5.1.5.RELEASE]
at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:56) [spring-security-web-5.1.5.RELEASE.jar!/:5.1.5.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-5.1.6.RELEASE.jar!/:5.1.6.RELEASE]
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334) [spring-security-web-5.1.5.RELEASE.jar!/:5.1.5.RELEASE]
at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:215) [spring-security-web-5.1.5.RELEASE.jar!/:5.1.5.RELEASE]
at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:178) [spring-security-web-5.1.5.RELEASE.jar!/:5.1.5.RELEASE]
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:357) [spring-web-5.1.6.RELEASE.jar!/:5.1.6.RELEASE]
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:270) [spring-web-5.1.6.RELEASE.jar!/:5.1.6.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [tomcat-embed-core-9.0.17.jar!/:9.0.17]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-9.0.17.jar!/:9.0.17]
at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99) [spring-web-5.1.6.RELEASE.jar!/:5.1.6.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-5.1.6.RELEASE.jar!/:5.1.6.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [tomcat-embed-core-9.0.17.jar!/:9.0.17]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-9.0.17.jar!/:9.0.17]
at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:92) [spring-web-5.1.6.RELEASE.jar!/:5.1.6.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-5.1.6.RELEASE.jar!/:5.1.6.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [tomcat-embed-core-9.0.17.jar!/:9.0.17]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-9.0.17.jar!/:9.0.17]
at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:93) [spring-web-5.1.6.RELEASE.jar!/:5.1.6.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-5.1.6.RELEASE.jar!/:5.1.6.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [tomcat-embed-core-9.0.17.jar!/:9.0.17]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-9.0.17.jar!/:9.0.17]
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200) [spring-web-5.1.6.RELEASE.jar!/:5.1.6.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-5.1.6.RELEASE.jar!/:5.1.6.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [tomcat-embed-core-9.0.17.jar!/:9.0.17]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-9.0.17.jar!/:9.0.17]
at org.springframework.web.filter.CorsFilter.doFilterInternal(CorsFilter.java:96) [spring-web-5.1.6.RELEASE.jar!/:5.1.6.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) [spring-web-5.1.6.RELEASE.jar!/:5.1.6.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) [tomcat-embed-core-9.0.17.jar!/:9.0.17]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) [tomcat-embed-core-9.0.17.jar!/:9.0.17]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:200) [tomcat-embed-core-9.0.17.jar!/:9.0.17]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) [tomcat-embed-core-9.0.17.jar!/:9.0.17]
at org.keycloak.adapters.tomcat.AbstractAuthenticatedActionsValve.invoke(AbstractAuthenticatedActionsValve.java:67) [spring-boot-container-bundle-4.8.3.Final.jar!/:4.8.3.Final]
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490) [tomcat-embed-core-9.0.17.jar!/:9.0.17]
at org.keycloak.adapters.tomcat.AbstractKeycloakAuthenticatorValve.invoke(AbstractKeycloakAuthenticatorValve.java:181) [spring-boot-container-bundle-4.8.3.Final.jar!/:4.8.3.Final]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139) [tomcat-embed-core-9.0.17.jar!/:9.0.17]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) [tomcat-embed-core-9.0.17.jar!/:9.0.17]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74) [tomcat-embed-core-9.0.17.jar!/:9.0.17]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) [tomcat-embed-core-9.0.17.jar!/:9.0.17]
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408) [tomcat-embed-core-9.0.17.jar!/:9.0.17]
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) [tomcat-embed-core-9.0.17.jar!/:9.0.17]
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:834) [tomcat-embed-core-9.0.17.jar!/:9.0.17]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1415) [tomcat-embed-core-9.0.17.jar!/:9.0.17]
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-9.0.17.jar!/:9.0.17]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_65]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_65]
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-9.0.17.jar!/:9.0.17]
at java.lang.Thread.run(Thread.java:745) [na:1.8.0_65]
Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:387) ~[na:1.8.0_65]
at sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:292) ~[na:1.8.0_65]
at sun.security.validator.Validator.validate(Validator.java:260) ~[na:1.8.0_65]
at sun.security.ssl.X509TrustManagerImpl.validate(X509TrustManagerImpl.java:324) ~[na:1.8.0_65]
at sun.security.ssl.X509TrustManagerImpl.checkTrusted(X509TrustManagerImpl.java:229) ~[na:1.8.0_65]
at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:124) ~[na:1.8.0_65]
at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1491) ~[na:1.8.0_65]
... 87 common frames omitted
Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at sun.security.provider.certpath.SunCertPathBuilder.build(SunCertPathBuilder.java:146) ~[na:1.8.0_65]
at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(SunCertPathBuilder.java:131) ~[na:1.8.0_65]
at java.security.cert.CertPathBuilder.build(CertPathBuilder.java:280) ~[na:1.8.0_65]
at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:382) ~[na:1.8.0_65]
... 93 common frames omitted
2020-03-17 15:29:35.373 DEBUG 1 --- [nio-8081-exec-4] f.KeycloakAuthenticationProcessingFilter : Auth outcome: FAILED
2020-03-17 15:29:35.377 DEBUG 1 --- [nio-8081-exec-4] f.KeycloakAuthenticationProcessingFilter : Authentication request failed: org.keycloak.adapters.springsecurity.KeycloakAuthenticationException: Invalid authorization header, see WWW-Authenticate header for details
org.keycloak.adapters.springsecurity.KeycloakAuthenticationException: Invalid authorization header, see WWW-Authenticate header for details
at org.keycloak.adapters.springsecurity.filter.KeycloakAuthenticationProcessingFilter.attemptAuthentication(KeycloakAuthenticationProcessingFilter.java:157) ~[keycloak-spring-security-adapter-4.8.3.Final.jar!/:4.8.3.Final]
at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:212) ~[spring-security-web-5.1.5.RELEASE.jar!/:5.1.5.RELEASE]
In the last error trace, I am able to see something about SSL handshake error, and other error mesage saying:
Invalid authorization header, see WWW-Authenticate header for details
but... Why this error is not present when I run the java app directly, without a docker container?
I have found some references but they are not useful for my problem:
Keycloak secure app in container
Docker (Spring Boot or Thorntail) and Keycloak
Spring Boot Application using Keycloak, single sign on doesn't work behind an Apache Web Server
This is my Spring boot configuration class for keycloak that is part of the code that work perfectly outside the docker container but NOT inside a docker container:
#KeycloakConfiguration
class SecurityConfig extends KeycloakWebSecurityConfigurerAdapter {
#Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) {
KeycloakAuthenticationProvider keycloakAuthenticationProvider = keycloakAuthenticationProvider();
keycloakAuthenticationProvider.setGrantedAuthoritiesMapper(new SimpleAuthorityMapper());
auth.authenticationProvider(keycloakAuthenticationProvider);
}
#Bean
#Override
protected SessionAuthenticationStrategy sessionAuthenticationStrategy() {
return new RegisterSessionAuthenticationStrategy(new SessionRegistryImpl());
}
#Bean
#Primary
public KeycloakSpringBootConfigResolver KeycloakConfigResolver() {
return new KeycloakSpringBootConfigResolver();
}
#Override
protected void configure(HttpSecurity http) throws Exception {
super.configure(http);
http.cors().and().csrf().disable();
http.authorizeRequests()
.antMatchers("/api/sample*").hasRole("user")
.antMatchers("/ui/second*").hasRole("user")
.and()
.logout()
.logoutUrl("/logout")
.logoutSuccessUrl("/")
.permitAll();
}
}
And, this is the config for keycloak:
And, this is my Dockerfile were bad behavior is detected:
FROM openjdk:8
COPY app.jar /deploy/app.jar
WORKDIR /deploy
CMD java -jar app.jar
It is built by doing:
docker build . -t example
And it is executed like this:
docker run -d -p 8081:8081 example
You can see that in the last way, the security is not working properly.
Now, I have to say that, in a direct way it works great:
java -jar app.jar
So, my obviouse question (to the jboss guys or RedHat guys or any guy with the enought wisdom) is, How can I make it work Keycloak Server from within a containerized Springboot application?
Finally, after several weeks of testing, I found the answer: The bad docker image was done by using jdk 1.8.0_65-b17 and the one that worked to me was 1.8.0_232-b09:
So, as soon as I tested the keycloak server with this new image, everything worked as expected.
Maybe this could help someone some day with the same problem or similar.

org.apache.http.client.HttpResponseException: No authentication header supplied

I am configuring neo4j database with Spring Boot. I am able to setup Spring Boot and it is working fine. But When I configure neo4j it is throwing exception org.apache.http.client.HttpResponseException: No authentication header supplied.
Log stash is below:
2016-11-08 15:20:54.962 INFO 4932 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization completed in 23 ms
2016-11-08 15:24:29.062 INFO 4932 --- [nio-8080-exec-2] o.n.o.drivers.http.request.HttpRequest : Thread: 27, url: http://localhost:7474/db/data/transaction/commit, request: {"statements":[{"statement":"MATCH (user:User) WHERE user.id = {id} RETURN user","parameters":{"id":"10"},"resultDataContents":["graph"],"includeStats":false}]}
2016-11-08 15:24:29.285 WARN 4932 --- [nio-8080-exec-2] o.n.o.drivers.http.request.HttpRequest : Thread: 27, response: No authentication header supplied.
2016-11-08 15:24:29.288 INFO 4932 --- [nio-8080-exec-2] o.s.d.neo4j.config.Neo4jConfiguration : Intercepted exception
2016-11-08 15:24:29.299 ERROR 4932 --- [nio-8080-exec-2] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.neo4j.ogm.drivers.http.request.HttpRequestException: http://localhost:7474/db/data/transaction/commit: No authentication header supplied.] with root cause
org.apache.http.client.HttpResponseException: No authentication header supplied.
at org.neo4j.ogm.drivers.http.request.HttpRequest.execute(HttpRequest.java:203) ~[neo4j-ogm-http-driver-2.0.5.jar:na]
at org.neo4j.ogm.drivers.http.request.HttpRequest.executeRequest(HttpRequest.java:168) ~[neo4j-ogm-http-driver-2.0.5.jar:na]
at org.neo4j.ogm.drivers.http.request.HttpRequest.execute(HttpRequest.java:87) ~[neo4j-ogm-http-driver-2.0.5.jar:na]
at org.neo4j.ogm.session.delegates.ExecuteQueriesDelegate.executeAndMap(ExecuteQueriesDelegate.java:114) ~[neo4j-ogm-core-2.0.5.jar:na]
at org.neo4j.ogm.session.delegates.ExecuteQueriesDelegate.query(ExecuteQueriesDelegate.java:87) ~[neo4j-ogm-core-2.0.5.jar:na]
at org.neo4j.ogm.session.delegates.ExecuteQueriesDelegate.queryForObject(ExecuteQueriesDelegate.java:61) ~[neo4j-ogm-core-2.0.5.jar:na]
at org.neo4j.ogm.session.Neo4jSession.queryForObject(Neo4jSession.java:363) ~[neo4j-ogm-core-2.0.5.jar:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_31]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_31]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_31]
at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_31]
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:333) ~[spring-aop-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190) ~[spring-aop-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) ~[spring-aop-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:133) ~[spring-aop-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:121) ~[spring-aop-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213) ~[spring-aop-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at com.sun.proxy.$Proxy60.queryForObject(Unknown Source) ~[na:na]
Configuration Class:
public class ApplicationConfiguration extends Neo4jConfiguration{
#Bean
public Configuration getConfiguration(){
Configuration config = new Configuration();
config.driverConfiguration()
.setDriverClassName("org.neo4j.ogm.drivers.http.driver.HttpDriver")
.setURI("http://neo4j:welcome*123#localhost:7474");
return config;
}
#Bean
public SessionFactory getSessionFactory(){
return new SessionFactory(getConfiguration(), "com.ent.entity");
}
#Bean
#Scope(value = "session", proxyMode = ScopedProxyMode.TARGET_CLASS)
public Session getSession() throws Exception{
return super.getSession();
}
}
Spring Boot has the list of the configuration properties, which can be set in the "application.properties" file.
Setting these might solve the problem:
spring.data.neo4j.username=neo4j (default user)
spring.data.neo4j.password=neo4j (default password)
This requires an authentication in the header or you can disable authentication try to edit the neo4j.conf install dir bin/neo4j.conf
and uncomment this line
# Whether requests to Neo4j are authenticated.
# To disable authentication, uncomment this line
dbms.security.auth_enabled=false
OR enable neo DBMS connector
# HTTP Connector. There must be exactly one HTTP connector.
dbms.connector.http.enabled=true
#dbms.connector.http.listen_address=:7474

Spring Batch repeats step with chunk size 1 even after success

Summary: Job restarts/retries even when reader/processor/writer succeed.
My step is defined as follows:
return stepBuilder.get("job.transaction-export.step1")
// .startLimit(stepStartLimit)
.<AfxEntity, AfxEntity> chunk(chunkSize)
.reader(reader)
.processor(processor)
.writer(writer)
// .faultTolerant()
// .backOffPolicy(exponentialRandomBackOffPolicy)
// .retry(HttpServerErrorException.class)
// .retry(UnknownHttpStatusCodeException.class)
// .retry(ResourceAccessException.class)
// .noRetry(HttpClientErrorException.class)
.build();
At some point I want certain HTTP errors to trigger a retry, but at this point, all of that code is commented out. I just have simple classes implementing the Item* interfaces, and a chunk size of 1.
I have done nothing that I can tell to cause the repeat policy to be more than once.
My application is a Spring Boot application that has several JMS listeners. When a listener gets a message, it dispatches the appropriate Job with the message contents.
This job is an export. The JMS message provides the ID of the record to be exported. The ItemReader (annotated with #StepScope) pulls the record into a Map. The ItemProcessor adds additional data to the Map. The ItemWriter does an HTTP POST with Basic Auth with the data gathered previously.
The test class, in a separate process, registers REST listener and posts a JMS message. When the REST method gets the message it exits. This means success. (Test needs to be enhanced.)
What is happening right now is that, in spite of a successful (no exceptions/errors, auth passes, data is exchanged both ways) REST transaction, the Batch framework repeats the step. Since the test class exits after responding to the REST request, the new POSTs fail. I let it run once and it went to over 120 retries.
The Question: In case of success, how do I keep the retry/repeat mechanism from being triggered?
The logs:
2016-03-03 14:19:44.952 TRACE 26954 --- [enerContainer-1] c.a.a.e.t.TransactionMQListener : Received message ActiveMQTextMessage {message found in here} with listener com.abc.afx.exporter.transaction.TransactionMQListener$$EnhancerBySpringCGLIB$$11c2ee83#480f78d0.
2016-03-03 14:19:44.955 DEBUG 26954 --- [enerContainer-1] c.a.a.e.t.TransactionMQListener : jobParameters = {job parameters here}
2016-03-03 14:19:44.956 DEBUG 26954 --- [enerContainer-1] BatchConfiguration$ReferenceTargetSource : Initializing lazy target object
2016-03-03 14:19:45.847 INFO 26954 --- [enerContainer-1] o.s.b.c.l.support.SimpleJobLauncher : Job: [SimpleJob: [name=job.transaction-export]] launched with the following parameters: [{job parameters here, launchTime=1457032784898}]
2016-03-03 14:19:45.848 DEBUG 26954 --- [enerContainer-1] o.s.batch.core.job.AbstractJob : Job execution starting: JobExecution: id=371, version=0, startTime=null, endTime=null, lastUpdated=Thu Mar 03 14:19:45 EST 2016, status=STARTING, exitStatus=exitCode=UNKNOWN;exitDescription=, job=[JobInstance: id=370, version=0, Job=[job.transaction-export]], jobParameters=[{job parameters here, launchTime=1457032784898}]
2016-03-03 14:19:45.850 DEBUG 26954 --- [enerContainer-1] BatchConfiguration$ReferenceTargetSource : Initializing lazy target object
// step starts here
2016-03-03 14:19:46.658 INFO 26954 --- [enerContainer-1] o.s.batch.core.job.SimpleStepHandler : Executing step: [job.transaction-export.step1]
2016-03-03 14:19:46.658 DEBUG 26954 --- [enerContainer-1] o.s.batch.core.step.AbstractStep : Executing: id=372
2016-03-03 14:19:46.810 DEBUG 26954 --- [enerContainer-1] o.s.batch.core.scope.StepScope : Creating object in scope=step, name=scopedTarget.reader
2016-03-03 14:19:46.817 DEBUG 26954 --- [enerContainer-1] o.s.batch.core.scope.StepScope : Registered destruction callback in scope=step, name=scopedTarget.reader
2016-03-03 14:19:46.817 DEBUG 26954 --- [enerContainer-1] o.s.batch.core.scope.StepScope : Creating object in scope=step, name=scopedTarget.reader.transaction
2016-03-03 14:19:46.819 DEBUG 26954 --- [enerContainer-1] o.s.batch.core.scope.StepScope : Registered destruction callback in scope=step, name=scopedTarget.reader.transaction
2016-03-03 14:19:46.947 DEBUG 26954 --- [enerContainer-1] o.s.batch.repeat.support.RepeatTemplate : Starting repeat context.
2016-03-03 14:19:46.947 DEBUG 26954 --- [enerContainer-1] o.s.batch.repeat.support.RepeatTemplate : Repeat operation about to start at count=1
2016-03-03 14:19:46.948 DEBUG 26954 --- [enerContainer-1] o.s.b.c.s.c.StepContextRepeatCallback : Preparing chunk execution for StepContext: org.springframework.batch.core.scope.context.StepContext#d9db406
2016-03-03 14:19:46.948 DEBUG 26954 --- [enerContainer-1] o.s.b.c.s.c.StepContextRepeatCallback : Chunk execution starting: queue size=0
2016-03-03 14:19:46.950 DEBUG 26954 --- [enerContainer-1] BatchConfiguration$ReferenceTargetSource : Initializing lazy target object
2016-03-03 14:19:46.981 DEBUG 26954 --- [enerContainer-1] o.s.batch.repeat.support.RepeatTemplate : Starting repeat context.
2016-03-03 14:19:46.981 DEBUG 26954 --- [enerContainer-1] o.s.batch.repeat.support.RepeatTemplate : Repeat operation about to start at count=1
2016-03-03 14:19:46.992 TRACE 26954 --- [enerContainer-1] c.a.a.e.t.job.reader.TransactionReader : In TransactionReader.read
2016-03-03 14:19:47.034 TRACE 26954 --- [enerContainer-1] c.a.a.e.t.job.reader.TransactionReader : paymentTransaction = {map data in here}
2016-03-03 14:19:47.034 DEBUG 26954 --- [enerContainer-1] o.s.batch.repeat.support.RepeatTemplate : Repeat is complete according to policy and result value.
2016-03-03 14:19:47.035 TRACE 26954 --- [enerContainer-1] c.a.a.e.t.j.p.TransactionProcessor : In TransactionProcessor.process with paymentTransaction {map data in here}
2016-03-03 14:19:47.038 TRACE 26954 --- [enerContainer-1] c.a.a.e.t.j.p.TransactionProcessor : returnAfxEntity = {map data in here}
2016-03-03 14:19:47.038 DEBUG 26954 --- [enerContainer-1] o.s.batch.core.scope.StepScope : Creating object in scope=step, name=scopedTarget.writer.transaction-xyz
2016-03-03 14:19:47.041 DEBUG 26954 --- [enerContainer-1] o.s.batch.core.scope.StepScope : Registered destruction callback in scope=step, name=scopedTarget.writer.transaction-xyz
2016-03-03 14:19:47.068 TRACE 26954 --- [enerContainer-1] c.a.a.e.t.j.w.v.TransactionXyzWriter : POSTing to http://localhost:19999/transactionExportJob
2016-03-03 14:19:47.307 TRACE 26954 --- [enerContainer-1] c.a.a.e.t.j.w.v.TransactionXyzWriter : jsonObject = {"success":"true"}
2016-03-03 14:19:47.308 DEBUG 26954 --- [enerContainer-1] o.s.b.c.step.item.ChunkOrientedTasklet : Inputs not busy, ended: false
2016-03-03 14:19:47.308 DEBUG 26954 --- [enerContainer-1] o.s.batch.core.step.tasklet.TaskletStep : Applying contribution: [StepContribution: read=1, written=1, filtered=0, readSkips=0, writeSkips=0, processSkips=0, exitStatus=EXECUTING]
2016-03-03 14:19:47.341 DEBUG 26954 --- [enerContainer-1] o.s.batch.core.step.tasklet.TaskletStep : Saving step execution before commit: StepExecution: id=372, version=1, name=job.transaction-export.step1, status=STARTED, exitStatus=EXECUTING, readCount=1, filterCount=0, writeCount=1 readSkipCount=0, writeSkipCount=0, processSkipCount=0, commitCount=1, rollbackCount=0, exitDescription=
// repeat starts here
2016-03-03 14:19:47.466 DEBUG 26954 --- [enerContainer-1] o.s.batch.repeat.support.RepeatTemplate : Repeat operation about to start at count=2
2016-03-03 14:19:47.466 DEBUG 26954 --- [enerContainer-1] o.s.b.c.s.c.StepContextRepeatCallback : Preparing chunk execution for StepContext: org.springframework.batch.core.scope.context.StepContext#d9db406
2016-03-03 14:19:47.466 DEBUG 26954 --- [enerContainer-1] o.s.b.c.s.c.StepContextRepeatCallback : Chunk execution starting: queue size=0
2016-03-03 14:19:47.496 DEBUG 26954 --- [enerContainer-1] o.s.batch.repeat.support.RepeatTemplate : Starting repeat context.
2016-03-03 14:19:47.497 DEBUG 26954 --- [enerContainer-1] o.s.batch.repeat.support.RepeatTemplate : Repeat operation about to start at count=1
2016-03-03 14:19:47.497 TRACE 26954 --- [enerContainer-1] c.a.a.e.t.job.reader.TransactionReader : In TransactionReader.read
2016-03-03 14:19:47.534 TRACE 26954 --- [enerContainer-1] c.a.a.e.t.job.reader.TransactionReader : paymentTransaction = {map details here}
2016-03-03 14:19:47.534 DEBUG 26954 --- [enerContainer-1] o.s.batch.repeat.support.RepeatTemplate : Repeat is complete according to policy and result value.
2016-03-03 14:19:47.534 TRACE 26954 --- [enerContainer-1] c.a.a.e.t.j.p.TransactionProcessor : In TransactionProcessor.process with paymentTransaction {map details here}
2016-03-03 14:19:47.534 TRACE 26954 --- [enerContainer-1] c.a.a.e.t.j.p.TransactionProcessor : returnAfxEntity = {map details here}
2016-03-03 14:19:47.542 TRACE 26954 --- [enerContainer-1] c.a.a.e.t.j.w.v.TransactionXyzWriter : POSTing to http://localhost:19999/transactionExportJob
2016-03-03 14:19:47.546 DEBUG 26954 --- [enerContainer-1] o.s.batch.core.step.tasklet.TaskletStep : Applying contribution: [StepContribution: read=1, written=0, filtered=0, readSkips=0, writeSkips=0, processSkips=0, exitStatus=EXECUTING]
2016-03-03 14:19:47.546 DEBUG 26954 --- [enerContainer-1] o.s.batch.core.step.tasklet.TaskletStep : Rollback for RuntimeException: org.springframework.web.client.ResourceAccessException: I/O error on POST request for "http://localhost:19999/transactionExportJob": Unexpected end of file from server; nested exception is java.net.SocketException: Unexpected end of file from server
2016-03-03 14:19:47.601 DEBUG 26954 --- [enerContainer-1] o.s.batch.repeat.support.RepeatTemplate : Handling exception: org.springframework.web.client.ResourceAccessException, caused by: org.springframework.web.client.ResourceAccessException: I/O error on POST request for "http://localhost:19999/transactionExportJob": Unexpected end of file from server; nested exception is java.net.SocketException: Unexpected end of file from server
2016-03-03 14:19:47.601 DEBUG 26954 --- [enerContainer-1] o.s.batch.repeat.support.RepeatTemplate : Handling fatal exception explicitly (rethrowing first of 1): org.springframework.web.client.ResourceAccessException: I/O error on POST request for "http://localhost:19999/transactionExportJob": Unexpected end of file from server; nested exception is java.net.SocketException: Unexpected end of file from server
2016-03-03 14:19:47.608 ERROR 26954 --- [enerContainer-1] o.s.batch.core.step.AbstractStep : Encountered an error executing step job.transaction-export.step1 in job job.transaction-export
org.springframework.web.client.ResourceAccessException: I/O error on POST request for "http://localhost:19999/transactionExportJob": Unexpected end of file from server; nested exception is java.net.SocketException: Unexpected end of file from server
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:607) ~[spring-web-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:557) ~[spring-web-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:475) ~[spring-web-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at com.abc.afx.exporter.transaction.job.writer.xyz.TransactionXyzWriter.write(TransactionXyzWriter.java:89) ~[classes/:na]
at com.abc.afx.exporter.transaction.job.writer.xyz.TransactionXyzWriter$$FastClassBySpringCGLIB$$7020a21.invoke(<generated>) ~[classes/:na]
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204) ~[spring-core-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:720) ~[spring-aop-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) [spring-aop-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:133) ~[spring-aop-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:121) ~[spring-aop-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) [spring-aop-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:655) ~[spring-aop-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at com.abc.afx.exporter.transaction.job.writer.xyz.TransactionXyzWriter$$EnhancerBySpringCGLIB$$3eabc04e.write(<generated>) ~[classes/:na]
at org.springframework.batch.core.step.item.SimpleChunkProcessor.writeItems(SimpleChunkProcessor.java:175) ~[spring-batch-core-3.0.6.RELEASE.jar:3.0.6.RELEASE]
at org.springframework.batch.core.step.item.SimpleChunkProcessor.doWrite(SimpleChunkProcessor.java:151) ~[spring-batch-core-3.0.6.RELEASE.jar:3.0.6.RELEASE]
at org.springframework.batch.core.step.item.SimpleChunkProcessor.write(SimpleChunkProcessor.java:274) ~[spring-batch-core-3.0.6.RELEASE.jar:3.0.6.RELEASE]
at org.springframework.batch.core.step.item.SimpleChunkProcessor.process(SimpleChunkProcessor.java:199) ~[spring-batch-core-3.0.6.RELEASE.jar:3.0.6.RELEASE]
at org.springframework.batch.core.step.item.ChunkOrientedTasklet.execute(ChunkOrientedTasklet.java:75) ~[spring-batch-core-3.0.6.RELEASE.jar:3.0.6.RELEASE]
at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:406) ~[spring-batch-core-3.0.6.RELEASE.jar:3.0.6.RELEASE]
at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:330) ~[spring-batch-core-3.0.6.RELEASE.jar:3.0.6.RELEASE]
at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:133) ~[spring-tx-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.batch.core.step.tasklet.TaskletStep$2.doInChunkContext(TaskletStep.java:271) ~[spring-batch-core-3.0.6.RELEASE.jar:3.0.6.RELEASE]
at org.springframework.batch.core.scope.context.StepContextRepeatCallback.doInIteration(StepContextRepeatCallback.java:81) ~[spring-batch-core-3.0.6.RELEASE.jar:3.0.6.RELEASE]
at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:374) ~[spring-batch-infrastructure-3.0.6.RELEASE.jar:3.0.6.RELEASE]
at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:215) ~[spring-batch-infrastructure-3.0.6.RELEASE.jar:3.0.6.RELEASE]
at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:144) ~[spring-batch-infrastructure-3.0.6.RELEASE.jar:3.0.6.RELEASE]
at org.springframework.batch.core.step.tasklet.TaskletStep.doExecute(TaskletStep.java:257) ~[spring-batch-core-3.0.6.RELEASE.jar:3.0.6.RELEASE]
at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:200) ~[spring-batch-core-3.0.6.RELEASE.jar:3.0.6.RELEASE]
at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:148) [spring-batch-core-3.0.6.RELEASE.jar:3.0.6.RELEASE]
at org.springframework.batch.core.job.AbstractJob.handleStep(AbstractJob.java:392) [spring-batch-core-3.0.6.RELEASE.jar:3.0.6.RELEASE]
at org.springframework.batch.core.job.SimpleJob.doExecute(SimpleJob.java:135) [spring-batch-core-3.0.6.RELEASE.jar:3.0.6.RELEASE]
at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:306) [spring-batch-core-3.0.6.RELEASE.jar:3.0.6.RELEASE]
at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:135) [spring-batch-core-3.0.6.RELEASE.jar:3.0.6.RELEASE]
at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50) [spring-core-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:128) [spring-batch-core-3.0.6.RELEASE.jar:3.0.6.RELEASE]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_51]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_51]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_51]
...
Caused by: java.net.SocketException: Unexpected end of file from server
at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:792) ~[na:1.8.0_51]
at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:647) ~[na:1.8.0_51]
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1535) ~[na:1.8.0_51]
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1440) ~[na:1.8.0_51]
at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:480) ~[na:1.8.0_51]
at org.springframework.http.client.SimpleClientHttpResponse.getRawStatusCode(SimpleClientHttpResponse.java:48) ~[spring-web-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.http.client.AbstractClientHttpResponse.getStatusCode(AbstractClientHttpResponse.java:33) ~[spring-web-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.web.client.DefaultResponseErrorHandler.getHttpStatusCode(DefaultResponseErrorHandler.java:56) ~[spring-web-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.web.client.DefaultResponseErrorHandler.hasError(DefaultResponseErrorHandler.java:50) ~[spring-web-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.web.client.RestTemplate.handleResponse(RestTemplate.java:629) ~[spring-web-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:597) ~[spring-web-4.2.4.RELEASE.jar:4.2.4.RELEASE]
... 63 common frames omitted
2016-03-03 14:19:47.758 DEBUG 26954 --- [enerContainer-1] o.s.b.c.r.dao.JdbcStepExecutionDao : Truncating long message before update of StepExecution, original message is: org.springframework.web.client.ResourceAccessException: I/O error on POST request for "http://localhost:19999/transactionExportJob": Unexpected end of file from server; nested exception is java.net.SocketException: Unexpected end of file from server
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:607)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:557)
at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:475)
at com.abc.afx.exporter.transaction.job.writer.xyz.TransactionXyzWriter.write(TransactionXyzWriter.java:89)
at com.abc.afx.exporter.transaction.job.writer.xyz.TransactionXyzWriter$$FastClassBySpringCGLIB$$7020a21.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:720)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:133)
at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:121)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:655)
at com.abc.afx.exporter.transaction.job.writer.xyz.TransactionXyzWriter$$EnhancerBySpringCGLIB$$3eabc04e.write(<generated>)
at org.springframework.batch.core.step.item.SimpleChunkProcessor.writeItems(SimpleChunkProcessor.java:175)
at org.springframework.batch.core.step.item.SimpleChunkProcessor.doWrite(SimpleChunkProcessor.java:151)
at org.springframework.batch.core.step.item.SimpleChunkProcessor.write(SimpleChunkProcessor.java:274)
at org.springframework.batch.core.step.item.SimpleChunkProcessor.process(SimpleChunkProcessor.java:199)
at org.springframework.batch.core.step.item.ChunkOrientedTasklet.execute(ChunkOrientedTasklet.java:75)
at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:406)
at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:330)
at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:133)
at org.springframework.batch.core.step.tasklet.TaskletStep$2.doInChunkContext(TaskletStep.java:271)
at org.springframework.batch.core.scope.context.StepContextRepeatCallback.doInIteration(StepContextRepeatCallback.java:81)
at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:374)
at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:215)
at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:144)
at org.springframework.batch.core.step.tasklet.TaskletStep.doExecute(TaskletStep.java:257)
at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:200)
at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:148)
at org.springframework.batch.core.job.AbstractJob.handleStep(AbstractJob.java:392)
at org.springframework.batch.core.job.SimpleJob.doExecute(SimpleJob.java:135)
at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:306)
at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:135)
at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50)
at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:128)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
...
Caused by: java.net.SocketException: Unexpected end of file from server
at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:792)
at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:647)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1535)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1440)
at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:480)
at org.springframework.http.client.SimpleClientHttpResponse.getRawStatusCode(SimpleClientHttpResponse.java:48)
at org.springframework.http.client.AbstractClientHttpResponse.getStatusCode(AbstractClientHttpResponse.java:33)
at org.springframework.web.client.DefaultResponseErrorHandler.getHttpStatusCode(DefaultResponseErrorHandler.java:56)
at org.springframework.web.client.DefaultResponseErrorHandler.hasError(DefaultResponseErrorHandler.java:50)
at org.springframework.web.client.RestTemplate.handleResponse(RestTemplate.java:629)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:597)
... 63 more
2016-03-03 14:19:47.892 DEBUG 26954 --- [enerContainer-1] o.s.batch.core.step.AbstractStep : Step execution complete: StepExecution: id=372, version=3, name=job.transaction-export.step1, status=FAILED, exitStatus=FAILED, readCount=2, filterCount=0, writeCount=1 readSkipCount=0, writeSkipCount=0, processSkipCount=0, commitCount=1, rollbackCount=1
2016-03-03 14:19:48.017 DEBUG 26954 --- [enerContainer-1] o.s.batch.core.job.AbstractJob : Upgrading JobExecution status: StepExecution: id=372, version=3, name=job.transaction-export.step1, status=FAILED, exitStatus=FAILED, readCount=2, filterCount=0, writeCount=1 readSkipCount=0, writeSkipCount=0, processSkipCount=0, commitCount=1, rollbackCount=1, exitDescription=org.springframework.web.client.ResourceAccessException: I/O error on POST request for "http://localhost:19999/transactionExportJob": Unexpected end of file from server; nested exception is java.net.SocketException: Unexpected end of file from server
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:607)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:557)
at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:475)
at com.abc.afx.exporter.transaction.job.writer.xyz.TransactionXyzWriter.write(TransactionXyzWriter.java:89)
at com.abc.afx.exporter.transaction.job.writer.xyz.TransactionXyzWriter$$FastClassBySpringCGLIB$$7020a21.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:720)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:133)
at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:121)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:655)
at com.abc.afx.exporter.transaction.job.writer.xyz.TransactionXyzWriter$$EnhancerBySpringCGLIB$$3eabc04e.write(<generated>)
at org.springframework.batch.core.step.item.SimpleChunkProcessor.writeItems(SimpleChunkProcessor.java:175)
at org.springframework.batch.core.step.item.SimpleChunkProcessor.doWrite(SimpleChunkProcessor.java:151)
at org.springframework.batch.core.step.item.SimpleChunkProcessor.write(SimpleChunkProcessor.java:274)
at org.springframework.batch.core.step.item.SimpleChunkProcessor.process(SimpleChunkProcessor.java:199)
at org.springframework.batch.core.step.item.ChunkOrientedTasklet.execute(ChunkOrientedTasklet.java:75)
at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:406)
at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:330)
at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:133)
at org.springframework.batch.core.step.tasklet.TaskletStep$2.doInChunkContext(TaskletStep.java:271)
at org.springframework.batch.core.scope.context.StepContextRepeatCallback.doInIteration(StepContextRepeatCallback.java:81)
at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:374)
at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:215)
at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:144)
at org.springframework.batch.core.step.tasklet.TaskletStep.doExecute(TaskletStep.java:257)
at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:200)
at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:148)
at org.springframework.batch.core.job.AbstractJob.handleStep(AbstractJob.java:392)
at org.springframework.batch.core.job.SimpleJob.doExecute(SimpleJob.java:135)
at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:306)
at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:135)
at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50)
at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:128)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
...
Caused by: java.net.SocketException: Unexpected end of file from server
... 74 more
...
, job=[JobInstance: id=370, version=0, Job=[job.transaction-export]], jobParameters=[{job parameters here, launchTime=1457032784898}]
2016-03-03 14:19:48.018 TRACE 26954 --- [enerContainer-1] .p.j.PatientScheduleJobExecutionListener : Job {job parameters here, launchTime=1457032784898} has completed.
You can try to use step listener and then decide repeat a step or finish the job. Check this answer.

Inject mock services when testing a #RestController

I am testing a REST controller annotated with #RestController, and I'd like to inject mock services.
I am looking for help here spring boot ones but with no luck.
I am starting a test of a spring-boot application with the following annotations:
#RunWith(SpringJUnit4ClassRunner.class)
#SpringApplicationConfiguration(classes = Application.class)
#WebIntegrationTest
where Application.class is annotated with #SpringBootApplication, but it seems that I can't find a way to inject a mock dependency on my controller, for example doing this:
#Mock
private BlogPostService blogPostService;
#Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
}
This is the stack trace I see, and it fails after going in timeout since it tries to inject all dependencies down to the database (the exact thing I am trying to avoid trying to introduce mocks at the services level):
com.xxx.cms.web.resources.BlogPostControllerWithTemplateTestCase
13:30:12.924 [main] DEBUG o.s.t.c.j.SpringJUnit4ClassRunner - SpringJUnit4ClassRunner constructor called with [class com.xxx.cms.web.resources.BlogPostControllerWithTemplateTestCase]
13:30:12.934 [main] DEBUG o.s.test.context.BootstrapUtils - Instantiating CacheAwareContextLoaderDelegate from class [org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate]
13:30:12.943 [main] DEBUG o.s.test.context.BootstrapUtils - Instantiating BootstrapContext using constructor [public org.springframework.test.context.support.DefaultBootstrapContext(java.lang.Class,org.springframework.test.context.CacheAwareContextLoaderDelegate)]
13:30:12.965 [main] DEBUG o.s.test.context.BootstrapUtils - Instantiating TestContextBootstrapper for test class [com.xxx.cms.web.resources.BlogPostControllerWithTemplateTestCase] from class [org.springframework.boot.test.WebAppIntegrationTestContextBootstrapper]
13:30:12.998 [main] DEBUG o.s.b.t.WebAppIntegrationTestContextBootstrapper - Found explicit ContextLoader class [org.springframework.boot.test.SpringApplicationContextLoader] for context configuration attributes [ContextConfigurationAttributes#2b552920 declaringClass = 'com.xxx.cms.web.resources.BlogPostControllerWithTemplateTestCase', classes = '{class com.xxx.cms.web.Application}', locations = '{}', inheritLocations = true, initializers = '{}', inheritInitializers = true, name = [null], contextLoaderClass = 'org.springframework.boot.test.SpringApplicationContextLoader']
13:30:13.015 [main] DEBUG o.s.t.c.s.AbstractContextLoader - Did not detect default resource location for test class [com.xxx.cms.web.resources.BlogPostControllerWithTemplateTestCase]: class path resource [com/xxx/cms/web/resources/BlogPostControllerWithTemplateTestCase-context.xml] does not exist
13:30:13.016 [main] DEBUG o.s.t.c.s.AbstractContextLoader - Did not detect default resource location for test class [com.xxx.cms.web.resources.BlogPostControllerWithTemplateTestCase]: class path resource [com/xxx/cms/web/resources/BlogPostControllerWithTemplateTestCaseContext.groovy] does not exist
13:30:13.016 [main] INFO o.s.t.c.s.AbstractContextLoader - Could not detect default resource locations for test class [com.xxx.cms.web.resources.BlogPostControllerWithTemplateTestCase]: no resource found for suffixes {-context.xml, Context.groovy}.
13:30:13.019 [main] DEBUG o.s.t.c.support.ActiveProfilesUtils - Could not find an 'annotation declaring class' for annotation type [org.springframework.test.context.ActiveProfiles] and class [com.xxx.cms.web.resources.BlogPostControllerWithTemplateTestCase]
13:30:13.026 [main] DEBUG o.s.test.util.ReflectionTestUtils - Setting field 'propertySourceProperties' of type [null] on target object [[WebMergedContextConfiguration#5f282abb testClass = BlogPostControllerWithTemplateTestCase, locations = '{}', classes = '{class com.xxx.cms.web.Application}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{}', resourceBasePath = '', contextLoader = 'org.springframework.boot.test.SpringApplicationContextLoader', parent = [null]]] or target class [class org.springframework.test.context.web.WebMergedContextConfiguration] to value [[Ljava.lang.String;#167fdd33]
13:30:13.027 [main] DEBUG o.s.b.t.WebAppIntegrationTestContextBootstrapper - #TestExecutionListeners is not present for class [com.xxx.cms.web.resources.BlogPostControllerWithTemplateTestCase]: using defaults.
13:30:13.036 [main] INFO o.s.b.t.WebAppIntegrationTestContextBootstrapper - Loaded default TestExecutionListener class names from location [META-INF/spring.factories]: [org.springframework.test.context.web.ServletTestExecutionListener, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener, org.springframework.test.context.support.DependencyInjectionTestExecutionListener, org.springframework.test.context.support.DirtiesContextTestExecutionListener, org.springframework.test.context.transaction.TransactionalTestExecutionListener, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener]
13:30:13.060 [main] INFO o.s.b.t.WebAppIntegrationTestContextBootstrapper - Using TestExecutionListeners: [org.springframework.test.context.web.ServletTestExecutionListener#7b69c6ba, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener#46daef40, org.springframework.test.context.support.DependencyInjectionTestExecutionListener#12f41634, org.springframework.test.context.support.DirtiesContextTestExecutionListener#13c27452, org.springframework.test.context.transaction.TransactionalTestExecutionListener#262b2c86, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener#371a67ec]
13:30:13.063 [main] DEBUG o.s.t.annotation.ProfileValueUtils - Retrieved #ProfileValueSourceConfiguration [null] for test class [com.xxx.cms.web.resources.BlogPostControllerWithTemplateTestCase]
13:30:13.064 [main] DEBUG o.s.t.annotation.ProfileValueUtils - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [com.xxx.cms.web.resources.BlogPostControllerWithTemplateTestCase]13:30:13.105 [main] DEBUG o.s.t.annotation.ProfileValueUtils - Retrieved #ProfileValueSourceConfiguration [null] for test class [com.xxx.cms.web.resources.BlogPostControllerWithTemplateTestCase]
13:30:13.105 [main] DEBUG o.s.t.annotation.ProfileValueUtils - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [com.xxx.cms.web.resources.BlogPostControllerWithTemplateTestCase]13:30:13.107 [main] DEBUG o.s.t.annotation.ProfileValueUtils - Retrieved #ProfileValueSourceConfiguration [null] for test class [com.xxx.cms.web.resources.BlogPostControllerWithTemplateTestCase]
13:30:13.107 [main] DEBUG o.s.t.annotation.ProfileValueUtils - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [com.xxx.cms.web.resources.BlogPostControllerWithTemplateTestCase]
13:30:13.108 [main] DEBUG o.s.t.annotation.ProfileValueUtils - Retrieved #ProfileValueSourceConfiguration [null] for test class [com.xxx.cms.web.resources.BlogPostControllerWithTemplateTestCase]
13:30:13.108 [main] DEBUG o.s.t.annotation.ProfileValueUtils - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [com.xxx.cms.web.resources.BlogPostControllerWithTemplateTestCase]
13:30:13.115 [main] DEBUG o.s.t.c.s.AbstractDirtiesContextTestExecutionListener - Before test class: context [DefaultTestContext#74a10858 testClass = BlogPostControllerWithTemplateTestCase, testInstance = [null], testMethod = [null], testException = [null], mergedContextConfiguration = [WebMergedContextConfiguration#5f282abb testClass = BlogPostControllerWithTemplateTestCase, locations = '{}', classes = '{class com.xxx.cms.web.Application}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{org.springframework.boot.test.IntegrationTest=true}', resourceBasePath = '', contextLoader = 'org.springframework.boot.test.SpringApplicationContextLoader', parent = [null]]], class annotated with #DirtiesContext [false] with mode [null].
13:30:13.124 [main] DEBUG o.s.t.annotation.ProfileValueUtils - Retrieved #ProfileValueSourceConfiguration [null] for test class [com.xxx.cms.web.resources.BlogPostControllerWithTemplateTestCase]
13:30:13.125 [main] DEBUG o.s.t.annotation.ProfileValueUtils - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [com.xxx.cms.web.resources.BlogPostControllerWithTemplateTestCase]
13:30:13.132 [main] DEBUG o.s.t.c.s.DependencyInjectionTestExecutionListener - Performing dependency injection for test context [[DefaultTestContext#74a10858 testClass = BlogPostControllerWithTemplateTestCase, testInstance = com.xxx.cms.web.resources.BlogPostControllerWithTemplateTestCase#75881071, testMethod = [null], testException = [null], mergedContextConfiguration = [WebMergedContextConfiguration#5f282abb testClass = BlogPostControllerWithTemplateTestCase, locations = '{}', classes = '{class com.xxx.cms.web.Application}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{org.springframework.boot.test.IntegrationTest=true}', resourceBasePath = '', contextLoader = 'org.springframework.boot.test.SpringApplicationContextLoader', parent = [null]]]].
13:30:13.259 [main] DEBUG o.s.core.env.StandardEnvironment - Adding [systemProperties] PropertySource with lowest search precedence
13:30:13.261 [main] DEBUG o.s.core.env.StandardEnvironment - Adding [systemEnvironment] PropertySource with lowest search precedence
13:30:13.261 [main] DEBUG o.s.core.env.StandardEnvironment - Initialized StandardEnvironment with PropertySources [systemProperties,systemEnvironment]
13:30:13.263 [main] DEBUG o.s.core.env.StandardEnvironment - Adding [integrationTest] PropertySource with search precedence immediately lower than [systemEnvironment]
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.3.1.RELEASE)
2016-01-18 13:30:14.252 INFO 3685 --- [ main] r.BlogPostControllerWithTemplateTestCase : Starting BlogPostControllerWithTemplateTestCase on Matteos-MacBook-Pro.local with PID 3685 (/Users/mox/Dati/Progetti/xxx/cms/cms-parent-pom/cms-web/target/test-classes started by mox in /Users/mox/Dati/Progetti/xxx/cms/cms-parent-pom/cms-web)
2016-01-18 13:30:14.253 INFO 3685 --- [ main] r.BlogPostControllerWithTemplateTestCase : No active profile set, falling back to default profiles: default
2016-01-18 13:30:14.362 INFO 3685 --- [ main] ationConfigEmbeddedWebApplicationContext : Refreshing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#36902638: startup date [Mon Jan 18 13:30:14 CET 2016]; root of context hierarchy
2016-01-18 13:30:17.504 INFO 3685 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat initialized with port(s): 8080 (http)
2016-01-18 13:30:17.521 INFO 3685 --- [ main] o.apache.catalina.core.StandardService : Starting service Tomcat
2016-01-18 13:30:17.525 INFO 3685 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet Engine: Apache Tomcat/8.0.30
2016-01-18 13:30:17.693 INFO 3685 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2016-01-18 13:30:17.694 INFO 3685 --- [ost-startStop-1] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 3337 ms
2016-01-18 13:30:17.887 INFO 3685 --- [ost-startStop-1] o.s.b.c.e.ServletRegistrationBean : Mapping servlet: 'dispatcherServlet' to [/]
2016-01-18 13:30:17.892 INFO 3685 --- [ost-startStop-1] o.s.b.c.embedded.FilterRegistrationBean : Mapping filter: 'characterEncodingFilter' to: [/*]
2016-01-18 13:30:18.528 INFO 3685 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/post/{id}],methods=[PUT]}" onto public org.springframework.http.ResponseEntity<com.xxx.cms.services.dtos.BlogPostDTO> com.xxx.cms.web.resources.BlogPostController.update(com.xxx.cms.services.dtos.BlogPostDTO)
2016-01-18 13:30:18.528 INFO 3685 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/post/{id}],methods=[DELETE]}" onto public org.springframework.http.ResponseEntity<com.xxx.cms.services.dtos.BlogPostDTO> com.xxx.cms.web.resources.BlogPostController.delete(long)
2016-01-18 13:30:18.529 INFO 3685 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/post],methods=[POST]}" onto public org.springframework.http.ResponseEntity<com.xxx.cms.services.dtos.BlogPostDTO> com.xxx.cms.web.resources.BlogPostController.create(com.xxx.cms.services.dtos.BlogPostDTO)
2016-01-18 13:30:18.529 INFO 3685 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/post/{id}],methods=[GET]}" onto public org.springframework.http.ResponseEntity<com.xxx.cms.services.dtos.BlogPostDTO> com.xxx.cms.web.resources.BlogPostController.findById(long)
2016-01-18 13:30:18.529 INFO 3685 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/post],methods=[GET]}" onto public org.springframework.http.ResponseEntity<java.util.List<com.xxx.cms.services.dtos.BlogPostDTO>> com.xxx.cms.web.resources.BlogPostController.findAll()
2016-01-18 13:30:18.529 INFO 3685 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/hello/{player}]}" onto public com.xxx.cms.persistence.domain.model.Message com.xxx.cms.web.resources.HelloWorldRestController.message(java.lang.String)
2016-01-18 13:30:18.537 INFO 3685 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest)
2016-01-18 13:30:18.538 INFO 3685 --- [ main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2016-01-18 13:30:18.580 INFO 3685 --- [ main] o.s.w.s.handler.SimpleUrlHandlerMapping : Mapped URL path [/resources/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2016-01-18 13:30:18.655 INFO 3685 --- [ main] s.w.s.m.m.a.RequestMappingHandlerAdapter : Looking for #ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#36902638: startup date [Mon Jan 18 13:30:14 CET 2016]; root of context hierarchy
2016-01-18 13:30:18.786 INFO 3685 --- [ main] c.i.c.p.config.MongoConfiguration : localhost:27017/smart-cms
2016-01-18 13:30:19.264 INFO 3685 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
2016-01-18 13:30:19.270 INFO 3685 --- [ main] r.BlogPostControllerWithTemplateTestCase : Started BlogPostControllerWithTemplateTestCase in 5.996 seconds (JVM running for 7.084)2016-01-18 13:30:19.756 INFO 3685 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring FrameworkServlet 'dispatcherServlet'
2016-01-18 13:30:19.756 INFO 3685 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization started
2016-01-18 13:30:19.771 INFO 3685 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization completed in 15 ms
2016-01-18 13:30:29.844 ERROR 3685 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.dao.DataAccessResourceFailureException: Timed out after 10000 ms while waiting to connect. Client view of cluster state is {type=Unknown, servers=[{address=localhost:27017, type=Unknown, state=Connecting, exception={com.mongodb.MongoException$Network: Exception opening the socket}, caused by {java.net.ConnectException: Connection refused}}]; nested exception is com.mongodb.MongoTimeoutException: Timed out after 10000 ms while waiting to connect. Client view of cluster state is {type=Unknown, servers=[{address=localhost:27017, type=Unknown, state=Connecting, exception={com.mongodb.MongoException$Network: Exception opening the socket}, caused by {java.net.ConnectException: Connection refused}}]] with root cause
com.mongodb.MongoTimeoutException: Timed out after 10000 ms while waiting to connect. Client view of cluster state is {type=Unknown, servers=[{address=localhost:27017, type=Unknown, state=Connecting, exception={com.mongodb.MongoException$Network: Exception opening the socket}, caused by {java.net.ConnectException: Connection refused}}]
at com.mongodb.BaseCluster.getDescription(BaseCluster.java:128) ~[mongo-java-driver-2.13.3.jar:na]
at com.mongodb.DBTCPConnector.getClusterDescription(DBTCPConnector.java:402) ~[mongo-java-driver-2.13.3.jar:na]
at com.mongodb.DBTCPConnector.getType(DBTCPConnector.java:579) ~[mongo-java-driver-2.13.3.jar:na]
at com.mongodb.DBTCPConnector.isMongosConnection(DBTCPConnector.java:376) ~[mongo-java-driver-2.13.3.jar:na]
at com.mongodb.Mongo.isMongosConnection(Mongo.java:622) ~[mongo-java-driver-2.13.3.jar:na]
at com.mongodb.DBCollection.findOne(DBCollection.java:936) ~[mongo-java-driver-2.13.3.jar:na]
at com.mongodb.DBCollection.findOne(DBCollection.java:914) ~[mongo-java-driver-2.13.3.jar:na]
at com.mongodb.DBCollection.findOne(DBCollection.java:858) ~[mongo-java-driver-2.13.3.jar:na]
at org.springframework.data.mongodb.core.MongoTemplate$FindOneCallback.doInCollection(MongoTemplate.java:2098) ~[spring-data-mongodb-1.8.2.RELEASE.jar:na]
at org.springframework.data.mongodb.core.MongoTemplate$FindOneCallback.doInCollection(MongoTemplate.java:2082) ~[spring-data-mongodb-1.8.2.RELEASE.jar:na]
at org.springframework.data.mongodb.core.MongoTemplate.executeFindOneInternal(MongoTemplate.java:1855) ~[spring-data-mongodb-1.8.2.RELEASE.jar:na]
at org.springframework.data.mongodb.core.MongoTemplate.doFindOne(MongoTemplate.java:1672) ~[spring-data-mongodb-1.8.2.RELEASE.jar:na]
at org.springframework.data.mongodb.core.MongoTemplate.findById(MongoTemplate.java:614) ~[spring-data-mongodb-1.8.2.RELEASE.jar:na]
at org.springframework.data.mongodb.repository.support.SimpleMongoRepository.findOne(SimpleMongoRepository.java:119) ~[spring-data-mongodb-1.8.2.RELEASE.jar:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_25]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_25]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_25]
at java.lang.reflect.Method.invoke(Method.java:483) ~[na:1.8.0_25]
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.executeMethodOn(RepositoryFactorySupport.java:483) ~[spring-data-commons-1.11.2.RELEASE.jar:na]
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:468) ~[spring-data-commons-1.11.2.RELEASE.jar:na]
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:440) ~[spring-data-commons-1.11.2.RELEASE.jar:na]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:61) ~[spring-data-commons-1.11.2.RELEASE.jar:na]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) ~[spring-aop-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:208) ~[spring-aop-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at com.sun.proxy.$Proxy66.findOne(Unknown Source) ~[na:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_25]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_25]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_25]
at java.lang.reflect.Method.invoke(Method.java:483) ~[na:1.8.0_25]
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:302) ~[spring-aop-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190) ~[spring-aop-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) ~[spring-aop-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136) ~[spring-tx-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:208) ~[spring-aop-4.2.4.RELEASE.jar:4.2.4.RELEASE]
at com.sun.proxy.$Proxy66.findOne(Unknown Source) ~[na:na]
at com.xxx.cms.services.BlogPostService.findTodoById(BlogPostService.java:54) ~[classes/:na]
at com.xxx.cms.services.BlogPostService.findById(BlogPostService.java:43) ~[classes/:na]
at com.xxx.cms.web.resources.BlogPostController.findById(BlogPostController.java:55) ~[classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_25]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_25]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_25]
at java.lang.reflect.Method.invoke(Method.java:483) ~[na:1.8.0_25]
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221) ~[spring-web-4.1.7.RELEASE.jar:4.1.7.RELEASE]
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137) ~[spring-web-4.1.7.RELEASE.jar:4.1.7.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110) ~[spring-webmvc-4.1.7.RELEASE.jar:4.1.7.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:776) ~[spring-webmvc-4.1.7.RELEASE.jar:4.1.7.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:705) ~[spring-webmvc-4.1.7.RELEASE.jar:4.1.7.RELEASE]
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) ~[spring-webmvc-4.1.7.RELEASE.jar:4.1.7.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:959) ~[spring-webmvc-4.1.7.RELEASE.jar:4.1.7.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:893) ~[spring-webmvc-4.1.7.RELEASE.jar:4.1.7.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:967) ~[spring-webmvc-4.1.7.RELEASE.jar:4.1.7.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:858) ~[spring-webmvc-4.1.7.RELEASE.jar:4.1.7.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:622) ~[tomcat-embed-core-8.0.30.jar:8.0.30]
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:843) ~[spring-webmvc-4.1.7.RELEASE.jar:4.1.7.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729) ~[tomcat-embed-core-8.0.30.jar:8.0.30]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291) ~[tomcat-embed-core-8.0.30.jar:8.0.30]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) ~[tomcat-embed-core-8.0.30.jar:8.0.30]
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) ~[tomcat-embed-websocket-8.0.30.jar:8.0.30]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) ~[tomcat-embed-core-8.0.30.jar:8.0.30]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) ~[tomcat-embed-core-8.0.30.jar:8.0.30]
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:85) ~[spring-web-4.1.7.RELEASE.jar:4.1.7.RELEASE]
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.1.7.RELEASE.jar:4.1.7.RELEASE]
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239) ~[tomcat-embed-core-8.0.30.jar:8.0.30]
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) ~[tomcat-embed-core-8.0.30.jar:8.0.30]
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212) ~[tomcat-embed-core-8.0.30.jar:8.0.30]
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106) [tomcat-embed-core-8.0.30.jar:8.0.30]
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) [tomcat-embed-core-8.0.30.jar:8.0.30]
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141) [tomcat-embed-core-8.0.30.jar:8.0.30]
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79) [tomcat-embed-core-8.0.30.jar:8.0.30]
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88) [tomcat-embed-core-8.0.30.jar:8.0.30]
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:521) [tomcat-embed-core-8.0.30.jar:8.0.30]
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1096) [tomcat-embed-core-8.0.30.jar:8.0.30]
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:674) [tomcat-embed-core-8.0.30.jar:8.0.30]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500) [tomcat-embed-core-8.0.30.jar:8.0.30]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456) [tomcat-embed-core-8.0.30.jar:8.0.30]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_25]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_25]
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-8.0.30.jar:8.0.30]
at java.lang.Thread.run(Thread.java:745) [na:1.8.0_25]
2016-01-18 13:30:29.905 INFO 3685 --- [ Thread-4] ationConfigEmbeddedWebApplicationContext : Closing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#36902638: startup date [Mon Jan 18 13:30:14 CET 2016]; root of context hierarchy
Process finished with exit code 0
You're using Mockito, why don't you use the Mockito test runner?
In stead of annotating your tests with the annotations you provided, use the following annotation:
#RunWith(MockitoJUnitRunner.class)
For example:
#RunWith(MockitoJUnitRunner.class)
public class MyControllerTest {
}
To inject a mock with Mockito in your controller, you use:
#RunWith(MockitoJUnitRunner.class)
public class MyControllerTest {
#InjectMocks
private MyController controller;
#Mock
private BlogPostService service;
}
In this case Mockito will create a new instance of MyController (your REST controller) and inject a mock of type BlogPostService in all fields of your controller with the given field.
The annotations you provided are great for integration testing, but you don't need them when you're testing your controller as a unit.
And if you're integration testing, mocking a service isn't right either.

Resources