0

我一直在构建一个客户端来替换我们拥有的连接社交网站上的一些内容。我按照 Github repo 中的示例代码编写了一个 java 客户端:https ://github.com/OpenNTF/SocialSDK/tree/master/sdk/com.ibm.sbt.core.test/src/test/java/ com/ibm/sbt/services/客户端/连接/文件

并且还使用本教程作为参考来创建端点,然后将其传递给不同的服务。 http://bastide.org/2014/01/28/how-to-develop-a-simple-java-integration-with-the-ibm-social-business-toolkit-sdk/

需要明确的是,我在社区上发布内容,所以我使用 CommunityService 上传内容和 FileService 来更新社区文件。

此方法工作正常: fileservice.updateCommunityFile(iStream, fileId, title, communityLibraryId, params) 这在服务器上创建了多个版本,这不是我想要的。

但是,我想使用这个 - fileservice.updateFile(inputStream, file, params) 如果我在我的代码中使用上面的一个,它会导致以下错误:

Error updating the file
com.ibm.sbt.services.client.connections.files.FileServiceException: Error updating the file
    at com.ibm.sbt.services.client.connections.files.FileService.updateFile(FileService.java:2686)
    at sbt.sample.standalone.java.StandaloneDemo.ReplacePhoto(StandaloneDemo.java:332)
    at sbt.sample.standalone.java.StandaloneDemo.main(StandaloneDemo.java:239)
Caused by: java.lang.IllegalStateException: SBT context is not initialized for the request
    at com.ibm.commons.runtime.Context.get(Context.java:57)
    at com.ibm.sbt.services.endpoints.BasicEndpoint.authenticate(BasicEndpoint.java:151)
    at com.ibm.sbt.services.client.ClientService.forceAuthentication(ClientService.java:296)
    at com.ibm.sbt.services.client.ClientService.processResponse(ClientService.java:1154)
    at com.ibm.sbt.services.client.ClientService._xhr(ClientService.java:1072)
    at com.ibm.sbt.services.client.ClientService.execRequest(ClientService.java:1037)
    at com.ibm.sbt.services.client.ClientService.xhr(ClientService.java:1003)
    at com.ibm.sbt.services.client.ClientService.put(ClientService.java:937)
    at com.ibm.sbt.services.client.ClientService.put(ClientService.java:933)
    at com.ibm.sbt.services.client.base.BaseService.updateData(BaseService.java:439)
    at com.ibm.sbt.services.client.connections.files.FileService.updateFile(FileService.java:2683)

注意:我在程序中使用的用户是发布内容的社区管理员。此外,有什么方法可以在 sbtsdk api 中指定来替换其他文件而不创建其他版本?

我发现这很相似 - Liferay Portal & IBM SBT SDK: SBT context is not initialized for the request 但我不明白是否有任何解决方案。

谢谢。

4

1 回答 1

1

首先,很难理解为什么您会看到“未针对请求初始化 SBT 上下文”,因为您可以运行一个文件服务 API 而不是另一个。

两者fileservice.updateCommunityFile(iStream, fileId, title, communityLibraryId, params)fileservice.updateFile(inputStream, file, params)创建新版本。它们不会替换最新版本。这个 API 有一个参数控制是否创建新版本。

这是你需要做的:

使用值为“false”的参数 createVersion。像这样:

Map<String, String> paramsMap = new HashMap<String, String>(); 
paramsMap.put("createVersion", "false");

现在在 updateCommunityFile API 中使用这个 paramsMap,如下所示:

fileservice.updateCommunityFile(iStream, fileId, title, communityLibraryId, paramsMap) 
于 2015-05-07T12:16:05.543 回答