Forum Discussion

Kumar_107292's avatar
Kumar_107292
Icon for Nimbostratus rankNimbostratus
Feb 19, 2013

How do I use sessions in Icontrol API using java.

How do I use sessions in Icontrol API using java.

 

I have got the iControl Interface object. Then from the interface object I am getting the session object.

 

Now My question is How do I make sure that this is the very same session I am using when issuing create api calls throw iCOntrol SDK.

 

 

iCtrlInterface = IControlInterface.getIControlInterface(ipAddress, port, username, password);

 

iSession = iCtrlIntf.getSystemSession();

 

 

now i want to make use of this session object to make other calls through API so that I am in the same session.

 

 

Thanks

 

Kumar

 

2 Replies

  • Posted By Kumar on 02/19/2013 08:09 AM

     

    How do I use sessions in Icontrol API using java.

     

    I have got the iControl Interface object. Then from the interface object I am getting the session object.

     

    Now My question is How do I make sure that this is the very same session I am using when issuing create api calls throw iCOntrol SDK.

     

     

    iCtrlInterface = IControlInterface.getIControlInterface(ipAddress, port, username, password);

     

    iSession = iCtrlIntf.getSystemSession();

     

     

    now i want to make use of this session object to make other calls through API so that I am in the same session.

     

     

    Thanks

     

    Kumar

     

     

     

    going through various documents what I realized is that i can send session Id as a SOAP header element.

     

    But how? Pls Help on How to send the header element with my iControl Api call. I am using Java.

     

  • Did you figure this out? I thought it was as simple as setting the session header, but it took me forever to get this to work. The tricky part was finding the right namespace. See the code below:

     

    -----

     

    SystemSessionBindingStub systemSessionStub1 = new Interfaces(config.host11(), config.user(), config.password()).getSystemSession();

     

    Long sessionId1 = systemSessionStub1.get_session_identifier();

     

    systemSessionStub1.setHeader("urn:iControl", "session", sessionId1.toString());

     

    systemSessionStub1.set_session_timeout(300);

     

    systemSessionStub1.set_active_folder("/Common");

     

     

    SystemSessionBindingStub systemSessionStub2 = new Interfaces(config.host11(), config.user(), config.password()).getSystemSession();

     

    Long sessionId2 = systemSessionStub2.get_session_identifier();

     

    systemSessionStub2.setHeader("urn:iControl", "session", sessionId2.toString());

     

    systemSessionStub2.set_session_timeout(300);

     

    systemSessionStub2.set_active_folder("/Common");

     

     

    systemSessionStub1.start_transaction();

     

    try {

     

    systemSessionStub2.start_transaction();

     

    logger.debug("Opened two transactions!");

     

    systemSessionStub2.rollback_transaction();

     

    } catch (Exception e) {

     

    Assert.fail("Couldn't create two transactions at the same time.", e);

     

    } finally {

     

    systemSessionStub1.rollback_transaction();

     

    }

     

    -----

     

    Hopefully this saves someone the wasted time trying to debug this. Perhaps we should move this code near the API documentation?

     

    Ryan