I am trying to get the body of an HTTP request, but it seems that it is not as simple as it might sound, unless, of course, I am missing something.
I have an instance HttpRequest(from akka.http.javadsl.model) and I can get from it RequestEntity, but I cannot figure out how to extract a string from an object.
I want to do this synchronously, just a simple operation of getting a string from there.
I tried two different ways:
(1)
Source<ByteString, Object> source = RequestEntity.getDataBytes();
I'm not sure what I should do with source, it has many methods, and it is not clear how to use them, and if any of them can really help me.
(2)
Unmarshaller<HttpEntity, String> unmarshaller = Unmarshaller.entityToString();
CompletionStage<String> result = unmarshaller.unmarshall(entity, ExecutionContext, Materializer);
unmarshaller.unmarshall RequestEntity, ExecutionContext a Materializer, , CompletionStage<String>, , .
java , , , , Unmarshalling:
Unmarshaller.entityToString, Unmarshaller.entityToByteString, Unmarshaller.entityToByteArray, Unmarshaller.entityToCharArray
, .
?