Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
We use a framework that reads context variables from a database table at the beginning of a job. The framework also prints out the context variables, but masks any defined as "Password".
This is fine, as long as every job contains all of the context variables. However, if a job reads a context set but does not have a particular context variable defined, it gets printed out in plain text.
For instance, lets say I have several jobs that all use the same context set. I add "SFTP_Password" to one of them, define it as a password, and add a value to the database. Now, when I run any of the other jobs that have not had "SFTP_Password" added to them (because they do not need the SFTP password), the password is printed out in plain text in the job log.
The framework runs by feeding the values in from a tMySqlInput component to a tContextLoad, and then a tContextDump prints them out. I would have thought that the extraneous values would be ignored by the tContextLoad, because there is nowhere in the context object to put them, but that is not the case. The context is expanded to hold all the values, and they then get printed out later on.
Is there any way to prevent the nonexistent context variables from being added to the context?
For instance, if you had a context variable in your job called "dir_bulk", then in a tJava you could:
String myVar = "dir_bulk";
java.lang.reflect.Field field = context.getClass().getField(myVar);
System.out.println(field.getName());
System.out.println(String.valueOf(field.get(context)));
This would print the variable name and the default value.
EDIT: You can also set your context values using:
field.set(context, "some new value");
Then you could set your values without using the tContext component (if you wanted).
Maybe you could use a tjava row to filter before sending to tContextLoad? You could try to read the default value for each variable from your job's context in a try{} block, and if the variable doesn't exist you can skip it.
How would I read the default value?
For instance, if you had a context variable in your job called "dir_bulk", then in a tJava you could:
String myVar = "dir_bulk";
java.lang.reflect.Field field = context.getClass().getField(myVar);
System.out.println(field.getName());
System.out.println(String.valueOf(field.get(context)));
This would print the variable name and the default value.
EDIT: You can also set your context values using:
field.set(context, "some new value");
Then you could set your values without using the tContext component (if you wanted).
Brilliant thanks! Here's the code I added to a tJavaRow:
output_row.found = true; try { String myVar = input_row.key; java.lang.reflect.Field field = context.getClass().getField(myVar); } catch(java.lang.NoSuchFieldException e) { output_row.found = false; }
That is followed by a tFilterRow with advanced condition of just "row2.found".