Reputation: 385
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>
Upvotes: 0
Views: 417
Reputation: 281
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.
Upvotes: 0