| 305 | |
| 306 | === 3.3 Troubleshooting messages === |
| 307 | When things go wrong, messages will either be thrown away and never reach your handlers, or will exceptions that may or may not reach logging. One way to minimize this is to check that the messages can be built and read/written from/to !ChannelBuffers within your controller. !BasicFactory has a !dumpBuffer() function that returns a hexdump of a message as a string that you can check more thoroughly to see if what you think you have implemented is actually what you have. |
| 308 | |
| 309 | {{{ |
| 310 | //where msg below is your Vendor message |
| 311 | ChannelBuffer bb = ChannelBuffers.dynamicBuffer(); |
| 312 | bb.clear(); |
| 313 | msg.writeTo(bb); |
| 314 | bb.resetReaderIndex(); |
| 315 | |
| 316 | //print vendor data as string |
| 317 | System.out.println(msg.getVendorData().toString()); |
| 318 | //print a hexdump |
| 319 | System.out.println(BasicFactory.dumpBuffer(bb)) |
| 320 | }}} |
| 321 | |
| 322 | The above should produce something like below as output (demonstrated with a custom message not discussed here) |
| 323 | {{{ |
| 324 | CPLCommandMsg[[UID=2561 peer=false SID=1 TID=2][RCmd=8 EType=any] Command=CONTINUE] |
| 325 | |
| 326 | 01040028 00000000 0000ffff 00000005 00000000 00000a01 01000000 02080000 |
| 327 | 00000000 00000000 |
| 328 | }}} |
| 329 | |
| 330 | Note, a local check won't prevent everything. In general, providing the correct getLength() value helps to prevent many common errors, so it is important to check that this function is returning the right value. |
| 331 | |