Hi,
I'm trying to set up a Camel Route that reads and deserializes objects from
a socket. I'm deriving this from the camel-spring example program.
However, MINA Deserialization fails with Negative dataLength. I looked at
the Camel and MINA user forums and found nothing like this.
Thanks
Conrad
p.s. In the meanwhile, I'll look at building my own custom MINA codec for
using a length-protocol on a byte-array wrapping the Object Stream, like I
had to do with Mule
Here's the pertinent output:
14094 [AnonymousIoService-1] WARN
org.apache.camel.component.mina.MinaConsumer$ReceiveHandler -
[/127.0.0.1:3086] Unexpe
cted exception from exceptionCaught handler.
org.apache.camel.CamelException:
org.apache.mina.filter.codec.ProtocolDecoderException:
org.apache.mina.common.BufferDat
aException: dataLength: -1393754107 (Hexdump: AC ED 00 05 73 72 00 18 63 6F
6D 2E 66 6F 6F 2E 73 69 72 2E 44 6F 6D 61 69
6E 4F 62 6A 65 63 74 05 3C E6 61 EE C4 B8 10 02 00 09 49 00 03 63 49 64 4A
00 08 64 74 67 5F 6D 73 65 63 43 00 04 65 78
65 72 44 00 01 66 4A 00 02 69 64 4A 00 02 6C 61 4A 00 02 6C 6F 4C 00 02 63
63 74 00 12 4C 6A 61 76 61 2F 6C 61 6E 67 2F
53 74 72 69 6E 67 3B 4C 00 03 73 49 64 71 00 7E 00 01 78 70 00 00 03 E8 00
00 01 1C 2E B9 05 8B 00 00 40 6F 40 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00
01 74 00 02 41 41 71 00 7E 00 03 73 71 00 7E
00 00 00 00 03 E9 00 00 01 1C 2E B9 05 9B 00 00 40 6F 40 00 00 00 00 00 00
00 00 00 00 00 00 01 00 00 00 00 00 00 00 01
00 00 00 00 00 00 00 01 74 00 02 42 42 71 00 7E 00 05 73 71 00 7E 00 00 00
00 03 EA 00 00 01 1C 2E B9 05 9B 00 00 40 6F
40 00 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00 00 01 00 00 00
00 00 00 00 01 74 00 02 43 43 71 00 7E 00 07
73 71 00 7E 00 00 00 00 03 EB 00 00 01 1C 2E B9 05 9B 00 00 40 6F 40 00 00
00 00 00 00 00 00 00 00 00 00 03 00 00 00 00
00 00 00 01 00 00 00 00 00 00 00 01 74 00 02 44 44 71 00 7E 00 09 73 71 00
7E 00 00 00 00 03 EC 00 00 01 1C 2E B9 05 9B
00 00 40 6F 40 00 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00
01 00 00 00 00 00 00 00 01 74 00 02 45 45 71
00 7E 00 0B)
at
org.apache.camel.component.mina.MinaConsumer$ReceiveHandler.exceptionCaught(MinaConsumer.java:85)
at
org.apache.mina.common.support.AbstractIoFilterChain$TailFilter.exceptionCaught(AbstractIoFilterChain.java:564)
at
org.apache.mina.common.support.AbstractIoFilterChain.callNextExceptionCaught(AbstractIoFilterChain.java:345)
at
org.apache.mina.common.support.AbstractIoFilterChain.access$1000(AbstractIoFilterChain.java:53)
at
org.apache.mina.common.support.AbstractIoFilterChain$EntryImpl$1.exceptionCaught(AbstractIoFilterChain.java:643)
at
org.apache.mina.common.IoFilterAdapter.exceptionCaught(IoFilterAdapter.java:75)
at
org.apache.mina.common.support.AbstractIoFilterChain.callNextExceptionCaught(AbstractIoFilterChain.java:345)
at
org.apache.mina.common.support.AbstractIoFilterChain.access$1000(AbstractIoFilterChain.java:53)
at
org.apache.mina.common.support.AbstractIoFilterChain$EntryImpl$1.exceptionCaught(AbstractIoFilterChain.java:643)
at
org.apache.mina.filter.executor.ExecutorFilter.processEvent(ExecutorFilter.java:224)
at
org.apache.mina.filter.executor.ExecutorFilter$ProcessEventsRunnable.run(ExecutorFilter.java:264)
at
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
at
org.apache.mina.util.NamePreservingRunnable.run(NamePreservingRunnable.java:51)
at java.lang.Thread.run(Thread.java:619)
Caused by: org.apache.mina.filter.codec.ProtocolDecoderException:
org.apache.mina.common.BufferDataException: dataLength
: -1393754107 (Hexdump: AC ED 00 05 73 72 00 18 63 6F 6D 2E 66 6F 6F 2E 73
69 72 2E 44 6F 6D 61 69 6E 4F 62 6A 65 63 74
05 3C E6 61 EE C4 B8 10 02 00 09 49 00 03 63 49 64 4A 00 08 64 74 67 5F 6D
73 65 63 43 00 04 65 78 65 72 44 00 01 66 4A
00 02 69 64 4A 00 02 6C 61 4A 00 02 6C 6F 4C 00 02 63 63 74 00 12 4C 6A 61
76 61 2F 6C 61 6E 67 2F 53 74 72 69 6E 67 3B
4C 00 03 73 49 64 71 00 7E 00 01 78 70 00 00 03 E8 00 00 01 1C 2E B9 05 8B
00 00 40 6F 40 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 01 74 00 02 41 41 71
00 7E 00 03 73 71 00 7E 00 00 00 00 03 E9 00
00 01 1C 2E B9 05 9B 00 00 40 6F 40 00 00 00 00 00 00 00 00 00 00 00 00 01
00 00 00 00 00 00 00 01 00 00 00 00 00 00 00
01 74 00 02 42 42 71 00 7E 00 05 73 71 00 7E 00 00 00 00 03 EA 00 00 01 1C
2E B9 05 9B 00 00 40 6F 40 00 00 00 00 00 00
00 00 00 00 00 00 02 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 01 74 00
02 43 43 71 00 7E 00 07 73 71 00 7E 00 00 00
00 03 EB 00 00 01 1C 2E B9 05 9B 00 00 40 6F 40 00 00 00 00 00 00 00 00 00
00 00 00 03 00 00 00 00 00 00 00 01 00 00 00
00 00 00 00 01 74 00 02 44 44 71 00 7E 00 09 73 71 00 7E 00 00 00 00 03 EC
00 00 01 1C 2E B9 05 9B 00 00 40 6F 40 00 00
00 00 00 00 00 00 00 00 00 00 04 00 00 00 00 00 00 00 01 00 00 00 00 00 00
00 01 74 00 02 45 45 71 00 7E 00 0B)
at
org.apache.mina.filter.codec.ProtocolCodecFilter.messageReceived(ProtocolCodecFilter.java:165)
at
org.apache.mina.common.support.AbstractIoFilterChain.callNextMessageReceived(AbstractIoFilterChain.java:299)
at
org.apache.mina.common.support.AbstractIoFilterChain.access$1100(AbstractIoFilterChain.java:53)
at
org.apache.mina.common.support.AbstractIoFilterChain$EntryImpl$1.messageReceived(AbstractIoFilterChain.java:648)
at
org.apache.mina.filter.executor.ExecutorFilter.processEvent(ExecutorFilter.java:220)
... 5 more
Caused by: org.apache.mina.common.BufferDataException: dataLength:
-1393754107
at
org.apache.mina.common.ByteBuffer.prefixedDataAvailable(ByteBuffer.java:1631)
at
org.apache.mina.filter.codec.serialization.ObjectSerializationDecoder.doDecode(ObjectSerializationDecoder.java:88)
at
org.apache.mina.filter.codec.CumulativeProtocolDecoder.decode(CumulativeProtocolDecoder.java:133)
at
org.apache.mina.filter.codec.ProtocolCodecFilter.messageReceived(ProtocolCodecFilter.java:158)
... 9 more
Here's the RouteBuilder Main...I've set up my MINA route here:
package com.foo.sir;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.spring.Main;
import static org.apache.camel.builder.xml.XPathBuilder.xpath;
/**
* A Camel Router
*
* @version $
*/
public class MyRouteBuilder extends RouteBuilder {
/**
* A main() so we can easily run these routing rules in our IDE
*/
public static void main(String... args) {
Main.main(args);
}
/**
* Lets configure the Camel routing rules using Java code...
*/
public void configure() {
from("mina:tcp://localhost:9860").process(new Processor() {
public void process(Exchange exchange) throws Exception {
DomainObject body =
exchange.getIn().getBody(DomainObject.class);
System.out.println("Got a TCP body: " +
body.toString());
}
});
}
}
Here's the Camel Context...Nothing Special here:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://activemq.apache.org/camel/schema/spring
http://activemq.apache.org/camel/schema/spring/camel-spring.xsd">
<camelContext xmlns="http://activemq.apache.org/camel/schema/spring">
<package>com.foo.sir</package>
</camelContext>
</beans>
Here's the Socket Client that I'm serializing the objects with. Nothing
Special here either.
package com.foo.sir;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.net.Socket;
import java.util.Date;
public class MiniSocketClient {
public static void main(String[] args) {
MiniSocketClient m = new MiniSocketClient();
m.spew(args.length == 1 ? args[0] : "localhost", args.length ==
2 ?
args[1] : "9860");
}
protected void spew(String hostname, String port) {
Socket s = null;
String[] seriesTable = { "AA", "BB", "CC", "DD", "EE", "FF",
"GG", "HH", "II", "JJ"};
try {
s = new Socket(hostname, Integer.parseInt(port));
ObjectOutputStream oos = new
ObjectOutputStream(s.getOutputStream());
//spew out 5 DomainObjects
for (int i = 0; i<5; i++) {
DomainObject d = new DomainObject();
d.setId(i);
Date now = new Date();
d.setDtg_msec(now.getTime());
d.setLa(1L);
d.setLo(1L);
d.setF(250.0);
d.setCc(seriesTable[i]);
d.setSId(seriesTable[i]);
d.setCId(1000 + i);
System.out.println("Generating and sending A
DomainObject: " +
d.getCc());
oos.writeObject(d);
oos.flush();
}
} catch (IOException e) {
System.err.println(e);
e.printStackTrace();
} finally { // cleanup
try {
if (s != null)
s.close();
} catch (IOException ignoreMe) {
// nothing
}
}
}
}
Finally, here's the object I'm trying to pass over the socket.
package com.foo.sir;
import java.io.Serializable;
public class DomainObject implements Serializable {
private static final long serialVersionUID = 377429777084364816L;
private long id;
private long dtg_msec;
private long la;
private long lo;
private double f;
private String cc;
private String sId;
private int cId;
private char exer;
//snipped a bunch of setters and getters
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(this.id + "|" + this.dtg_msec + "|");
sb.append(this.la + "|" + this.lo + "|" + this.f);
sb.append("|" + this.cc + "|" + this.sId + "|" + this.cId + "|"
+
this.exer);
return sb.toString();
}
}
--
View this message in context:
http://www.nabble.com/MINA-Deserialization-fails-with-Negative-dataLength-tp19318349s22882p19318349.html
Sent from the Camel - Users mailing list archive at Nabble.com.