0
votes

I am trying to call a reactive rest but while doing it I have to call another request inside it and create few folders but quarkus-hibernate-reactive is showing below error what is best practice to it?

Error:

Caused by: java.lang.IllegalStateException: The current thread cannot be blocked: vert.x-eventloop-thread-2
    at io.smallrye.mutiny.operators.UniBlockingAwait.await(UniBlockingAwait.java:29)

My code is as below:

@POST
@javax.ws.rs.Path("/add") 
@Produces({MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN})
@Consumes({ MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN })
public Uni<Response> addUser(@HeaderParam("userName") String addedBy) throws Exception{
     //Here I have one if condition which is checking from database if user exist!

     if (checkUser(addedBy).await().indefinitely().intValue() > 0) {
        //then creatingfolders

        if (createFolders(addedBy) > 0) {
             UserBean u = new UserBean(addedBy);
             return Uni.createFrom().item(userRepository.addUser(u)).onItem().transform(f -> f != null ? Response.ok(f) : Response.ok(null))
                 .onItem().transform(ResponseBuilder::build);
        }
     }
}

public Uni<Long> addUser(UserBean userIN) {
   return Panache.withTransaction(userIN::persist)
                .replaceWith(userIN.getId());
}

How we can make it wait for completion of creating folders and checking user exists? I have tried using @Blocking but it didn't worked. Please help