Focal Point
[CLOSED] trying to write a standalone java api to schedule report

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/8341025592

August 14, 2008, 01:59 PM
<Barry>
[CLOSED] trying to write a standalone java api to schedule report
We are trying to create a Schedule using Report Caster java API. We are getting
a null pointer exception while creating a schedule instance using an API call
similar to

manager.createScheduleInstance(TimeInfo.ONCE,Distribution.LIBRARY,Task.WEBFOCUS-
_SERVER_PROCEDURE);

We are running a simple stand alone java program using the API to connect to
Report Caster on SOLARIS Server. Not using MRE client or any application server.
Included the following Jar files in class path.
reportcaster.jar,ibi_xml_apis_1_3.jar,webfocus_caster.jar,ojdbc14.jar.

The exception is java.lang.NullPointerException
at ibi.broker.security.ManagementContext.getConnectionManager(ManagementContext-
.java:111)
at ibi.broker.api.cci.interactive.AbstractInteractive.init(AbstractInteractive.-
java:64)
at ibi.broker.api.cci.interactive.AbstractInteractive.(AbstractInteractiv-
e.java:57)
at ibi.broker.api.cci.interactive.schedule.CreateScheduleInstance.(Create-
ScheduleInstance.java:58)
at ibi.broker.api.cci.interactive.schedule.ScheduleManagerImpl.createScheduleIn-
stance(ScheduleManagerImpl.java:129)

are we missing any jar files

This message has been edited. Last edited by: Kerry,
August 14, 2008, 03:19 PM
<Barry>
I was wondering if the problem is in the connection to the Oracle Rcaster repository. We think that we copied over the correct jar files but do we have to configure to connect to the Oracle database.

We have a distribution server and WebFOCUS Reporting Server available and we tried the sample java api and had a connection failure. Do we have to set up the Oracle connection and send the Webfocus id for the Reporting server or will the java api automatically go to the connection on the reporting server?
August 18, 2008, 01:33 PM
Fernando
Barry,

The first thing that I would try is to create a test job in caster itself.

Fernando


Prod WF 8.1.04, QA WF 8.2.03, Dev WF 8.2.03
August 19, 2008, 01:53 PM
dhagen
You WILL have to have the Oracle JAR files available and on the classpath, but you do not need to pass and credentials. The API will query the report caster server to get the appropriate credentials. You will need to have everything on the classpath that is required, including a bunch of other stuff that you wouldn't necessarily think of. The following is a stand alone for executing an existing schedule. You might find stuff you need in there:

