英文:
How to send JSON reply from a jetty endpoint in Apache Camel?
问题
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"
}
}
英文:
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"
}
}
答案1
得分: 1
以下是您要翻译的部分:
"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}");"
"unmarshalling needs to be added in pom.xml
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jackson</artifactId>
</dependency>
```"
<details>
<summary>英文:</summary>
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>
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论