1
votes

The Connections Java API docs and examples make assumptions the user is using a Web server to interact with Connections. In my case, I want to use the Java API using jRuby and there is no web server.

I want to upload a file to a Connections community, or more specifically connect to the Connections server directly, authenticate and do the upload. I tried the following code and hit a wall with the error:

"SBT context is not initialized for the request"

This error message seems to be complaining about a servlet which of course I don't have.

Here is the code I tried...

    ep = new BasicEndpoint();
    ep.setUrl(connections_url);
    ep.login(userid, pw);
    service = new CommunityService();
    service.setEndpoint(ep);
    istream = new FileInputStream(temp_file);
    uploaded_file = service.uploadFile(istream, community_id, filename, filesize)

The API calls used above are just a guess on my part however the login to the Endpoint seems to work as the method returns true and that gave me some hope I was on the right track. But the upload failed with the context error so now I'm stuck.

Any ideas to make this work?

2

2 Answers

0
votes

IBM SBT can work on standalone applications too. There is an example in the Github repository.

Basically, you should initialize an application and a context for that.

RuntimeFactory runtimeFactory=new RuntimeFactoryStandalone();
Context context=null;
Application application=null;

try {
    application=runtimeFactory.initApplication(null);
    context = Context.init(application, null, null);

    // Whatever you want to do...


} catch(Throwable t) {
    // Error handling
    t.printStackTrace();
} finally {
    if (context != null)
        Context.destroy(context);
    if (application != null)
         Application.destroy(application);
}
0
votes

I originally wrote an blog on this...

Basically you create an Endpoint, I start off with BasicEndpoint.

/**
* creates a new Basic Endpoint to connect to Connections
* @param url
* @param user
* @param password
* @return
*/
private BasicEndpoint createEndpoint(String url, String user, String password) {
BasicEndpoint endpoint = new ConnectionsBasicEndpoint();
endpoint.setUrl(url);
endpoint.setUser(user);
endpoint.setPassword(password);
endpoint.setForceTrustSSLCertificate(true);
return endpoint;
}

Now, I have the basis for making a call to the backend ForumService by passing in the Endpoint I construct.

ForumService svc = new ForumService(demo.endpoint);
try {
ForumList forumList = svc.getAllForums();
for(BaseForumEntity forumEntity : forumList){
Forum forum = (Forum) forumEntity;
System.out.println(“+F: ” + forum.getTitle());
TopicList topics = forum.getTopics();

for(BaseForumEntity topicEntity : topics){
ForumTopic topic = (ForumTopic) topicEntity;
System.out.println(“– ” + topic.getTitle());
}

}
} catch (ForumServiceException e) {
e.printStackTrace();
}

You can repeat this method for making almost any call.

The blog entry is at http://bastide.org/2014/01/28/how-to-develop-a-simple-java-integration-with-the-ibm-social-business-toolkit-sdk/