Author |
Message
|
vininx |
Posted: Fri Oct 21, 2011 7:17 am Post subject: Getting null while accessing UDP in JCN impl |
|
|
Acolyte
Joined: 13 Oct 2009 Posts: 69
|
Hi All,
I am facing 2 problems in my user defined node,
Problem 1:-
-------------
While accessing the user defined node properties, in the Java implementation, I am getting null values, please find below the code.
public void onInitialize ()
{
System.out.println (">>> Getting user defined properties");
this.logVar = (String) this.getUserDefinedAttribute ("LogText");
System.out.println (">>> Log Variables" + logVar);
this.attnVar = (String) this.getUserDefinedAttribute("AttnCode");
System.out.println (">>> Attention code" + attnVar);
this.evntVar = (String) this.getUserDefinedAttribute("EventCode");
System.out.println (">>> Event code" + evntVar);
}
Output in console:-
--------------------
>>> Getting user defined properties
>>> Log Variablesnull
>>> Attention codenull
>>> Event codenull
I am having getter and setter methods for UDP's as well.
Problem2:-
------------
I am populating the environment in Java implementation as below
public void evaluate(MbMessageAssembly contact admin, MbInputTerminal arg1)
throws MbException {
// TODO Auto-generated method stub
System.out.println (">>> User defined node implementation");
MbMessage newMsg = new MbMessage(contact admin.getMessage());
MbMessageAssembly newAssembly = new MbMessageAssembly (contact admin, newMsg);
System.out.println (">>> New message assembly created");
MbElement env = newAssembly.getGlobalEnvironment().getRootElement();
System.out.println (">>> New global environment created");
MbElement var = env.createElementAsFirstChild(MbElement.TYPE_NAME, "Variables", null);
System.out.println (">>> Variables created");
var = var.getFirstElementByPath("Variables");
MbElement esb = var.createElementAsFirstChild(MbElement.TYPE_NAME, "ESB", null);
System.out.println (">>> ESB created");
esb = esb.getFirstElementByPath("ESB");
esb.createElementAsFirstChild(MbElement.TYPE_NAME_VALUE, "LogText", this.logVar);
esb.createElementAsFirstChild(MbElement.TYPE_NAME_VALUE, "AttnCode", this.attnVar);
esb.createElementAsFirstChild(MbElement.TYPE_NAME_VALUE, "EventCode", this.evntVar);
System.out.println (">>> Children's added to ESB");
MbOutputTerminal out = getOutputTerminal ("out");
out.propagate(newAssembly);
}
Event Log:-
-----------
( MB7BROKER.default ) Java exception: ''java.lang.NullPointerException''; thrown from class name: ''com.bankofny.plugins.PassMessageNode'', method name: ''evaluate'', file: ''PassMessageNode.java'', line: '42'
and then 42nd line is,
MbElement esb = var.createElementAsFirstChild(MbElement.TYPE_NAME, "ESB", null);
My intention is to create something like, Environment.Variables.ESB.LogText = 'XYZ'; which should be propagated out.
Please help me out, what I am missing in the implementation |
|
Back to top |
|
 |
fjb_saper |
Posted: Fri Oct 21, 2011 7:33 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
Quote: |
Code: |
and then 42nd line is,
MbElement esb = var.createElementAsFirstChild(MbElement.TYPE_NAME, "ESB", null);
|
|
My understanding you really meant the type to be NAME_VALUE. As a name type only, wouldn't passing null mean you delete the element just after creating it?
Have you tried passing it an empty string, instead of null?
Are you sure that the offending line is not this one?
Code: |
esb = esb.getFirstElementByPath("ESB"); |
Wouldn't that be looking for .....ESB.ESB (ESB as the first occurrence of a child of tag ESB) and as such return null (not found)? _________________ MQ & Broker admin |
|
Back to top |
|
 |
vininx |
Posted: Fri Oct 21, 2011 9:26 am Post subject: Getting null while accessing UDP in JCN impl |
|
|
Acolyte
Joined: 13 Oct 2009 Posts: 69
|
Hi...
I have corrected the second problem putting like,
Code: |
globEnv.getRootElement().createElementAsFirstChild(MbElement.TYPE_NAME, "Variables", "").
createElementAsFirstChild(MbElement.TYPE_NAME, "ESB", "").
createElementAsFirstChild(MbElement.TYPE_NAME_VALUE, "LogText", "MyValue"); |
It is working fine now.
But still I am facing issue with accessing User defined node's UDP. The getUserDefinedAttribute method is returning null. I have defined the UDP in the User defined node, promoted it across the flow to configure in BAR file and then accessed it via java implementation. Please let me know whether I am missing anything while accessing the user defined properties. |
|
Back to top |
|
 |
vininx |
Posted: Fri Oct 21, 2011 10:18 am Post subject: Getting null while accessing UDP in JCN impl |
|
|
Acolyte
Joined: 13 Oct 2009 Posts: 69
|
please confirm whether I need to access the UDP's in the constructor or in onInitialize() method. I have read that it can be done by onInitialize() method, but I am only getting null values. |
|
Back to top |
|
 |
Gaya3 |
Posted: Fri Oct 21, 2011 10:29 am Post subject: Re: Getting null while accessing UDP in JCN impl |
|
|
 Jedi
