我们正在使用Abdera与 IBM Connections API 进行交互,但我们的问题主要与 Abdera 本身有关。
我认为 Abdera 中存在一个错误,它不允许您在单个请求中发送包含内容和附件的条目。作为一种解决方法,您可能可以发送两个单独的请求,首先使用内容创建,然后使用附件进行更新。遗憾的是,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上找到