gpt4 book ai didi

java - Apache Camel 路由到路由时生成异常

转载 作者:行者123 更新时间:2023-12-01 16:38:10 28 4
gpt4 key购买 nike

我对 spring-boot 和 apache Camel 还很陌生。我正在尝试创建一个应用程序,它将调用一个休息端点,我使用 Camel 进行路由在本地托管该端点。

当我运行应用程序时,收到错误:CamelExecutionException: Exception occurred during execution on the exchangeHttpOperationFailedException: HTTP operation failed invoking http://localhost:8080/myservice with statusCode: 415errorDescription":"Unsupported Media Type"

POM:

    <dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-spring-boot-starter</artifactId>
<version>2.22.0</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-http</artifactId>
<version>3.2.0</version>
</dependency>

MsgRouteBuilder:

public void configure() throws Exception {
from("direct:firstRoute")
.setHeader(Exchange.HTTP_METHOD, simple("GET"))
.setHeader(Exchange.CONTENT_TYPE, constant("application/json"))
.to("http://localhost:8080/myservice");
}

MainApp.java:

package me.ad.myCamel;

import org.apache.camel.CamelContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.EnableAspectJAutoProxy;

import me.ad.myCamel.router.MessageRouteBuilder;

@SpringBootApplication
@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})
@EnableAspectJAutoProxy(proxyTargetClass = true)
@EnableCaching
public class MeAdApp implements CommandLineRunner {

private static final Logger LOG = LoggerFactory.getLogger(MeAdApp.class);

public static void main(String[] args) {
try {
SpringApplication.run(MeAdApp.class, args);
} catch (Exception ex) {
LOG.error(ex.getMessage(), ex);
}
}

@Override
public void run(String... args) throws Exception {
LOG.info("Starting MeAdApp...");
}
}

MyController.java:

@GetMapping(value = "/routing")
public boolean sendMyData() {
sendMyInfo.startRouting();
return true;
}

SendMyInfo.java:

MsgRouteBuilder routeBuilder = new MsgRouteBuilder();
CamelContext ctx = new DefaultCamelContext();


public void startRouting(){

try {
ctx.addRoutes(routeBuilder);
ctx.start();
ProducerTemplate producerTemplate = ctx.createProducerTemplate();
producerTemplate.sendBody("direct:firstRoute", "Hello WFS");
ctx.stop();
}
catch (Exception e) {
e.printStackTrace();
}

}

所以,每当我调用我的休息终点时:/routing ,我收到错误:CamelExecutionException: Exception occurred during execution on the exchangeHttpOperationFailedException: HTTP operation failed invoking http://localhost:8080/myservice with statusCode: 415errorDescription":"Unsupported Media Type, content type: null not supported"

有人可以帮我吗?

最佳答案

问题是 Camel 版本错误。一旦我开始使用 3.2.0 作为统一版本,一切最终都成功了。

关于java - Apache Camel 路由到路由时生成异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61915690/

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