Hi folks,
Is there a blog post somewhere to help me write a simple helloworld application in Java with the TM1 API?
I'm looking for something to simply connect to a TM1 server and list the cubes on it. I'm using Eclipse and have the API imported, but I must be missing something.
-Bob
TM1 Java HelloWorld App using TM1 API
-
- Posts: 38
- Joined: Thu Oct 11, 2012 6:15 am
- OLAP Product: TM1
- Version: 10.2.2.4
- Excel Version: 2010
- Location: Melbourne, Australia
Re: TM1 Java HelloWorld App using TM1 API
Code: Select all
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.applix.tm1.TM1Bean;
import com.applix.tm1.TM1Cube;
import com.applix.tm1.TM1Dimension;
import com.applix.tm1.TM1Server;
import com.applix.tm1.TM1Val;
/**
* This is a sample code that uses the TM1 java API.
*/
public final class TM1ConnectTest {
private static final int THREE = 3;
private static final String TM1HOSTNAME = "host01";
private static final String TM1SERVERNAME = "server01";
private static final String TM1USERNAME = "user01";
private static final String TM1PASSWORD = "password01";
private static Log log = LogFactory.getLog(TM1ConnectTest.class);
private TM1ConnectTest() {
}
/**
* @param args .
*/
public static void main(String[] args) {
TM1Bean bean = new TM1Bean();
bean.setAdminHost(TM1HOSTNAME);
log.info("No. of Servers: " + bean.getNumberOfServers());
TM1Server server = bean.openConnection(TM1SERVERNAME, TM1USERNAME, TM1PASSWORD);
log.info("Clientname: " + server.getClientName().getString());
TM1Dimension tm1d = server.getDimension("dim01");
log.info("Element index: " + tm1d.getElement("element01").getIndex().getString());
TM1Cube tm1c = server.getCube("cube01");
log.info("Cube: " + tm1c.getName().getString());
TM1Val cell = TM1Val.makeArrayVal(THREE);
cell.addToArray(server.getDimension("dim02").getElement("element01"));
cell.addToArray(server.getDimension("dim03").getElement("element01"));
cell.addToArray(server.getDimension("dim04_m").getElement("element01"));
log.info("Cell value: " + tm1c.getCellValue(cell).getString());
bean.closeConnection(server);
}
}
-
- Posts: 80
- Joined: Tue Jun 04, 2013 3:35 pm
- OLAP Product: TM1
- Version: 10.2.2
- Excel Version: 2010
Re: TM1 Java HelloWorld App using TM1 API
Hi,
I get an error when I write similar code as above. I am trying to connect to TM1.
TM1 version - 10.2.2 FP4. using Eclipse IDE. Can someone help me with the exception error? Any help is good.
----------code--------
package FirstPackage;
import com.applix.tm1.*;
import com.applix.tm1.TM1Bean;
import com.applix.tm1.TM1Server;
import javax.net.ssl.SSLContext;
public class HelloWorld {
public static void main(String[] args) {
// TODO Auto-generated method stub
TM1Bean bean = new TM1Bean();
bean.setAdminHost("localhost");
/*ssl 5498
/non-ssl 5495 */
bean.setAdminPort(5495);
TM1Server srvr = new TM1Server();
srvr = bean.openConnection("Planning Sample", "admin", "apple");
System.out.println("I am here 2");
}
}
----------
--- errorException in thread "main" java.lang.IllegalArgumentException: SSL_TLSv2
at sun.security.ssl.ProtocolVersion.valueOf(ProtocolVersion.java:161)
at sun.security.ssl.ProtocolList.convert(ProtocolList.java:84)
at sun.security.ssl.ProtocolList.<init>(ProtocolList.java:52)
at sun.security.ssl.SSLSocketImpl.setEnabledProtocols(SSLSocketImpl.java:2442)
at com.applix.tm1.TM1NetClass.ConnectToHost(TM1NetClass.java:260)
at com.applix.tm1.TM1NetClass.ConnectUsingIPv4(TM1NetClass.java:191)
at com.applix.tm1.TM1NetClass.Connect(TM1NetClass.java:173)
at com.applix.tm1.TM1Bean.getAdmEntryList(TM1Bean.java:539)
at com.applix.tm1.TM1Bean.getNumberOfServers(TM1Bean.java:369)
at FirstPackage.HelloWorld.main(HelloWorld.java:32)
------------------
Thanks,
Paul.
I get an error when I write similar code as above. I am trying to connect to TM1.
TM1 version - 10.2.2 FP4. using Eclipse IDE. Can someone help me with the exception error? Any help is good.
----------code--------
package FirstPackage;
import com.applix.tm1.*;
import com.applix.tm1.TM1Bean;
import com.applix.tm1.TM1Server;
import javax.net.ssl.SSLContext;
public class HelloWorld {
public static void main(String[] args) {
// TODO Auto-generated method stub
TM1Bean bean = new TM1Bean();
bean.setAdminHost("localhost");
/*ssl 5498
/non-ssl 5495 */
bean.setAdminPort(5495);
TM1Server srvr = new TM1Server();
srvr = bean.openConnection("Planning Sample", "admin", "apple");
System.out.println("I am here 2");
}
}
----------
--- error
-
- Posts: 38
- Joined: Thu Oct 11, 2012 6:15 am
- OLAP Product: TM1
- Version: 10.2.2.4
- Excel Version: 2010
- Location: Melbourne, Australia
Re: TM1 Java HelloWorld App using TM1 API
Oh wow! that code I posted is more than 3 years old now.
Since then looks like we did a number of changes, especially SSL updates. However, the error looks like your AdminServer is looking at the v2 certificate, while the java packages might be using the "standard" certificate. I haven't done much Java API since, but if I do get a chance I'll try it out again. Anyway, is there a difference in the certificate versions?
Since then looks like we did a number of changes, especially SSL updates. However, the error looks like your AdminServer is looking at the v2 certificate, while the java packages might be using the "standard" certificate. I haven't done much Java API since, but if I do get a chance I'll try it out again. Anyway, is there a difference in the certificate versions?
-
- Posts: 80
- Joined: Tue Jun 04, 2013 3:35 pm
- OLAP Product: TM1
- Version: 10.2.2
- Excel Version: 2010
Re: TM1 Java HelloWorld App using TM1 API
Hi Upali,
Thanks for the response.
There was a certificate expiry late last year and we did the change. Otherwise it's a working system.
I was able pass the error with the below code but the server does not get connected.
System.setProperty("com.ibm.jsse2.overrideDefaultProtocol", "TLSv1.2");
The bean methods fail with error 'Error: SystemServerNotFound'. Updated code is below. I will update if there is any improvement on my side.
--code
import com.applix.tm1.*;
public class HelloWorld {
public static void main(String[] args) {
System.out.println("I am here ");
System.setProperty("com.ibm.jsse2.overrideDefaultProtocol", "TLSv1.2");
TM1Bean bean = new TM1Bean();
bean.setAdminHost("localhost");
/*ssl 5498
/non-ssl 5495 */
bean.setAdminPort(5495);
System.out.println("I am here 21");
TM1Server srvr = new TM1Server();
try{
srvr = bean.openConnection("Planning Sample", "admin", "apple");
System.out.println("before adding chore \n" + srvr);
// fails at this line or while calling any code
srvr.createEmptyChore();
System.out.println("after adding chore");
}
catch(Exception myexception) {
//System.out.println((new StringBuilder()).append("TM1 Error: \t").append(myexception).toString());
System.out.println(myexception.getMessage());
}
//bean.openConnection("SData", "admin", "apple");
System.out.println("I am here 22");
System.out.println("hash code:"+ bean.hashCode());
System.out.println("I am here 2");
}
}
Thanks for the response.
There was a certificate expiry late last year and we did the change. Otherwise it's a working system.
I was able pass the error with the below code but the server does not get connected.
System.setProperty("com.ibm.jsse2.overrideDefaultProtocol", "TLSv1.2");
The bean methods fail with error 'Error: SystemServerNotFound'. Updated code is below. I will update if there is any improvement on my side.
--code
import com.applix.tm1.*;
public class HelloWorld {
public static void main(String[] args) {
System.out.println("I am here ");
System.setProperty("com.ibm.jsse2.overrideDefaultProtocol", "TLSv1.2");
TM1Bean bean = new TM1Bean();
bean.setAdminHost("localhost");
/*ssl 5498
/non-ssl 5495 */
bean.setAdminPort(5495);
System.out.println("I am here 21");
TM1Server srvr = new TM1Server();
try{
srvr = bean.openConnection("Planning Sample", "admin", "apple");
System.out.println("before adding chore \n" + srvr);
// fails at this line or while calling any code
srvr.createEmptyChore();
System.out.println("after adding chore");
}
catch(Exception myexception) {
//System.out.println((new StringBuilder()).append("TM1 Error: \t").append(myexception).toString());
System.out.println(myexception.getMessage());
}
//bean.openConnection("SData", "admin", "apple");
System.out.println("I am here 22");
System.out.println("hash code:"+ bean.hashCode());
System.out.println("I am here 2");
}
}
-
- MVP
- Posts: 264
- Joined: Mon Nov 03, 2014 8:23 pm
- OLAP Product: TM1
- Version: 9.5.2 10.1 10.2 PA2
- Excel Version: 2016
Re: TM1 Java HelloWorld App using TM1 API
That looks like an IBM specific property. Are you using the IBM JRE (as installed by TM1) or an Oracle JRE?LutherPaul wrote: System.setProperty("com.ibm.jsse2.overrideDefaultProtocol", "TLSv1.2");
-
- Posts: 80
- Joined: Tue Jun 04, 2013 3:35 pm
- OLAP Product: TM1
- Version: 10.2.2
- Excel Version: 2010
Re: TM1 Java HelloWorld App using TM1 API
Hi Brian,
Thanks for the reply. we use Oracle JRE.
Thanks,
Paul.
Thanks for the reply. we use Oracle JRE.
Thanks,
Paul.
-
- MVP
- Posts: 264
- Joined: Mon Nov 03, 2014 8:23 pm
- OLAP Product: TM1
- Version: 9.5.2 10.1 10.2 PA2
- Excel Version: 2016
Re: TM1 Java HelloWorld App using TM1 API
That might be your problem then. Does the code work if you run with the IBM JRE?
-
- Posts: 80
- Joined: Tue Jun 04, 2013 3:35 pm
- OLAP Product: TM1
- Version: 10.2.2
- Excel Version: 2010
Re: TM1 Java HelloWorld App using TM1 API
I have added the below lines and it worked. Lines were provided by IBM. This will help others who are stuck here.
System is on 10.2.2 FP6; windows, Oracle JRE.
System.setProperty("com.ibm.jsse2.overrideDefaultProtocol", "TLSv1.2");
System.setProperty("javax.net.ssl.trustStore", "D:/Program Files/ibm/cognos/tm1_64/bin64/ssl/tm1store");
System.setProperty("javax.net.ssl.trustStorePassword", "applix");
System.setProperty("java.net.preferIPv4Stack" , "true");
Thanks for the help.
Paul.
System is on 10.2.2 FP6; windows, Oracle JRE.
System.setProperty("com.ibm.jsse2.overrideDefaultProtocol", "TLSv1.2");
System.setProperty("javax.net.ssl.trustStore", "D:/Program Files/ibm/cognos/tm1_64/bin64/ssl/tm1store");
System.setProperty("javax.net.ssl.trustStorePassword", "applix");
System.setProperty("java.net.preferIPv4Stack" , "true");
Thanks for the help.
Paul.