I'm working on a pass-through REST service in Apache Camel. Exposed an end point with jetty component which invokes another REST end point which responds with JSON like below. But when I hit the exposed URL of Camel in a browser not getting desired output. Since I just started working on Camel, any help would be highly appreciated.
from("jetty:http://0.0.0.0:8080/api/camel/appoverview")
.to("http4://10.150.60.237:80/api/itsb/applicationoverview?httpMethod=GET&bridgeEndpoint=true&throwExceptionOnFailure=false")
.transform().simple("<out>${body}</out>")
.log("Response sent -> ${body}");
Getting output -
<out> {
"applicationId": "1",
"applicationName": "NetInfo",
"serviceNoticeCount": "13",
"operationalStatus": {
"id": "2",
"status": "red",
"statusLevel": "3"
}
}
</out>
Desired output -
{
"applicationId": "1",
"applicationName": "NetInfo",
"serviceNoticeCount": "13",
"operationalStatus": {
"id": "2",
"status": "red",
"statusLevel": "3"
}
}
It worked after unmarshalling the JSON reply like below -
from("jetty:http://0.0.0.0:8080/api/camel/appoverview")
.to("http4://10.150.60.237:80/api/itsb/applicationoverview?httpMethod=GET&bridgeEndpoint=true&throwExceptionOnFailure=true")
.unmarshal().json(JsonLibrary.Jackson)
.transform().simple("${body}")
.log("Response sent -> ${body}");
Dependency for unmarshalling needs to be added in pom.xml
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jackson</artifactId>
</dependency>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.