Initial attempt at fixing akka rest
This commit is contained in:
parent
0f783d9594
commit
f0e2fa1327
3 changed files with 13 additions and 55 deletions
|
|
@ -1,29 +0,0 @@
|
|||
/**
|
||||
* Copyright (C) 2009-2010 Scalable Solutions AB <http://scalablesolutions.se>
|
||||
*/
|
||||
|
||||
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]
|
||||
}
|
||||
}
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
/**
|
||||
* Copyright (C) 2009-2010 Scalable Solutions AB <http://scalablesolutions.se>
|
||||
*/
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue