1

I am using Spring-webflux to create RouterFunction and Handler. I have @Aspect for My handler functions as follow to store ServerRequest body and ServerResponse body in in database.But when try to get Object my request is getting hanged. Is there any sample code to achieve this functionality.

@Around("@annotation(Log")
public Object log(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {
    Object o = proceedingJoinPoint.proceed();
    ServerRequest serverRequest = ServerRequest.class.cast(proceedingJoinPoint.getArgs()[0]);
    Mono<Customer> customerMono = serverRequest.bodyToMono(Customer.class);
    Customer customer = customerMono.block() //Request Hanged here
    log.info("customer" + customer);
    return o;
}
Jdafda
  • 47
  • 1
  • 4
  • 1
    Did you get a solution for this? – Niranjan Mar 13 '18 at 05:28
  • Please check my answer in this thread https://stackoverflow.com/a/50712697/3073945 – Md. Sajedul Karim Jun 06 '18 at 05:26
  • @Md.SajedulKarim it's been a long time...but I have a related question since I am trying to solve a similar problem. The answer you provided, is related only to the use case, where an explicit request is sent (i.e. via POST). What are the options, if I want to get the whole request - including headers? I.e. raw request from GET . So not request body, only headers. Then...it is not part of the arguments(getArgs() )...how to access this type of request? thx a lot. – Kevin Macejko Apr 14 '22 at 16:16

1 Answers1

0

block() is a blocking call, hence it hangs when you invoke it.

To print out customer data from within the Mono<Customer> customer, try this:

customerMono.flatMap(customer -> System.out.println(customer)); // longhand form
customerMono.flatMap(System.out::println); // shorthand form of the above
AjCodez
  • 360
  • 3
  • 10