Re: Netty TCP Producer- unable to get byte array from response

2024-03-07 Thread Gawie van der Merwe
Thanks we need the good luck :)


From: Claus Ibsen 
Sent: Thursday, March 7, 2024 1:03:16 PM
To: users@camel.apache.org 
Subject: Re: Netty TCP Producer- unable to get byte array from response

Hi

Thanks for sharing your solution. And good luck on the Camel upgrade.

On Thu, Mar 7, 2024 at 11:34 AM Gawie van der Merwe 
wrote:

> We finally solved it by adding another decoder which returns a byte[]
>
> @BindToRegistry
> public ChannelHandlerFactory epdecoderbyte() {
> return ChannelHandlerFactories.newByteArrayDecoder("tcp");
> }
>
> 
> From: Gawie van der Merwe 
> Sent: Thursday, 07 March 2024 10:51
> To: users@camel.apache.org 
> Subject: Netty TCP Producer- unable to get byte array from response
>
> Hi guys,
>
> We are upgrading from camel 2.12.2 --> 3.21.2. And we have been stuck on
> Netty TCP.
>
> On the old version we recieved a response as "BodyType:
> org.jboss.netty.buffer.BigEndianHeapChannelBuffer"
> Now we get it as "PooledSlicedByteBuf(freed)". For the life of me are not
> able to get the bytes from the ByteBuf. It seems the camel netty component
> has already read the bytes. How can we get the bytes from the response? We
> tried retain()/release()/unwrap()/etc. Below a simple example to reproduce.
>
>
> --
> [  main] MainSupportINFO
> Apache Camel (Main) 3.21.2 is starting
> [  main] BaseMainSupportINFO
> Classpath scanning enabled from base package: com.adumo.test.netty
> [  main] BaseMainSupportINFO
> Auto-configuration summary
> [  main] BaseMainSupportINFO
> [application.properties]   camel.main.routesIncludePattern=routes/*.xml
> [  main] BaseMainSupportINFO
> [application.properties]   camel.main.name=MyXmlCamel
> [  main] BaseMainSupportINFO
> [application.properties]   camel.main.routesReloadEnabled=true
> [  main] BaseMainSupportINFO
> [application.properties]
>  camel.main.routesReloadDirectory=src/main/resources/routes
> [  main] BaseMainSupportINFO
> [application.properties]   camel.main.routesReloadPattern=*.xml
> [  main] AbstractCamelContext   INFO
> Apache Camel 3.21.2 (MyXmlCamel) is starting
> [  main] NettyComponent INFO
> Creating shared NettyConsumerExecutorGroup with 17 threads
> [  main] eWatcherResourceReloadStrategy INFO  Live
> route reloading enabled (directory: src/main/resources/routes)
> [  main] BaseMainSupportINFO
> Property-placeholders summary
> [  main] BaseMainSupportINFO
> [application.properties]   hi=Hello
> [  main] BaseMainSupportINFO
> [application.properties]   bye=Bye
> [  main] AbstractCamelContext   INFO
> Routes startup (started:1)
> [  main] AbstractCamelContext   INFO
> Started test-route1 (direct://test1)
> [  main] AbstractCamelContext   INFO
> Apache Camel 3.21.2 (MyXmlCamel) started in 305ms (build:42ms init:139ms
> start:124ms JVM-uptime:1s)
> Sending
> bufRes PooledSlicedByteBuf(freed)
> lenght 635
> io.netty.util.IllegalReferenceCountException: refCnt: 0
> at
> io.netty.buffer.AbstractByteBuf.ensureAccessible(AbstractByteBuf.java:1454)
> at
> io.netty.buffer.AbstractByteBuf.checkReadableBytes0(AbstractByteBuf.java:1440)
> at
> io.netty.buffer.AbstractByteBuf.checkReadableBytes(AbstractByteBuf.java:1428)
> at
> io.netty.buffer.AbstractByteBuf.readBytes(AbstractByteBuf.java:895)
> at
> io.netty.buffer.AbstractByteBuf.readBytes(AbstractByteBuf.java:903)
> at com.adumo.test.netty.MyApplication$1.run(MyApplication.java:38)
> at java.base/java.lang.Thread.run(Thread.java:829)
>
> --
>
> import java.nio.file.Files;
> import java.nio.file.Path;
> import java.nio.file.Paths;
>
> import org.apache.camel.ProducerTemplate;
> import org.apache.camel.main.Main;
>
> import io.netty.buffer.ByteBuf;
> import io.netty.buffer.Unpooled;
>
> public final class MyApplication {
>
> private MyApplication() {
> }
>
> public static void main(String[] args) throws Exception {
> Main main = new

Re: Netty TCP Producer- unable to get byte array from response

2024-03-07 Thread Claus Ibsen
Hi

Thanks for sharing your solution. And good luck on the Camel upgrade.

On Thu, Mar 7, 2024 at 11:34 AM Gawie van der Merwe 
wrote:

> We finally solved it by adding another decoder which returns a byte[]
>
> @BindToRegistry
> public ChannelHandlerFactory epdecoderbyte() {
> return ChannelHandlerFactories.newByteArrayDecoder("tcp");
> }
>
> 
> From: Gawie van der Merwe 
> Sent: Thursday, 07 March 2024 10:51
> To: users@camel.apache.org 
> Subject: Netty TCP Producer- unable to get byte array from response
>
> Hi guys,
>
> We are upgrading from camel 2.12.2 --> 3.21.2. And we have been stuck on
> Netty TCP.
>
> On the old version we recieved a response as "BodyType:
> org.jboss.netty.buffer.BigEndianHeapChannelBuffer"
> Now we get it as "PooledSlicedByteBuf(freed)". For the life of me are not
> able to get the bytes from the ByteBuf. It seems the camel netty component
> has already read the bytes. How can we get the bytes from the response? We
> tried retain()/release()/unwrap()/etc. Below a simple example to reproduce.
>
>
> --
> [  main] MainSupportINFO
> Apache Camel (Main) 3.21.2 is starting
> [  main] BaseMainSupportINFO
> Classpath scanning enabled from base package: com.adumo.test.netty
> [  main] BaseMainSupportINFO
> Auto-configuration summary
> [  main] BaseMainSupportINFO
> [application.properties]   camel.main.routesIncludePattern=routes/*.xml
> [  main] BaseMainSupportINFO
> [application.properties]   camel.main.name=MyXmlCamel
> [  main] BaseMainSupportINFO
> [application.properties]   camel.main.routesReloadEnabled=true
> [  main] BaseMainSupportINFO
> [application.properties]
>  camel.main.routesReloadDirectory=src/main/resources/routes
> [  main] BaseMainSupportINFO
> [application.properties]   camel.main.routesReloadPattern=*.xml
> [  main] AbstractCamelContext   INFO
> Apache Camel 3.21.2 (MyXmlCamel) is starting
> [  main] NettyComponent INFO
> Creating shared NettyConsumerExecutorGroup with 17 threads
> [  main] eWatcherResourceReloadStrategy INFO  Live
> route reloading enabled (directory: src/main/resources/routes)
> [  main] BaseMainSupportINFO
> Property-placeholders summary
> [  main] BaseMainSupportINFO
> [application.properties]   hi=Hello
> [  main] BaseMainSupportINFO
> [application.properties]   bye=Bye
> [  main] AbstractCamelContext   INFO
> Routes startup (started:1)
> [  main] AbstractCamelContext   INFO
> Started test-route1 (direct://test1)
> [  main] AbstractCamelContext   INFO
> Apache Camel 3.21.2 (MyXmlCamel) started in 305ms (build:42ms init:139ms
> start:124ms JVM-uptime:1s)
> Sending
> bufRes PooledSlicedByteBuf(freed)
> lenght 635
> io.netty.util.IllegalReferenceCountException: refCnt: 0
> at
> io.netty.buffer.AbstractByteBuf.ensureAccessible(AbstractByteBuf.java:1454)
> at
> io.netty.buffer.AbstractByteBuf.checkReadableBytes0(AbstractByteBuf.java:1440)
> at
> io.netty.buffer.AbstractByteBuf.checkReadableBytes(AbstractByteBuf.java:1428)
> at
> io.netty.buffer.AbstractByteBuf.readBytes(AbstractByteBuf.java:895)
> at
> io.netty.buffer.AbstractByteBuf.readBytes(AbstractByteBuf.java:903)
> at com.adumo.test.netty.MyApplication$1.run(MyApplication.java:38)
> at java.base/java.lang.Thread.run(Thread.java:829)
>
> --
>
> import java.nio.file.Files;
> import java.nio.file.Path;
> import java.nio.file.Paths;
>
> import org.apache.camel.ProducerTemplate;
> import org.apache.camel.main.Main;
>
> import io.netty.buffer.ByteBuf;
> import io.netty.buffer.Unpooled;
>
> public final class MyApplication {
>
> private MyApplication() {
> }
>
> public static void main(String[] args) throws Exception {
> Main main = new Main(MyApplication.class);
> Thread sendThread = new Thread(new Runnable() {
> @Override
> public void run() {
> try {
> Thread.sleep(2000);
>
>  

Re: Netty TCP Producer- unable to get byte array from response

2024-03-07 Thread Gawie van der Merwe
We finally solved it by adding another decoder which returns a byte[]

@BindToRegistry
public ChannelHandlerFactory epdecoderbyte() {
return ChannelHandlerFactories.newByteArrayDecoder("tcp");
}


From: Gawie van der Merwe 
Sent: Thursday, 07 March 2024 10:51
To: users@camel.apache.org 
Subject: Netty TCP Producer- unable to get byte array from response

Hi guys,

We are upgrading from camel 2.12.2 --> 3.21.2. And we have been stuck on Netty 
TCP.

On the old version we recieved a response as "BodyType: 
org.jboss.netty.buffer.BigEndianHeapChannelBuffer"
Now we get it as "PooledSlicedByteBuf(freed)". For the life of me are not able 
to get the bytes from the ByteBuf. It seems the camel netty component has 
already read the bytes. How can we get the bytes from the response? We tried 
retain()/release()/unwrap()/etc. Below a simple example to reproduce.

--
[  main] MainSupportINFO  Apache 
Camel (Main) 3.21.2 is starting
[  main] BaseMainSupportINFO  Classpath 
scanning enabled from base package: com.adumo.test.netty
[  main] BaseMainSupportINFO  
Auto-configuration summary
[  main] BaseMainSupportINFO  
[application.properties]   camel.main.routesIncludePattern=routes/*.xml
[  main] BaseMainSupportINFO  
[application.properties]   camel.main.name=MyXmlCamel
[  main] BaseMainSupportINFO  
[application.properties]   camel.main.routesReloadEnabled=true
[  main] BaseMainSupportINFO  
[application.properties]   
camel.main.routesReloadDirectory=src/main/resources/routes
[  main] BaseMainSupportINFO  
[application.properties]   camel.main.routesReloadPattern=*.xml
[  main] AbstractCamelContext   INFO  Apache 
Camel 3.21.2 (MyXmlCamel) is starting
[  main] NettyComponent INFO  Creating 
shared NettyConsumerExecutorGroup with 17 threads
[  main] eWatcherResourceReloadStrategy INFO  Live 
route reloading enabled (directory: src/main/resources/routes)
[  main] BaseMainSupportINFO  
Property-placeholders summary
[  main] BaseMainSupportINFO  
[application.properties]   hi=Hello
[  main] BaseMainSupportINFO  
[application.properties]   bye=Bye
[  main] AbstractCamelContext   INFO  Routes 
startup (started:1)
[  main] AbstractCamelContext   INFO  
Started test-route1 (direct://test1)
[  main] AbstractCamelContext   INFO  Apache 
Camel 3.21.2 (MyXmlCamel) started in 305ms (build:42ms init:139ms start:124ms 
JVM-uptime:1s)
Sending
bufRes PooledSlicedByteBuf(freed)
lenght 635
io.netty.util.IllegalReferenceCountException: refCnt: 0
at 
io.netty.buffer.AbstractByteBuf.ensureAccessible(AbstractByteBuf.java:1454)
at 
io.netty.buffer.AbstractByteBuf.checkReadableBytes0(AbstractByteBuf.java:1440)
at 
io.netty.buffer.AbstractByteBuf.checkReadableBytes(AbstractByteBuf.java:1428)
at io.netty.buffer.AbstractByteBuf.readBytes(AbstractByteBuf.java:895)
at io.netty.buffer.AbstractByteBuf.readBytes(AbstractByteBuf.java:903)
at com.adumo.test.netty.MyApplication$1.run(MyApplication.java:38)
at java.base/java.lang.Thread.run(Thread.java:829)
--

import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

import org.apache.camel.ProducerTemplate;
import org.apache.camel.main.Main;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;

public final class MyApplication {

private MyApplication() {
}

public static void main(String[] args) throws Exception {
Main main = new Main(MyApplication.class);
Thread sendThread = new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(2000);

System.out.println("Sending");
ProducerTemplate pdt = main.getCamelTemplate();

Path path = Paths.get("isoAuthReq");
byte[] data = Files.readAllBytes(path);

ByteBuf bu

Netty TCP Producer- unable to get byte array from response

2024-03-07 Thread Gawie van der Merwe
Hi guys,

We are upgrading from camel 2.12.2 --> 3.21.2. And we have been stuck on Netty 
TCP.

On the old version we recieved a response as "BodyType: 
org.jboss.netty.buffer.BigEndianHeapChannelBuffer"
Now we get it as "PooledSlicedByteBuf(freed)". For the life of me are not able 
to get the bytes from the ByteBuf. It seems the camel netty component has 
already read the bytes. How can we get the bytes from the response? We tried 
retain()/release()/unwrap()/etc. Below a simple example to reproduce.

--
[  main] MainSupportINFO  Apache 
Camel (Main) 3.21.2 is starting
[  main] BaseMainSupportINFO  Classpath 
scanning enabled from base package: com.adumo.test.netty
[  main] BaseMainSupportINFO  
Auto-configuration summary
[  main] BaseMainSupportINFO  
[application.properties]   camel.main.routesIncludePattern=routes/*.xml
[  main] BaseMainSupportINFO  
[application.properties]   camel.main.name=MyXmlCamel
[  main] BaseMainSupportINFO  
[application.properties]   camel.main.routesReloadEnabled=true
[  main] BaseMainSupportINFO  
[application.properties]   
camel.main.routesReloadDirectory=src/main/resources/routes
[  main] BaseMainSupportINFO  
[application.properties]   camel.main.routesReloadPattern=*.xml
[  main] AbstractCamelContext   INFO  Apache 
Camel 3.21.2 (MyXmlCamel) is starting
[  main] NettyComponent INFO  Creating 
shared NettyConsumerExecutorGroup with 17 threads
[  main] eWatcherResourceReloadStrategy INFO  Live 
route reloading enabled (directory: src/main/resources/routes)
[  main] BaseMainSupportINFO  
Property-placeholders summary
[  main] BaseMainSupportINFO  
[application.properties]   hi=Hello
[  main] BaseMainSupportINFO  
[application.properties]   bye=Bye
[  main] AbstractCamelContext   INFO  Routes 
startup (started:1)
[  main] AbstractCamelContext   INFO  
Started test-route1 (direct://test1)
[  main] AbstractCamelContext   INFO  Apache 
Camel 3.21.2 (MyXmlCamel) started in 305ms (build:42ms init:139ms start:124ms 
JVM-uptime:1s)
Sending
bufRes PooledSlicedByteBuf(freed)
lenght 635
io.netty.util.IllegalReferenceCountException: refCnt: 0
at 
io.netty.buffer.AbstractByteBuf.ensureAccessible(AbstractByteBuf.java:1454)
at 
io.netty.buffer.AbstractByteBuf.checkReadableBytes0(AbstractByteBuf.java:1440)
at 
io.netty.buffer.AbstractByteBuf.checkReadableBytes(AbstractByteBuf.java:1428)
at io.netty.buffer.AbstractByteBuf.readBytes(AbstractByteBuf.java:895)
at io.netty.buffer.AbstractByteBuf.readBytes(AbstractByteBuf.java:903)
at com.adumo.test.netty.MyApplication$1.run(MyApplication.java:38)
at java.base/java.lang.Thread.run(Thread.java:829)
--

import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

import org.apache.camel.ProducerTemplate;
import org.apache.camel.main.Main;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;

public final class MyApplication {

private MyApplication() {
}

public static void main(String[] args) throws Exception {
Main main = new Main(MyApplication.class);
Thread sendThread = new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(2000);

System.out.println("Sending");
ProducerTemplate pdt = main.getCamelTemplate();

Path path = Paths.get("isoAuthReq");
byte[] data = Files.readAllBytes(path);

ByteBuf bufReq = Unpooled.wrappedBuffer(data);
ByteBuf bufRes = (ByteBuf) 
pdt.requestBody("netty:tcp://x.x.x.x:49002?decoders=#epdecoder&encoders=#epencoder&disconnect=false&sync=true&reuseAddress=true&keepAlive=true&synchronous=true&requestTimeout=8000",
 bufReq);

int lenght = bufRes.readableBytes();
System.out.println("lenght " + lenght);