I am trying to run a RESTClient in Groovy to perform a HTTP PUT request usingthe below code, I am however facing the an issue
def jsonObj = JsonOutput.toJson(version)
println(jsonObj)
def jsonObjtrim = jsonObj.trim()
println("**** FIND 1ST CHAR *******")
println((int)jsonObjtrim.charAt(0))
def response = client.put(path: "/cli/snapshot/createSnapshot",
contentType: "application/json",
body: "$jsonObjtrim",
headers: [Accept: 'application/json'])
println("JSON value is $jsonObj")
I've made the above code print the JSON value after i construct the JSON just to be sure that i am passing the right value and it can be seen in output below. In the error printed below, the 1st line is the JSON that i constructed, the 3rd line confirms my 1st character of the JSON object is a { as that is what the error is as per the logs.
OUTPUT LOGS
{"name":"RESTSnapshot3","application":"JKEBank","description":"Requesting deployment","versions":[{"Mortgage":"448.20170828-1755250845"},{"Mortgage":"845.20190507-1820230086"}]}
**** FIND 1ST CHAR *******
123
Nov 11, 2019 2:39:02 PM groovyx.net.http.HTTPBuilder$1 handleResponse
WARNING: Error parsing 'text/plain;charset=UTF-8' response
groovy.json.JsonException: Unable to determine the current character, it is not a string, number, array, or object
The current character read is 'E' with an int value of 69
Unable to determine the current character, it is not a string, number, array, or object
line number 1
index number 0
Error processing command: A JSONObject text must begin with '{' at character 1 of ?????z???????????k???????????z?????k???????????z?????????@??????????k????????z?????????z???K????????`???????????k????????z???K????????`????????????
at org.apache.groovy.json.internal.JsonParserCharArray.decodeValueInternal(JsonParserCharArray.java:202)
at org.apache.groovy.json.internal.JsonParserCharArray.decodeValue(JsonParserCharArray.java:153)
at org.apache.groovy.json.internal.JsonParserCharArray.decodeFromChars(JsonParserCharArray.java:42)
at org.apache.groovy.json.internal.JsonParserCharArray.parse(JsonParserCharArray.java:380)
at org.apache.groovy.json.internal.BaseJsonParser.parse(BaseJsonParser.java:131)
at groovy.json.JsonSlurper.parse(JsonSlurper.java:218)
at groovyx.net.http.ParserRegistry.parseJSON(ParserRegistry.java:280)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:95)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:55)
at java.lang.reflect.Method.invoke(Method.java:507)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1213)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1080)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1022)
at groovy.lang.Closure.call(Closure.java:414)
at groovy.lang.Closure.call(Closure.java:430)
at groovyx.net.http.HTTPBuilder.parseResponse(HTTPBuilder.java:560)
at groovyx.net.http.HTTPBuilder$1.handleResponse(HTTPBuilder.java:489)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:223)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:165)
at groovyx.net.http.HTTPBuilder.doRequest(HTTPBuilder.java:515)
at groovyx.net.http.RESTClient.put(RESTClient.java:163)
at groovyx.net.http.RESTClient$put$0.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
at groovy_script_7303971688153863540.run(groovy_script_7303971688153863540.groovy:146)
at groovy.lang.GroovyShell.runScriptOrMainOrTestOrRunnable(GroovyShell.java:263)
at groovy.lang.GroovyShell.run(GroovyShell.java:518)
at groovy.lang.GroovyShell.run(GroovyShell.java:507)
at groovy.ui.GroovyMain.processOnce(GroovyMain.java:653)
at groovy.ui.GroovyMain.run(GroovyMain.java:384)
at groovy.ui.GroovyMain.process(GroovyMain.java:370)
at groovy.ui.GroovyMain.processArgs(GroovyMain.java:129)
at groovy.ui.GroovyMain.main(GroovyMain.java:109)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:95)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:55)
at java.lang.reflect.Method.invoke(Method.java:507)
at org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:109)
at org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:131)
Caught: groovyx.net.http.ResponseParseException: status code: 400, reason phrase: Bad Request
groovyx.net.http.ResponseParseException: status code: 400, reason phrase: Bad Request
at groovyx.net.http.HTTPBuilder$1.handleResponse(HTTPBuilder.java:495)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:223)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:165)
at groovyx.net.http.HTTPBuilder.doRequest(HTTPBuilder.java:515)
at groovyx.net.http.RESTClient.put(RESTClient.java:163)
at groovyx.net.http.RESTClient$put$0.call(Unknown Source)
at groovy_script_7303971688153863540.run(groovy_script_7303971688153863540.groovy:146)
Caused by: groovy.json.JsonException: Unable to determine the current character, it is not a string, number, array, or object
^
Please note that this works perfectly on Groovy 2.5.6 on my IntellIJ but doesnt when i execute it on Linux based OMVS on Mainframe z/OS that currently runs on Groovy 2.4.12. Also, i tried HTTPBuilder 0.5.0/0.5.2/0.7.1 and still the same response.