Upload files to Websphere Liberty using JAX-RS 1.1 feature

1.2k Views Asked by At

I know that jax-rs 1.1 not supports upload directly and every application server has its own implementation to handle multipart/form-data. I can't realize how to do it with Websphere Liberty 17 using jax-rs 1.1 feature. jaxrs-2.0 feature I can't use because it conflicts with openidConnectClient-1.0

I understand that Websphere Liberty's solution to upload files based on Apache Wink but it doesn't recognize any of the following files: InMultiPart or BufferedInMultiPart as described here: Apache Wink : 7.8 MultiPart

Where am I wrong? Thank you.

2

There are 2 best solutions below

3
Andy McCright On BEST ANSWER

You should be able to use the InMultiPart and BufferedInMultiPart APIs when using the jaxrs-1.1 feature. The knowledge center provides some instructions here: https://www.ibm.com/support/knowledgecenter/en/SSEQTP_8.5.5/com.ibm.websphere.base.doc/ae/twbs_jaxrs_multipartcontent.html

However, I suspect that the problem is resulting because your application does not specify the "third-party" API type. This is required in order to access APIs from non-IBM sources - in this case, Apache Wink. I don't think that this gotcha is well documented in the knowledge center (I will work with the IBM documentation team and try to improve the docs).

Can you check your server.xml file for something like this:

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

The apiTypeVisibility of "spec" and "ibm-api" are enabled by default, but "third-party" is not. Adding this line should allow your application to load the org.apache.wink.* classes.

Hope this helps, Andy

0
Anatoly On

I didn't mentioned this in my question because I didn't think it can be relevant to my issue, but I have built project with Maven by using archetype provided by Liberty Maven Repository. Default configuration of the project provided by this archetype: webapp-jee7-liberty doesn't contain all third-party libraries, for example com.ibm.websphere.appserver.thirdp‌​arty.jaxrs_1.0.*.jar as mentioned by Andy McCright in comments to him answer. So you have two options, or add this dependency manually (what I'd like to avoid) or add it through pom.xml as following:

<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.

For more detailed explanation look at this resource: Configuring dependency POM files that emulate the classpath of specific WebSphere runtime environments

Of course you should add to server.xml the following code: <application id="myApp" name="myApp" type="war" location="myApp.war"> <classloader apiTypeVisibility="spec, ibm-api, third-party" /> </application> As Andy McCright explained here: https://stackoverflow.com/a/44632423/947111