using filed value in HTTPBuilder in scriptrunner

sahere August 6, 2019

hi all,

I am using HTTPBuilder in scriptrunner to post something. I want to use a filed value in it as following:

 

def ss=issue.get("Summary")

def http=new HTTPBuilder('http://IP:Port/httpservice?user=msd&password=123&message=${ss}')

 

but above command leads to following error:

Message:
java.net.URISyntaxException: Illegal character in query at index 165: http://IP:Port/httpservice?user=msd&password=123&message=${ss}
Stack:
java.net.URI$Parser.fail(URI.java:2848)
java.net.URI$Parser.checkChars(URI.java:3021)
java.net.URI$Parser.parseHierarchical(URI.java:3111)
java.net.URI$Parser.parse(URI.java:3053)
java.net.URI.<init>(URI.java:588)
groovyx.net.http.URIBuilder.convertToURI(URIBuilder.java:93)
groovyx.net.http.HTTPBuilder.setUri(HTTPBuilder.java:794)
groovyx.net.http.HTTPBuilder.<init>(HTTPBuilder.java:213)
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
java.lang.reflect.Constructor.newInstance(Constructor.java:423)
org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:83)
org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrapNoCoerce.callConstructor(ConstructorSite.java:105)
org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:60)
org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:235)
org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:247)
script1565154997357525974272.run(script1565154997357525974272.groovy:20)

  it is noted that, when i used a solid value instead of ${ss} , as test, it works correctlt; but, I want to used a field value instead. any advise will be so appreciated

1 answer

0 votes
Mark Markov
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 7, 2019

Hello @sahere 

If you want use GStrings you must use double quotes instead of  single

def ss=issue.get("Summary")

def http=new HTTPBuilder("http://IP:Port/httpservice?user=msd&password=123&message=${ss}")
sahere August 9, 2019

many thanks for your reply it works.

now i have another problem. i have a custom field named as "Down time" and i want to send message consists of this fields as following:

MutableIssue issue = issue as MutableIssue
def created =issue.created
def closed=issue.resolutionDate
def s1=issue.summary
def bvField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Down time")
def s2 = (Date)issue.getCustomFieldValue(bvField)

def http = new HTTPBuilder("http://IP:Port/httpservice?user=msd&password=123&message=${s1}+${s2}")

http.request( groovyx.net.http.Method.POST) {
}

but it makes following error:

2019-08-10 09:05:05,202 ERROR [workflow.ScriptWorkflowFunction]: *************************************************************************************
2019-08-10 09:05:05,202 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: CHKVKSER-48, actionId: 21, file: <inline script>
java.net.URISyntaxException: Illegal character in query at index 174: http://IP:Port/httpservice?user=msd&password=123&message=test9+2019-08-10 04:21:00.0
	at groovyx.net.http.URIBuilder.convertToURI(URIBuilder.java:93)
	at groovyx.net.http.HTTPBuilder.setUri(HTTPBuilder.java:794)
	at groovyx.net.http.HTTPBuilder.<init>(HTTPBuilder.java:213)
	at Script572.run(Script572.groovy:25)

could you please advise me about this?

sahere August 9, 2019

many thanks for your reply. it works. but still there is a problem. i have a custom filed named as "Down time" and i want to use its value in message as following:

MutableIssue issue = issue as MutableIssue
def created =issue.created
def closed=issue.resolutionDate
def s1=issue.summary
def bvField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Down time")
def s2 = (Date)issue.getCustomFieldValue(bvField)

def http = new HTTPBuilder("http://IP:Port/httpservice?user=msd&password=123&message=${s1}+${s2}")
http.request( groovyx.net.http.Method.POST) {
}

 

but it makes following error:

2019-08-10 09:05:05,202 ERROR [workflow.ScriptWorkflowFunction]: ************************************************************************************* 2019-08-10 09:05:05,202 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: CHKVKSER-48, actionId: 21, file: <inline script> java.net.URISyntaxException: Illegal character in query at index 174: http://IP:Port/httpservice?user=msd&password=123&message=test9+2019-08-10 04:21:00.0 at groovyx.net.http.URIBuilder.convertToURI(URIBuilder.java:93) at groovyx.net.http.HTTPBuilder.setUri(HTTPBuilder.java:794) at groovyx.net.http.HTTPBuilder.<init>(HTTPBuilder.java:213) at Script572.run(Script572.groovy:25)

 

could you please advise me about this?

sahere August 9, 2019

it seems above issue is due to whitespace in summary and down time field. how can i handle the whitespace issue? 

the input field has white space but in the message part whitespace leads to error

Darren Stevens
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
January 12, 2022

Add after defining the http fully the line: http = http .replaceAll("\\s","")

This removes the whitespace / carriage returns.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events