Skip to content
Browse files

Added an implicit conversion for Jersey's ClientResponse

  • Loading branch information...
1 parent dd6a6f1 commit a5e404ab6143a3d3561decc1deceed911550b211 @ept committed May 23, 2010
Showing with 13 additions and 0 deletions.
  1. +13 −0 src/main/scala/com/eptcomputing/neo4j/JerseyConverters.scala
View
13 src/main/scala/com/eptcomputing/neo4j/JerseyConverters.scala
@@ -13,6 +13,7 @@ import org.codehaus.jettison.json.JSONObject
* to pass an ugly type parameter. With these conversions, you can just use
* e.g. getResponse instead of get, and it defaults to a type of ClientResponse, or
* e.g. getJSON instead of get, and it defaults to a type of JSONObject.
+ * - If you want to get the body of a ClientResponse as a string, just call the body method.
*/
trait JerseyConverters {
@@ -42,10 +43,22 @@ trait JerseyConverters {
def putJSON (entity: java.lang.Object) = uniformInterface.put (classOf[JSONObject], entity)
}
+ class ClientResponseMethods(clientResponse: ClientResponse) {
+ private var _body: Option[String] = None
+ def body = _body match {
+ case Some(b) => b
+ case None =>
+ _body = Some(clientResponse.getEntity(classOf[String]))
+ _body.get
+ }
+ }
implicit def addContentTypeMethodToWebResource(resource: WebResource) =
new WebResourceMethods(resource)
implicit def addResponseMethodsToUniformInterface(uniformInterface: UniformInterface) =
new UniformInterfaceMethods(uniformInterface)
+
+ implicit def addBodyMethodsToClientResponse(clientResponse: ClientResponse) =
+ new ClientResponseMethods(clientResponse)
}

0 comments on commit a5e404a

Please sign in to comment.
Something went wrong with that request. Please try again.