Reputation: 437
For some reason, I want to read the key I have set inside the QMUX config file (20_client_mux.xml) with <key>37</key>
.I could not find any way from jpos itself, so I am using the below code to get things done. I want to do it without using Reflection and I am happy if there is no need for creating a subclass extending either QMUX
or XMLConfigurable
.
import org.springframework.util.ReflectionUtils;
private static String getUniqueFieldId() {
final String[][] key = {new String[1]};
ReflectionUtils.doWithFields(QMUX.class, field -> {
if (field.getName().equals("key")) {
field.setAccessible(true);
key[0] = (String[]) field.get(mux);
}
});
return key[0][0];
}
Upvotes: 3
Views: 214
Reputation: 437
After all, I was able to access the keys through a short and single line of code and there is no need to create a new class just for this purpose.
mux.getPersist().getChildTextTrim("key");
Upvotes: 5
Reputation: 1343
You can extend QMUX, implement XMLConfigurable
and call getChildTextTrim("key")
on the XML Element. Remember of course to call super.setXmlConfiguration
.
Relevant code is at QMUX lines 78-87:
key = toStringArray(DEFAULT_KEY, ", ", null);
returnRejects = cfg.getBoolean("return-rejects", false);
for (Element keyElement : e.getChildren("key")) {
String mtiOverride = QFactory.getAttributeValue(keyElement, "mti");
if (mtiOverride != null && mtiOverride.length() >= 2) {
mtiKey.put (mtiOverride.substring(0,2), toStringArray(keyElement.getTextTrim(), ", ", null));
} else {
key = toStringArray(e.getChildTextTrim("key"), ", ", DEFAULT_KEY);
}
}
Upvotes: 1
Reputation: 1865
You can extend QMUX and add a public getKey()
method, like:
package mypackage;
import org.jpos.q2.iso.QMUX;
public class MyQMUX extends QMUX {
public String[] getKey() {
return key;
}
}
Then in the xml deploy descriptor use your QMUX
implementation:
<mux class="mypackage.MyQMUX" ...>
...
</mux>
Upvotes: 0