|
This topic describes how to create a stand-alone (non-web, command line) Java™ application that consumes the Social Business Toolkit SDK.
|
The Social Business Toolkit SDK provides the following classes for stand-alone Java applications:
- com.ibm.commons.runtime.impl.app.ApplicationStandalone implements the managed beans and properties factories for a Java application.
- com.ibm.commons.runtime.impl.app.ContextStandalone implements SBT Context for a Java application.
- com.ibm.commons.runtime.impl.app.RuntimeFactoryStandalone implements a run-time factory to be used in a Java application.
- Create a new Java project.
- Add the following libraries from the SDK:
com.ibm.sbt.core
com.ibm.commons
com.ibm.commons.runtime
com.ibm.commons.xml
- Examine the managed-beans.xml file configuration.
- The managed-beans.xml file contains bean definitions for endpoints and other beans required by the application. This file is read and the beans are initialized at application startup.
- The file can be in the META-INF folder in the classpath of the project or can be in the user directory.
- The com.ibm.commons.runtime.beans.FileResourceBeanFactory class reads managed-beans.xml from the user directory using System.getProperty("sbt.dir") or System.getProperty("user.dir").
- The com.ibm.commons.runtime.beans.MetaResourceBeanFactory class reads managed-beans.xml from the META-INF folder in the classpath if it is not in the user directory.
- Here is a sample managed-beans.xml with an endpoint bean for IBM® Connections:
connections com.ibm.sbt.services.endpoints.ConnectionsBasicEndpoint session url %{connections.url} passwordStore PwdStore forceTrustSSLCertificate true
- Examine the optional sbt.properties file configuration.
- The sbt.properties file can be added if there are properties (key/value pairs) that the application requires.
- This file is read and the beans are initialized at application startup.
- The file can be in the META-INF folder in the classpath of the project or can be in the user directory.
- The com.ibm.commons.runtime.properties.FileResourcePropertiesFactory class reads sbt.properties from the META-INF folder in the classpath if it is not in the user directory.
- Create a new Java class with a main method and add the following initialization code:
RuntimeFactory runtimeFactory = new RuntimeFactoryStandalone();
Application application = runtimeFactory.initApplication(null);
Context context = Context.init(application, null, null)
- Access any high-level or low-level API offered by SDK.
For example:
Endpoint endpoint = EndpointFactory.getEndpoint("connections");
endpoint.login("{userId}","{password}"); // optional step, required if connecting to API requiring authentication
String profileUrl = "profiles/atom/profile.do";
Map parameters = new HashMap();
parameters.put("email", "FrankAdams@renovations.com");
Object result = endpoint.xhrGet(profileUrl, parameters, ClientService.FORMAT_XML).getData();
String xml = DOMUtil.getXMLString((Node)result);
In this example, the low-level API of the SDK is used to get an endpoint bean for connections (defined in managed-beans.xml). Then xhrGet is called to execute a get API call on the IBM Connections Profiles API.
Note : Only endpoints using basic authentication can be used from stand alone IBM client since OAuth based endpoints require UI to be be authenticated.
Parent topic: Creating and deploying applications
|