Skip to content
This repository has been archived by the owner on Dec 5, 2023. It is now read-only.

Commit

Permalink
Added an implicit conversion for Jersey's ClientResponse
Browse files Browse the repository at this point in the history
  • Loading branch information
ept committed May 23, 2010
1 parent dd6a6f1 commit a5e404a
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/main/scala/com/eptcomputing/neo4j/JerseyConverters.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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.