Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/mercurial/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何使用Abdera atom客户端发送内容和附件_Java_Atom Feed_Ibm Connections_Atompub_Apache Abdera - Fatal编程技术网

Java 如何使用Abdera atom客户端发送内容和附件

Java 如何使用Abdera atom客户端发送内容和附件,java,atom-feed,ibm-connections,atompub,apache-abdera,Java,Atom Feed,Ibm Connections,Atompub,Apache Abdera,我们正在使用它与IBMConnectionsAPI交互,但我们的问题主要与Abdera本身有关 我认为Abdera中存在一个bug,它不允许您在单个请求中发送包含内容和附件的条目。作为一个整体,您可能能够发送两个单独的请求,首先创建内容,然后更新附件。遗憾的是,Connections API要求您在一个请求中拥有所有数据,或者您的旧数据没有被保留 以下代码显示创建的Abdera条目: ClassLoader classloader = Thread.currentThread().getCont

我们正在使用它与IBMConnectionsAPI交互,但我们的问题主要与Abdera本身有关

我认为Abdera中存在一个bug,它不允许您在单个请求中发送包含内容和附件的条目。作为一个整体,您可能能够发送两个单独的请求,首先创建内容,然后更新附件。遗憾的是,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");
这是因为它需要一个content“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
 */
/**
*
*RFC4287:atom:content可能有一个“src”属性,其值必须是IRI引用。如果“src”属性为
*当前,atom:内容必须为空。Atom处理器可以使用IRI检索内容,也可以选择
*忽略远程内容或以与本地内容不同的方式呈现远程内容。
*

* *如果存在“src”属性,则应提供“type”属性,并且该属性必须是MIME媒体类型,而不是 *而不是“文本”、“html”或“xhtml”。 *

* *@param src用作内容的src属性值的IRI *如果src值格式不正确,@将抛出IRISyntaxException */

为了说明这一点,我将一个参考应用程序连接放在了IBM温室连接上,但还包括了两个单元测试,其中可以在不需要连接的情况下测试nullpointer。这可以在

上找到,可以让它与Abdera一起使用,以供将来参考。这里是一个示例,用于发布包含文本内容和一个(或多个)附件的条目。您需要使用底层HttpClient框架:

final Entry=this.createActivityEntry();
final RequestOptions=this.client.getDefaultRequestOptions();
options.setHeader(“内容类型”,“多部分/相关;类型=\”应用程序/atom+xml\”);
StringPart entryPart=新的StringPart(“entry”,entry.toString());
setContentType(“application/atom+xml”);
FilePart FilePart=newfilepart(“文件”,新文件(resource.getFile());
RequestEntity request=新的MultipartRequestEntity(新部分[]{entryPart,filePart},this.client.getHttpClientParams());
ClientResponse response=client.post(this.url+this.activityId、请求、选项);

这允许我们在一个请求中创建一个包含内容和附件的应用程序,因为API需要它。

您可以包含网络跟踪吗?从连接服务器返回的错误代码是什么?它将通过实例化一个新的MultipartRelatedRequestEntity来告诉我错误来自何处空指针来自Abdera。它甚至还没有连接到CNX。我已经创建了一个示例应用程序,它可以连接到温室,但也可以创建一个单独的单元测试,在其中显示空指针。通常我会发送两个请求:一个是使用内容创建,另一个是使用附件进行更新,但连接要求每次更新都包含所有内容(内容+文件)。谢谢@Paulbastide这取决于api。您使用的是哪种API?我们使用的是活动API 5.0。这就是我们正在使用的:更新方法说:“所有现有的活动条目信息都将替换为新数据。为了避免删除现有数据,请先检索要保留的任何数据,然后将其与此请求一起发送回。有关详细信息,请参阅检索活动节点。”您可能需要查看此
/**
 * <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
 */