【发布时间】:2015-07-24 12:23:39
【问题描述】:
我们正在使用Abdera 与 IBM Connections API 进行交互,但我们的问题主要与 Abdera 本身有关。
我认为 Abdera 中存在一个错误,不允许您在单个请求中发送包含内容和附件的条目。作为workaround,您可能能够发送两个单独的请求,首先创建内容,然后更新附件。遗憾的是,Connections API 要求您在一个请求中包含所有数据,否则您的旧数据不会被保留。
以下代码显示了一个已创建的 Abdera 条目:
ClassLoader classloader = Thread.currentThread().getContextClassLoader();
InputStream is = classloader.getResourceAsStream("google-trends.tiff");
final Abdera abdera = new Abdera();
Entry entry = abdera.getFactory().newEntry();
entry.setTitle("THIS IS THE TITLE");
entry.setContentAsHtml("<p>CONTENT AS HTML</p>");
entry.setPublished(new Date());
Category category = abdera.getFactory().newCategory();
category.setLabel("Entry");
category.setScheme("http://www.ibm.com/xmlns/prod/sn/type");
category.setTerm("entry");
entry.addCategory(category);
RequestEntity request =
new MultipartRelatedRequestEntity(entry, is, "image/jpg",
"asdfasdfasdf");
创建 MultipartRelatedRequestEntity 时会抛出 NullPointer:
java.lang.NullPointerException
at
org.apache.abdera.protocol.client.util.MultipartRelatedRequestEntity.writeInput(MultipartRelatedRequestEntity.java:74)
发生这种情况是因为它需要一个内容“src”元素,但在深入研究 Abdera 的源代码后,根据规范,这似乎不是必需的元素。这看起来像是 Abdera 代码中的错误,不是吗?
/**
* <p>
* RFC4287: atom:content MAY have a "src" attribute, whose value MUST be an IRI reference. If the "src" attribute is
* present, atom:content MUST be empty. Atom Processors MAY use the IRI to retrieve the content and MAY choose to
* ignore remote content or to present it in a different manner than local content.
* </p>
* <p>
* If the "src" attribute is present, the "type" attribute SHOULD be provided and MUST be a MIME media type, rather
* than "text", "html", or "xhtml".
* </p>
*
* @param src The IRI to use as the src attribute value for the content
* @throws IRISyntaxException if the src value is malformed
*/
我已经将参考应用程序连接到 IBM Greenhouse Connections 来说明这一点,但还包括两个单元测试,其中可以在不需要连接的情况下测试空指针。这可以在GitHub找到。
【问题讨论】:
-
您可以包含网络跟踪吗?从连接服务器返回的错误代码是什么?它会告诉我错误来自哪里
-
空指针来自 Abdera,只需实例化一个 new MultipartRelatedRequestEntity。它甚至还没有连接到 CNX。我创建了一个可以连接到 Greenhouse 的示例应用程序,但也创建了一个单独的单元测试,它在 github.com/drissamri/abdera-connections-pmr/blob/master/src/… 中显示空指针。通常我会发送两个请求:一个是创建内容,另一个是更新附件,但是连接要求每个更新都包含所有内容(内容+文件)。谢谢@PaulBastide
-
这取决于 api。您使用的是哪个 API?
-
我们使用的是 Activity API 5.0。这是我们正在使用的:www-10.lotus.com/ldd/lcwiki.nsf/… UPDATE 方法说:“所有现有的活动条目信息将被新数据替换。为避免删除现有数据,请先检索您要保留的任何数据,然后将其与此请求一起发回。有关详细信息,请参阅检索活动节点。"
标签: java atom-feed ibm-connections atompub apache-abdera