At the moment, I am trying to create and update blog posts using the java sbt sdk api.
I could read blogs and blog posts and was able to retrieve a single blog post, using the .getBlogPost(bkogHandle, postId) method of the SDK.
But if I try to update or create a blog post, either I run into a NullPointerException or nothing happens.
For testing purposes I created a demo blog and tried to update the blog post inside it:
String blogHandle = "citb";
String postId = "7973d29e-26b6-4d23-ab04-ebfb734bf512";
BlogPost post = sbcs.getBlogService().getBlogPost(blogHandle, postId);
if (null != post){
System.out.println("Found post "+post.getTitle()+" ("+post.getAlternateUrl()+")");
Map<String, Object> fieldMap = post.getFieldsMap();
System.out.println("Found "+fieldMap.keySet().size()+" Entries in the field Map");
try{
//Save the post
System.out.println("Update blog post");
post.setContent("<p dir='ltr'>blabla "+new Date()+"</p>");
System.out.println(post.getContent());
post.setTitle(post.getTitle()+" +");
sbcs.getBlogService().updateBlogPost(post, blogHandle);
}catch(Exception e){
e.printStackTrace();
}
}
This example runs without throwing an exception but doesn't update the blog. Do I miss something?
If I use post.save(blogHandle); I get the this error messages:
com.ibm.sbt.services.client.connections.blogs.BlogServiceException: error creating blog post
at com.ibm.sbt.services.client.connections.blogs.BlogService.createBlogPost(BlogService.java:627)
at com.ibm.sbt.services.client.connections.blogs.BlogPost.save(BlogPost.java:128)
Caused by: java.lang.NullPointerException
at com.ibm.sbt.services.client.connections.blogs.feedhandler.BlogsFeedHandler.createEntity(BlogsFeedHandler.java:42)
at com.ibm.sbt.services.client.connections.blogs.BlogService.createBlogPost(BlogService.java:624)
... 2 more
I get the same errors if I use createBlogPost(post, blogHandle)to create a new post.
Any ideas what the problem is or any suggestions what I could do to save blog posts?
EDIT:
In the BlogService class the problem seems to be in the following method
public BlogPost createBlogPost(BlogPost post, String blogHandle) throws BlogServiceException {
if (null == post){
throw new BlogServiceException(null,"null post");
}
Response result = null;
try {
BaseBlogTransformer transformer = new BaseBlogTransformer(post);
Object payload = transformer.transform(post.getFieldsMap());
Map<String, String> headers = new HashMap<String, String>();
headers.put("Content-Type", "application/atom+xml");
String createPostUrl = resolveUrl(blogHandle, FilterType.CREATE_BLOG_POST, null);
**result = createData(createPostUrl, null, headers, payload);**
**post = (BlogPost) new BlogPostsFeedHandler(this).createEntity(result);**
} catch (Exception e) {
throw new BlogServiceException(e, "error creating blog post");
}
return post;
}