I am trying below code to access the layers, which is token based rest service with username and password..It is not working any idea???
UserCredentials creds = new UserCredentials();
creds.setUserAccount("username", "password");
creds.setUserToken("huiqyuidhiqkljklwejk6Qzwgehwj6bqoKbjhwejkhiTBx", "localhost"); ArcGISDynamicMapServiceLayer layer = new ArcGISDynamicMapServiceLayer("http://.........", creds);
Thanks
Solved! Go to Solution.
Solved last week. Problem was token not created using same domain.
Solution:
String tokenUrl = | url + "tokens/generateToken?username=" *****&password=*****"; | ||
URL uRl = new URL(tokenUrl); | |||
HttpURLConnection con = (HttpURLConnection) uRl.openConnection(); | |||
con.setDoOutput(true); | |||
con.setDoInput(true); | |||
con.setRequestProperty("Client", "HTTP Referer"); | |||
con.setRequestProperty("HTTP referer", "******"); | |||
con.connect(); |
use this generated token as below:
uRl = new URL(url+"&token=*******");
con = (HttpURLConnection) uRl.openConnection(); | |||
con.setDoOutput(true); | |||
con.setDoInput(true); | |||
con.setRequestProperty("Client", "HTTP Referer"); | |||
con.setRequestProperty("HTTP referer", "*****"); | |||
con.connect(); | |||
wr = new OutputStreamWriter(con.getOutputStream()); | |||
wr.flush(); |
Have you tried not calling setUserToken? Normally setting the username and password in the credentials is all that's required, the API does the rest.
Is it a specific service giving you grief?
~Elise
Yes, We do have other services but not based on token, which are working fine. I have tried not calling setUserToken but no use..If i debug and check the variables I am seeing LayerStatus=UNINITIALIZED...
I am able to see the layers if i go directly in the browser after giving user name and password....
-Naveen
any help??
Do we need to do any kind of settings from ArcGIS side??
It's hard to say without more info about the service, how you're obtaining the token, and perhaps some context around the code.
You could try debugging using a program like Fiddler to see the chat to and from the service?
For reference here's some ArcGIS Server (10.2) doc on tokens: About ArcGIS Tokens
~Elise
Solved last week. Problem was token not created using same domain.
Solution:
String tokenUrl = | url + "tokens/generateToken?username=" *****&password=*****"; | ||
URL uRl = new URL(tokenUrl); | |||
HttpURLConnection con = (HttpURLConnection) uRl.openConnection(); | |||
con.setDoOutput(true); | |||
con.setDoInput(true); | |||
con.setRequestProperty("Client", "HTTP Referer"); | |||
con.setRequestProperty("HTTP referer", "******"); | |||
con.connect(); |
use this generated token as below:
uRl = new URL(url+"&token=*******");
con = (HttpURLConnection) uRl.openConnection(); | |||
con.setDoOutput(true); | |||
con.setDoInput(true); | |||
con.setRequestProperty("Client", "HTTP Referer"); | |||
con.setRequestProperty("HTTP referer", "*****"); | |||
con.connect(); | |||
wr = new OutputStreamWriter(con.getOutputStream()); | |||
wr.flush(); |