使用 JAX-RS 1.1 功能将文件上传到 Websphere Liberty

Upload files to Websphere Liberty using JAX-RS 1.1 feature

我知道 jax-rs 1.1 不支持直接上传,每个应用程序服务器都有自己的实现来处理 multipart/form-data。 我不知道如何使用 Websphere Liberty 17 using jax-rs 1.1 feature. jaxrs-2.0 feature I can't use because it conflicts with openidConnectClient-1.0

我了解到Websphere Liberty的上传文件的解决方案是基于Apache Wink but it doesn't recognize any of the following files: InMultiPart or BufferedInMultiPart as described here: Apache Wink : 7.8 MultiPart

我哪里错了?谢谢。

在使用 jaxrs-1.1 功能时,您应该能够使用 InMultiPart 和 BufferedInMultiPart APIs。知识中心在这里提供了一些说明: https://www.ibm.com/support/knowledgecenter/en/SSEQTP_8.5.5/com.ibm.websphere.base.doc/ae/twbs_jaxrs_multipartcontent.html

但是,我怀疑问题是由于您的应用程序未指定 "third-party" API 类型造成的。这是从非 IBM 来源访问 APIs 所必需的 - 在本例中为 Apache Wink。我认为知识中心没有很好地记录这个陷阱(我将与 IBM 文档团队合作并尝试改进文档)。

你能检查一下你的 server.xml 文件是否有这样的东西:

    <application id="myApp" name="myApp" type="war" location="myApp.war">
        <classloader apiTypeVisibility="spec, ibm-api, third-party"  />
    </application>

默认启用"spec"和"ibm-api"的apiTypeVisibility,但"third-party"不启用。添加此行应该允许您的应用程序加载 org.apache.wink.* 类.

希望这对您有所帮助, 安迪

我没有在我的问题中提到这个,因为我认为它与我的问题无关,但我已经使用 Liberty Maven Repository. Default configuration of the project provided by this archetype: webapp-jee7-liberty 提供的原型用 Maven 构建了项目没有'包含所有第三方库,例如 Andy McCright 在对他回答的评论中提到的 com.ibm.websphere.appserver.thirdp‌​arty.jaxrs_1.0.*.jar。所以你有两个选择,或者手动添加这个依赖项(我想避免的)或者通过 pom.xml 添加它,如下所示:

<dependency> <groupId>com.ibm.tools.target</groupId> <artifactId>was-liberty-impl</artifactId> <version>RELEASE</version> <type>pom</type> <scope>provided</scope> </dependency>

was-liberty-impl: This dependency contains third-party implementation libraries such as Open JPA, Wind, and Jackson.

有关更详细的说明,请查看此资源:Configuring dependency POM files that emulate the classpath of specific WebSphere runtime environments

当然你应该添加到server.xml下面的代码: <application id="myApp" name="myApp" type="war" location="myApp.war"> <classloader apiTypeVisibility="spec, ibm-api, third-party" /> </application> 正如 Andy McCright 在这里解释的那样: