I need to send request with groovy HTTPBuilder, here is code:
String authToken = "token"
def cfManager = ComponentAccessor.getCustomFieldManager()
def addressJira = "http://xxx"
def http = new HTTPBuilder("${address}")
http.setClient(HttpClients.custom().setDefaultRequestConfig(defaultRequestConfig).build())
try {
http.request(POST, ContentType.JSON) {
headers.'Authorization' = "token ${authToken}"
headers.'Content-Type' = 'application/json'
headers.'cache-control' = 'no-cache'
body = [
"request": [
"token":"${authToken}",
"commonData":[
"taskId":"${issue.id.toString()}"
],
"phonesData":[
"phone":"${cfManager.getCustomFieldObject("customfield_xxx")?.getValue(issue)?.toString()}",
"phoneType": 1
],
"addData": [
"title":"${issue.summary.toString()}",
"description":"${issue.description.toString()}"
]
]
]
requestContentType = ContentType.JSON
response.success = { resp, json ->
log.info("Resp status " + resp.status.toString())
log.info("JSON ${json.toString()}")
log.info("JSON text ${json.text}")
}
response.failure = { resp ->
log.warn("response code is : " + resp.status.toString())
log.warn("response is : " + resp.getEntity().getContent().getText())
}
}
} catch (Exception e) {
log.warn("Exceptiion while request" + e)
}
I get resp code 200 but on the other side they get JSON like this and can't parse it because of "valueCount", "strings" and "bytes":
{
"request": {
"token": {
"valueCount": 1,
"strings": ["", ""],
"bytes": [85, 69, 108, 112, 108, 120, 90, 99, 113, 107, 100, 106, 71, 108, 121, 102, 199, 115, 103, 107, 33, 45, 109, 70, 37, 65, 91, 33, 47, 77, 54, 83, 111, 115, 77, 49, 77, 50, 107, 74, 65, 122],
"values": ["token"]
},
"commonData": {
"taskId": {
"valueCount": 1,
"strings": ["", ""],
"bytes": [48, 49, 55, 56, 56],
"values": ["here is issue id"]
}
},
"phonesData": {
"phone": {
"valueCount": 1,
"strings": ["", ""],
"bytes": [43, 53, 54, 55, 56, 57, 48],
"values": ["+01234567890"]
},
"phoneType": 1
},
"addData": {
"title": {
"valueCount": 1,
"strings": ["", ""],
"bytes": [84, 101, 115, 116],
"values": ["Test"]
},
"description": {
"valueCount": 1,
"strings": ["", ""],
"bytes": [-113, -48, -78, -48, -70, -48, -80, 32, -48, -76, -48, -69, -47, -113, 32, -48, -102, -48, -90, 32, -48, -98, -48, -73, -48, -66, -48, -67, 46],
"values": ["here is issue summary"]
}
}
}
}
So the question is why they get that parameters and what I have to do not to send that "valueCount", "strings" and "bytes"? Thanks to any help
The serializer in some versions of Camel does not recognise GString type. Hence, you would need to force conversion to string by calling toString()
def v_stringvar = "${var1} text ${var2}";
And then you use it in this way
v_stringvar?.toString()