/*
 * Created on Apr 14, 2008
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package com.ibi.rcaster;

import ibi.broker.api.cci.ScheduleManager;
import ibi.broker.api.data.schedule.Schedule;
import ibi.broker.api.CasterManagedConnectionFactory;
import ibi.broker.api.cci.CasterConnection;
import ibi.broker.api.cci.CasterConnectionFactory;
import ibi.broker.api.cci.PasswordCredential;
import javax.resource.cci.ConnectionSpec;

public class InvokeSchedule {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		System.out.println("*--- ReportCaster Schedule Invoke Procedure ---*");

		String scheduleId = null;
		String userId = null;
		String passWord = null;
		String hostName = null;
		String hostPort = null;

		try {

			for (int i=0; i<args.length; i++) {
				String argument = args[i];

				if (!argument.startsWith("-")) {
					// called with the wrong argument.
					System.out.println("Error: Arguments must start with a [-]");
					displayHelp();
					System.out.println("*--- Schedule Invokation Utility FAILED. ---*");
					System.out.println("*--- Schedule Invokation Utility END ---*");
					System.exit(-1);
				}

				// check for help
				if (argument.startsWith("-?")) 
					displayHelp();

				if (argument.startsWith("-S"))
					scheduleId = argument.substring(2);

				if (argument.startsWith("-H")) 
					hostName = argument.substring(2);

				if (argument.startsWith("-L")) 
					hostPort = argument.substring(2);

				if (argument.startsWith("-U")) 
					userId = argument.substring(2);

				if (argument.startsWith("-P")) 
					passWord = argument.substring(2);
			}

			if (scheduleId == null || hostPort == null || hostName == null || userId == null || passWord == null) {
				
				System.out.println("Error: command line arguments were not valid.");
				displayHelp();
				System.out.println("*--- Schedule Invokation Utility FAILED. ---*");
				System.out.println("*--- Schedule Invokation Utility END ---*");
				System.exit(-1);
			
			} else {

				System.out.println(" ");
				System.out.println("Schedule Invokation Procedure:");
				System.out.println("Schedule Id: " + scheduleId);
				System.out.println("ReportCaster Host: " + hostName);
				System.out.println("ReportCaster Port: " + hostPort);
				System.out.println("User id: " + userId);
				System.out.println(" ");

				CasterManagedConnectionFactory managedConnectionFactory = new CasterManagedConnectionFactory();
				managedConnectionFactory.setServerName(hostName);
				managedConnectionFactory.setPortNumber(hostPort);
				CasterConnectionFactory connectionFactory = (CasterConnectionFactory)managedConnectionFactory.createConnectionFactory();
				ConnectionSpec credential = new PasswordCredential(userId, passWord.toCharArray());
				CasterConnection casterConnection = ((CasterConnection)connectionFactory.getConnection(credential));

				ScheduleManager manager = casterConnection.getScheduleManager();

				//get schedule by id
				Schedule schedule = manager.getSchedule(scheduleId);

				//run schedule 
				String processId = manager.run(schedule);

				// Print result
				System.out.println("processId = " + processId);
				System.out.println(" ");
				System.out.println("*--- Schedule Invokation Utility END ---*");
			}

		} 
		catch (Exception e) {
			System.out.println("Exception in main: " + e.toString());
			System.exit(-1); 
		}
		System.exit(0);
	}

	private static void displayHelp() {
		System.out.println(" ");
		System.out.println("Schedule Invokation Utility Command Line Help");
		System.out.println("    -?      Display Help.");
		System.out.println("    -H      Server Host Name: [localhost]");
		System.out.println("    -L      Server Listening Port: [8200]");
		System.out.println("    -U      Connection User ID.");
		System.out.println("    -P      Connection Password.");
		System.out.println("    -S      Schedule ID: [S1356osnpo01]");
		System.out.println(" ");
		System.out.println("Examples:");
		System.out.println(" java com.ibi.rcaster.InvokeSchedule -Hlocalhost -L8200 -Uuserid -Ppassword -SS1356osnpo01");
		System.exit(-1);		
	}

}
  


The followin are all the JARs that were required on my classpath (I was using MySQL tables).

C:/ibi/WebFOCUS76/webapps/rcaster76/WEB-INF/lib/reportcaster.jar
C:/ibi/WebFOCUS76/webapps/rcaster76/WEB-INF/lib/connector-api.jar
C:/ibi/WebFOCUS76/webapps/rcaster76/WEB-INF/lib/ibi_xml_apis_1_3.jar
C:/ibi/WebFOCUS76/webapps/rcaster76/WEB-INF/lib/webfocus_caster.jar
C:/ibi/WebFOCUS76/webapps/rcaster76/WEB-INF/lib/jlink.jar
C:/ibi/ReportCaster76/lib/ibi_xerces_2_7_1.jar
C:/install/MySql/mysql-connector-java-5.0.8/mysql-connector-java-5.0.8-bin.jar 



"There is no limit to what you can achieve ... if you don’t care who gets the credit." Roger Abbott
August 19, 2008, 04:45 PM
<Barry>
dhagan

Thanks for the post we were missing a jar file, you were a great help
September 10, 2009, 11:39 AM
tobauer
dhagan,

i know this is an old post but maybe you can help... your solution is exactly what i was looking for but i fail to get it running.

i can compile your code but during executin i got some errors - also i'm not that good in java programming to be honest :

compile:

dwh1 tmp # javac -classpath "/opt/ibi/WebFOCUS76/webapps/rcaster76/WEB-INF/lib/reportcaster.jar:/opt/ibi/WebFOCUS76/webapps/rcaster76/WEB-INF/lib/connector-api.jar:/opt/ibi/WebFOCUS76/webapps/rcaster76/WEB-INF/lib/ibi_xml_apis_1_3.jar:/opt/ibi/WebFOCUS76/webapps/rcaster76/WEB-INF/lib/webfocus_caster.jar:/opt/ibi/WebFOCUS76/webapps/rcaster76/WEB-INF/lib/jlink.jar:/opt/ibi/ReportCaster76/lib/ibi_xerces_2_7_1.jar:/usr/lib/jvm/java-6-sun-1.6.0.12/jre/lib/ext/mysql-connector-java-5.1.7-bin.jar" InvokeSchedule.java
dwh1 tmp #

execution:

dwh1 tmp # java -classpath ".:/opt/ibi/WebFOCUS76/webapps/rcaster76/WEB-INF/lib/reportcaster.jar:/opt/ibi/WebFOCUS76/webapps/rcaster76/WEB-INF/lib/connector-api.jar:/opt/ibi/WebFOCUS76/webapps/rcaster76/WEB-INF/lib/ibi_xml_apis_1_3.jar:/opt/ibi/WebFOCUS76/webapps/rcaster76/WEB-INF/lib/webfocus_caster.jar:/opt/ibi/WebFOCUS76/webapps/rcaster76/WEB-INF/lib/jlink.jar:/opt/ibi/ReportCaster76/lib/ibi_xerces_2_7_1.jar:/usr/lib/jvm/java-6-sun-1.6.0.12/jre/lib/ext/mysql-connector-java-5.1.7-bin.jar" InvokeSchedule
Exception in thread "main" java.lang.NoClassDefFoundError: InvokeSchedule (wrong name: com/ibi/rcaster/InvokeSchedule)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
at java.net.URLClassLoader.access$000(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
Could not find the main class: InvokeSchedule. Program will exit.


any easy hint what i do wrong?

thanks
torsten


webfocus76
debian linux
HTML
September 10, 2009, 09:57 PM
dhagen
I posted this in a PM, but just to state this for the record: My guess is that you java file is not in the directory that is reflected in the package statement. Easy fix is to comment out the package line in the java code, then recompile, then re-execute.


"There is no limit to what you can achieve ... if you don’t care who gets the credit." Roger Abbott
September 11, 2009, 10:27 AM
tobauer
thanks a lot - works like a charm


webfocus76
debian linux
HTML