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

Apache Camel Exception Generated when routing to a route

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

当我 运行 应用程序时,出现错误:CamelExecutionException: Exception occurred during execution on the exchange and HttpOperationFailedException: HTTP operation failed invoking http://localhost:8080/myservice with statusCode: 415 and errorDescription":"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 exchange and HttpOperationFailedException: HTTP operation failed invoking http://localhost:8080/myservice with statusCode: 415 and errorDescription":"Unsupported Media Type, content type: null not supported"

有人可以帮助我吗?

骆驼版本错误。一旦我开始使用 3.2.0 作为统一版本,它最终就成功了。