getUrlContentAsBytes not using nonProxyHosts?


I’m xwiki 9.11.4 and getUrlContentAsBytes. If I set http.proxyHost and http.proxyPort on the command line of tomcat everything is sent over to the proxy regardless of the configuration of http.nonProxyHosts.

I have other Java Web apps where I also set http.nonProxyHosts in tomcat, so I’m fairly confident that my config is right. Can anybody confirm this or even better has a working config? Maybe I’m missing something special for xwiki?

Best regards,


Indeed as far as I can see getUrlContentAsBytes is using an old HTTPClient version plus instead of letting it get the standard configuration it more or less do it itself. It would really worth some refactoring, don’t hesitate to create a BUG issue on Loading....

This rings a bell and I think it was asked before but I don’t know if an issue was created.

We should provide a Velocity Tool for this.

The workaround is not to use velocity but groovy which makes it extra easy to do so.

I guess something like this would work: ["http.proxyHost":"proxy-host", "http.proxyPort":"proxy-port"] )  
def url = "http://...."
def content = url.text

@vmassol I think you are mixing with Velocity suppressing all errors.

What @rbr reported here is actually a bug in getUrlContentAsBytes that should be fixed.

ok read too fast, I thought the proxy settings were not working fully. Seems it’s half working and http.nonProxyHosts is not taken into account.

The workaround I mentioned should work though.


@tmortagne: thanks for the analysis. I will file a bug report this evening.

@vmassol: Thank you for the work around, will try this later.

It’s good to have a workaround, it would be better to have it fixed and the best would be to have it refactored so that it returns an “object” with maybe httpStatus and data properties. That would fix the “issue” on the other thread too.

have it refactored so that it returns an “object” with maybe httpStatus and data properties

Unfortunately this would be an API breakage. Also frankly this API is not very good and a new HTTPClient-like script service or Velocity tool would be much better.

I created the bug now, sorry took me a bit longer than expected.
Could you please help with adding the right component(s)?

Thank you.

Using groovy works fine. I did not even need to configure the, because all of them are already configured on the app server level.

I used:

def urlstring = "https://..."
def url = new URL(urlstring)
def content = URL.getBytes()

And it honours nonProxyHosts and even the trust store.
So thanks for the suggestion.

So one problem solved, but a new one arises: How do I integrate the document picker with groovy?

You don’t need to. Velocity and Groovy can share variables (they share the script context).

Thanks it now works for me. I now have two blocks one velocity and one groovy block.

If there is no spaceReference in request the velocity block gets executed else the groovy block.
This works well.