Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parsing JSON response error #62

Open
sfrogner opened this issue May 15, 2016 · 3 comments
Open

Parsing JSON response error #62

sfrogner opened this issue May 15, 2016 · 3 comments

Comments

@sfrogner
Copy link

Was curious if anyone has seen this issue? I have tested this call with insomnia and it returns with 200 Ok.

def https = new RESTClient('https://d.la10.salesforceliveagent.com/chat/rest/')

def payload = [
"organizationId":"00D28000000f5N9",
"deploymentId":"572280000008R6L",
"buttonId":"573D000000000OC",
"agentId":"005B0000000F3b2",
"doFallback":true,
"sessionId":sid,
"userAgent":"Lynx/2.8.8",
"screenResolution":"2560x1440",
"visitorName":"Gerald",
"prechatDetails":prechat,
"prechatEntities":PreEnt,
"receiveQueueUpdates":true,
"isPost":true,
"language":"en-US"
]
println(payload)
def myheaders = [
'Content-Type': 'application/json',
'X-LIVEAGENT-API-VERSION':'36',
'X-LIVEAGENT-SEQUENCE':'1',
'X-LIVEAGENT-SESSION-KEY': skey,
'X-LIVEAGENT-AFFINITY': stoken
]

try {
def resp = https.post(
path:'Chasitor/ChasitorInit',
requestContentType: JSON,
headers: myheaders,
body:payload,
)

}
catch(HttpResponseException e) {
r = e.response
println("Success: $r.success")
println("Status: $r.status")
println("Reason: $r.statusLine.reasonPhrase")
//println("Content: \n${JsonOutput.prettyPrint(JsonOutput.toJson(r.data))}")
}

I always get the following
May 15, 2016 10:06:22 AM groovyx.net.http.RESTClient handleResponse
WARNING: Error parsing 'application/json' response
groovy.json.JsonException: Unable to determine the current character, it is not a string, number, array, or object

The current character read is 'O' with an int value of 79
Unable to determine the current character, it is not a string, number, array, or object
line number 1
index number 0
OK��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������

at groovy.json.internal.JsonParserCharArray.decodeValueInternal(JsonParserCharArray.java:207)
at groovy.json.internal.JsonParserCharArray.decodeValue(JsonParserCharArray.java:158)
at groovy.json.internal.JsonParserCharArray.decodeFromChars(JsonParserCharArray.java:46)
at groovy.json.internal.JsonParserCharArray.parse(JsonParserCharArray.java:386)
at groovy.json.internal.BaseJsonParser.parse(BaseJsonParser.java:125)
at groovy.json.JsonSlurper.parse(JsonSlurper.java:221)
at groovyx.net.http.ParserRegistry.parseJSON(ParserRegistry.java:280)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
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:1212)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1079)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1021)
at groovy.lang.Closure.call(Closure.java:426)
at groovy.lang.Closure.call(Closure.java:442)
at groovyx.net.http.HTTPBuilder.parseResponse(HTTPBuilder.java:551)
at groovyx.net.http.HTTPBuilder$1.handleResponse(HTTPBuilder.java:480)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:1070)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:1044)
at groovyx.net.http.HTTPBuilder.doRequest(HTTPBuilder.java:506)
at groovyx.net.http.RESTClient.post(RESTClient.java:141)
at groovyx.net.http.RESTClient$post.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 REST_API_CALLS.run(REST_API_CALLS.groovy:68)
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:652)
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:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:109)
at org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:131)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)

Success: true
Status: 200
Reason: OK

@mattbroekhuis
Copy link

i cannot get the response body at all for any error response it seems. i think you are seeing the same thing

@kknagel
Copy link

kknagel commented Mar 10, 2017

did you ever find a solution to this problem?

@markhu
Copy link

markhu commented Mar 11, 2017

I reproduced the problem. After pasting in the following lines above the sample code:

@Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.7')
import groovyx.net.http.HTTPBuilder
import groovyx.net.http.RESTClient
import groovyx.net.http.HttpResponseException
import static groovyx.net.http.ContentType.*

...and replacing the last commented-out line with

println "Content: " + (r.data ? "\n${JsonOutput.prettyPrint(JsonOutput.toJson(r.data))}" : r.data)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants