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] MainSupport INFO Apache
Camel (Main) 3.21.2 is starting
[ main] BaseMainSupport INFO Classpath
scanning enabled from base package: com.adumo.test.netty
[ main] BaseMainSupport INFO
Auto-configuration summary
[ main] BaseMainSupport INFO
[application.properties] camel.main.routesIncludePattern=routes/*.xml
[ main] BaseMainSupport INFO
[application.properties] camel.main.name=MyXmlCamel
[ main] BaseMainSupport INFO
[application.properties] camel.main.routesReloadEnabled=true
[ main] BaseMainSupport INFO
[application.properties]
camel.main.routesReloadDirectory=src/main/resources/routes
[ main] BaseMainSupport INFO
[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] BaseMainSupport INFO
Property-placeholders summary
[ main] BaseMainSupport INFO
[application.properties] hi=Hello
[ main] BaseMainSupport INFO
[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);
byte[] bytes = new byte[lenght];
bufRes.readBytes(bytes);
System.out.println("Result " + bytes);
} catch (Exception e) {
e.printStackTrace();
}
}
});
sendThread.start();
main.run(args);
System.out.println("Done");
}
}
Here is my encoder / decoder:
@BindToRegistry
public LengthFieldPrepender epencoder() {
// this will create an instance of this bean with the name of the
method (eg epencoder)
return new LengthFieldPrepender(2);
}
@BindToRegistry
public ChannelHandlerFactory epdecoder() {
// this will create an instance of this bean with the name of the
method (eg epdecoder)
return ChannelHandlerFactories.newLengthFieldBasedFrameDecoder(4096, 0,
2, 0, 2);
}
[photo]<http://adumo.com>
Gawie van der Merwe
Development Manager
[icon] 021 569 2468<tel:0215692468> | [icon] 060 334 5480<tel:0603345480> |
[icon] adumo.com<https://adumo.com>
[icon] [email protected]<mailto:[email protected]>
[icon] Foyer 3 1st Floor, The Colosseum, Century Way, Century City, Cape Town,
7441<https://maps.google.com/?q=Foyer%203%201st%20Floor,%20The%20Colosseum,%20Century%20Way,%20Century%20City,%20Cape%20Town,%207441>
[facebook]<https://www.facebook.com/adumogroup>
[instagram]<https://www.instagram.com/adumo_group/>
[linkedin]<https://www.linkedin.com/company/adumo/>
[App Banner Image]<https://www.adumo.com/payments/integrated#integrated-contact>
Confidentiality Notice:The contents of and attachments to this e-mail are
intended for the addressee only, and may contain the confidential information
of Adumo Payments (Pty) Ltd. Any review, use or dissemination thereof by anyone
other than the intended addressee is prohibited. If you are not the intended
addressee please notify the writer immediately and destroy the e-mail. Adumo
Payments (Pty) Ltd distances itself from and accepts no liability for
unauthorized use of its e-mail facilities or e-mails sent other than strictly
for business purposes.
[__tpx__]