[infinispan-commits] Infinispan SVN: r828 - in trunk/server/rest: src/main/scala/org/infinispan/rest and 3 other directories.
infinispan-commits at lists.jboss.org
infinispan-commits at lists.jboss.org
Wed Sep 16 21:58:45 EDT 2009
Author: michael.neale at jboss.com
Date: 2009-09-16 21:58:44 -0400 (Wed, 16 Sep 2009)
New Revision: 828
Modified:
trunk/server/rest/
trunk/server/rest/src/main/scala/org/infinispan/rest/Server.scala
trunk/server/rest/src/main/webapp/WEB-INF/web.xml
trunk/server/rest/src/main/webapp/index.html
trunk/server/rest/src/test/scala/org/infinispan/rest/IntegrationTest.scala
trunk/server/rest/src/test/scala/org/infinispan/rest/ServerInstance.scala
Log:
can deal with Serializable and String types on GET
Property changes on: trunk/server/rest
___________________________________________________________________
Name: svn:ignore
- .git
target
*.gitignore
test-output
+ .git
target
*.gitignore
test-output
Infinispan-rest-server.ipr
Infinispan-rest-server.iws
rest-server.iml
Modified: trunk/server/rest/src/main/scala/org/infinispan/rest/Server.scala
===================================================================
--- trunk/server/rest/src/main/scala/org/infinispan/rest/Server.scala 2009-09-16 17:45:03 UTC (rev 827)
+++ trunk/server/rest/src/main/scala/org/infinispan/rest/Server.scala 2009-09-17 01:58:44 UTC (rev 828)
@@ -1,5 +1,6 @@
package org.infinispan.rest
+import java.io.{OutputStream, ObjectOutputStream, Serializable}
import remoting.MIMECacheEntry
import java.util.concurrent.TimeUnit
import javax.ws.rs._
@@ -20,6 +21,14 @@
case null => Response.ok(b.data, b.contentType).lastModified(b.lastModified).tag(calcETAG(b)).build
}
}
+ case s: String => Response.ok(s, "text/plain").build
+ case ser: Serializable => {
+ Response.ok.`type`("application/x-java-serialized-object").entity(new StreamingOutput {
+ def write(out: OutputStream) = {
+ new ObjectOutputStream(out).writeObject(ser)
+ }
+ }).build
+ }
case null => Response status(Status.NOT_FOUND) build
}
}
@@ -34,6 +43,7 @@
case null => Response.ok.`type`(b.contentType).lastModified(b.lastModified).tag(calcETAG(b)).build
}
}
+ case x: Any => Response.ok.build
case null => Response status(Status.NOT_FOUND) build
}
}
@@ -51,6 +61,7 @@
Response.status(Status.CONFLICT).build()
} else {
(ttl, idleTime, useAsync) match {
+ //todo, check if it is serialized object, and put it as such...
case (0, 0, false) => cache.put(key, new MIMECacheEntry(mediaType, data))
case (x, 0, false) => cache.put(key, new MIMECacheEntry(mediaType, data), ttl, TimeUnit.SECONDS)
case (x, y, false) => cache.put(key, new MIMECacheEntry(mediaType, data), ttl, TimeUnit.SECONDS, idleTime, TimeUnit.SECONDS)
@@ -92,9 +103,9 @@
object ManagerInstance {
var instance: CacheManager = null
def getCache(name: String) = {
- instance.getCache(name).asInstanceOf[Cache[String, MIMECacheEntry]]
+ instance.getCache(name).asInstanceOf[Cache[String, Any]]
}
- def getEntry(cacheName: String, key: String) : MIMECacheEntry = {
+ def getEntry(cacheName: String, key: String) : Any = {
getCache(cacheName).get(key)
}
}
Modified: trunk/server/rest/src/main/webapp/WEB-INF/web.xml
===================================================================
--- trunk/server/rest/src/main/webapp/WEB-INF/web.xml 2009-09-16 17:45:03 UTC (rev 827)
+++ trunk/server/rest/src/main/webapp/WEB-INF/web.xml 2009-09-17 01:58:44 UTC (rev 828)
@@ -27,8 +27,12 @@
<servlet-mapping>
<servlet-name>Resteasy</servlet-name>
- <url-pattern>/*</url-pattern>
+ <url-pattern>/rest/*</url-pattern>
</servlet-mapping>
+ <welcome-file-list>
+ <welcome-file>/index.html</welcome-file>
+ </welcome-file-list>
+
</web-app>
Modified: trunk/server/rest/src/main/webapp/index.html
===================================================================
--- trunk/server/rest/src/main/webapp/index.html 2009-09-16 17:45:03 UTC (rev 827)
+++ trunk/server/rest/src/main/webapp/index.html 2009-09-17 01:58:44 UTC (rev 828)
@@ -103,7 +103,7 @@
<h5>Clients</h5>
Any http client will do - from any language.
- (watch this space).
+ See <a href="http://www.jboss.org/community/wiki/InfinispanRESTserver">here</a> for more details.
<h5>Deployment</h5>
As Infinispan is a distributed cache, it shouldn't matter how many or which instance of the Server you access, as long as it is part
Modified: trunk/server/rest/src/test/scala/org/infinispan/rest/IntegrationTest.scala
===================================================================
--- trunk/server/rest/src/test/scala/org/infinispan/rest/IntegrationTest.scala 2009-09-16 17:45:03 UTC (rev 827)
+++ trunk/server/rest/src/test/scala/org/infinispan/rest/IntegrationTest.scala 2009-09-17 01:58:44 UTC (rev 828)
@@ -21,7 +21,7 @@
class IntegrationTest {
val HOST = "http://localhost:8888/"
- //val HOST = "http://localhost:8080/infinispan-rest/"
+ //val HOST = "http://localhost:8080/infinispan/"
def testBasicOperation = {
@@ -207,14 +207,48 @@
assertEquals(HttpServletResponse.SC_NOT_FOUND, Client.call(new HeadMethod(HOST + "rest/posteee/async")).getStatusCode)
}
+ @Test def shouldCopeWithSerializable = {
+ Client.call(new GetMethod(HOST + "rest/wang/wangKey"))
+ val obj = new MySer
+ obj.name = "mic"
+ ManagerInstance getCache("wang") put("wangKey", obj)
+ ManagerInstance getCache("wang") put("wangKey2", "hola")
+ val get = Client.call(new GetMethod(HOST + "rest/wang/wangKey"))
+ assertEquals(HttpServletResponse.SC_OK, get.getStatusCode)
+ val in = new ObjectInputStream(get.getResponseBodyAsStream)
+ val res = in.readObject.asInstanceOf[MySer]
+ assertNotNull(res)
+ assertEquals("mic", res.name)
+ assertEquals("application/x-java-serialized-object", get.getResponseHeader("Content-Type").getValue)
+// assertEquals("application/text", get.getResponseHeader("Content-Type").getValue)
+ //assertEquals("this is a thing with a thing", get.getResponseBodyAsString)
+ val getStr = Client.call(new GetMethod(HOST + "rest/wang/wangKey2"))
+ assertEquals("hola", getStr.getResponseBodyAsString)
+ assertEquals("text/plain", getStr.getResponseHeader("Content-Type").getValue)
+
+ }
-}
\ No newline at end of file
+
+
+
+
+
+
+
+
+}
+
+
+
+ class MySer extends Serializable {
+ var name: String = "mic"
+ }
\ No newline at end of file
Modified: trunk/server/rest/src/test/scala/org/infinispan/rest/ServerInstance.scala
===================================================================
--- trunk/server/rest/src/test/scala/org/infinispan/rest/ServerInstance.scala 2009-09-16 17:45:03 UTC (rev 827)
+++ trunk/server/rest/src/test/scala/org/infinispan/rest/ServerInstance.scala 2009-09-17 01:58:44 UTC (rev 828)
@@ -20,7 +20,7 @@
ctx.setInitParams(params)
ctx.addEventListener(new ResteasyBootstrap)
ctx.addEventListener(new StartupListener)
- ctx.addServlet(classOf[HttpServletDispatcher], "/*")
+ ctx.addServlet(classOf[HttpServletDispatcher], "/rest/*")
server.setStopAtShutdown(true)
server.start
server
More information about the infinispan-commits
mailing list