From f0e2fa13272df3c5c6896ff710d7e0bb3a79ee6e Mon Sep 17 00:00:00 2001 From: Viktor Klang Date: Tue, 25 May 2010 21:53:49 +0200 Subject: [PATCH] Initial attempt at fixing akka rest --- .../main/scala/ActorComponentProvider.scala | 29 ------------------- .../scala/ActorComponentProviderFactory.scala | 20 ------------- akka-http/src/main/scala/AkkaServlet.scala | 19 ++++++++---- 3 files changed, 13 insertions(+), 55 deletions(-) delete mode 100644 akka-http/src/main/scala/ActorComponentProvider.scala delete mode 100644 akka-http/src/main/scala/ActorComponentProviderFactory.scala diff --git a/akka-http/src/main/scala/ActorComponentProvider.scala b/akka-http/src/main/scala/ActorComponentProvider.scala deleted file mode 100644 index 52512b6929..0000000000 --- a/akka-http/src/main/scala/ActorComponentProvider.scala +++ /dev/null @@ -1,29 +0,0 @@ -/** - * Copyright (C) 2009-2010 Scalable Solutions AB - */ - -package se.scalablesolutions.akka.rest - -import com.sun.jersey.core.spi.component.ComponentScope -import com.sun.jersey.core.spi.component.ioc.IoCFullyManagedComponentProvider - -import se.scalablesolutions.akka.config.Configurator -import se.scalablesolutions.akka.util.Logging -import se.scalablesolutions.akka.actor.Actor - -class ActorComponentProvider(val clazz: Class[_], val configurators: List[Configurator]) - extends IoCFullyManagedComponentProvider with Logging { - - override def getScope = ComponentScope.Singleton - - override def getInstance: AnyRef = { - val instances = for { - conf <- configurators - if conf.isDefined(clazz) - instance <- conf.getInstance(clazz) - } yield instance - if (instances.isEmpty) throw new IllegalArgumentException( - "No Actor or Active Object for class [" + clazz + "] could be found.\nMake sure you have defined and configured the class as an Active Object or Actor in a supervisor hierarchy.") - else instances.head.asInstanceOf[AnyRef] - } -} diff --git a/akka-http/src/main/scala/ActorComponentProviderFactory.scala b/akka-http/src/main/scala/ActorComponentProviderFactory.scala deleted file mode 100644 index e1ea94347f..0000000000 --- a/akka-http/src/main/scala/ActorComponentProviderFactory.scala +++ /dev/null @@ -1,20 +0,0 @@ -/** - * Copyright (C) 2009-2010 Scalable Solutions AB - */ - -package se.scalablesolutions.akka.rest - -import com.sun.jersey.core.spi.component.ioc.{IoCComponentProvider,IoCComponentProviderFactory} -import com.sun.jersey.core.spi.component.{ComponentContext} - -import se.scalablesolutions.akka.config.Configurator -import se.scalablesolutions.akka.util.Logging - -class ActorComponentProviderFactory(val configurators: List[Configurator]) -extends IoCComponentProviderFactory with Logging { - override def getComponentProvider(clazz: Class[_]): IoCComponentProvider = getComponentProvider(null, clazz) - - override def getComponentProvider(context: ComponentContext, clazz: Class[_]): IoCComponentProvider = { - configurators.find(_.isDefined(clazz)).map(_ => new ActorComponentProvider(clazz, configurators)).getOrElse(null) - } -} diff --git a/akka-http/src/main/scala/AkkaServlet.scala b/akka-http/src/main/scala/AkkaServlet.scala index aecdaa9671..6a53e5629f 100644 --- a/akka-http/src/main/scala/AkkaServlet.scala +++ b/akka-http/src/main/scala/AkkaServlet.scala @@ -4,9 +4,8 @@ package se.scalablesolutions.akka.rest -import se.scalablesolutions.akka.config.ConfiguratorRepository import se.scalablesolutions.akka.config.Config.config - +import se.scalablesolutions.akka.actor.ActorModules import com.sun.jersey.api.core.ResourceConfig import com.sun.jersey.spi.container.servlet.ServletContainer import com.sun.jersey.spi.container.WebApplication @@ -21,13 +20,21 @@ class AkkaServlet extends ServletContainer { import scala.collection.JavaConversions._ override def initiate(resourceConfig: ResourceConfig, webApplication: WebApplication) = { - val configurators = ConfiguratorRepository.getConfigurators - - resourceConfig.getClasses.addAll(configurators.flatMap(_.getComponentInterfaces)) + resourceConfig.getProperties.put( + "com.sun.jersey.config.property.packages", + config.getList("akka.rest.resource_packages").mkString(";") + ) resourceConfig.getProperties.put( "com.sun.jersey.spi.container.ResourceFilters", config.getList("akka.rest.filters").mkString(",")) - webApplication.initiate(resourceConfig, new ActorComponentProviderFactory(configurators)) + val cl = Thread.currentThread.getContextClassLoader + Thread.currentThread.setContextClassLoader(ActorModules.loader_?.getOrElse(cl)) + try { + webApplication.initiate(resourceConfig) + } + finally{ + Thread.currentThread.setContextClassLoader(cl) + } } }