【发布时间】:2020-05-20 14:29:51
【问题描述】:
我对 spring-boot 和 apache camel 很陌生。我正在尝试创建一个应用程序,该应用程序将调用我在本地使用 Camel 进行路由的休息端点。
当我运行应用程序时,我收到错误:CamelExecutionException: Exception occurred during execution on the exchange 和 HttpOperationFailedException: HTTP operation failed invoking http://localhost:8080/myservice with statusCode: 415 和 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 和 HttpOperationFailedException: HTTP operation failed invoking http://localhost:8080/myservice with statusCode: 415 和 errorDescription":"Unsupported Media Type, content type: null not supported"
有人可以帮我吗?
【问题讨论】:
-
你在这里混合版本。
camel-spring-boot-starter的 groupId 将是org.apache.camel.springboot并将版本更改为 3.2.0。 -
@SneharghyaPathak 是的。我昨天发现了。抱歉忘了提到这个作为答案。
标签: java spring-boot apache-camel rest