1
I have a "problem" in the system I’m working on, it’s a Java api.
Not long ago, they started deploying filters from the request parameters. For every request, it has a preHandle
that filters this request and saves a request
, so far so good. After that, it redirects to the mapped method that it should access, for example:
Clientaction
@PostMapping("/rota/{param1}/{param2}/{param3}")
public void process(@PathVariable String param1, @PathVariable String param2, @PathVariable String param3) {
List<Clients> clients = clientService.getClients();
processService.process();
...
}
With this, it executes a method that returns all clients, but in this method there is a request filter, if you have a request, it returns it to be used, otherwise it returns null:
Clientservice
public List<Clients> getClients() {
HttpServletRequest request = SecurityService.getRequest();
if (request != null) {
.
.
.
return clients;
}
return null;
}
Securityservice
public static HttpServletRequest getRequest() {
HttpServletRequest request = null;
RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
if (requestAttributes != null && requestAttributes instanceof ServletRequestAttributes) {
request = ((ServletRequestAttributes) requestAttributes).getRequest();
}
return request;
}
In this first part, it returns the list of all customers normally.
After that, he executes the processService.process()
, as an example below:
Processservice
public void process() {
List<Clients> clients = clientService.getClients();
}
Here is the "problem", in this method that is called, he can not get the list of customers, because the request
blank ballot.
I tried to search, but I didn’t get a result, I found something that the request like this, it can’t be shared between the threads
executed, so it cannot return the value.
I know that a solution, would run in the first method and pass the client list to the methods below, but I want to find something that I can "share" and execute in the methods called, because it is a large method, with various logics and different processes. Also, have the possibility to call this method to get clients from anywhere in the system, without having to execute in the method where the request arrives.
If this is the "problem", there is some way to "share" it between the threads
?
If this is not the "problem", why does this occur ?