context.propertyName and context.setProperty("propertyName", .... )

Highlighted
One Star

context.propertyName and context.setProperty("propertyName", .... )

Shortly, I am trying to get the context variable name as string input and setting the context variable with a new value.
My problem is basicly;
context.setProperty("contextVariableName", "some value");
System.out.println( context.getProperty("contextVariableName"));
Works.

context.setProperty("contextVariableName", "some value");
System.out.println( context.contextVariableName);
I expect to get "some value". But nothing returns.
Four Stars

Re: context.propertyName and context.setProperty("propertyName", .... )

What is the default value set for context.contextVariableName?
Usually it is null when you create a context variable.
Vaibhav
One Star

Re: context.propertyName and context.setProperty("propertyName", .... )

When i execute this line;
context.setProperty("contextVariableName", "some value");
I am expecting that context.contextVariableName will be set as "some value".
Is this wrong ?
Four Stars

Re: context.propertyName and context.setProperty("propertyName", .... )

Hi,
>>
context.contextVariableName
Above is not a part of your routine. This is called from context, where default value assigned is null, so it won't return anything.
I am not sure why and how you are combining context variable with the routine. Getter setter routines are usually designed to set the value and get the values.
Context variables are also a type of variable which can be used to set the value and get the value.
globalMap.set("yourvariable","value") is a routine to set the value
globalMap.get("yourvariable") is a routine to get the value assigned by above variable
context.yourvariable is defined in your job level context
value is assigned to it say context.yourvariable =="value"
This can simple called by assigning its value to your output.
What is actual scenario?
Vaibhav
One Star

Re: context.propertyName and context.setProperty("propertyName", .... )

We have some talend jobs to simply transfer a data from one db to another.
We also need to hide password as plain text.
I created a user component. It has one input, the context variable name.
User of component is supposed to set the context variable value with encrypted text initial.
In java code, I can successfully get the context variable value with the given string "context variable name" as input.
And i can decrypt it.
After that i am trying to set the same context variable value with decrypted password, so it will be used on connection credentials.

Suppose that the input of component is "DbPassword". I am also creating a context variable named "DbPassword" and can access that variable' value as context.DbPassword.
The weird thing is when i use:
//contextParamName is set with component parameter getters.
String cipherText = (String)context.getProperty(contextParamName);
I am getting the exact value of context.DbPassword which is something like "bK9MAg6CbQsfat2f56jQQA=="
But when i use:
//plainText has the value of is encrypted password.
context.setProperty(contextParamName, plainText);
I see context.DbPassword is still "bK9MAg6CbQsfat2f56jQQA==".
And how can i reach context.DbPassword with context.getProperty("DbPassword ");
but i can't set the same variable with context.setProperty("DbPassword ", plainText);
Edit: I forgot to say I am very new to Talend.