AnsweredAssumed Answered

java httprequest arcgis server rest api longterm token

Question asked by cscillieri@siveco.com on Feb 23, 2016
Latest reply on Mar 4, 2016 by cscillieri@siveco.com

Hi all,

We have a client javascript app that based on a java n-tier.

For layers security pupose, java part calls arcgis server via REST API to get an ident. token this way :

 

url = new URL( strUrl );

HttpURLConnection conn;

conn = (HttpURLConnection)url.openConnection();

conn.setRequestMethod( "POST" );

conn.setRequestProperty( "Accept-Charset", "UTF-8" );

conn.setRequestProperty( "Content-type", "application/x-www-form-urlencoded" );

conn.setRequestProperty( "Accept", "application/json" );

conn.setDoOutput( true );

conn.setDoInput( true );

 

BufferedWriter bw = new BufferedWriter( new OutputStreamWriter( ( conn.getOutputStream() ), "UTF-8" ) );

 

String params = "username" + "=" + URLEncoder.encode( user, "UTF-8" ); params += "&";

params += "password" + "=" + URLEncoder.encode( pW, "UTF-8" ); params += "&";

params += "client" + "=" + URLEncoder.encode( "referer", "UTF-8" ); params += "&";

params += "referer" + "=" + URLEncoder.encode( referer, "UTF-8" ); params += "&";

params += "expiration" + "=" + URLEncoder.encode( duration, "UTF-8" ); params += "&";

params += "f" + "=" + URLEncoder.encode( "json", "UTF-8" );

bw.write( params ); bw.flush(); bw.close();

 

if( conn.getResponseCode() == HttpURLConnection.HTTP_OK )

//here we go with the returned TOKEN

 

We pass the returned token to the javascript client app which is init with a "esri.id.initialize(..)" and it works fine.

But it seems that in this way we only generate short-lived tokens.

How to generate long-live tokens with the arcgis server API REST ?

 

regards.

Chris.

Outcomes