The example provided in this document is provided “as-is” to the user and assumes that the user:
PREREQUISITES:
For the sample to work, the Strategy Web JAR files must be accessible by the Java Runtime
Environment. The Strategy Web JAR files can be found under:
Note:
Following example demostrates how to create a session then generate the URL to bypass the login page with Strategy SDK.
For explainations refer to the code comments.
Sample Code
package com.Strategy.sdk.samples.sessionmanagement;
import com.Strategy.web.objects.WebIServerSession;
import com.Strategy.web.objects.WebObjectsException;
import com.Strategy.web.objects.WebObjectsFactory;
public class SessionManagementSample {
private static WebObjectsFactory factory = null;
private static WebIServerSession serverSession = null;
/**
*
* Creates a new session that can be reused by other classes
*
* @return WebIServerSession
*/
public static WebIServerSession getSession() {
if (serverSession == null) {
// create factory object
factory = WebObjectsFactory.getInstance();
serverSession = factory.getIServerSession();
// Set up session properties
serverSession.setServerName("IServer"); // Should be replaced with the name of an Intelligence Server
serverSession.setServerPort(0);
serverSession.setProjectName("Strategy Tutorial"); // Project where session is created
serverSession.setLogin("administrator"); // User ID
serverSession.setPassword(""); // Password
// Initialize the session with the above parameters
try {
System.out.println("nSession created with ID: "+ serverSession.getSessionID());
System.out.println("Session State: "+ serverSession.saveState(0));
} catch (WebObjectsException ex) {
handleError(null, "Error creating session:" + ex.getMessage());
}
}
// Return session
return serverSession;
}
public static void closeSession(WebIServerSession serverSession) {
try {
serverSession.closeSession();
} catch (WebObjectsException ex) {
System.out.println("Error closing session:" + ex.getMessage());
return;
}
System.out.println("Session closed.");
}
/**
*
* Print out error message, close session and abort execution
*
* @param serverSession
* WebIServerSession
*
* @param message
* String
*/
public static void handleError(WebIServerSession serverSession,String message) {
if (serverSession != null) {
closeSession(serverSession);
}
System.exit(0);
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
getSession();
StringBuilder urlSB = new StringBuilder();
urlSB.append("http").append("://").append("WebServerName:8080"); //Web Server name and port
urlSB.append("/MicroStrategy/servlet/mstrWeb");
urlSB.append("?server=").append("IServerName"); //I Server name
// urlSB.append("&port=0");
urlSB.append("&project=").append("Strategy+Tutorial"); // Project name
urlSB.append("&evt=").append(4001);
urlSB.append("&reportID=").append("E0DE2E1B408BD9FA8941E5B2E4FE876D"); //Report ID
urlSB.append("&reportViewMode=").append(0);
urlSB.append("&src=mstrWeb.").append("reportNoHeaderNoFooterNoPath").append(".").append(4001);
urlSB.append("&usrSmgr=").append(serverSession.saveState(0));
System.out.println(urlSB.toString()); // Final URL is printed to console.
System.out.println();
}
}