I have implemented a REST endpoint in JavaEE that fires an asynchronous event to trigger a process each time the endpoint is used by a user.
This all works as intended and the process is triggered asynchronously, but results in a SEVERE
level log: No valid EE environment for injection of TagsProcessor
and I do not understand why.
Is this a bug in Payara? Or am I doing something wrong?
Here is an example implementation:
Rest endpoint where the event is fired on each login:
@Path("auth")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@RequestScoped
public class AuthenticationResource {
@POST
@Path("request-jwt")
@PermitAll
@Timed(name = "appV2RequestJwt", absolute = true)
public Response appRequestJwt(RefreshRequest refreshRequest) {
JwtResponse dto;
try {
dto = authenticationProcessor.appRequestJwt(refreshRequest);
//Fire asynchronous event
calculateTagsEvent.fireAsync(new CalculateTagsEvent(refreshRequest.getUsername()));
return Response.ok(dto).build();
} catch (Exception exception) {
LOGGER.log(Level.SEVERE, "Could not request jwt: {}", exception.getMessage());
dto = new JwtResponse(null, INTERNAL_SERVER_ERROR);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(dto).build();
}
}
}
Observer class:
@RequestScoped
public class TagsProcessor {
private static final Logger LOGGER = Logger.getLogger(TagsProcessor.class.getName());
@Inject
private BeanController beanController;
//Observe asynchronous event
public void manageCalculateTagsEvent(@ObservesAsync CalculateTagsEvent event) {
LOGGER.log(Level.WARNING, "Event observed");
beanController.create(new SomeBean());
}
}
This results in the logs:
[#|2022-08-17T06:39:39.461+0000|SEVERE|Payara 5.201||_ThreadID=473;_ThreadName=payara-executor-service-task;_TimeMillis=1660718379461;_LevelValue=1000;| No valid EE environment for injection of TagsProcessor|#]
[#|2022-08-17T06:39:39.473+0000|WARNING|Payara 5.201|TagsProcessor|_ThreadID=473;_ThreadName=payara-executor-service-task;_TimeMillis=1660718379473;_LevelValue=900;| Event observed|#]
So it's working as intended, but is giving me the warning about the injection...
As mentioned in my comment I did try various scopes but in the end it's supposed to be a @Stateless
EJB that can be spawned from a pool without being attached to the client's state.