Joined: 12 Sep 2006 Posts: 2493 Location: Boston, US
|
vininx wrote: |
please confirm whether I need to access the UDP's in the constructor or in onInitialize() method. I have read that it can be done by onInitialize() method, but I am only getting null values. |
use localEnvironment to store the values, and try to fetch it will work. _________________ Regards
Gayathri
-----------------------------------------------
Do Something Before you Die |
|
Back to top |
|
 |
vininx |
Posted: Fri Oct 21, 2011 10:35 am Post subject: Getting null while accessing UDP in JCN impl |
|
|
Acolyte
Joined: 13 Oct 2009 Posts: 69
|
Hi Gayathri,
There is a need for me to keep the variables as user defined nodes and access it at run time. How the variables can be kept in localEnvironment Tree... please elaborate.... |
|
Back to top |
|
 |
vininx |
Posted: Fri Oct 21, 2011 10:37 am Post subject: Getting null while accessing UDP in JCN impl |
|
|
Acolyte
Joined: 13 Oct 2009 Posts: 69
|
Sorry... a small typo... There is a need for me to keep variables as user defined properties.... |
|
Back to top |
|
 |
mqjeff |
Posted: Fri Oct 21, 2011 10:39 am Post subject: Re: Getting null while accessing UDP in JCN impl |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
vininx wrote: |
Hi Gayathri,
There is a need for me to keep the variables as user defined nodes and access it at run time. How the variables can be kept in localEnvironment Tree... please elaborate.... |
You are still apparently trying to populate the contents of UDPs into the Environment tree that will then be read by a common subflow further downstream.
This is an extra, unnecessary, step that is requiring you to create an extra, unnecessary user-defined node.
There is nothing about the use of User Defined Properties that requires that you create a user defined node. There is nothing that prevents any flow from declaring and accessing User Defined Properties directly. There is nothing that makes the properties of a user defined node any more customizable than normal User Defined Properties.
You do not need to define a user defined node if you want to expose properties that can be set in the runtime. You can define User Defined Properties. |
|
Back to top |
|
 |
Gaya3 |
Posted: Fri Oct 21, 2011 10:47 am Post subject: Re: Getting null while accessing UDP in JCN impl |
|
|
 Jedi
Joined: 12 Sep 2006 Posts: 2493 Location: Boston, US
|
vininx wrote: |
Hi Gayathri,
There is a need for me to keep the variables as user defined nodes and access it at run time. How the variables can be kept in localEnvironment Tree... please elaborate.... |
a small conversation happened before in this forum
http://www.mqseries.net/phpBB2/viewtopic.php?p=260404&sid=434349308f63e2b3760c48c2bd80226b
you have to use LocalEnv to make use of UDP _________________ Regards
Gayathri
-----------------------------------------------
Do Something Before you Die |
|
Back to top |
|
 |
Gaya3 |
Posted: Fri Oct 21, 2011 10:49 am Post subject: |
|
|
 Jedi
Joined: 12 Sep 2006 Posts: 2493 Location: Boston, US
|
i still did not understand what you are trying to achieve by this design ?
Let us know what you are looking for _________________ Regards
Gayathri
-----------------------------------------------
Do Something Before you Die |
|
Back to top |
|
 |
fjb_saper |
Posted: Fri Oct 21, 2011 10:55 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
|
Back to top |
|
 |
Esa |
Posted: Mon Oct 24, 2011 4:14 am Post subject: |
|
|
 Grand Master
Joined: 22 May 2008 Posts: 1387 Location: Finland
|
fjb_saper wrote: |
As per the examples in the JAVA API (infocenter), this is how you get UDP's in Java:
Code: |
MessageFlow mf1 = patternInstanceManager.getMessageFlow("MyFlowProject", "main.msgflow");
Vector<FlowProperty> flowProperties = mf1.getFlowProperties(); |
|
I think this is quite a misleading code snippet as it is from the new Java API for user defined patterns. For developing ordinary JCN:s you would use the MbNode method getUserDefinedAttribute.
The OP's problem is that he or she is calling the method from onInitialize(). That method is called upon deployment and the UDP:s propably won't be available yet. Anything you put in LocalEnvironment in onInitialize() will not be available when processing the actual messages, and trying to access LocalEnvironment will also give a nullPointerException (I am not sure of it as it has never crossed my mind to try such a bad idea ). Implementing a cache for UDP:s does not make any sense as there is no overhead in calling getUserDefinedAttribute. And LocalEnvironment is definitely not the place for implementing any cache as anyone who has read the manuals can tell. |
|
Back to top |
|
 |
mqjeff |
Posted: Mon Oct 24, 2011 4:30 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
Esa wrote: |
The OP's problem is that he or she is calling the method from onInitialize(). |
More generally, the OP seems to be confusing User Defined Properties and node properties, and trying to access node properties as if they were User Defined Properties.
Node properties need to be defined as member variables and have appropriately named getters and setters defined on the node, and then can be accessed as member variables or using the getters during evaluate() without needing to do anything special in onInitialize().
User Defined properties require no special considerations when defining the class, but merely require being accessed by the getUserDefinedAttribute method.
And, again, there's no specific need to create a new node just to define or access User Defined Properties. |
|
Back to top |
|
 |
|