Skip to Content
avatar image
Former Member

How to determine validity of IEnterpriseSession Instance using BO Enterprise Java SDK?

Hello there,

we're using BI 4.1 SP6. I found this solution here: https://apps.support.sap.com/sap/support/knowledge/public/en/1251959

public static String[] openDocumentSerSes(String username, String password, String cms_name, String cms_auth_type) throws UnsupportedEncodingException, SDKException

{

String[] result = new String[2];

if (session != null) {

// IEnterpriseSession enterpriseSession retrieved from HTTP Session

IInfoStore infoStore = null;

try {

infoStore = (IInfoStore) session.getService("InfoStore");

result[0] = "Session available and still valid";

} catch (SDKException sdkException) {

result[0] = "Session available, but no longer valid - generating new session";

session = CrystalEnterprise.getSessionMgr().logon(username, password, cms_name, cms_auth_type);

}

} else {

result[0] = "Session NOT available - generating new session";

session = CrystalEnterprise.getSessionMgr().logon(username, password, cms_name, cms_auth_type);

} String serSession = session.getSerializedSession();

String serSesEncode = URLEncoder.encode(serSession, "UTF-8");

result[1] = serSesEncode; return result;

}

}

but it shows me that the session is valid even though it's not, i.e. even after manually removing it from CMC. What am I missing?

Thomas

Add comment
10|10000 characters needed characters exceeded

  • The code isn't valid -- where does the value of session come from?

  • Former Member

    Thanks for you reply Joe and sorry for the delay. The code below works just fine however in some cases the statement (IInfoStore) session.getService("InfoStoreā€); doesn't throw an exception so that the url with the serialized session doesn't work and the user gets a login screen... Is there any documentation when to expect the exception to be thrown? Are there cases when this code won't throw an exception but the session will already be invalid?

    package com.mycompany.ars.bologontoken;
    
    
    import java.lang.StringBuilder;
    import java.util.ArrayList;
    import java.util.List;
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
    import java.util.HashMap;
    import java.net.URLEncoder;
    import java.io.UnsupportedEncodingException;
    
    
    import com.bmc.arsys.api.ARException;
    import com.bmc.arsys.api.DataType;
    import com.bmc.arsys.api.Entry;
    import com.bmc.arsys.api.SQLResult;
    import com.bmc.arsys.api.StatusInfo;
    import com.bmc.arsys.api.Value;
    import com.bmc.arsys.pluginsvr.plugins.ARPluginContext;
    import com.bmc.arsys.pluginsvr.plugins.ARPluginInfo;
    
    
    import com.crystaldecisions.sdk.exception.*;
    import com.crystaldecisions.sdk.framework.*;
    import com.crystaldecisions.sdk.occa.infostore.IInfoStore;
    import com.crystaldecisions.sdk.occa.infostore.IInfoObject;
    import com.crystaldecisions.sdk.occa.infostore.IInfoObjects;
    import com.crystaldecisions.sdk.framework.IEnterpriseSession;
    import com.crystaldecisions.sdk.framework.CrystalEnterprise;
    
    
    import com.mycompany.ars.bologontoken.*;
    
    
    public class LogonTokenApp {
      private ARPluginInfo pluginInfo = null;
      private ARPluginContext pluginContext = null;
    
    
      private static IEnterpriseSession session = null;
    
    
      public LogonTokenApp() throws ARException {
        super();
        
        pluginContext = null;
        
        init();
      }
      
      public LogonTokenApp(ARPluginContext context, ARPluginInfo pluginInfo) throws ARException {
        super();
        this.pluginContext = context;
        this.pluginInfo = pluginInfo;
        
        init();
      }
        
      private void init() {	    	
        // init code
      }
      
      public ArrayList<Value> RunService(List<Value> inList) throws ARException {
        String action = inList.get(0).getValue().toString();
        String username = inList.get(1).getValue().toString();
        String password = inList.get(2).getValue().toString();
        String doc_id = inList.get(3).getValue().toString();
        String s_id_type = inList.get(4).getValue().toString();
        String cms_name = inList.get(5).getValue().toString();
        String cms_auth_type = inList.get(6).getValue().toString();
        String url_server_with_port = inList.get(7).getValue().toString();
        String output_format = inList.get(8).getValue().toString();
    
    
        ArrayList<Value> out = new ArrayList<Value>(2);
    
    
        String messageAndSerSession[] = getSerSession(username, password, doc_id, s_id_type, cms_name, cms_auth_type);
        out.set(0, new Value(messageAndSerSession[0]));
        out.set(1, new Value(messageAndSerSession[1]));
        
        return out;
      }
    
    
      public static String[] getSerSession(String username, String password, String doc_id, String s_id_type, String cms_name, String cms_auth_type) {
        try {
          return openDocumentSerSes(username, password, cms_name, cms_auth_type);
        } catch (UnsupportedEncodingException e) {
          // TODO Auto-generated catch block
          String[] error = new String[2];
          error[0] = "ERROR: " + e.getMessage();
          error[1] = "";
          return error;
        } catch (SDKException e) {
          String[] error = new String[2];
          error[0] = "ERROR: " + e.getMessage();
          error[1] = "";
          return error;
        }
      }
    
    
      public static String[] openDocumentSerSes(String username, String password, String cms_name, String cms_auth_type) throws UnsupportedEncodingException, SDKException  
      { 
        String[] result = new String[2];
        if (session != null) {
          IInfoStore infoStore = null;
          try {
            infoStore = (IInfoStore) session.getService("InfoStore");
            result[0] = "Session available and still valid";
          } catch (SDKException sdkException) {
            result[0] = "Session available, but no longer valid - generating new session";
            session = CrystalEnterprise.getSessionMgr().logon(username, password, cms_name, cms_auth_type);
          }
        } else {
          result[0] = "Session NOT available - generating new session";
          session = CrystalEnterprise.getSessionMgr().logon(username, password, cms_name, cms_auth_type);
        }
    
    
        String serSession = session.getSerializedSession();
        String serSesEncode = URLEncoder.encode(serSession, "UTF-8");
    
    
        result[1] = serSesEncode;
    
    
        return result;
      }
    }
    
  • Get RSS Feed

0 Answers