1

目前,我正在尝试使用 java sbt sdk api 创建和更新博客文章。

我可以阅读博客和博客文章,并且能够使用 SDK 的 .getBlogPost(bkogHandle, postId) 方法检索单个博客文章。

但是,如果我尝试更新或创建博客文章,要么遇到 NullPointerException,要么什么也没有发生。

出于测试目的,我创建了一个演示博客并尝试更新其中的博客文章:

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

此示例运行时不会引发异常,但不会更新博客。我错过了什么吗?

如果我使用post.save(blogHandle);我会收到以下错误消息:

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

如果我createBlogPost(post, blogHandle)用来创建新帖子,我会遇到同样的错误。

任何想法是什么问题或任何建议我可以做些什么来保存博客帖子?

编辑:

在 BlogService 类中,问题似乎出在以下方法中

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;
    }
4

2 回答 2

0

您可以从服务特定的异常类(在本例中为 BlogServiceException)获取失败的确切原因。BlogServiceException 封装了与连接通信时可能导致的所有异常,包括身份验证和授权。

调试和查看所有网络调用的另一种方法是将所有流量重定向到调试实用程序,如提琴手,可以从此链接SBT Wiki获取使用提琴手设置 SBT 的详细信息

于 2013-11-14T12:07:31.057 回答
0

I couldn't reproduce this issue but I fixed a bug on updateBlogPost just few days back , I don't think it is available in the mentioned build. So we'll have to check when the next build is due and we can confirm if the issue still comes.

for the save() in BlogPost -I'll make changes in it so as to return the updated BlogPost

于 2013-11-12T13:15:41.357 回答