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?
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);
}