[infinispan-commits] Infinispan SVN: r2530 - in trunk/server/rest/src: test/scala/org/infinispan/rest and 1 other directory.

infinispan-commits at lists.jboss.org infinispan-commits at lists.jboss.org
Wed Oct 20 12:14:29 EDT 2010


Author: manik.surtani at jboss.com
Date: 2010-10-20 12:14:28 -0400 (Wed, 20 Oct 2010)
New Revision: 2530

Modified:
   trunk/server/rest/src/main/scala/org/infinispan/rest/Server.scala
   trunk/server/rest/src/test/scala/org/infinispan/rest/IntegrationTest.scala
Log:
ISPN-714 - REST server shouldn't attempt to deserialize application/x-java-serialized-object mime type

Modified: trunk/server/rest/src/main/scala/org/infinispan/rest/Server.scala
===================================================================
--- trunk/server/rest/src/main/scala/org/infinispan/rest/Server.scala	2010-10-20 16:00:21 UTC (rev 2529)
+++ trunk/server/rest/src/main/scala/org/infinispan/rest/Server.scala	2010-10-20 16:14:28 UTC (rev 2530)
@@ -42,6 +42,8 @@
                   case MediaType.APPLICATION_XML => Response.ok.`type`(selectedMediaType).entity(streamIt(xstream.toXML(obj, _))).build
                   case _ =>
                      obj match {
+                        case ba: Array[Byte] =>
+                           Response.ok.`type`("application/x-java-serialized-object").entity(streamIt(_.write(ba))).build
                         case ser: Serializable =>
                            Response.ok.`type`("application/x-java-serialized-object").entity(streamIt(new ObjectOutputStream(_).writeObject(ser))).build
                         case _ => Response.notAcceptable(variantList).build
@@ -90,9 +92,13 @@
       if (request.getMethod == "POST" && cache.containsKey(key)) {
          Response.status(Status.CONFLICT).build()
       } else {
-         val obj = if (mediaType == "application/x-java-serialized-object")
-            new ObjectInputStream(new ByteArrayInputStream(data)).readObject
-         else new MIMECacheEntry(mediaType, data)
+         val obj = if (mediaType == "application/x-java-serialized-object") {
+            try {
+               new ObjectInputStream(new ByteArrayInputStream(data)).readObject
+            } catch {
+               case e: Exception => data
+            }
+         } else new MIMECacheEntry(mediaType, data)
          (ttl, idleTime, useAsync) match {
             case (0, 0, false) => cache.put(key, obj)
             case (x, 0, false) => cache.put(key, obj, ttl, TimeUnit.SECONDS)

Modified: trunk/server/rest/src/test/scala/org/infinispan/rest/IntegrationTest.scala
===================================================================
--- trunk/server/rest/src/test/scala/org/infinispan/rest/IntegrationTest.scala	2010-10-20 16:00:21 UTC (rev 2529)
+++ trunk/server/rest/src/test/scala/org/infinispan/rest/IntegrationTest.scala	2010-10-20 16:14:28 UTC (rev 2530)
@@ -304,6 +304,29 @@
       Client call get
       assertEquals(HttpServletResponse.SC_NOT_FOUND, get.getStatusCode)
    }
+
+   def testSerializedObjects(m: Method) = {
+      // assume this has been serialized on the client.  So it is a byte array.
+      val serializedOnClient: Array[Byte] = Array(0x65, 0x66, 0x67)
+      val fullPathKey = fullPath + "/" + m.getName
+      val put = new PutMethod(fullPathKey)
+      put.setRequestHeader("Content-Type", "application/x-java-serialized-object")
+      put.setRequestBody(new ByteArrayInputStream(serializedOnClient))
+      Client call put
+      assertEquals(HttpServletResponse.SC_OK, put.getStatusCode)
+
+      val get = new GetMethod(fullPathKey)
+      get.setRequestHeader("Accept", "application/x-java-serialized-object")
+      Client call get
+      assertEquals(HttpServletResponse.SC_OK, get.getStatusCode)
+
+      // lets assert that the byte array received is the same as what we put in
+      val dataRead = new BufferedInputStream(get.getResponseBodyAsStream)
+      val bytesRead = new Array[Byte](3)
+      dataRead.read(bytesRead)
+
+      assertEquals(serializedOnClient, bytesRead)
+   }
 }
 
 



More information about the infinispan-commits mailing list