Getting Started as Java Developer

Introduction

The SDK comes with Java and JavaScript APIs to easily access IBM Connections and IBM SmartCloud for Social Business. Watch this video for a short overview of the SDK or watch this longer video to learn about the IBM Collaboration Solutions app dev strategy.


Watch a Video with Sample Snippets

Watch the video (at 2m30s) to see some simple JSP samples.


Prepare your Environment

In order to use the SDK within your applications, you need to download and install the SDK.

Download the latest SDK

There are simple Java snippets that can be run from an Eclipse IDE. The complete Eclipse workspace with the samples and a local Tomcat server comes with the SDK which can easily be used in Eclipse IDEs. Read the documentation (tbd: add link) how to set up the samples and how to run (tbd: add link) them.


Code your first app

Build a Hello World web application using Eclipse and Tomcat 7.0

  1. Click File -> New -> Dynamic Web Project.

    Specify the project name as social.helloworld-web.

    Click Finish.


    New Dynamic Web Project dialog 1


    New Dynamic Web Project dialog 2
  2. Right-click social.helloworld-web and create a new folder named lib.
    Add the following SDK dependency jar files to the lib folder (available from one of the existing sample WAR files).

    apache-mime4j-0.6.jar
    com.ibm.commons-1.0.0.jar
    com.ibm.commons.runtime-1.0.0.jar
    com.ibm.commons.xml-1.0.0.jar
    com.ibm.sbt.core-1.0.0.jar
    com.ibm.sbt.playground-1.0.0.jar
    commons-codec-1.3.jar
    commons-logging-1.1.1.jar
    httpclient-4.0.1.jar
    httpcore-4.0.1.jar
    httpmime-4.0.1.jar
    commons-fileupload-1.2.2.jar    
    commons-io-2.4.jar


    They appear as follows in the file system.

    sbt.helloworld.libs


  3. Update the build path and deployment assembly properties of social.helloworld-web as follows.
    Right-click social.helloworld-web and select properties.

    Select Java Build Path -> Add Jars and add all SDK jar files from the lib folder.

    Select Deployment Assembly -> Add -> Java Build Path Enteries and select all SDK jar files.

    Click Apply and OK.


    Java Build Path dialog


    Web Deployment Assembly dialog
  4. Click File -> New -> Servlet to create a new servlet for toolkit services. Provide the following information:
    • Use the existing servlet class: com.ibm.sbt.service.core.servlet.ServiceServlet
    • Name: ServiceServlet
    • Description: The service servlet handles requests from the toolkit to access external resources.
    • URL mappings: /service/*
    Create Servlet dialog
  5. Click File -> New -> Servlet to create a new servlet for initializing the toolkit JavaScript library.
    • Use the existing servlet class: com.ibm.sbt.jslibrary.servlet.LibraryServlet
    • Name: LibraryServlet
    • Description: This servlet initializes the specified JavaScript library for use by the Social Business Toolkit.
    • URL Patterns: /library/*
  6. Click File -> New -> Filter to create a new filter for creating the toolkit application and context objects. . Provide the following information:
    • Use the existing filter class: com.ibm.sbt.util.SBTFilter
    • Description: This filter is responsible for creating the toolkit application and context objects for every servlet within this web application.
    • URL Patterns: /*

  7. Add the following lines to web.xml.
    <resource-ref>
    <description>Reference to a URL resource which points to the configuration properties for the Social Business Toolkit.</description>
    <res-ref-name>url/ibmsbt-sbtproperties</res-ref-name>
    <res-type>java.net.URL</res-type>
    <res-auth>Container</res-auth>
    <res-sharing-scope>Shareable</res-sharing-scope>
    </resource-ref>
                    
  8. Create the file managed-beans.xml in the WebContent\WEB-INF folder.
  9. Copy sbt.properties from sbtsdk\config and place it in tomcat-config. This file needs to be customized, e.g. the URL to IBM Connections.

    sbt
  10. Create a new jsp file named ViewMyConnectionsFiles.jsp.
    <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <%@page import="com.ibm.sbt.services.client.connections.files.model.FileRequestParams"%>
    <%@page import="java.util.HashMap"%>
    <%@page import="com.ibm.sbt.services.client.connections.files.FileService"%>
    <%@page import="com.ibm.sbt.services.client.connections.files.model.FileEntry"%>
    <%@page import="java.util.List"%>
    <%@page import="java.util.Map"%>
    <%@page import="com.ibm.commons.runtime.Application"%>
    <%@page import="com.ibm.commons.runtime.Context"%>  
    <html>
      <head><title>My Files</title></head>
      <body>
        <div id="content">
        <%
          try {
            FileService fileService = new FileService();
            List<FileEntry> files = fileService.getPublicFiles(null);
            if(files != null && ! files.isEmpty()) {
              for (Iterator iterator = files.iterator(); iterator.hasNext();) {
                FileEntry file = (FileEntry)iterator.next();
                out.println("<a href=\"" + file.getDownloadLink() + "\"> " + file.getLabel() + "</a><br/>" );
              }
            } else {
              out.println("No Results");
            }
          } catch (Throwable e) {} 
        %>
      </div>
    </body> 
    </html>
  11. Right-click the jsp file and select Run as -> Run on Server for the configured server.
  12. Click Finish.
    Run on Server menu

Learn More

To find out what functionality the SDK provides read the Java API documentation. There are articles how to install and configure the SDK. Additionally there is a tutorial and the following webinar to learn how to create a J2EE application from scratch.