From 65963a732a315d44cf80133a9cf89c43a3e60708 Mon Sep 17 00:00:00 2001 From: Chris Weller Date: Thu, 29 Jan 2015 22:40:16 -0500 Subject: [PATCH] CF9 compatibility fixes --- ElasticSearchClient.cfc | 20 ++++++++++---------- requests/GetRequest.cfc | 6 +++--- responses/GetResponse.cfc | 1 + responses/IResponse.cfc | 2 +- responses/Response.cfc | 15 +++++++++++---- 5 files changed, 26 insertions(+), 18 deletions(-) diff --git a/ElasticSearchClient.cfc b/ElasticSearchClient.cfc index 63dd0ab..04d3f17 100644 --- a/ElasticSearchClient.cfc +++ b/ElasticSearchClient.cfc @@ -30,19 +30,19 @@ component accessors="true" extends="Base" { } public IndexRequest function prepareIndex(string index="", string type="", string id=""){ - var index = new requests.IndexRequest(ClusterManager=getClusterManager()); - index.setIndex(arguments.index); - index.setType(arguments.type); - index.setId(arguments.id); - return index; + var ix = new requests.IndexRequest(ClusterManager=getClusterManager()); + ix.setIndex(arguments.index); + ix.setType(arguments.type); + ix.setId(arguments.id); + return ix; } public MappingRequest function prepareMapping(required string index, required string type, required elasticsearch.indexing.TypeMapping typeMapping){ - var index = new requests.MappingRequest(ClusterManager=getClusterManager()); - index.setIndex(arguments.index); - index.setType(arguments.type); - index.setBody(typeMapping.getJson()); - return index; + var ix = new requests.MappingRequest(ClusterManager=getClusterManager()); + ix.setIndex(arguments.index); + ix.setType(arguments.type); + ix.setBody(arguments.typeMapping.getJson()); + return ix; } public BulkRequest function prepareBulk(boolean Transactional=false){ diff --git a/requests/GetRequest.cfc b/requests/GetRequest.cfc index c3be97b..9c95158 100644 --- a/requests/GetRequest.cfc +++ b/requests/GetRequest.cfc @@ -12,15 +12,15 @@ component accessors="true" { property name="ClusterManager" type="ClusterManager"; public GetRequest function init(required ClusterManager ClusterManager){ - variables.ClusterManager = arguments.ClusterManager + variables.ClusterManager = arguments.ClusterManager; return this; } public GetResponse function execute(){ var _url = "/#getIndex()#/#getType()#/#getId()#"; - if(getSourceOnly()){ - _url = _url & "/_source" + if(NOT isNull(getSourceOnly())){ + _url = _url & "/_source"; } _url = _url & "?realtime=#getRealtime()#"; diff --git a/responses/GetResponse.cfc b/responses/GetResponse.cfc index df4523e..5ced8b7 100644 --- a/responses/GetResponse.cfc +++ b/responses/GetResponse.cfc @@ -31,6 +31,7 @@ component extends="Response" accessors="true" implements="IResponse" { setExists(getBody()["exists"]); } if(getSuccess()){ + setExists(true); // default does not work in CF9 if(structKeyExists(getBody(), "_source")){ setSource(getBody()["_source"]); } diff --git a/responses/IResponse.cfc b/responses/IResponse.cfc index 3c82c86..2398986 100644 --- a/responses/IResponse.cfc +++ b/responses/IResponse.cfc @@ -1,3 +1,3 @@ interface{ - public void function handleResponse(){} + public void function handleResponse(); } \ No newline at end of file diff --git a/responses/Response.cfc b/responses/Response.cfc index 2ca8cd0..6b98e88 100644 --- a/responses/Response.cfc +++ b/responses/Response.cfc @@ -14,11 +14,18 @@ component accessors="true" implements="IResponse"{ public void function handleResponse(){ var _httpResponse = arguments[1]; - - setStatusCode(_httpResponse.status_code); - setStatus(_httpResponse.StatusCode); - setBody(deserializeJSON(_httpResponse.FileContent)); + + local.content = _httpResponse.FileContent; + + if(getMetaData(local.content).getName() IS "java.io.ByteArrayOutputStream") { + local.content = _httpResponse.FileContent.toString(); + } + + setStatusCode(_httpResponse.Responseheader.Status_Code); + setStatus(_httpResponse.Responseheader.Explanation); + setBody(deserializeJSON(local.content)); setHeaders(_httpResponse.responseHeader); + setSuccess(false); // default does not work in CF9 if(getStatusCode() <= 206 && getStatusCode() >= 200){ setSuccess(true);