RequestContextHolder null when using Camunda dependency

I recently stumbled across a problem in my Camunda/Spring Boot application. I just want to expose the Camunda REST-API and thus let Maven incorporate the camunda-bpm-spring-boot-starter-rest dependency. Unfortunately, this seems to mess with the Spring Boot configurations I am having already in place for non-Camunda API endpoints.

Specific Problem Description
I have a class of type AccessDecisionVoter (Spring) in which the RequestContextHolder (Spring) is queried for the current request details, while querying a self-made REST endpoint. This decision voter class is involved in method security and basically decides whether a user is authorized for this endpoint. While this approach works fine with all sorts of other camunda dependencies the above mentioned dependency modifies the request handling for my own API in some way. The result being a RequestContextHolder that returns null which ultimately leads to an AccessDeniedException.

Using the RequestContextHolder:

HttpServletRequest request = ((ServletRequestAttributes) Objects.requireNonNull(RequestContextHolder.getRequestAttributes())).getRequest();

Interpretation and Possible Solution
It seems like the problem could possibly be related to a thread problem in which the request information is not handed down to some child thread. But this would require the dependency to mess with the DispatcherServlet or something else and spawn a new thread to handle a request to a non-Camunda API. Seems weird, but on the other hand spawning a Bean of type RequestContextListener (Spring) indeed solves the problem.

public RequestContextListener requestContextListener() {
    return new RequestContextListener();

It would be great to understand this problem and how the dependency is messing with my endpoints. Ultimately I am looking for some modification that helps me get rid of the RequestContextListener bean, but it seems fine as a workaround.

Any good explanations?

Cheers, Thomas

1 Like

Luckily, I was able to answer my own question.

Using the RequestContextListener seems like the correct approach.

Explanation in short
Camunda replaces with the Camunda REST-API dependency the RequestContextFilter with another bean and thus no request details are shared with child threads.

The full answer can be found on Stack Overflow.

1 Like