gpt4 book ai didi

java - 你如何在 apache camel 中对 servlet 端点进行单元测试?

转载 作者:搜寻专家 更新时间:2023-10-31 19:34:32 26 4
gpt4 key购买 nike

我是 Camel 的新手,现在在我的 Tomcat 服务器中运行了一个简单的路由。路由是这样构建的:

Processor generateWebResponse = new MySpecialProcessor();
from("servlet:///url?matchOnUriPrefix=true").process(generateWebResponse);

我尝试了这样一个简单的单元测试:

Exchange lAuthRequest = createExchangeWithBody("[json body!]");
template.send("servlet:///url", lAuthRequest);
assertEquals("baseline body", lAuthRequest.getOut().getBody());

但出现异常,表明我无法创建 servlet 端点。这是异常消息:

org.apache.camel.FailedToCreateProducerException: Failed to create Producer for endpoint: Endpoint[servlet:///url]. Reason: java.lang.UnsupportedOperationException: You cannot create producer with servlet endpoint, please consider to use http or http4 endpoint.

这是新开发项目,所以除了良好的设计外,我没有太多限制。我愿意接受需要更改路线的建议。此外,如果我在上面做的事情不是惯用的,我很乐意通过任何建议的改进来修改问题。

最佳答案

您需要使用http 客户端组件向Tomcat 发送消息,例如camel--http 组件:http://camel.apache.org/http

然后您需要知道 Tomcat 运行 servlet 的端口号,例如

template.send("http://localhost:8080/myapp/myserver", lAuthRequest);

您需要将 camel-http 添加到类路径中,例如,如果您使用 maven,则将其添加为依赖项。

关于java - 你如何在 apache camel 中对 servlet 端点进行单元测试?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10703537/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com