Configure Geoserver to Use Proxy for External Services – How to

geoserverPROXY

I don't want to access my geoserver behind a proxy. I can access it directly. It is in same network as I with no proxy between us.

I have a Geoserver and created some layers consuming WMS services from somewhere.

My problem is that my geoserver is behind a proxy. its a governamental institution and all access to external world needs to authenticate do the proxy to go out. I need to configure it in my browser to use the internet, but need an exclusion rule in browser to access internal network (to ignore proxy).

I don't know how to tell Geoserver to login into that proxy to allow it access the outside WMS service I need to consume.

The result is as follow:

2016-05-02 10:03:59,749 ERROR [org.geoserver.ows] - 
org.geoserver.platform.ServiceException: Internal error 
    at org.geoserver.wms.GetMap.run(GetMap.java:129)
    at org.geoserver.wms.DefaultWebMapService.getMap(DefaultWebMapService.java:320)
    at sun.reflect.GeneratedMethodAccessor300.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:319)
...
Caused by: java.io.IOException: Server returned HTTP error code 407 for URL http://mapas.icmbio.gov.br/i3geo/ogc.php?TEMA=uc_esec&REQUEST=GetCapabilities&VERSION=1.3.0&SERVICE=WMS
    at org.geotools.data.ows.MultithreadedHttpClient.get(MultithreadedHttpClient.java:202)
    at org.geotools.data.ows.AbstractOpenWebService.internalIssueRequest(AbstractOpenWebService.java:426)
    at org.geotools.data.wms.WebMapServer.issueRequest(WebMapServer.java:419)
    at org.geotools.data.ows.AbstractOpenWebService.negotiateVersion(AbstractOpenWebService.java:260)
    at org.geotools.data.ows.AbstractOpenWebService.<init>(AbstractOpenWebService.java:110)
    at org.geotools.data.wms.WebMapServer.<init>(WebMapServer.java:382)
    at org.geoserver.catalog.ResourcePool.getWebMapServer(ResourcePool.java:1653)
    at org.geoserver.catalog.impl.WMSStoreInfoImpl.getWebMapServer(WMSStoreInfoImpl.java:102)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.geoserver.catalog.impl.ModificationProxy.invoke(ModificationProxy.java:146)
    at com.sun.proxy.$Proxy6.getWebMapServer(Unknown Source)
    at org.geoserver.wms.GetMap.executeInternal(GetMap.java:464)
    at org.geoserver.wms.GetMap.run(GetMap.java:248)
    at org.geoserver.wms.GetMap.run(GetMap.java:119)

To go to http://mapas.icmbio.gov.br/i3geo/ogc.php?TEMA=uc_esec&REQUEST=GetCapabilities&VERSION=1.3.0&SERVICE=WMS it needs to login into same proxy I have configured in my browser (to go outside my network)

My proxy allow url auth like <user>:<password>@<proxy_address>:<port>

2016-05-02 10:03:53,627 DEBUG [org.geotools.data.ows] - Found 'http.proxyHost' Java System property. Using it as proxy server. Port: 6060
2016-05-02 10:03:53,627 DEBUG [org.geotools.data.ows] - Initialized with nonProxyHosts: [localhost, 10.5.115.122, 10.5.115.123, *.defesa.mil.br, 10.5.115.136, 10.5.115.110, 10.5.115.22, siglmd-app.defesa.mil.br]
2016-05-02 10:03:53,628 DEBUG [org.geotools.data.ows] - System property http.proxyUser and http.proxyPassword found, setting proxy auth credentials
2016-05-02 10:03:59,749 ERROR [org.geotools.data.ows] - Failed to execute request http://mapas.icmbio.gov.br/i3geo/ogc.php?TEMA=uc_esec&REQUEST=GetCapabilities&VERSION=1.3.0&SERVICE=WMS
2016-05-02 10:03:59,749 ERROR [org.geoserver.ows] - 
org.geoserver.platform.ServiceException: Internal error 
    at org.geoserver.wms.GetMap.run(GetMap.java:129)
    at org.geoserver.wms.DefaultWebMapService.getMap(DefaultWebMapService.java:320)
    at sun.reflect.GeneratedMethodAccessor300.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:319)

EDIT: Strange… some links are working others don't. This service gives me a Server returned HTTP response code: 407 for URL: http://mapas.icmbio.gov.br/i3geo/ogc.php?tema=uc_esec&service=wms&request=getcapabilities and this don't: http://sigel.aneel.gov.br/arcgis/services/SIGEL/Distribuicao/MapServer/WMSServer. I conclude it is not problem in my proxy since I can go outside in some cases…

Other cases: Work:

http://sigel.aneel.gov.br/arcgis/services/SIGEL/Transmissao/MapServer/WMSServer?service=WMS&version=1.1.0&request=GetCapabilities

Don't work ( error 407 ):

http://geoportal.lneg.pt/arcgis/services/RecursosHidro/MapServer/WMSServer?request=GetCapabilities&service=WMS&version=1.1.0

Geoserver proxy auth implementaion problem? https://stackoverflow.com/questions/14113341/http-407-proxy-authentication-required-how-to-handle-in-java-code

EDIT

This must be corrected to accept a password and an user name:
enter image description here

Still receiving Internal error : Server returned HTTP error code 407 for URL http://XYZ/?REQUEST=GetCapabilities&amp;VERSION=1.3.0&SERVICE=WMS because it is ignoring username and password from -Dxxx configuration.

Best Answer

You need to set the http proxy variables either using a system environment variable or through a JVM property set in catalina.sh. There are detailed steps on how to do this on the WFS Store page.

In the past there have been issues with the HTTP COnnection pooling not picking up the proxy variables so if it continues to not work try unclicking the connection pooling box.

enter image description here