Hi Pekka,
The URL got truncated can you resend.
I dunno what constraints Akka imposes when resource class (something
annotated with @Path) implements an Actor.
The error indicates that the HttpServletRequest is being accessed out
of the scope of a request. Looks like the case class Hello.toString
occurs for logging and that calls the HttpServletRequest.toString on
the HttpServletRequest field value of the case class.
This can happen if thread boundaries are crossed. But i would have
expected in this case that the HttpServletRequest instance passed to
the hello function would not be a proxy.
If you can package up a simple maven project i can investigate further.
Paul.
On May 17, 2010, at 12:34 PM, Pekka Mattila wrote:
> Hi,
>
> Here is a forwarded message about a problem of @Context and thread
> local.
>
> Cheers,
> Pekka :)
>
>
> ---------- Forwarded message ----------
> From: Viktor Klang <viktor.kl..._at_gmail.com>
> Date: May 17, 12:55 pm
> Subject: REST API: @Context raises java.lang.IllegalStateException
> exception
> To: Akka User List
>
>
> Hi Pekka!
>
> The relevant Jersey integration is provided by:
>
> http://github.com/jboner/akka/blob/master/akka-http/src/main/scala/Ac...http://github.com/jboner/akka/blob/master/akka-http/src/main/scala/Ac...http://github.com/jboner/akka/blob/master/akka-http/src/main/scala/Ak
> ...
>
> Perhaps you could crosspost this to the jersey user ML to see if
> anyone
> knows the root of this?
>
> Cheers,
>
> On Mon, May 17, 2010 at 11:48 AM, Pekka Mattila
> <pe..._at_starduckstudios.com>wrote:
>
>
>
>
>
>> Hi all,
>
>> I am trying to use @Context annotation with Akka REST, but it raises
>> java.lang.IllegalStateException.
>
>> Here is an example code:
>
>> @Path("/hello")
>> class TestService extends Actor {
>
>> private case class Hello(request: HttpServletRequest)
>
>> @GET
>> @Produces(Array("text/plain"))
>> def hello(@Context request: HttpServletRequest): Any = {
>> (this !! Hello(request)).getOrElse("Couldn't say hello!")
>> }
>
>> def receive = {
>> case Hello(request) => reply(helloImpl(request))
>> }
>
>> private def helloImpl(request: HttpServletRequest): Response = {
>> try {
>> println("request: "+request)
>> } catch {
>> case e: Throwable =>
>> throw new RuntimeException(e)
>> }
>
>> return Response.status(Response.Status.OK).build
>> }
>
>> }
>
>> I get the following stack trace:
>
>> java.lang.IllegalStateException
>> at
>
>> com
>> .sun
>> .jersey
>> .server.impl.container.servlet.ThreadLocalInvoker.invoke(Thre
>> adLocalInvoker.java:
>> 90)
>> at $Proxy16.toString(Unknown Source)
>> at java.lang.String.valueOf(String.java:2826)
>> at scala.collection.Iterator$class.addString(Iterator.scala:1192)
>> at scala.Product$$anon$1.addString(Product.scala:37)
>> at scala.collection.Iterator$class.mkString(Iterator.scala:1159)
>> at scala.Product$$anon$1.mkString(Product.scala:37)
>> at scala.runtime.ScalaRunTime$._toString(ScalaRunTime.scala:146)
>> at rest.TestService$Hello.toString(TestService.scala:16)
>> at java.util.Formatter$FormatSpecifier.printString(Formatter.java:
>> 2794)
>> at java.util.Formatter$FormatSpecifier.print(Formatter.java:2677)
>> at java.util.Formatter.format(Formatter.java:2433)
>> at java.util.Formatter.format(Formatter.java:2367)
>> at java.lang.String.format(String.java:2769)
>> at net.lag.logging.Formatter.format(Formatter.scala:161)
>> at net.lag.logging.FileHandler.liftedTree1$1(FileHandler.scala:
>> 123)
>> at net.lag.logging.FileHandler.publish(FileHandler.scala:119)
>> at java.util.logging.Logger.log(Logger.java:458)
>> at net.lag.logging.Logger.log(Logger.scala:108)
>> at net.lag.logging.Logger.error(Logger.scala:118)
>> at se.scalablesolutions.akka.actor.Actor
>> $class.transactionalDispatch(Actor.scala:971)
>> at se.scalablesolutions.akka.actor.Actor
>> $class.liftedTree1$1(Actor.scala:901)
>> at se.scalablesolutions.akka.actor.Actor$class.invoke(Actor.scala:
>> 900)
>> at rest.TestService.invoke(TestService.scala:14)
>> at
>> se
>> .scalablesolutions
>> .akka.dispatch.MessageInvocation.invoke(Reactor.scala:
>> 23)
>> at
>> se
>> .scalablesolutions.akka.dispatch.ExecutorBasedEventDrivenDispatcher$
>> $anon$1.run(ExecutorBasedEventDrivenDispatcher.scala:75)
>> at java.util.concurrent.ThreadPoolExecutor
>> $Worker.runTask(ThreadPoolExecutor.java:886)
>> at java.util.concurrent.ThreadPoolExecutor
>> $Worker.run(ThreadPoolExecutor.java:908)
>> at java.lang.Thread.run(Thread.java:637)
>> at se.scalablesolutions.akka.dispatch.ThreadPoolBuilder
>> $MonitorableThread.run(ThreadPoolBuilder.scala:244)
>
>> Here is the Jersey code that throws the exception:
>
>> public Object invoke(Object proxy, Method method, Object[] args)
>> throws Throwable {
>> if (threadLocalInstance.get() == null)
>> throw new IllegalStateException(); <====== EXCEPTION
>
>> try {
>> return method.invoke(threadLocalInstance.get(), args);
>> } catch (IllegalAccessException ex) {
>> throw new IllegalStateException(ex);
>> } catch (InvocationTargetException ex) {
>> throw ex.getTargetException();
>> }
>> }
>
>> Related Jersey code can be downloaded from:
>
>> http://download.java.net/maven/2/com/sun/jersey/jersey-server/1.2/
>> jer...
>> .
>
>> When TestService isn't Actor, everything works:
>
>> @Path("/hello")
>> class TestService {
>
>> @GET
>> @Produces(Array("text/plain"))
>> def hello(@Context request: HttpServletRequest): Any = {
>> helloImpl(request)
>> }
>
>> private def helloImpl(request: HttpServletRequest): Response = {
>> try {
>> println("request: "+request)
>> } catch {
>> case e: Throwable =>
>> throw new RuntimeException(e)
>> }
>
>> return Response.status(Response.Status.OK).build
>> }
>
>> }
>
>> So, any ideas how we can get this working with Akka?
>
>> Cheers,
>> Pekka
>
>> --
>> You received this message because you are subscribed to the Google
>> Groups
>> "Akka User List" group.
>> To post to this group, send email to akka-user_at_googlegroups.com.
>> To unsubscribe from this group, send email to
>> akka-user+unsubscribe_at_googlegroups.com<akka-user
>> %2Bunsubscribe_at_googlegroups .com>
>> .
>> For more options, visit this group at
>> http://groups.google.com/group/akka-user?hl=en.
>
> --
> Viktor Klang
> | "A complex system that works is invariably
> | found to have evolved from a simple system
> | that worked." - John Gall
>
> Akka - the Actor Kernel: Akkasource.org
> Twttr: twitter.com/viktorklang
>
> --
> You received this message because you are subscribed to the Google
> Groups "Akka User List" group.
> To post to this group, send email to akka-user_at_googlegroups.com.
> To unsubscribe from this group, send email to akka-user
> +unsubscribe_at_googlegroups.com.
> For more options, visit this group athttp://groups.google.com/group/akka-user?hl=en
> .
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>