From b1900b0a257fa01d7de003f704b3ea2e316d1fda Mon Sep 17 00:00:00 2001 From: Jonas Boner Date: Fri, 15 May 2009 15:39:52 +0200 Subject: [PATCH] first step towards jax-rs support, first tests passing --- akka.ipr | 638 ++++++++++------ akka.iws | 708 +++++++++--------- api-java/akka-api-java.iml | 109 +-- api-java/pom.xml | 31 + .../akka/api/PersistentStateTest.java | 3 +- .../scalablesolutions/akka/api/RestTest.java | 54 ++ kernel/akka-kernel.iml | 100 +-- kernel/pom.xml | 57 +- kernel/src/test/scala/JerseySpec.scala | 98 +++ pom.xml | 11 + util-java/akka-util-java.iml | 4 - 11 files changed, 1144 insertions(+), 669 deletions(-) create mode 100644 api-java/src/test/java/se/scalablesolutions/akka/api/RestTest.java create mode 100644 kernel/src/test/scala/JerseySpec.scala diff --git a/akka.ipr b/akka.ipr index f7df527504..e7cad30257 100644 --- a/akka.ipr +++ b/akka.ipr @@ -480,28 +480,6 @@ - - - - - - - - - - - - - - - - - - - - - - @@ -546,116 +524,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -667,17 +535,6 @@ - - - - - - - - - - - @@ -700,17 +557,6 @@ - - - - - - - - - - - @@ -744,17 +590,6 @@ - - - - - - - - - - - @@ -837,17 +672,6 @@ - - - - - - - - - - - @@ -859,17 +683,6 @@ - - - - - - - - - - - @@ -914,39 +727,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -1024,6 +804,424 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/akka.iws b/akka.iws index fa115068be..d488d6278d 100644 --- a/akka.iws +++ b/akka.iws @@ -4,20 +4,15 @@ - - - - - - - - - - - - + + + + + + + @@ -108,19 +103,10 @@ - - + + - - - - - - - - - - + @@ -128,55 +114,48 @@ - - + + - + + + + + + + + + + + + - - + + - + - - + + - + - - + + - - - - - - - - - - - - - - - - - - - + @@ -256,14 +235,70 @@ - + @@ -1023,12 +960,93 @@ - - + + - + - + - + - + @@ -1145,120 +1163,122 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - + - + - + - + - + - + - + - + - + - + + + + + + + + + + + + + + + - + - + + + + + + + + - + - + - + - + - + - + - + - + - + + + + + + + + + + diff --git a/api-java/pom.xml b/api-java/pom.xml index 8ab294bad4..4541313c1d 100755 --- a/api-java/pom.xml +++ b/api-java/pom.xml @@ -20,6 +20,31 @@ akka-kernel ${akka.version} + + com.sun.grizzly + grizzly-servlet-webserver + 1.9.9 + + + com.sun.jersey + jersey-server + 1.0.3 + + + com.sun.jersey + jersey-json + 1.0.3 + + + com.sun.jersey + jersey-client + 1.1.0-ea + + + com.sun.jersey + jersey-atom + 1.0.3 + junit junit @@ -31,6 +56,12 @@ 2.4.0 test + + com.sun.jersey.test.framework + jersey-test-framework + 1.0.3 + test + diff --git a/api-java/src/test/java/se/scalablesolutions/akka/api/PersistentStateTest.java b/api-java/src/test/java/se/scalablesolutions/akka/api/PersistentStateTest.java index 8e80d54f34..2e36bca2fa 100755 --- a/api-java/src/test/java/se/scalablesolutions/akka/api/PersistentStateTest.java +++ b/api-java/src/test/java/se/scalablesolutions/akka/api/PersistentStateTest.java @@ -22,7 +22,8 @@ public class PersistentStateTest extends TestCase { static String messageLog = ""; static { - Kernel.startCassandra(); + System.setProperty("storage-config", "config"); + Kernel.startCassandra(); } final private ActiveObjectGuiceConfiguratorForJava conf = new ActiveObjectGuiceConfiguratorForJava(); diff --git a/api-java/src/test/java/se/scalablesolutions/akka/api/RestTest.java b/api-java/src/test/java/se/scalablesolutions/akka/api/RestTest.java new file mode 100644 index 0000000000..6244d27528 --- /dev/null +++ b/api-java/src/test/java/se/scalablesolutions/akka/api/RestTest.java @@ -0,0 +1,54 @@ +/** + * Copyright (C) 2009 Scalable Solutions. + */ + +package se.scalablesolutions.akka.api; + +import com.sun.jersey.api.container.grizzly.GrizzlyWebContainerFactory; +import com.sun.jersey.api.client.Client; +import com.sun.jersey.api.client.WebResource; +import com.sun.grizzly.http.SelectorThread; + +import javax.ws.rs.core.UriBuilder; + +import org.junit.*; +import static org.junit.Assert.*; + +import java.util.Map; +import java.io.IOException; +import java.net.URI; + +import junit.framework.TestSuite; + +public class RestTest extends TestSuite { + + private static URI URI = UriBuilder.fromUri("http://localhost/").port(9998).build(); + private static SelectorThread selector = null; + + @BeforeClass + public static void initialize() throws IOException { + selector = startJersey(); + } + + @AfterClass + public static void cleanup() throws IOException { + selector.stopEndpoint(); + System.exit(0); + } + + @Test + public void simpleRequest() throws IOException, InstantiationException { + selector.start(); + Client client = Client.create(); + WebResource webResource = client.resource(URI); + String responseMsg = webResource.path("/foo").get(String.class); + assertEquals("hello foo", responseMsg); + selector.stopEndpoint(); + } + + private static SelectorThread startJersey() throws IOException { + Map initParams = new java.util.HashMap(); + initParams.put("com.sun.jersey.config.property.packages", "se.scalablesolutions.akka.api"); + return GrizzlyWebContainerFactory.create(URI, initParams); + } +} diff --git a/kernel/akka-kernel.iml b/kernel/akka-kernel.iml index 80c27d51c9..9bce29e1b2 100644 --- a/kernel/akka-kernel.iml +++ b/kernel/akka-kernel.iml @@ -16,49 +16,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -90,7 +47,62 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/kernel/pom.xml b/kernel/pom.xml index b9f8badec9..0dcfa96fc0 100755 --- a/kernel/pom.xml +++ b/kernel/pom.xml @@ -30,15 +30,20 @@ configgy 1.2 + + org.guiceyfruit + guiceyfruit-core + 2.0-beta-7 + org.guiceyfruit guice-core - 2.0-SNAPSHOT + 2.0-beta-4 org.guiceyfruit guice-jsr250 - 2.0-SNAPSHOT + 2.0-beta-4 org.apache.camel @@ -55,26 +60,46 @@ com.sun.grizzly grizzly-servlet-webserver - 1.8.6.3 + 1.9.9 com.sun.jersey jersey-server - 1.0.1 + 1.0.3 com.sun.jersey jersey-json - 1.0.1 + 1.0.3 + + + com.sun.jersey + jersey-client + 1.1.0-ea com.sun.jersey jersey-atom - 1.0.1 + 1.0.3 + + com.sun.jersey.contribs + jersey-multipart + 1.0.3 + + + com.sun.jersey.contribs + jersey-guice + 1.0.3 + + - - + + org.apache.cassandra cassandra 0.3.0-dev @@ -94,6 +119,16 @@ commons-collections 3.2.1 + + high-scale-lib + high-scale-lib + 1.0 + + + org.apache.commons + commons-lang + 2.4 + diff --git a/kernel/src/test/scala/JerseySpec.scala b/kernel/src/test/scala/JerseySpec.scala new file mode 100644 index 0000000000..83c3d43881 --- /dev/null +++ b/kernel/src/test/scala/JerseySpec.scala @@ -0,0 +1,98 @@ +/** + * Copyright (C) 2009 Scalable Solutions. + */ + +package se.scalablesolutions.akka.kernel + +import akka.kernel.config.ActiveObjectGuiceConfigurator +import kernel.config.ScalaConfig._ + +import com.sun.grizzly.http.SelectorThread +import com.sun.jersey.api.client.Client +import com.sun.jersey.core.header.MediaTypes +import com.sun.jersey.api.container.grizzly.GrizzlyWebContainerFactory +import javax.ws.rs.core.UriBuilder +import javax.ws.rs.{Produces, Path, GET} + +import com.google.inject.{AbstractModule, Scopes} + +import org.scalatest.Spec +import org.scalatest.matchers.ShouldMatchers + +import com.jteigen.scalatest.JUnit4Runner +import org.junit.runner.RunWith +import org.junit.Test +import org.junit.Assert._ + +/** + * @author Jonas Bonér + */ +@RunWith(classOf[JUnit4Runner]) +class JerseySpec extends Spec with ShouldMatchers { + + describe("A Jersey REST service") { + it("should ...") { + //val selector = startJersey + //oselector.start + + val conf = new ActiveObjectGuiceConfigurator + conf.configureActiveObjects( + RestartStrategy(AllForOne, 3, 5000), + Component( + "jerseyfoo", + classOf[resource.JerseyFoo], + classOf[resource.JerseyFooImpl], + LifeCycle(Permanent, 1000), + 1000) :: + Nil).supervise + + conf.getActiveObject("jerseyfoo") + +/* + val client = Client.create + val webResource = client.resource(UriBuilder.fromUri("http://localhost/").port(9998).build) + //val webResource = client.resource("http://localhost:9998/foo") + val responseMsg = webResource.get(classOf[String]) + responseMsg should equal ("Hello World") + selector.stopEndpoint +*/ + } + } + + def startJersey: SelectorThread = { + val initParams = new java.util.HashMap[String, String] + initParams.put("com.sun.jersey.config.property.packages", "se.scalablesolutions.akka.kernel") + GrizzlyWebContainerFactory.create(UriBuilder.fromUri("http://localhost/").port(9998).build(), initParams) + } +} + +// @GET +// @Produces("application/json") +// @Path("/network/{id: [0-9]+}/{nid}") +// def getUserByNetworkId(@PathParam {val value = "id"} id: Int, @PathParam {val value = "nid"} networkId: String): User = { +// val q = em.createQuery("SELECT u FROM User u WHERE u.networkId = :id AND u.networkUserId = :nid") +// q.setParameter("id", id) +// q.setParameter("nid", networkId) +// q.getSingleResult.asInstanceOf[User] +// } + +package resource { + import javax.ws.rs.{Produces, Path, GET} + + trait JerseyFoo { + def foo: String + } + trait JerseyBar { + def bar(msg: String): String + } + + @Path("/foo") + class JerseyFooImpl extends JerseyFoo { + @GET + @Produces(Array("application/json")) + def foo: String = { val ret = "JerseyFoo.foo"; println(ret); ret } + } + class JerseyBarImpl extends JerseyBar { + def bar(msg: String) = msg + "return_bar " + } +} diff --git a/pom.xml b/pom.xml index c28b4b0c6d..db2ecf4095 100644 --- a/pom.xml +++ b/pom.xml @@ -54,6 +54,17 @@ Java.net Legacy Repository for Maven http://download.java.net/maven/1 legacy + + + guiceyfruit.release + GuiceyFruit Release Repository + http://guiceyfruit.googlecode.com/svn/repo/releases/ + + false + + + true + repository.jboss.org diff --git a/util-java/akka-util-java.iml b/util-java/akka-util-java.iml index 1dd8480230..cfa9153dc5 100644 --- a/util-java/akka-util-java.iml +++ b/util-java/akka-util-java.iml @@ -10,10 +10,6 @@ - - - -