# getUrlContentAsBytes not using nonProxyHosts?

**URL:** <https://forum.xwiki.org/t/geturlcontentasbytes-not-using-nonproxyhosts/3091>\
**Category:** Help / Discuss\
**Created:** [June 8, 2018, 5:22am UTC](https://forum.xwiki.org/t/geturlcontentasbytes-not-using-nonproxyhosts/3091 "2018-06-08T05:22:27Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![rbr](https://forum.xwiki.org/letter_avatar_proxy/v4/letter/r/58f4c7/32.png) [@rbr](https://forum.xwiki.org/u/rbr)\
**Post date:** [June 8, 2018, 5:22am UTC](https://forum.xwiki.org/t/geturlcontentasbytes-not-using-nonproxyhosts/3091/1 "2018-06-08T05:22:28Z")

</div>

Hi,

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,

rbr

---

<div class="post-metadata">

**Author:** ![tmortagne](https://forum.xwiki.org/user_avatar/forum.xwiki.org/tmortagne/32/4930_2.png) [@tmortagne](https://forum.xwiki.org/u/tmortagne)\
**Post date:** [June 8, 2018, 7:10am UTC](https://forum.xwiki.org/t/geturlcontentasbytes-not-using-nonproxyhosts/3091/2 "2018-06-08T07:10:03Z")

</div>

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...](https://jira.xwiki.org/browse/XWIKI).

---

<div class="post-metadata">

**Author:** ![vmassol](https://forum.xwiki.org/user_avatar/forum.xwiki.org/vmassol/32/6_2.png) [@vmassol](https://forum.xwiki.org/u/vmassol)\
**Post date:** [June 8, 2018, 7:44am UTC](https://forum.xwiki.org/t/geturlcontentasbytes-not-using-nonproxyhosts/3091/3 "2018-06-08T07:44:25Z")

</div>

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:

```auto
System.properties.putAll( ["http.proxyHost":"proxy-host", "http.proxyPort":"proxy-port"] )  
def url = "http://...."
def content = url.text

```

---

<div class="post-metadata">

**Author:** ![tmortagne](https://forum.xwiki.org/user_avatar/forum.xwiki.org/tmortagne/32/4930_2.png) [@tmortagne](https://forum.xwiki.org/u/tmortagne)\
**Post date:** [June 8, 2018, 7:58am UTC](https://forum.xwiki.org/t/geturlcontentasbytes-not-using-nonproxyhosts/3091/4 "2018-06-08T07:58:15Z")

</div>

@vmassol I think you are mixing with [Velocity suppressing all errors](https://forum.xwiki.org/t/velocity-suppressing-all-errors/3071).

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

---

<div class="post-metadata">

**Author:** ![vmassol](https://forum.xwiki.org/user_avatar/forum.xwiki.org/vmassol/32/6_2.png) [@vmassol](https://forum.xwiki.org/u/vmassol)\
**Post date:** [June 8, 2018, 8:03am UTC](https://forum.xwiki.org/t/geturlcontentasbytes-not-using-nonproxyhosts/3091/5 "2018-06-08T08:03:48Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![rbr](https://forum.xwiki.org/letter_avatar_proxy/v4/letter/r/58f4c7/32.png) [@rbr](https://forum.xwiki.org/u/rbr)\
**Post date:** [June 8, 2018, 8:31am UTC](https://forum.xwiki.org/t/geturlcontentasbytes-not-using-nonproxyhosts/3091/6 "2018-06-08T08:31:25Z")

</div>

Hi,

@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.

---

<div class="post-metadata">

**Author:** ![tmortagne](https://forum.xwiki.org/user_avatar/forum.xwiki.org/tmortagne/32/4930_2.png) [@tmortagne](https://forum.xwiki.org/u/tmortagne)\
**Post date:** [June 8, 2018, 8:48am UTC](https://forum.xwiki.org/t/geturlcontentasbytes-not-using-nonproxyhosts/3091/7 "2018-06-08T08:48:05Z")

</div>

> 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.

---

<div class="post-metadata">

**Author:** ![rbr](https://forum.xwiki.org/letter_avatar_proxy/v4/letter/r/58f4c7/32.png) [@rbr](https://forum.xwiki.org/u/rbr)\
**Post date:** [June 11, 2018, 4:28am UTC](https://forum.xwiki.org/t/geturlcontentasbytes-not-using-nonproxyhosts/3091/8 "2018-06-11T04:28:42Z")

</div>

I created the [bug](https://jira.xwiki.org/browse/XWIKI-15341) now, sorry took me a bit longer than expected.  
Could you please help with adding the right component(s)?

Thank you.

---

<div class="post-metadata">

**Author:** ![rbr](https://forum.xwiki.org/letter_avatar_proxy/v4/letter/r/58f4c7/32.png) [@rbr](https://forum.xwiki.org/u/rbr)\
**Post date:** [June 12, 2018, 9:51am UTC](https://forum.xwiki.org/t/geturlcontentasbytes-not-using-nonproxyhosts/3091/9 "2018-06-12T09:51:53Z")

</div>

> [@vmassol](#):
>
> System.properties.putAll( [“http.proxyHost”:“proxy-host”, “http.proxyPort”:“proxy-port”] )  
> def url = “http://…”  
> def content = url.text

Using groovy works fine. I did not even need to configure the System.properties, 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?

---

<div class="post-metadata">

**Author:** ![mflorea](https://forum.xwiki.org/user_avatar/forum.xwiki.org/mflorea/32/49_2.png) [@mflorea](https://forum.xwiki.org/u/mflorea)\
**Post date:** [June 13, 2018, 8:31am UTC](https://forum.xwiki.org/t/geturlcontentasbytes-not-using-nonproxyhosts/3091/10 "2018-06-13T08:31:46Z")

</div>

> [@rbr](#):
>
> 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).

---

<div class="post-metadata">

**Author:** ![rbr](https://forum.xwiki.org/letter_avatar_proxy/v4/letter/r/58f4c7/32.png) [@rbr](https://forum.xwiki.org/u/rbr)\
**Post date:** [June 13, 2018, 8:45am UTC](https://forum.xwiki.org/t/geturlcontentasbytes-not-using-nonproxyhosts/3091/11 "2018-06-13T08:45:26Z")

</div>

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.
