1

I am new to Apache Camel. I am using REST API with Apache Camel and Spring Boot integration. I am done with get request, it is working as expected. But, I stuck with one issue while posting the data by using POST call.

I have seen bit similar error in below link. But, that doesn't help me. org.apache.camel.NoTypeConversionAvailableException: No type converter available to convert from type:

I have tried couple of solutions available in Stackoverflow, youtube and other websites as well. But, no luck. Could you please help me to solve the problem,

Error Description:

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 Routing logic is as follows,

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 Logic Is:

@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;  
     }
 }

Bank.java:

private int id;

private String name;

private String location;

//Getter & Setter methods
pvpkiran
  • 25,582
  • 8
  • 87
  • 134
Nallamachu
  • 1,420
  • 18
  • 34

1 Answers1

2

I could not exactly reproduce the error with the above code. hoeever when I tried the above code , this is the exception I got.

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

Fix for this is to Change rest configuration from

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

to

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

or you can omit bindingmode altogether.

pvpkiran
  • 25,582
  • 8
  • 87
  • 134
  • I have tried with RestBindingMode.auto. But, I faced the same issue. I have removed bindingMode() completely. It started working. Thanks again. – Nallamachu Aug 21 '18 at 12:01