REST module error querying a specific location: Illegal character in query

Hi Guys,

I’m using rest to query a specific location from openmrs database. Using a java client it gives me an error but the same query works fine when using rest from within openmrs.

I know the error has to do with the space in the parameter HD Gile

Can somebody help me?

Query:

/openmrs3/ws/rest/v1/location?q=HD Gile

Error:

Exception in thread "main" java.lang.IllegalArgumentException
	at java.net.URI.create(Unknown Source)
	at org.apache.http.client.methods.HttpGet.<init>(HttpGet.java:69)
	at cl.ciochile.victoraravena.ApiAuthRest.getRequestGet(ApiAuthRest.java:73)
	at cl.ciochile.test.Test.main(Test.java:32)
Caused by: java.net.URISyntaxException: Illegal character in query at index 55: http://localhost:8080/openmrs3/ws/rest/v1/location?q=HD Gile
	at java.net.URI$Parser.fail(Unknown Source)
	at java.net.URI$Parser.checkChars(Unknown Source)
	at java.net.URI$Parser.parseHierarchical(Unknown Source)
	at java.net.URI$Parser.parse(Unknown Source)
	at java.net.URI.<init>(Unknown Source)
	... 4 more

Try escaping the query parameter to URI.

1 Like

it worked replacing the white space with &

/openmrs3/ws/rest/v1/location?q=HD&Gile

I guess the “Gile” part is ignored because & is the parameter separator.

You should replace whitespace with “%20”.

1 Like

Thankx Luis. Your suggestion it’s the actual solution.