@Test public void testToIdObjectWithStringContainingBinaryHexThrowsICEWithNonHexCharacters() { char nonHexChar = '/'; String nonHexString = AmqpMessageIdHelper.JMS_ID_PREFIX + AmqpMessageIdHelper.AMQP_BINARY_PREFIX + nonHexChar + nonHexChar; try { AmqpMessageIdHelper.toIdObject(nonHexString); fail("expected exception was not thrown"); } catch (IdConversionException ice) { String msg = ice.getCause().getMessage(); assertTrue("Message was not as expected: " + msg, msg.contains("non-hex")); } nonHexChar = ':'; nonHexString = AmqpMessageIdHelper.JMS_ID_PREFIX + AmqpMessageIdHelper.AMQP_BINARY_PREFIX + nonHexChar + nonHexChar; try { AmqpMessageIdHelper.toIdObject(nonHexString); fail("expected exception was not thrown"); } catch (IdConversionException ice) { String msg = ice.getCause().getMessage(); assertTrue("Message was not as expected: " + msg, msg.contains("non-hex")); } nonHexChar = 'G'; nonHexString = AmqpMessageIdHelper.JMS_ID_PREFIX + AmqpMessageIdHelper.AMQP_BINARY_PREFIX + nonHexChar + nonHexChar; try { AmqpMessageIdHelper.toIdObject(nonHexString); fail("expected exception was not thrown"); } catch (IdConversionException ice) { String msg = ice.getCause().getMessage(); assertTrue("Message was not as expected: " + msg, msg.contains("non-hex")); } nonHexChar = 'g'; nonHexString = AmqpMessageIdHelper.JMS_ID_PREFIX + AmqpMessageIdHelper.AMQP_BINARY_PREFIX + nonHexChar + nonHexChar; try { AmqpMessageIdHelper.toIdObject(nonHexString); fail("expected exception was not thrown"); } catch (IdConversionException ice) { String msg = ice.getCause().getMessage(); assertTrue("Message was not as expected: " + msg, msg.contains("non-hex")); } }
public static Object toIdObject(final String origId) throws IdConversionException { if (origId == null) { return null; } if (!AmqpMessageIdHelper.hasMessageIdPrefix(origId)) { return origId; } try { if (hasAmqpNoPrefix(origId, JMS_ID_PREFIX_LENGTH)) { return origId.substring(JMS_ID_PREFIX_LENGTH + AMQP_NO_PREFIX_LENGTH); } else if (hasAmqpUuidPrefix(origId, JMS_ID_PREFIX_LENGTH)) { String uuidString = origId.substring(JMS_ID_PREFIX_LENGTH + AMQP_UUID_PREFIX_LENGTH); return UUID.fromString(uuidString); } else if (hasAmqpUlongPrefix(origId, JMS_ID_PREFIX_LENGTH)) { String ulongString = origId.substring(JMS_ID_PREFIX_LENGTH + AMQP_ULONG_PREFIX_LENGTH); return UnsignedLong.valueOf(ulongString); } else if (hasAmqpStringPrefix(origId, JMS_ID_PREFIX_LENGTH)) { return origId.substring(JMS_ID_PREFIX_LENGTH + AMQP_STRING_PREFIX_LENGTH); } else if (hasAmqpBinaryPrefix(origId, JMS_ID_PREFIX_LENGTH)) { String hexString = origId.substring(JMS_ID_PREFIX_LENGTH + AMQP_BINARY_PREFIX_LENGTH); byte[] bytes = convertHexStringToBinary(hexString); return new Binary(bytes); } else { return origId; } } catch (IllegalArgumentException e) { throw new IdConversionException("Unable to convert ID value", e); } }
AmqpMessageIdHelper { public static Object toIdObject(final String origId) throws IdConversionException { if (origId == null) { return null; } if (!AmqpMessageIdHelper.hasMessageIdPrefix(origId)) { return origId; } try { if (hasAmqpNoPrefix(origId, JMS_ID_PREFIX_LENGTH)) { return origId.substring(JMS_ID_PREFIX_LENGTH + AMQP_NO_PREFIX_LENGTH); } else if (hasAmqpUuidPrefix(origId, JMS_ID_PREFIX_LENGTH)) { String uuidString = origId.substring(JMS_ID_PREFIX_LENGTH + AMQP_UUID_PREFIX_LENGTH); return UUID.fromString(uuidString); } else if (hasAmqpUlongPrefix(origId, JMS_ID_PREFIX_LENGTH)) { String ulongString = origId.substring(JMS_ID_PREFIX_LENGTH + AMQP_ULONG_PREFIX_LENGTH); return UnsignedLong.valueOf(ulongString); } else if (hasAmqpStringPrefix(origId, JMS_ID_PREFIX_LENGTH)) { return origId.substring(JMS_ID_PREFIX_LENGTH + AMQP_STRING_PREFIX_LENGTH); } else if (hasAmqpBinaryPrefix(origId, JMS_ID_PREFIX_LENGTH)) { String hexString = origId.substring(JMS_ID_PREFIX_LENGTH + AMQP_BINARY_PREFIX_LENGTH); byte[] bytes = convertHexStringToBinary(hexString); return new Binary(bytes); } else { return origId; } } catch (IllegalArgumentException e) { throw new IdConversionException("Unable to convert ID value", e); } } }
AmqpMessageIdHelper { public static Object toIdObject(final String origId) throws IdConversionException { if (origId == null) { return null; } if (!AmqpMessageIdHelper.hasMessageIdPrefix(origId)) { return origId; } try { if (hasAmqpNoPrefix(origId, JMS_ID_PREFIX_LENGTH)) { return origId.substring(JMS_ID_PREFIX_LENGTH + AMQP_NO_PREFIX_LENGTH); } else if (hasAmqpUuidPrefix(origId, JMS_ID_PREFIX_LENGTH)) { String uuidString = origId.substring(JMS_ID_PREFIX_LENGTH + AMQP_UUID_PREFIX_LENGTH); return UUID.fromString(uuidString); } else if (hasAmqpUlongPrefix(origId, JMS_ID_PREFIX_LENGTH)) { String ulongString = origId.substring(JMS_ID_PREFIX_LENGTH + AMQP_ULONG_PREFIX_LENGTH); return UnsignedLong.valueOf(ulongString); } else if (hasAmqpStringPrefix(origId, JMS_ID_PREFIX_LENGTH)) { return origId.substring(JMS_ID_PREFIX_LENGTH + AMQP_STRING_PREFIX_LENGTH); } else if (hasAmqpBinaryPrefix(origId, JMS_ID_PREFIX_LENGTH)) { String hexString = origId.substring(JMS_ID_PREFIX_LENGTH + AMQP_BINARY_PREFIX_LENGTH); byte[] bytes = convertHexStringToBinary(hexString); return new Binary(bytes); } else { return origId; } } catch (IllegalArgumentException e) { throw new IdConversionException("Unable to convert ID value", e); } }  }
AmqpMessageIdHelper { public static Object toIdObject(final String origId) throws IdConversionException { if (origId == null) { return null; } if (!AmqpMessageIdHelper.hasMessageIdPrefix(origId)) { return origId; } try { if (hasAmqpNoPrefix(origId, JMS_ID_PREFIX_LENGTH)) { return origId.substring(JMS_ID_PREFIX_LENGTH + AMQP_NO_PREFIX_LENGTH); } else if (hasAmqpUuidPrefix(origId, JMS_ID_PREFIX_LENGTH)) { String uuidString = origId.substring(JMS_ID_PREFIX_LENGTH + AMQP_UUID_PREFIX_LENGTH); return UUID.fromString(uuidString); } else if (hasAmqpUlongPrefix(origId, JMS_ID_PREFIX_LENGTH)) { String ulongString = origId.substring(JMS_ID_PREFIX_LENGTH + AMQP_ULONG_PREFIX_LENGTH); return UnsignedLong.valueOf(ulongString); } else if (hasAmqpStringPrefix(origId, JMS_ID_PREFIX_LENGTH)) { return origId.substring(JMS_ID_PREFIX_LENGTH + AMQP_STRING_PREFIX_LENGTH); } else if (hasAmqpBinaryPrefix(origId, JMS_ID_PREFIX_LENGTH)) { String hexString = origId.substring(JMS_ID_PREFIX_LENGTH + AMQP_BINARY_PREFIX_LENGTH); byte[] bytes = convertHexStringToBinary(hexString); return new Binary(bytes); } else { return origId; } } catch (IllegalArgumentException e) { throw new IdConversionException("Unable to convert ID value", e); } }  static boolean hasMessageIdPrefix(String string); static String toMessageIdString(Object idObject); static String toCorrelationIdString(Object idObject); static Object toIdObject(final String origId); static byte[] convertHexStringToBinary(String hexString); static String convertBinaryToHexString(byte[] bytes); }
AmqpMessageIdHelper { public static Object toIdObject(final String origId) throws IdConversionException { if (origId == null) { return null; } if (!AmqpMessageIdHelper.hasMessageIdPrefix(origId)) { return origId; } try { if (hasAmqpNoPrefix(origId, JMS_ID_PREFIX_LENGTH)) { return origId.substring(JMS_ID_PREFIX_LENGTH + AMQP_NO_PREFIX_LENGTH); } else if (hasAmqpUuidPrefix(origId, JMS_ID_PREFIX_LENGTH)) { String uuidString = origId.substring(JMS_ID_PREFIX_LENGTH + AMQP_UUID_PREFIX_LENGTH); return UUID.fromString(uuidString); } else if (hasAmqpUlongPrefix(origId, JMS_ID_PREFIX_LENGTH)) { String ulongString = origId.substring(JMS_ID_PREFIX_LENGTH + AMQP_ULONG_PREFIX_LENGTH); return UnsignedLong.valueOf(ulongString); } else if (hasAmqpStringPrefix(origId, JMS_ID_PREFIX_LENGTH)) { return origId.substring(JMS_ID_PREFIX_LENGTH + AMQP_STRING_PREFIX_LENGTH); } else if (hasAmqpBinaryPrefix(origId, JMS_ID_PREFIX_LENGTH)) { String hexString = origId.substring(JMS_ID_PREFIX_LENGTH + AMQP_BINARY_PREFIX_LENGTH); byte[] bytes = convertHexStringToBinary(hexString); return new Binary(bytes); } else { return origId; } } catch (IllegalArgumentException e) { throw new IdConversionException("Unable to convert ID value", e); } }  static boolean hasMessageIdPrefix(String string); static String toMessageIdString(Object idObject); static String toCorrelationIdString(Object idObject); static Object toIdObject(final String origId); static byte[] convertHexStringToBinary(String hexString); static String convertBinaryToHexString(byte[] bytes); static final String AMQP_STRING_PREFIX; static final String AMQP_UUID_PREFIX; static final String AMQP_ULONG_PREFIX; static final String AMQP_BINARY_PREFIX; static final String AMQP_NO_PREFIX; static final String JMS_ID_PREFIX; }