java Apache Camel http 到 http 路由(有可能吗?)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5646557/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 12:04:28  来源:igfitidea点击:

Apache Camel http to http routing (Is it possible?)

javahttproutingapache-camel

提问by kazanaki

I am starting now with Camel. I have seen the http4 component for http clients and the jetty component for http servers.

我现在从骆驼开始。我已经看到了 http 客户端的 http4 组件和 http 服务器的 jetty 组件。

I have seen several examples that use one or the other. I would like to know if it is possible to combine them together.

我见过几个使用其中一个的例子。我想知道是否可以将它们组合在一起。

Example

例子

from("jetty:http://0.0.0.0:8080/myapp/myservice")
.to("http4://www.google.com");

This would make camel a simple http based router/proxy. Web browsers would hit the camel URL and instead get google. (Google is just an example, I have a real POST based service that I want to use)

这将使骆驼成为一个简单的基于 http 的路由器/代理。网络浏览器会点击骆驼网址,而不是谷歌。(谷歌只是一个例子,我有一个真正的基于 POST 的服务,我想使用)

Is this route possible? Should I research Camel or do I need a different software framework for this? In the future I would also need to add transformations/filters in between.

这条路线可以吗?我应该研究 Camel 还是为此需要不同的软件框架?将来我还需要在两者之间添加转换/过滤器​​。

I have tried it and got a nullpointer exception

我试过了,得到了一个空指针异常

[qtp757856402-14] SendProcessor       DEBUG >>>> Endpoint[http4://www.google.com] Exchange[Message: [Body is instance of java.io.InputStream]]
[qtp757856402-14] DefaultErrorHandler DEBUG Failed delivery for exchangeId: ID-IT12-53265-1302683969823-0-1. On delivery attempt: 0 caught: java.lang.NullPointerException
[qtp757856402-14] DefaultErrorHandler ERROR Failed delivery for exchangeId: ID-IT12-53265-1302683969823-0-1. Exhausted after delivery attempt: 1 caught: java.lang.NullPointerException
java.lang.NullPointerException

回答by Claus Ibsen

You need to bridge the endpoint.

您需要桥接端点。

from("jetty:http://0.0.0.0:8080/myapp/myservice")
.to("http4://www.google.com?bridgeEndpoint=true&throwExceptionOnFailure=false");