Problem with CMP fiield

3 views
Skip to first unread message

Sachin Parnami

unread,
Sep 29, 2008, 4:24:11 AM9/29/08
to mobicents-public
Hi All,

How can i persist data by appending String or StringBuffer in CMP
field.

use case:-

StringBuffer temp= new StringBuffer(); // CMP field

onMessageEvent()
{
.....
...
//getTemp();
..
temp= messageBody
this.setTemp(temp);


}

But here i want to get the old CMP data append the new one in it and
then want to store it back in CMP.
So in that case if i put getTemp() in the beginning to get the old
data(as commented above) will give me a NullPointerException when ever
that event is going to hit first time, because its never persisted
before :).

Any idea about it.

Regards,
Sachin Parnami

Vicky Kak

unread,
Sep 29, 2008, 4:49:19 AM9/29/08
to mobicent...@googlegroups.com
>>will give me a NullPointerException when ever
>>that event is going to hit first time,

Which line of the code is giving you the NullPointerException, can you explain it properly?

Sachin Parnami

unread,
Sep 29, 2008, 4:58:38 AM9/29/08
to mobicent...@googlegroups.com
Hi Vicky,

Thanks for your reply.
Here is the detail

onMessageEvent()
{
.....
...
StringBuffer tempStringBuffer= new StringBuffer();

tempStringBuffer= this.getTemp();
..
StringBuffer temp= new StringBuffer();
temp= messageBody

tempStringBuffer.append(tempStringBuffer);// Line where i am getting Error

this.setTemp(tempStringBuffer);

Vicky Kak

unread,
Sep 29, 2008, 5:14:27 AM9/29/08
to mobicent...@googlegroups.com
>>tempStringBuffer= this.getTemp();

Is this line giving the NullPointerException?

Vicky Kak

unread,
Sep 29, 2008, 5:17:44 AM9/29/08
to mobicent...@googlegroups.com
>>tempStringBuffer.append(
>>tempStringBuffer);// Line where i am getting Error

Okay here you get it, looks to me that you need to handle it by this line

tempStringBuffer = (tempStringBuffer==null)?"":tempStringBuffer;

you can handle it using the application code.

Sachin Parnami

unread,
Sep 29, 2008, 8:21:19 AM9/29/08
to mobicent...@googlegroups.com
Not able to get the persist data in CMP field.

public void onMessageEvent(javax.sip.RequestEvent event,
            ActivityContextInterface aci) {
StringBuffer stringBuffer= this.getStringBuffer();
        stringBuffer= (stringBuffer==null)?new StringBuffer():stringBuffer;
        System.out.println("## "+ stringBuffer.toString());// Always prints nothing
.
.
.
stringBuffer.append("Data");
this.setStringBuffer(stringBuffer);
.
.
.
System.out.println("Data persisted in CMP "+ this.getStringBuffer().toString());//Always gives the persisted data's output
}

any idea what i am doing wrong :(
Reply all
Reply to author
Forward
0 new messages