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:
java.net.URISyntaxException: Illegal character in query at index 165: http://IP:Port/httpservice?user=msd&password=123&message=${ss}
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
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Add after defining the http fully the line: http = http .replaceAll("\\s","")
This removes the whitespace / carriage returns.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.