Hi, I found anomaly, that yet to find what went wrong on these ByteBuffer?

I'm trying to decode a specific switch protocol, that based on
content-length information. So following is from my decoder class that
trying to search the length from 'in' buffer.

Attached is the log output from last run, here you can before doing
anything, The buffer dump show content-length of "1619". Then I continue
with logic to parse this into integer, with in.get(i) methods. But, from
this methods, it return '3284'. Which, I believe from previous buffer. Now,
At the end of these routines, I dump again this 'in' bytebuffer. This time,
it still showing the content-length of '1619'. After this, the subsequent
protocol parsing is getting screw, since the length is not chop properly.

This symptom occurs on high load messages from the server, during low load,
everything seems fine.

Anybody encounter similar problem? your hints is appreciated.

Thanks,
Johny K.


================================================================


   private int getContentLength(ByteBuffer in, int last) {

        String str = getBufferString(in);               // in.getHexDump();
        logger.debug("last = "+last);
        logger.debug("***** Buffer in getContentLength 1 *****\n"+str);

        for (int i = 0; i < last; i++) {
            boolean found = false;
            for (int j = 0; j < CONTENT_LENGTH.length; j++) {
                if (in.get(i + j) != CONTENT_LENGTH[j]) {
                    found = false;
                    break;
                }
                found = true;
            }
            if (found) {
                // retrieve value from this position till next 0x0D 0x0A
                logger.debug("Found content-length index at "+i);

                StringBuilder contentLength = new StringBuilder();
                for (int j = i + CONTENT_LENGTH.length; j < last; j++) {
                    if (in.get(j) == 0x0A)
                        break;
                    contentLength.append(new String( new byte[] { in.get(j)
}));
                    logger.debug("["+new String( new byte[]
{in.get(j)})+"]");
                }
                // if content-length worth of data has been received then
the message is complete

                str = getBufferString(in);               // in.getHexDump();
                logger.debug("***** Buffer in getContentLength 2
*****\n"+str);

                logger.debug("ContentLength = "+contentLength);
                logger.debug("total buffer length = "+in.remaining());
                return Integer.parseInt(contentLength.toString().trim());
            }
        }
        return -1;
    }







10:27:55,867 [AnonymousIoService-1] DEBUG FSResponseDecoder  - ***** Buffer
in getContentLength 1 *****
Content-Length: 1619
Content-Type: text/event-plain

Channel-State: CS_NEW
Channel-State-Number: 0
Channel-Name: sofia/external/nobody%40192.168.3.12
Unique-ID: fd2229c0-2d6c-11dd-9acd-0b28d09a52aa
Call-Direction: inbound
Answer-State: ringing
variable_sip_from_user: nobody
variable_sip_from_uri: nobody%40192.168.3.12
variable_sip_from_host: 192.168.3.12
variable_sip_from_tag: 02H917ryecvgp
variable_sofia_profile_name: external
variable_sofia_profile_domain_name: external
variable_sip_req_user: 6001
variable_sip_req_port: 5080
variable_sip_req_uri: 6001%40192.168.3.11%3A5080
variable_sip_req_host: 192.168.3.11
variable_sip_to_user: 6001
variable_sip_to_port: 5080
variable_sip_to_uri: 6001%40192.168.3.11%3A5080
variable_sip_to_host: 192.168.3.11
variable_sip_contact_user: mod_sofia
variable_sip_contact_port: 5060
variable_sip_contact_uri: mod_sofia%40192.168.3.12%3A5060
variable_sip_contact_host: 192.168.3.12
variable_channel_name: sofia/external/nobody%40192.168.3.12
variable_endpoint_disposition: INBOUND%20CALL
variable_sip_call_id: 824f7531-a82e-122b-8485-000f1f644b48
variable_sip_user_agent: FreeSWITCH-mod_sofia/1.0.pre4-8539
variable_sip_via_host: 192.168.3.12
variable_sip_via_rport: 5060
variable_max_forwards: 70
Event-Name: CHANNEL_CREATE
Core-UUID: ed9888ba-2c94-11dd-
10:27:55,867 [AnonymousIoService-1] DEBUG FSResponseDecoder  - Found
content-length index at 0
10:27:55,867 [AnonymousIoService-1] DEBUG FSResponseDecoder  - [ ]
10:27:55,867 [AnonymousIoService-1] DEBUG FSResponseDecoder  - [3]
10:27:55,867 [AnonymousIoService-1] DEBUG FSResponseDecoder  - [2]
10:27:55,867 [AnonymousIoService-1] DEBUG FSResponseDecoder  - [8]
10:27:55,867 [AnonymousIoService-1] DEBUG FSResponseDecoder  - [4]
10:27:55,867 [AnonymousIoService-1] DEBUG FSResponseDecoder  - ***** Buffer
in getContentLength 2 *****
Content-Length: 1619
Content-Type: text/event-plain

Channel-State: CS_NEW
Channel-State-Number: 0
Channel-Name: sofia/external/nobody%40192.168.3.12
Unique-ID: fd2229c0-2d6c-11dd-9acd-0b28d09a52aa
Call-Direction: inbound
Answer-State: ringing
variable_sip_from_user: nobody
variable_sip_from_uri: nobody%40192.168.3.12
variable_sip_from_host: 192.168.3.12
variable_sip_from_tag: 02H917ryecvgp
variable_sofia_profile_name: external
variable_sofia_profile_domain_name: external
variable_sip_req_user: 6001
variable_sip_req_port: 5080
variable_sip_req_uri: 6001%40192.168.3.11%3A5080
variable_sip_req_host: 192.168.3.11
variable_sip_to_user: 6001
variable_sip_to_port: 5080
variable_sip_to_uri: 6001%40192.168.3.11%3A5080
variable_sip_to_host: 192.168.3.11
variable_sip_contact_user: mod_sofia
variable_sip_contact_port: 5060
variable_sip_contact_uri: mod_sofia%40192.168.3.12%3A5060
variable_sip_contact_host: 192.168.3.12
variable_channel_name: sofia/external/nobody%40192.168.3.12
variable_endpoint_disposition: INBOUND%20CALL
variable_sip_call_id: 824f7531-a82e-122b-8485-000f1f644b48
variable_sip_user_agent: FreeSWITCH-mod_sofia/1.0.pre4-8539
variable_sip_via_host: 192.168.3.12
variable_sip_via_rport: 5060
variable_max_forwards: 70
Event-Name: CHANNEL_CREATE
Core-UUID: ed9888ba-2c94-11dd-
10:27:55,867 [AnonymousIoService-1] DEBUG FSResponseDecoder  - ContentLength
=  3284
10:27:55,867 [AnonymousIoService-1] DEBUG FSResponseDecoder  - total buffer
length = 1295

Reply via email to