简体   繁体   English

骆驼:java.lang.IllegalArgumentException:必须指定defaultEndpoint

[英]Camel: java.lang.IllegalArgumentException: defaultEndpoint must be specified

I am new to Apache Camel. 我是Apache Camel的新手。 I am trying to send headers along with request body to a route in Apache Camel. 我正在尝试将标头和请求正文一起发送到Apache Camel中的路由。

// headers is a map
APIResponse response = (APIResponse) producer.requestBodyAndHeader("direct:route1",body,headers);

I am getting the following error: 我收到以下错误:

java.lang.IllegalArgumentException: defaultEndpoint must be specified
    at org.apache.camel.util.ObjectHelper.notNull(ObjectHelper.java:308)
    at org.apache.camel.impl.DefaultProducerTemplate.getMandatoryDefaultEndpoint(DefaultProducerTemplate.java:462)
    at org.apache.camel.impl.DefaultProducerTemplate.requestBodyAndHeader(DefaultProducerTemplate.java:289)

You probably confused the actual method to invoke. 您可能会混淆要调用的实际方法。 Instead of invoking template.requestBodyAndHeaders(String, Object, Map<String, Object>) , which you actually intended to invoke, you most likely invoked template.requestBodyAndHeader(Object, String, Object) in case your message body was actually of type String . 如果您的消息正文实际上是String类型,则最有可能调用了template.requestBodyAndHeader(Object, String, Object) ,而不是实际上要调用的template.requestBodyAndHeaders(String, Object, Map<String, Object>)

The latter case would only set one single header value with the key being the second input parameter and its value the 3rd parameter. 在后一种情况下,将只设置一个单个标头值,而键是第二个输入参数,其值是第三个参数。 Here also, as no endpoint information is given, it would fallback to the default endpoint which would explain the error you are seeing. 同样,在这里,由于未提供端点信息,因此它将回退到默认端点,这将解释您所看到的错误。

I'm not sure off the top of my head why that's not working, it looks okay to me. 我不确定我为什么不这样做,对我来说还好。 As a test, you could try splitting out the endpoint and see if it works? 作为测试,您可以尝试拆分端点,看看是否可行?

Endpoint endpoint = context.getEndpoint("direct:route1");
producer.setDefaultEndpoint(endpoint);
producer.requestBodyAndHeader(body,headers);

Another thing you could test is to try "seda" instead of "direct", as the "direct" endpoints can have issues if you are loading your components in a funny order (ie if the consumer is not intialized yet, the "direct" endpoint might not exist) 您可以测试的另一件事是尝试使用“ seda”而不是“ direct”,因为如果您以有趣的顺序加载组件,则“ direct”端点可能会出现问题(即,如果消费者尚未初始化,则“ direct”端点可能不存在)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM