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



我对弹簧靴和阿帕奇骆驼很陌生。 我正在尝试创建一个应用程序,该应用程序将ivok一个休息端点,我使用Camel在本地托管该端点进行路由。

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

聚 甲醛:

<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");
}

主应用.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...");
}  
}

我的控制器.java :

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

发送我的信息.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"

有人可以在这里帮助我吗?

问题是错误的骆驼版本.一旦我开始使用 3.2.0 作为统一版本,最终一切都解决了.

最新更新