Not able to add ArcGISDynamicMapServiceLayer in Arc

4298
5
Jump to solution
03-20-2013 10:27 PM
RavindraSingh
Occasional Contributor
I am creating a very simple program to add dynamic map service from ArcGISOnline.
I am getting following error when i rung the application:

Can any one help in this. is there any setting which is required to be done, in terms of proxy or something?

Java version : 1.6.0_27 (Sun Microsystems Inc.) x86
Rendering engine : DirectX
org.apache.http.conn.HttpHostConnectException: Connection to http://sampleserver1.arcgisonline.com refused
at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:127)
at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:147)
at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:108)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:415)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:641)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:731)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:709)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:700)
at com.esri.core.internal.io.handler.l.a(Unknown Source)
at com.esri.core.internal.io.handler.l.a(Unknown Source)
at com.esri.core.internal.tasks.a.p.a(Unknown Source)
at com.esri.core.internal.tasks.a.p.execute(Unknown Source)
at com.esri.map.Layer.loadServiceInfo(Unknown Source)
at com.esri.map.Layer.getMapServerInfo(Unknown Source)
at com.esri.map.ArcGISDynamicMapServiceLayer$1.run(Unknown Source)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
at java.util.concurrent.FutureTask.run(FutureTask.java:138)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:662)
Caused by: java.net.ConnectException: Connection timed out: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:529)
at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:123)
at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:123)
... 20 more
0 Kudos
1 Solution

Accepted Solutions
EricBader
Occasional Contributor III
It appears that the service may be secured? You may need to pass the user credentials in when creating the layer. Maybe?

View solution in original post

0 Kudos
5 Replies
EricBader
Occasional Contributor III
It appears that the service may be secured? You may need to pass the user credentials in when creating the layer. Maybe?
0 Kudos
RavindraSingh
Occasional Contributor
The service is not secured::
ArcGISTiledMapServiceLayer tiledLayer = new ArcGISTiledMapServiceLayer(
                "http://services.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer");
        //LayerList layers = map.getLayers();
       // layers.add(tiledLayer);
        map.getLayers().add(tiledLayer);

even this is also not being displayed... i am getting same error.
0 Kudos
SachinKanaujia
Occasional Contributor III
If you are behind a proxy (authenticated or otherwise) then you need to configure the proxy details to access external servers (services). The ESRI Proxy code is broken so its recommended you set up the system properties to do the same.

            String username = "username";
            String password = "password";
            System.setProperty("http.proxySet", "true");
            System.setProperty("http.proxyType", "4");
            System.setProperty("http.proxyHost", "proxy server");
            System.setProperty("http.proxyPort", "proxy port");
            System.setProperty("http.proxyUser", username);
            System.setProperty("http.proxyPassword", password);
            System.setProperty("http.nonProxyHosts", "127.0.0.1");   // to allow local server


Adjust the code accordingly

The service is not secured::
ArcGISTiledMapServiceLayer tiledLayer = new ArcGISTiledMapServiceLayer(
                "http://services.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer");
        //LayerList layers = map.getLayers();
       // layers.add(tiledLayer);
        map.getLayers().add(tiledLayer);

even this is also not being displayed... i am getting same error.
0 Kudos
EdgarCanul
New Contributor III

Great! Thanks.

I just have one question. May be the proxy parameters are not correct. How can you catch this connection exception (org.apache.http.conn.HttpHostConnectException) since it's not thrown by JMap class itself. I need to catch this error and take suitable actions or an appropriate warning message about the proxy parameters correctness.

I tried:

MapOptions mapOptions = new MapOptions(MapType.STREETS, 24.43261, -102.92041, 4);

try{

JMap jMap = new JMap(mapOptions);

  jMap.setWrapAroundEnabled(true);

}

catch(org.apache.http.conn.HttpHostConnectException){

   // Handle error connection due to incorrect proxy parameters

}

But, of course, the compiler claims "Out of Reach try catch clause"

0 Kudos
EricBader
Occasional Contributor III

First of all, good "catch". by the way.

What happens when you try to catch a general Exception?

This is what works for me. Surround your layer definition code with a try/catch for Exception, instead of a specific one. I know it sounds improper, but this may get you farther along, hopefully?

0 Kudos