Skip to content

Instantly share code, notes, and snippets.

@CAFxX
Created August 31, 2012 12:25
Show Gist options
  • Save CAFxX/3552140 to your computer and use it in GitHub Desktop.
Save CAFxX/3552140 to your computer and use it in GitHub Desktop.
Convert IBM Websphere MQ reason codes to their human-readable description string
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import com.ibm.mq.constants.CMQC;
public class MQReasonCodes {
/* Use reflection on the CMQC class to fetch a human readable description of the
MQ reason code (e.g. getReason(2035) will return "MQRC_NOT_AUTHORIZED"). If the
reason code rc is not found, null will be returned */
public static String getReason(int rc) {
for (Field f: CMQC.class.getDeclaredFields()) try {
if (Modifier.isStatic(f.getModifiers()) && f.getType() == int.class
&& f.getName().startsWith("MQRC") && f.getInt(null) == rc)
return f.getName();
} catch (Exception e) { }
return null;
}
}
@ricostrydom
Copy link

Thanks for snippet. It helped me a lot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment