Feedback requested: Integrating Jersey 2 and Akka

385 views
Skip to first unread message

Paul O'Fallon

unread,
Jul 21, 2013, 1:27:18 PM7/21/13
to akka...@googlegroups.com
Hello!  I've been working on a project which delivers an asynchronous implementation of a REST API in Java using Tomcat 7, Jersey 2 and Akka.  Being neither an expert in Jersey nor Akka, I spent a tremendous amount of time figuring out how to integrate the two (specifically how to instantiate an ActorSystem at server startup and inject it into each service request).  I've created a sample project that demonstrates my approach:


(The "magic" is in the constructor of the ExampleApplication class)

That all being said, I'm in the process of writing a blog entry chronicling my experiences in which I'll highlight the above github project.  Before I publish it, I'd be interested in any feedback on the sample from folks more experienced in Akka than myself.  Is this a reasonable way to integrate the two?  Anything you would do differently? (knowing that it has to be Tomcat and Jersey... :-)

Thanks in advance!

- Paul

Rafał Krzewski

unread,
Jul 21, 2013, 4:29:10 PM7/21/13
to akka...@googlegroups.com
Hello Paul,

an alternative approach would be spawning a short-lived helper actor for each request, passing AsyncResponse to it in it's Props. The helper actor would then send a message to the actual worker actor, and once reply message arrives, complete the response and terminate itself. ActorContext.setReceiveTimeout should be used to ensure that the helper actor does not hang around indefinitely, but completes the response with an error in case the worker actor does not respond. 

Cheers,
Rafał

Paul O'Fallon

unread,
Jul 22, 2013, 12:17:42 PM7/22/13
to akka...@googlegroups.com
Hello Rafał -- thank you for the feedback!  In my "real world" implementation, I am indeed creating a short lived actor (but I was afraid that was an anti-pattern so I didn't include it here).  However, the passing via Props and setReceiveTimeout are new to me so I'll look into those further and possibly add them to the github project as well.

Thanks again!

- Paul

Rishi K

unread,
Dec 15, 2014, 11:13:35 AM12/15/14
to akka...@googlegroups.com
Hi Paul,

Do you have any working example of rest+akka+jersey using java 6. I saw your example which uses Java 7. Some how i could not able to run the DoublerTest it gives NPE something needs to be configured on my env. I am kind of stuck on making it to work for java 6. Thanks

Paul O'Fallon

unread,
Dec 15, 2014, 8:55:14 PM12/15/14
to akka...@googlegroups.com
Hello!  Apparently as of Jersey 2.7, Java 6 is no longer supported (see here:  https://jersey.java.net/release-notes/2.7.html).  If you change the POM in the project to use Jersey 2.6 (and Java 6) the project will run -- but the tests won't work (the test container still requires Java 7).

- Paul

--
>>>>>>>>>> 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 a topic in the Google Groups "Akka User List" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/akka-user/527pKufl5qU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to akka-user+...@googlegroups.com.
To post to this group, send email to akka...@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.
Message has been deleted

Rishi K

unread,
Dec 16, 2014, 7:57:36 AM12/16/14
to akka...@googlegroups.com
Thank you Paul. The test container sending sync request?
Reply all
Reply to author
Forward
0 new messages