Spring AOP : Aspect around a method returning ResponseBodyEmitter

159 views Asked by At

I've create a custom annotation to perform double-check on controller responses. The annotation is working fine for blocking controllers. However for non-blocking controllers which are returning ResponseBodyEmitter, I didn't find out how to get response and perform checks.

Any solution ?

@Around("@annotation(foo.bar.CustomAnnotation)")
public Object handleCustomAnnotation(ProceedingJoinPoint pjp) throws Throwable {

    ResponseEntity response = (ResponseEntity) pjp.proceed();

    if (response != null && response.hasBody()) {
        Object body = response.getBody();
        if (body instanceof ResponseBodyEmitter) {
            ResponseBodyEmitter rbe = (ResponseBodyEmitter) body;
           // How to get or subscribe to the response emitter ? 
        }else{
          // Performs checks for blocking controllers --> Works fine !
        }
      }
      return response;
   }

Even onCompletion doesn't provide any consumer on the emitted data.

Thanks

0

There are 0 answers