title: Akka http using java - get String from RequestEntity
body: <p>I'm trying to get the body of an http request, but it seems like it's not as simple as it might sound, unless of course I'm missing something.</p>
  
  <p>I have an instance of the <code>HttpRequest</code> (from <code>akka.http.javadsl.model</code>) and from that I can get the <code>RequestEntity</code>, but I can't figure out how to extract the string out of the entity.<br>
  I want to do that synchronously, just a simple operation of getting the string out of there.</p>
  
  <p>I tried two different paths:</p>
  
  <p>(1) </p>
  
  <pre><code>Source&lt;ByteString, Object&gt; source = RequestEntity.getDataBytes();
  </code></pre>
  
  <p>I'm not sure what I'm supposed to do with the <code>source</code>, it has a lot of methods, and it's unclear how to use those and if any of them can actually help me.</p>
  
  <p>(2)</p>
  
  <pre><code>Unmarshaller&lt;HttpEntity, String&gt; unmarshaller = Unmarshaller.entityToString();
  CompletionStage&lt;String&gt; result = unmarshaller.unmarshall(entity, ExecutionContext, Materializer);
  </code></pre>
  
  <p>Calling <code>unmarshaller.unmarshall</code> requires not only an instance of <code>RequestEntity</code> but also an <code>ExecutionContext</code> and a <code>Materializer</code> which I do not have at the part of the unmarshalling, also it returns a <code>CompletionStage&lt;String&gt;</code> which is completely redundant as I want it to be done synced.</p>
  
  <p>The documentation and examples for java don't help much as they are very short and brief if they exist at all, for example in the <a href="http://doc.akka.io/docs/akka/2.4/java/http/routing-dsl/marshalling.html" rel="nofollow">Marshalling &amp; Unmarshalling section</a>:</p>
  
  <blockquote>
    <p>Use the predefined Unmarshaller.entityToString,
    Unmarshaller.entityToByteString, Unmarshaller.entityToByteArray,
    Unmarshaller.entityToCharArray to convert to those basic types</p>
  </blockquote>
  
  <p>As you can see, this isn't very informative.</p>
  
  <p>Any ideas?</p>