Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

using filed value in HTTPBuilder in scriptrunner

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

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}")

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?

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?

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

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
Community showcase
Published in Apps & Integrations

Send an Email or Publish to Confluence - What should you do with your release notes?

Background When you hear the words ‘Release notes’, almost always you think of an unsolicited email from a software vendor. But I am here to tell you that from our data, sending release notes via E...

130 views 1 2
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you