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

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"));

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.
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", .... )

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?
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.


Talend named a Leader.

Get your copy


Kickstart your first data integration and ETL projects.

Download now

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables


How Media Organizations Achieved Success with Data Integration

Learn how media organizations have achieved success with Data Integration


6 Ways to Start Utilizing Machine Learning with Amazon We Services and Talend

Look at6 ways to start utilizing Machine Learning with Amazon We Services and Talend