Skip to content

apply URL encoding in RestClient#5840

Closed
PhilipCubix wants to merge 1 commit into
apache:mainfrom
PhilipCubix:main
Closed

apply URL encoding in RestClient#5840
PhilipCubix wants to merge 1 commit into
apache:mainfrom
PhilipCubix:main

Conversation

@PhilipCubix
Copy link
Copy Markdown
Contributor

Since the current method of URL encoding is to use a User defined Java Expression (see #5201), I would propose to apply URL encoding in the RestCLient component.

This avoids the need to add an extra step just to do URL encoding, that currently forces a java expression to be written, and run on the janino run-time compiler.

It also prevents users from having to find out they need to do this themselves by running into an "Illegal character in path" error, see https://pentaho.home.blog/2019/05/18/create-url-for-rest-query/ .

@hansva
Copy link
Copy Markdown
Contributor

hansva commented Oct 16, 2025

This might cause double encoding for people already encoding strings, won't it?

@PhilipCubix
Copy link
Copy Markdown
Contributor Author

hm, URL encoding of a path seems to be trickier than first thought:

  • encoding the entire url without exclusion of the question mark before query parameters leads to trouble
  • space can be encoded as '+' or '%20' and it can be required to use '%20' while java encodes with '+' by default

@PhilipCubix
Copy link
Copy Markdown
Contributor Author

This might cause double encoding for people already encoding strings, won't it?

I've looked into it and '%' would be encoded as '%25' again, so that would indeed cause trouble for people already encoding urls

@PhilipCubix
Copy link
Copy Markdown
Contributor Author

So FYI, I was able to fix my problem using the following User defined Java expression:
java.net.URLEncoder.encode(path, "UTF-8").replaceFirst("%3F", "?").replace("+", "%20")

What would need to be done on the Rest Client is to:

  1. check if the url is valid, and does not contain 'illegal characters',
  2. only in case the url contains illegal characters, apply url encoding,
  3. add an option for encoding spaces as '%20' instead of '+',
  4. take care of the question mark

So my pull request is not cutting this... :-(

@hansva
Copy link
Copy Markdown
Contributor

hansva commented Oct 16, 2025

I don't have a test setup, but is the error you are getting with a malformed URL helpful?
I see we could also add UriBuilder.fromUri(data.realUrl), which should return a helpful error message if it is a malformed URL.

The only real solution would be to not add Query parameters on the URL, but use Parameters tab which will handle the encoding properly

@hansva
Copy link
Copy Markdown
Contributor

hansva commented Oct 16, 2025

So I think you are trying to solve a non-issue. Either encode the parameters properly for the URL or use the parameters tab, which will handle it for you.

@PhilipCubix
Copy link
Copy Markdown
Contributor Author

Hi again,

ok, yes, using parameters is the solution!

thanks!!!

@PhilipCubix PhilipCubix reopened this Oct 16, 2025
@PhilipCubix
Copy link
Copy Markdown
Contributor Author

Hi,

sorry, too soon: parameters are not used on GET requests .... :-(
why are they not supported on GET requests????

@hansva
Copy link
Copy Markdown
Contributor

hansva commented Oct 16, 2025

Get should support it as far as I can see

@hansva
Copy link
Copy Markdown
Contributor

hansva commented Oct 16, 2025

I did a quick check in our Integration testing framework. The test used post initially but quickly changed it to a get and the parameter is being added correctly.
image
image
image

@PhilipCubix
Copy link
Copy Markdown
Contributor Author

well that should be fixed in documentation then :-)
documentation

@hansva
Copy link
Copy Markdown
Contributor

hansva commented Oct 16, 2025

good catch #5849

@hansva hansva closed this Oct 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants