Accessing a webmap in Arcgis enterprise from ArcGIS Runtime Java Application

597
3
04-30-2021 04:33 AM
JomonJacob
New Contributor

Hi, 

I have tried to access a webmap in my enterprise portal (airgapped) from  a runtime java application. When I try to access my enterprise portal using the following code

AuthenticationManager.setAuthenticationChallengeHandler(new DefaultAuthenticationChallengeHandler());

Portal portal = new Portal("http://xyz.com/arcgisportal",true") 

portal.loadAsync()

 A new window for entering user credentials is appearing on the screen and I have entered the credentials,  but I am not able to access the webmap and when i Print

System.out.println(portal.getPortalInfo);

Null is coming. 

Pls Suggest a solution

Thanks

J Jacob

 

0 Kudos
3 Replies
MarkBaird
Esri Regular Contributor

I wonder if you are reading the portalInfo on the line of code which is after portal.loadAsync() ?

It is entirely possible you will get a null value back because you've read the value before the portal has had chance to load.  Some asynchronous coding which uses the loadable pattern will help you here, even it only helps to diagnose the issue.

Some background notes on this are here

So in your example you should add a DoneLoadingListener something like this:

 

 

// portal we want to use
Portal portal = new Portal("http://www.arcgis.com/");

//trigger a load
portal.loadAsync();

// listen to it loading before reading
portal.addDoneLoadingListener(() -> {
    // check it is has loaded
    if (portal.getLoadStatus() == LoadStatus.LOADED) {
         // all is well and we can now read the portal info
         System.out.println("waiting for it to load we get : " + portal.getPortalInfo().getPortalName());
    }
});

 

 

 

You can also use the listener to diagnose loading issues.

Does this help?

0 Kudos
JomonJacob
New Contributor

Thank you for replying. 

I tried with addDoneLoadListner only. 

Can you pls elaborate on "You can also use the listener to diagnose loading issues"

 

Regards

"

0 Kudos
MarkBaird
Esri Regular Contributor

Had adding the doneLoadingListener allowed you to fix the issue?

For detecting loading issues, you can look at the load status to see if it failed to load.  I've updated my code to include a bad web address and reported the error in the console:

            // portal we want to use.  NOTE the bad web address!
            Portal portal = new Portal("chttp://www.arcgis.com/");

            //trigger a load
            portal.loadAsync();

            // listen to it loading before reading
            portal.addDoneLoadingListener(() -> {
                // check is has loaded
                if (portal.getLoadStatus() == LoadStatus.LOADED) {
                    // all is well and we can now read the portal info
                    System.out.println("waiting for it to load we get : " + portal.getPortalInfo().getPortalName());
                }

                // check for error condition
                if (portal.getLoadStatus() == LoadStatus.FAILED_TO_LOAD) {
                    System.out.println("load failure message : " + portal.getLoadError().getMessage());
                    System.out.println("load failure cause " + portal.getLoadError().getCause());
                }
            });
0 Kudos