0

I have the following in my URI

        uri.query = [id: "urn://salina/search/xplorer/XplorerApp",criteria:"{'includeNonGeotagged':'true','freetext':\{'text':" + "'" + "${searchString}" +"'}}",contentType:"rss20"]

I get an error saying java.net.URISyntaxException: Illegal character in query at index 94: https://pix.us.baesystems.com/search/query?id=urn://salina/search/xplorer/XplorerApp&criteria={'includeNonGeotagged':'true','freetext':{'text':'test'}}&contentType=rss20

when I dump the value of uri.toString() and put it in a browser, it works fine, so I can't figure out what the issue here is...

allthenutsandbolts
  • 1,513
  • 1
  • 13
  • 34

1 Answers1

0

You get this error because there are unencoded chars in your URI. Try encoding them or first make a URL out of the string:

def url = "https://pix.us.baesystems.com/search/query?id=urn://salina/search/xplorer/XplorerApp&criteria={'includeNonGeotagged':'true','freetext':  {'text':'test'}}&contentType=rss20"
URL url = new URL(url);
URI uri = new URI(url.getProtocol(), url.getHost(), url.getPath(), url.getQuery(), null);
println uri    

This will print the correct URI:

https://pix.us.baesystems.com/search/query?id=urn://salina/search/xplorer/XplorerApp&criteria=%7B'includeNonGeotagged':'true','freetext':%7B'text':'test'%7D%7D&contentType=rss20

Also see this answer for the basic idea.

Community
  • 1
  • 1
Kai Sternad
  • 22,214
  • 7
  • 47
  • 42