gpt4 book ai didi

java - 由 : org. apache.camel.NoTypeConversionAvailableException 引起:没有可用于从类型 POJO 转换为 byte[] 的类型转换器

转载 作者:行者123 更新时间:2023-11-30 02:03:49 24 4
gpt4 key购买 nike

我是 Apache Camel 新手。我正在使用 REST API 与 Apache Camel 和 Spring Boot 集成。我完成了获取请求,它按预期工作。但是,在使用 POST 调用发布数据时,我遇到了一个问题。

我在下面的链接中看到了类似的错误。但是,这对我没有帮助。 org.apache.camel.NoTypeConversionAvailableException: No type converter available to convert from type:

我也尝试过 Stackoverflow、youtube 和其他网站上提供的几种解决方案。但是,没有运气。您能帮我解决这个问题吗?

错误描述:

org.apache.camel.InvalidPayloadException: No body available of type: byte[] but has value: Bank [id=1, name=TEST, location=Bangalore] of type: com.ta.common.bean.Bank on: Message[ID-XDNS01271-1534835668677-10-2]. Caused by: No type converter available to convert from type: com.ta.common.bean.Bank to the required type: byte[] with value Bank [id=1, name=TEST, location=Bangalore]. Exchange[ID-XDNS01271-1534835668677-10-1]. Caused by: [org.apache.camel.NoTypeConversionAvailableException - No type converter available to convert from type: com.ta.common.bean.Bank to the required type: byte[] with value Bank [id=1, name=TEST, location=Bangalore]] at org.apache.camel.impl.MessageSupport.getMandatoryBody(MessageSupport.java:117) at org.apache.camel.component.netty4.http.DefaultNettyHttpBinding.toNettyRequest(DefaultNettyHttpBinding.java:488) at org.apache.camel.component.netty4.http.NettyHttpProducer.getRequestBody(NettyHttpProducer.java:65) at org.apache.camel.component.netty4.NettyProducer.process(NettyProducer.java:208) at org.apache.camel.component.netty4.http.NettyHttpProducer.process(NettyHttpProducer.java:56) at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:148) at org.apache.camel.processor.interceptor.TraceInterceptor.process(TraceInterceptor.java:181) at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:548) at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:201) at org.apache.camel.processor.Pipeline.process(Pipeline.java:138) at org.apache.camel.processor.Pipeline.process(Pipeline.java:101) at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:201) at org.apache.camel.component.direct.DirectBlockingProducer.process(DirectBlockingProducer.java:53) at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:148) at org.apache.camel.processor.interceptor.TraceInterceptor.process(TraceInterceptor.java:181) at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:548) at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:201) at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:201) at org.apache.camel.component.netty4.handlers.ServerChannelHandler.processAsynchronously(ServerChannelHandler.java:141) at org.apache.camel.component.netty4.handlers.ServerChannelHandler.channelRead0(ServerChannelHandler.java:112) at org.apache.camel.component.netty4.http.handlers.HttpServerChannelHandler.channelRead0(HttpServerChannelHandler.java:213) at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105) at org.apache.camel.component.netty4.http.handlers.HttpServerMultiplexChannelHandler.channelRead0(HttpServerMultiplexChannelHandler.java:113) at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) at io.netty.channel.AbstractChannelHandlerContext.access$600(AbstractChannelHandlerContext.java:38) at io.netty.channel.AbstractChannelHandlerContext$7.run(AbstractChannelHandlerContext.java:353) at io.netty.util.concurrent.DefaultEventExecutor.run(DefaultEventExecutor.java:66) at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:884) at java.lang.Thread.run(Thread.java:745) Caused by: org.apache.camel.NoTypeConversionAvailableException: No type converter available to convert from type: com.ta.common.bean.Bank to the required type: byte[] with value Bank [id=1, name=TEST, location=Bangalore] at org.apache.camel.impl.converter.BaseTypeConverterRegistry.mandatoryConvertTo(BaseTypeConverterRegistry.java:206) at org.apache.camel.impl.MessageSupport.getMandatoryBody(MessageSupport.java:115) ... 29 more

Camel路由逻辑如下,

restConfiguration().component("netty4-http").bindingMode(RestBindingMode.json).host("localhost").port(8000);

rest("/api").consumes("application/json").post("/addbank").type(Bank.class).to("direct:addbank");

from("direct:addbank").log("request body :
${body}").to("netty4-http:http://localhost:8181/bank/add?bridgeEndpoint=true").throwException(new
RuntimeException()).to("direct:cancelAdding");

from("direct:cancelAdding").log("Cancelled adding bank details");

Controller 逻辑是:

@RestController 

@RequestMapping(path="/bank")

public class BankController {

List<Bank> bankList = new ArrayList<>();

@PostMapping(path="/add",consumes="application/json")
public List<Bank> addBank(@RequestBody @Valid Bank bank) {
bankList.add(bank);
return bankList;
}
}

银行.java:

private int id;

private String name;

private String location;

//Getter & Setter methods

最佳答案

我无法用上面的代码准确地重现错误。然而,当我尝试上面的代码时,这是我得到的异常。

org.apache.camel.processor.binding.BindingException: Cannot bind to json as message body is not json compatible. Exchange[ID-DESKTOP-OS0TDG5-1534851950401-0-1]

解决这个问题的方法是更改其余配置

 restConfiguration().component("netty4-http").host("localhost").bindingMode(RestBindingMode.json)....;

 restConfiguration().component("netty4-http").host("localhost").bindingMode(RestBindingMode.auto)....;

或者您可以完全省略绑定(bind)模式。

关于java - 由 : org. apache.camel.NoTypeConversionAvailableException 引起:没有可用于从类型 POJO 转换为 byte[] 的类型转换器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51946527/

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