[infinispan-commits] Infinispan SVN: r2529 - in branches/4.2.x/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:00:22 EDT 2010
Author: manik.surtani at jboss.com
Date: 2010-10-20 12:00:21 -0400 (Wed, 20 Oct 2010)
New Revision: 2529
Modified:
branches/4.2.x/server/rest/src/main/scala/org/infinispan/rest/Server.scala
branches/4.2.x/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: branches/4.2.x/server/rest/src/main/scala/org/infinispan/rest/Server.scala
===================================================================
--- branches/4.2.x/server/rest/src/main/scala/org/infinispan/rest/Server.scala 2010-10-20 15:00:24 UTC (rev 2528)
+++ branches/4.2.x/server/rest/src/main/scala/org/infinispan/rest/Server.scala 2010-10-20 16:00:21 UTC (rev 2529)
@@ -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: branches/4.2.x/server/rest/src/test/scala/org/infinispan/rest/IntegrationTest.scala
===================================================================
--- branches/4.2.x/server/rest/src/test/scala/org/infinispan/rest/IntegrationTest.scala 2010-10-20 15:00:24 UTC (rev 2528)
+++ branches/4.2.x/server/rest/src/test/scala/org/infinispan/rest/IntegrationTest.scala 2010-10-20 16:00:21 UTC (rev 2529)
@@ -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