[ovirt-users] How to get logged in into restapi in java using session ID

Juan Hernández jhernand at redhat.com
Mon Mar 14 17:30:53 UTC 2016


On 02/18/2016 03:22 PM, shailendra saxena wrote:
> Has somebody tried to get  API object with the constructor having
> parameters- URL and restapisession-  by using java-sdk ?
> Here is the following syntax ?
> Api api =new Api(RestURL,restapisessionID)
> 
> I have searched a lot but i didn't find anything. Somewhere  I read that
> Ovirt has some issue on keeping restapisession. Is it correct ?
> 

This should work, but the value that you have to pass is the session
cookie plus its value:

  JSESSIONID=asfasdfasdfas

Also consider using the "ApiBuilder" object, instead of directly the
"Api" constructor, and secure the connection:

  // Get the session id from somewhere:
  String sessionId = ...;

  // Create the builder:
  ApiBuilder builder = new ApiBuilder()
    .url(URL)
    .sessionId("JSESSIONID=" + sessionId)
    .keyStorePath("ca.jks")
    .keyStorePassword("mykeystorepassword")
    .debug(DEBUG);

  // The "ca.jks" file above needs to be created from
  // the CA certificate of the engine, which is usually
  // located in the "/etc/pki/ovirt-engine/ca.pem" file.
  // Get that file, and then use a the "keytool" command
  // to import it to the "ca.jks" keystore file:
  //
  // keytool \
  // -importcert \
  // -keystore ca.jks \
  // -file ca.pem \
  // -alias ca \
  // -storepass mykeystorepassword \
  // -noprompt
  //
  // The resulting "ca.jks" file only contains the CA
  // certificate, so its content isn't confidential.

  // Create the API object:
  Api api = builder.build();

-- 
Dirección Comercial: C/Jose Bardasano Baos, 9, Edif. Gorbea 3, planta
3ºD, 28016 Madrid, Spain
Inscrita en el Reg. Mercantil de Madrid – C.I.F. B82657941 - Red Hat S.L.



More information about the Users mailing list