iso8583multiplexingjpos

How to read jpos QMUX key field programmatically?


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];
        }


Solution

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