我们正在使用Abdera https://abdera.apache.org/与 IBM Connections API 交互,但我们的问题主要与 Abdera 本身有关。
我认为 Abdera 中存在一个错误,不允许您在单个请求中发送包含内容和附件的条目。作为一个解决方法 https://stackoverflow.com/questions/22845854/apache-abdera-multipart-request-throwing-nullpointer-exceptionibm-connection-ap您可能可以发送两个单独的请求,首先创建内容,然后更新附件。遗憾的是,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");
创建多部分相关请求实体时,会抛出空指针:
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 来展示这一点,但还包括两个单元测试,其中可以在不需要 Connections 的情况下测试空指针。这可以在GitHub https://github.com/drissamri/abdera-connections-pmr