Search in sources :

Example 1 with MQDataException

use of com.ibm.mq.headers.MQDataException in project irontest by zheng-wang.

the class MQTeststepRunner method buildMessageFromFile.

private MQMessage buildMessageFromFile(byte[] bytes) throws MQDataException, IOException {
    MQMessage message = new MQMessage();
    MQMD mqmdHeader = null;
    try {
        mqmdHeader = new MQMD(new DataInputStream(new ByteArrayInputStream(bytes)), CMQC.MQENC_REVERSED, CMQC.MQCCSI_DEFAULT);
    } catch (Exception e) {
        LOGGER.info("Not able to construct MQMD out of the bytes. Exception details: ", e);
        mqmdHeader = null;
    }
    if (mqmdHeader != null && CMQC.MQMD_STRUC_ID.equals(mqmdHeader.getStrucId()) && (CMQC.MQMD_VERSION_1 == mqmdHeader.getVersion() || CMQC.MQMD_VERSION_2 == mqmdHeader.getVersion())) {
        LOGGER.info("MQMD constructed. Writing other bytes as application data.");
        message.putDateTime = new GregorianCalendar();
        mqmdHeader.copyTo(message);
        message.persistence = CMQC.MQPER_PERSISTENT;
        message.write(bytes, MQMD.SIZE2, bytes.length - MQMD.SIZE2);
    } else {
        LOGGER.info("No valid MQMD. Writing all bytes as application data.");
        message.write(bytes);
    }
    return message;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) GregorianCalendar(java.util.GregorianCalendar) DataInputStream(java.io.DataInputStream) MQDataException(com.ibm.mq.headers.MQDataException) IOException(java.io.IOException) MQMD(com.ibm.mq.headers.MQMD)

Aggregations

MQDataException (com.ibm.mq.headers.MQDataException)1 MQMD (com.ibm.mq.headers.MQMD)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 DataInputStream (java.io.DataInputStream)1 IOException (java.io.IOException)1 GregorianCalendar (java.util.GregorianCalendar)1