Okay. Well maybe you can help me figure out how to structure this better. I
currently have a route specified that breaks down different URLs and spawns
an actor whose job it is to process requests for that URL. The work of each
actor typically involves a fair amount of async business logic using an
fsm. This is why it seemed to make sense to me to do a request-per-actor
model versus the more simplified examples in the documentation.
My actual route looks more like this:
public Route createRoute() {
return route(
path("myPath", () ->
extractRequestContext(ctx -> onComplete(() ->
FutureConverters.toJava(Patterns.ask(system.actorOf("MyRequestHandler"),
ctx, 1000)),
extraction -> complete((HttpResponse)extraction.get())
));
}
So when the MyRequestHandler actor finishes it's work it creates a new
HttpResponse and sends it back to the original sender from the route,
completing the request. This works great so far for requests without an
entity (e.g. GET).
On Wednesday, September 28, 2016 at 11:59:05 AM UTC-7, Konrad Malawski
wrote:
>
> If you're a Java user I'm not quite sure how you arrived at the concept of
> per request actors, esp implemented like that.
>
> a) This won't work - completing must be done in a route.
>
> And ...
>
> b) use the entityAs() directive, it is documented, please check the docs.
> Also:
> http://doc.akka.io/docs/akka/2.4.10/java/http/implications-of-streaming-http-entity.html#consuming-the-http-request-entity-server
>
> Happy hakking!
>
>
> --
> Konrad `ktoso` Malawski
> Akka <http://akka.io> @ Lightbend <http://lightbend.com>
>
> On 28 September 2016 at 20:55:36, [email protected] <javascript:> (
> [email protected] <javascript:>) wrote:
>
> Hi,
>
> I'm new to Akka Http and have been working on implementing a RESTful
> service using the actor-per-request model. So far I've gotten everything
> working but I am stuck at unmarshalling the entity in my request handler
> actor. While there are lots of documentation for using unmarshal directives
> in the scaladsl I don't see anything specific to Java which will help me.
>
> This is currently what my request handler code looks like where I need the
> unmarshaller...
>
> public class MyRequestHandler extends UntypedActor {
> public void onReceive(Object msg) throws Throwable {
> if (msg instanceof RequestContext) {
> RequestContext context = (RequestContext)msg;
> if (context.getRequest().method() == HttpMethods.POST) {
> // TODO Unmarshal request entity
> }
> }
> }
> }
>
> Thanks in advance,
>
> Jean-Philippe Steinmetz
> --
> >>>>>>>>>> Read the docs: http://akka.io/docs/
> >>>>>>>>>> Check the FAQ:
> http://doc.akka.io/docs/akka/current/additional/faq.html
> >>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
> ---
> You received this message because you are subscribed to the Google Groups
> "Akka User List" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected] <javascript:>.
> To post to this group, send email to [email protected]
> <javascript:>.
> Visit this group at https://groups.google.com/group/akka-user.
> For more options, visit https://groups.google.com/d/optout.
>
>
--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ:
>>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to the Google Groups "Akka
User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.