0

is there any restriction for using external libraries with java adapters in IBM MobileFirst 8.0?

When I added guava my code have no errors (mfpdev adapter build Success), but when deploying to my server it respond with error:

[ERROR] Failed to execute goal com.ibm.mfp:adapter-maven-plugin:8.0.2016082422:deploy (default-cli) on project X: The output of /mfpadmin/management-apis/2.0/runtimes/mfp/adapters is of type text/html, which is unsupported. Expected an output of type text/xml or application/xml or application/json. -> [Help 1]

But when I delete guava in pom (mvn dependencies) I am able to deploy adapter. Problem as I can see happen to some other libraries also. Is there any option to use such libraries?

mfpdev -v: 8.0.0-2017012016

EDIT: I finally resolved problem by setting scope for guava in pom file:

<scope>provided</scope>
3squad
  • 355
  • 3
  • 14

1 Answers1

0

I tried this in my MFP 8.0 environment and do not see an issue.

mfpdev -v
8.0.0-2017012016

0. Create  a sample Java adapter "mfpdev adapter create" 
1. Added dependency with guava 21 in pom.xml
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>21.0</version>
</dependency>

2. added a simple guava package and used it.

import com.google.common.base.Optional;

@GET

        @Produces(MediaType.TEXT_PLAIN)
        public String getResourceData() {
                // log message to server log
                logger.info("Logging info message...");
                Integer invalidInput = new Integer(20);
      Optional<Integer> a =  Optional.of(Input);
      Optional<Integer> b =  Optional.of(new Integer(10));
      logger.info("Logging my message with guava");
      );
        return "Hello from guava resource "+sum(a,b) ;
       }

4. build, deploy went successful

5. Access above resource 

Request URL

http://localhost:9080/mfp/api/adapters/testGuavaAdapter/resource

Response Body

Hello from guava resource 30

Response Code

200

Response Headers

{
  "x-powered-by": "Servlet/3.1",
  "content-type": "text/plain",
  "date": "Thu, 08 Jun 2017 11:48:32 GMT",
  "content-length": "28"
}

Verify this working pom against your environment.

Vivin K
  • 2,681
  • 1
  • 11
  • 14
  • My problem occurs always when I have guava in dependency, even that I am not using it in java code. If I comment out dependency for guava I am able to deploy adapter without any issue, but when I add this dependency I can not. `` – 3squad Jun 08 '17 at 15:26
  • as you see above, I have added dependency and it works, MFP server version I hv used is latest MFP8 Product version: 8.0.0.00-20170412-235541. Can you confirm MFP server version used and if you are adding dependency same way as I hv in pom.xml? – Kavitha Varadarajan Jun 08 '17 at 16:09
  • sure I believe. I finally resolved problem by setting scope:provided for dependency. – 3squad Jun 08 '17 at 16:24
  • ok, Did you still continue with 21.0 ? and did scope:provided ? – Kavitha Varadarajan Jun 09 '17 at 04:16