I have the following function
public ReturnVal doSOmething(String value){
List<String> ids = Arrays.asList("val1", "val2", "val3");
List<Root> roots = new ArrayList();
List<Chain> chains= new ArrayList();
Root rootValue = new Root(value);
for(String id : ids){
RootBuilder builder = new RootBuilder();
builder.add(value, id);
String newRoot = builder.build();
roots.add(newRoot);
ChainBuilder chainBUilder = new ChainBuilder();
chains.add(builder.build(newRoot));
rootValue = new Root(newRoot.value(), newRoot.level());
}
Signature signature = signingService.sign(rootValue.value(), rootValue.level()); // Blocking, needs to connect to a server through TCP. Server needs a fix before webClient can be used.
SigntureFactory factory = new SignatureFactory();
for(int i = chains.size()-1; i >= 0; i--){
Root root = roots.get(i);
signature = factory.createSignature(signature, chains.get(i), root.value())
}
return signature;
}
What it does is that it signs some data (its a custom signing system) and then afterwards adds a chain of custom ID-s to the signature.
What i cant figure out is can this be somehow made into a java reactive setup somehow? Builders and factory are a API classes, i cant modify them.
This method is called when a REST endpoint is invoked.
I could proably wrap signingService.sign
into a Mono.just
or Mono.fromSupplier
But the loops seem like Flux but i need to return Mono in the end.