ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » Null pointer exception in custom Java node

Post new topic  Reply to topic
 Null pointer exception in custom Java node « View previous topic :: View next topic » 
Author Message
prasadpav
PostPosted: Sun May 01, 2005 2:36 am    Post subject: Null pointer exception in custom Java node Reply with quote

Centurion

Joined: 03 Oct 2004
Posts: 142

Hi all,
I'm creating java message processing node to
navigate through the message and modify an element if
it exists. And this is on Message Broker V5.0, CSD 02
on windows XP.
The sample XML i'm working on is:

<listofItems>
<Item>
<ItemTypeA>Data 1:Some data in here<\ItemTypeA>
<\Item
<Item>
<ItemTypeB>Data 2:Someother Typedata<\ItemTypeB>
<\Item>
<Item>
<ItemTypeA>Data 3:Some data in here<\ItemTypeA>
<\Item
<Item>
<ItemTypeA>Data 4:Some data in here<\ItemTypeA>
<\Item
<\listofItems>

Idea is to loop through all the repeating elements
<Item> and change the data for all those elements
which has element name as "ItemTypeA". <ItemTypeB>
should be left unchanged. We are using custom Java
node to this because we want to compress the data and
then Base64 encode the content.

I'm having problem in navigating to the next siblings
of <Item>. I tried lot of combinations but no success.
Here is the bit of code i'm doing:

within the evaluate method:

try {

MbMessage newMsg = new
MbMessage(oldAssembly.getMessage());
MbMessageAssembly newAssembly = new
MbMessageAssembly(oldAssembly, newMsg);

MbElement rootElement =
newAssembly.getMessage().getRootElement();

MbElement [] itemElement =
rootElement.getAllElementsByPath("/XML/listofItems//Item");

MbElement sibling = rootElement.getLastChild().getLastChild().getFirstChild().getFirstChild();
MbElement innerElement = rootElement.getFirstElementByPath("/XML/listofItems/Item/ItemTypeA");

for (int i=0; i< itemElement.length; i++)
{
if (innerElement.getName().equals("ItemTypeA")
{
.....<Then do something here>
}
else {
...<do nothing>....
}

sibling = sibling.getNextSibling(); // gives me next <item>
innerElement = sibling.getFirstChild();
//gives me <ItemTypeA> or <ItemTypeB> depending upon which one exists
}

Couple of problems i'm having while trying to execute this code:
1) In the following piece of code sibling is always null, I expected it to go to the next sibling of <Item>. At sibling.getFirstChild() is the point where i'm getting java.null pointer exception.
sibling = sibling.getNextSibling();
innerElement = sibling.getFirstChild();
2) The for loop worked the for the first occurance of the element <Item>, ONLY because I specified as following before for loop:
MbElement innerElement = rootElement.getFirstElementByPath ("/XML/listofItems/Item/ItemTypeA");
This actually must be sibling.getFirstChild(); (or) sibling.getLastChild() (doesn't make a difference for this example, i guess). If I had mentioned this, then i get null pointer exception in the If statement.

I'm debugging by generating system out println to the console.

Can anyone please suggest to make the looping for the repeatable element work and where i was wrong in the above code?? Sorry for this lengthy posting.....if you see this message till here...then you really are a very patient man !!!!!!

Cheers,
Prasad
Back to top
View user's profile Send private message
prasadpav
PostPosted: Sun May 01, 2005 2:40 am    Post subject: Reply with quote

Centurion

Joined: 03 Oct 2004
Posts: 142

While typing this lengthy post, i realised that my <ItemTypeA> data will be in a CDATA section. Not quite sure how to get the CDATA section using java API. or getValue() method gets the CDATA as well. I'll test this thing today afternoon.
Back to top
View user's profile Send private message
prasadpav
PostPosted: Thu May 05, 2005 4:57 am    Post subject: Reply with quote

Centurion

Joined: 03 Oct 2004
Posts: 142

Hi all,
I have done some more testing for navigating through the message, but still i'm having problems in doing the basic navigation through the message. Following is the one which I tried:

MbElement rootElement = newAssembly.getMessage().getRootElement();
System.out.println("Root Element is: " + rootElement.getName());

System.out.println("Child1:Root Child is: " + rootElement.getLastChild().getFirstChild().getName());

System.out.println("Child1:Root Child is: " + rootElement.getLastChild().getFirstChild().getFirstChild().getName());

For the same XML data which I mentioned in my above posting, first println statement works fine, but gets null pointer exception at the second println statment. here is the exception:
--------------------------------------------------------------------
( TESTBKR.NetworkCompression ) The method 'evaluate' in Java node 'Compress' has thrown the following exception: java.lang.NullPointerException.
---------------------------------------------------------------------

Seems like a chain of getLastChild().getFirstChild()...etc is not working.


I also tried the following, but I can't get the child elements.

MbElement[] tempElement = rootElement.getAllElementsByPath("/XML/ListOfItems//Item");

System.out.println("ParentName and ChildName 1 is: " + tempElement[1].getName() + " " + tempElement[1].getFirstChild().getName());
System.out.println("ParentName and ChildName 2 is: " + tempElement[2].getName() + " " + tempElement[2].getFirstChild().getName());


Any help is greatly appreciated.

Regards, Prasad
Back to top
View user's profile Send private message
jefflowrey
PostPosted: Thu May 05, 2005 5:08 am    Post subject: Reply with quote

Grand Poobah

Joined: 16 Oct 2002
Posts: 19981

When trying to figure out how to navigate a particular message tree, I always found the output from a trace node to a file to be very useful.

The thing I think you are getting tripped over is the difference between Name, Name/Value, and Value elements...

Sometimes the first child of an element is a Value element, which wouldn't have a Name associated with it.

Also, particularly when navigating XML, you may end up having value elements that represent line feeds in source text.
_________________
I am *not* the model of the modern major general.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » Null pointer exception in custom Java node
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.