Permalink
Browse files

2.10.0-M7 base work for the new Spray

  • Loading branch information...
1 parent adc3fea commit 8b63ed8e6ee779e92199baa9f12b0f7ffaee1f32 @janm janm committed Aug 24, 2012
View
@@ -44,7 +44,7 @@
<dependency>
<groupId>com.typesafe.akka</groupId>
- <artifactId>akka-actor</artifactId>
+ <artifactId>akka-actor_${scala.version}</artifactId>
</dependency>
<dependency>
@@ -1,7 +1,8 @@
package org.cakesolutions.akkapatterns.api
import akka.actor.{ActorRef, Props}
-import cc.spray.{RootService, Route, HttpService}
+import cc.spray._
+import http.{StatusCodes, HttpResponse}
import org.cakesolutions.akkapatterns.core.Core
import akka.util.Timeout
@@ -14,7 +15,11 @@ trait Api {
new CustomerService().route ::
Nil
- val svc: Route => ActorRef = route => actorSystem.actorOf(Props(new HttpService(route)))
+ def rejectionHandler: PartialFunction[scala.List[cc.spray.Rejection], cc.spray.http.HttpResponse] = {
+ case (rejections: List[Rejection]) => HttpResponse(StatusCodes.BadRequest)
+ }
+
+ val svc: Route => ActorRef = route => actorSystem.actorOf(Props(new HttpService(route, rejectionHandler)))
val rootService = actorSystem.actorOf(
props = Props(new RootService(
@@ -41,7 +41,7 @@ class DummyService(path: String)(implicit val actorSystem: ActorSystem) extends
scala.io.Source.fromInputStream(getClass.getResourceAsStream(filename)).mkString
}
catch {
- case _ => "{body of file " + filename + " -- Missing File!}"
+ case _: Throwable => "{body of file " + filename + " -- Missing File!}"
}
}
}
@@ -12,6 +12,7 @@ case class SystemInfo(implementation: Implementation, host: String)
class HomeService(implicit val actorSystem: ActorSystem) extends Directives with Marshallers with DefaultTimeout with LiftJSON {
def applicationActor = actorSystem.actorFor("/user/application")
+ import scala.concurrent.ExecutionContext.Implicits.global
val route = {
path(Slash) {
@@ -11,10 +11,10 @@ import java.util.UUID
trait Marshallers extends DefaultMarshallers {
this: LiftJSON =>
- implicit def liftJsonMarshaller[A <: Product] = new SimpleMarshaller[A] {
+ implicit def liftJsonMarshaller[A <: AnyRef] = new SimpleMarshaller[A] {
val canMarshalTo = ContentType(`application/json`) :: Nil
def marshal(value: A, contentType: ContentType) = {
- val jsonSource = write(value)
+ val jsonSource = write(value.asInstanceOf[AnyRef])
DefaultMarshallers.StringMarshaller.marshal(jsonSource, contentType)
}
}
@@ -1,7 +1,6 @@
package org.cakesolutions.akkapatterns.api
import cc.spray.test.SprayTest
-import akka.util.Duration
import java.util.concurrent.TimeUnit
import akka.actor.ActorRef
import cc.spray.RequestContext
@@ -10,6 +9,7 @@ import io.Source
import org.specs2.mutable.Specification
import org.cakesolutions.akkapatterns.test.{DefaultTestData, SpecConfiguration}
import org.cakesolutions.akkapatterns.core.Core
+import concurrent.util.Duration
trait RootSprayTest extends SprayTest {
protected def testRoot(request: HttpRequest, timeout: Duration = Duration(10000, TimeUnit.MILLISECONDS))
View
@@ -14,15 +14,15 @@
<dependencies>
<dependency>
<groupId>com.typesafe.akka</groupId>
- <artifactId>akka-actor</artifactId>
+ <artifactId>akka-actor_${scala.version}</artifactId>
</dependency>
<dependency>
<groupId>org.cakesolutions.akkapatterns</groupId>
<artifactId>domain</artifactId>
<version>0.1.RELEASE-SNAPSHOT</version>
</dependency>
- <!-- MongoDB -->
+ <!--
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>casbah-core_${scala.version}</artifactId>
@@ -35,10 +35,11 @@
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
</dependency>
+ -->
<dependency>
<groupId>com.typesafe.akka</groupId>
- <artifactId>akka-testkit</artifactId>
+ <artifactId>akka-testkit_${scala.version}</artifactId>
<scope>test</scope>
</dependency>
<dependency>
@@ -47,6 +48,17 @@
<scope>test</scope>
</dependency>
<dependency>
+ <groupId>org.specs2</groupId>
+ <artifactId>specs2-scalaz-core_${scala.version}</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.8.2</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>org.cakesolutions.akkapatterns</groupId>
<artifactId>test</artifactId>
<version>0.1.RELEASE-SNAPSHOT</version>
@@ -10,7 +10,7 @@ case class PoisonPill()
class ApplicationActor extends Actor {
- protected def receive = {
+ def receive = {
case GetImplementation() =>
val manifestStream = getClass.getResourceAsStream("/META-INF/MANIFEST.MF")
val manifest = new java.util.jar.Manifest(manifestStream)
@@ -1,109 +0,0 @@
-package org.cakesolutions.akkapatterns.core.application
-
-import com.mongodb.casbah.Imports._
-import java.util.UUID
-import org.cakesolutions.akkapatterns.domain.{Address, Customer}
-
-/**
- * Contains type classes that deserialize records from Casbah into "our" types.
- */
-trait CasbahDeserializers {
- type CasbahDeserializer[A] = DBObject => A
-
- /**
- * Convenience method that picks the ``CasbahDeserializer`` for the type ``A``
- * @param deserializer implicitly given deserializer
- * @tparam A the type A
- * @return the deserializer for ``A``
- */
- def casbahDeserializer[A](implicit deserializer: CasbahDeserializer[A]) = deserializer
-
- private def inner[A: CasbahDeserializer](o: DBObject, field: String): A = casbahDeserializer[A].apply(o.as[DBObject](field))
-
- private def innerList[A: CasbahDeserializer](o: DBObject, field: String): Seq[A] = {
- val deserializer = casbahDeserializer[A]
- o.as[MongoDBList](field).map {
- inner => deserializer(inner.asInstanceOf[DBObject])
- }
- }
-
- implicit object AddressDeserializer extends CasbahDeserializer[Address] {
- def apply(o: DBObject) =
- Address(o.as[String]("line1"), o.as[String]("line2"), o.as[String]("line3"))
- }
-
- implicit object CustomerDeserializer extends CasbahDeserializer[Customer] {
- def apply(o: DBObject) =
- Customer(o.as[String]("firstName"), o.as[String]("lastName"), o.as[String]("email"),
- innerList[Address](o, "addresses"), o.as[UUID]("id"))
- }
-
-}
-
-/**
- * Contains type classes that serialize "our" types into Casbah records.
- */
-trait CasbahSerializers {
- type CasbahSerializer[A] = A => DBObject
-
- /**
- * Convenience method that picks the ``CasbahSerializer`` for the type ``A``
- * @param serializer implicitly given serializer
- * @tparam A the type A
- * @return the serializer for ``A``
- */
- def casbahSerializer[A](implicit serializer: CasbahSerializer[A]) = serializer
-
- implicit object AddressSerializer extends CasbahSerializer[Address] {
- def apply(address: Address) = {
- val builder = MongoDBObject.newBuilder
-
- builder += "line1" -> address.line1
- builder += "line2" -> address.line2
- builder += "line3" -> address.line2
-
- builder.result()
- }
- }
-
- implicit object CustomerSerializer extends CasbahSerializer[Customer] {
- def apply(customer: Customer) = {
- val builder = MongoDBObject.newBuilder
-
- builder += "firstName" -> customer.firstName
- builder += "lastName" -> customer.lastName
- builder += "email" -> customer.email
- builder += "addresses" -> customer.addresses.map(AddressSerializer(_))
- builder += "id" -> customer.id
-
- builder.result()
- }
- }
-
-}
-
-/**
- * Contains convenience functions that can be used to find "entities-by-id"
- */
-trait SearchExpressions {
-
- def entityId(id: UUID) = MongoDBObject("id" -> id)
-
-// def entityId(id: UUID) = MongoDBObject("id" -> id, "active" -> true)
-
-}
-
-/**
- * Mix this trait into your classes to gain the functionality of the serializers, deserializers and mappers.
- */
-trait TypedCasbah extends CasbahDeserializers with CasbahSerializers {
-
- final def serialize[A: CasbahSerializer](a: A) = casbahSerializer[A].apply(a)
-
- final def deserialize[A: CasbahDeserializer](o: DBObject) = casbahDeserializer[A].apply(o)
-
- final def mapper[A: CasbahDeserializer] = {
- (o: DBObject) => deserialize[A](o)
- }
-
-}
@@ -3,7 +3,6 @@ package org.cakesolutions.akkapatterns.core.application
import akka.actor.Actor
import java.util.UUID
import org.cakesolutions.akkapatterns.domain.{Configured, Customer}
-import com.mongodb.casbah.MongoDB
case class Get(id: UUID)
case class FindAll()
@@ -12,19 +11,18 @@ case class Insert(customer: Customer)
/**
* @author janmachacek
*/
-class CustomerActor extends Actor with Configured with TypedCasbah with SearchExpressions {
+class CustomerActor extends Actor with Configured {
- def customers = configured[MongoDB].apply("customers")
- protected def receive = {
+ def receive = {
case Get(id) =>
- sender ! customers.findOne(entityId(id)).map(mapper[Customer])
+ sender ! None //customers.findOne(entityId(id)).map(mapper[Customer])
case FindAll() =>
- sender ! customers.find().map(mapper[Customer]).toList
+ sender ! List() //customers.find().map(mapper[Customer]).toList
case Insert(customer) =>
- customers += serialize(customer)
+ // customers += serialize(customer)
sender ! customer
}
}
@@ -1,10 +1,10 @@
package org.cakesolutions.akkapatterns.core
import akka.actor.{Props, ActorSystem}
-import akka.dispatch.Await
import application.ApplicationActor
import akka.pattern.ask
import akka.util.Timeout
+import concurrent.Await
case class Start()
case class Started()
@@ -6,11 +6,14 @@ import org.specs2.mutable.Specification
import akka.testkit.{ImplicitSender, TestActorRef, TestKit}
import akka.actor.ActorSystem
import org.cakesolutions.akkapatterns.domain.Customer
+import org.specs2.runner.JUnitRunner
+import org.junit.runner.RunWith
/**
* @author janmachacek
*/
-class CustomerActorSpec extends TestKit(ActorSystem()) with Specification with SpecConfiguration with DefaultTestData with ImplicitSender {
+@RunWith(classOf[JUnitRunner])
+class CustomerActorSpecx extends TestKit(ActorSystem()) with Specification with SpecConfiguration with DefaultTestData with ImplicitSender {
val customerActor = TestActorRef[CustomerActor]
"Getting a known customer works" in {
View
@@ -33,10 +33,6 @@
<version>0.1.RELEASE-SNAPSHOT</version>
</dependency>
<dependency>
- <groupId>org.mongodb</groupId>
- <artifactId>casbah-core_${scala.version}</artifactId>
- </dependency>
- <dependency>
<groupId>cc.spray</groupId>
<artifactId>spray-server</artifactId>
</dependency>
@@ -46,7 +42,7 @@
</dependency>
<dependency>
<groupId>com.typesafe.akka</groupId>
- <artifactId>akka-actor</artifactId>
+ <artifactId>akka-actor_${scala.version}</artifactId>
</dependency>
</dependencies>
@@ -5,19 +5,13 @@ import org.cakesolutions.akkapatterns.domain.Configuration
import org.cakesolutions.akkapatterns.core.Core
import org.cakesolutions.akkapatterns.api.Api
import org.cakesolutions.akkapatterns.web.Web
-import com.mongodb.casbah.MongoConnection
object Main extends App {
// -javaagent:/Users/janmachacek/.m2/repository/org/springframework/spring-instrument/3.1.1.RELEASE/spring-instrument-3.1.1.RELEASE.jar -Xmx512m -XX:MaxPermSize=256m
implicit val system = ActorSystem("AkkaPatterns")
class Application(val actorSystem: ActorSystem) extends Core with Api with Web with Configuration {
- configure {
- val mongoDb = MongoConnection()("akka-patterns")
-
- mongoDb
- }
}
new Application(system)
Oops, something went wrong.

0 comments on commit 8b63ed8

Please sign in to comment.