@Test public void testTransformBody() { Message msg = new DefaultMessage(); msg.setBody(null); assertThat(transformBody(msg), is("")); msg = new DefaultMessage(); msg.setBody("text"); assertThat(transformBody(msg), is("text")); byte[] byteBody = {(byte) 0xe0, 0x4f, (byte) 0xd0, 0x20}; msg.setBody(byteBody); assertThat(transformBody(msg), is(Hex.encodeHexString(byteBody))); org.cleverbus.api.entity.Message entity = new org.cleverbus.api.entity.Message(); entity.setMsgId(1L); entity.setCorrelationId(UUID.randomUUID().toString()); msg.setBody(entity); assertThat(transformBody(msg), is(entity.toHumanString())); byteBody = "<test>valueč</test>".getBytes(); msg.setBody(byteBody); assertThat(transformBody(msg), is("<test>valueč</test>")); }
public static String transformBody(Message obj) { if (obj.getBody() == null) { return ""; } if (obj.getBody() instanceof String) { return (String) obj.getBody(); } else if (obj.getBody() instanceof byte[]) { String result = obj.getBody(String.class) == null ? new String((byte[]) obj.getBody()) : obj.getBody(String.class); if (result != null && result.trim().length() > 0 && result.trim().startsWith("<") && result.trim().endsWith(">")) { return result.trim(); } return Hex.encodeHexString((byte[]) obj.getBody()); } else if (obj.getBody() instanceof HumanReadable) { return ((HumanReadable) obj.getBody()).toHumanString(); } else { return obj.getBody(String.class); } }
RequestResponseUtils { public static String transformBody(Message obj) { if (obj.getBody() == null) { return ""; } if (obj.getBody() instanceof String) { return (String) obj.getBody(); } else if (obj.getBody() instanceof byte[]) { String result = obj.getBody(String.class) == null ? new String((byte[]) obj.getBody()) : obj.getBody(String.class); if (result != null && result.trim().length() > 0 && result.trim().startsWith("<") && result.trim().endsWith(">")) { return result.trim(); } return Hex.encodeHexString((byte[]) obj.getBody()); } else if (obj.getBody() instanceof HumanReadable) { return ((HumanReadable) obj.getBody()).toHumanString(); } else { return obj.getBody(String.class); } } }
RequestResponseUtils { public static String transformBody(Message obj) { if (obj.getBody() == null) { return ""; } if (obj.getBody() instanceof String) { return (String) obj.getBody(); } else if (obj.getBody() instanceof byte[]) { String result = obj.getBody(String.class) == null ? new String((byte[]) obj.getBody()) : obj.getBody(String.class); if (result != null && result.trim().length() > 0 && result.trim().startsWith("<") && result.trim().endsWith(">")) { return result.trim(); } return Hex.encodeHexString((byte[]) obj.getBody()); } else if (obj.getBody() instanceof HumanReadable) { return ((HumanReadable) obj.getBody()).toHumanString(); } else { return obj.getBody(String.class); } } private  RequestResponseUtils(); }
RequestResponseUtils { public static String transformBody(Message obj) { if (obj.getBody() == null) { return ""; } if (obj.getBody() instanceof String) { return (String) obj.getBody(); } else if (obj.getBody() instanceof byte[]) { String result = obj.getBody(String.class) == null ? new String((byte[]) obj.getBody()) : obj.getBody(String.class); if (result != null && result.trim().length() > 0 && result.trim().startsWith("<") && result.trim().endsWith(">")) { return result.trim(); } return Hex.encodeHexString((byte[]) obj.getBody()); } else if (obj.getBody() instanceof HumanReadable) { return ((HumanReadable) obj.getBody()).toHumanString(); } else { return obj.getBody(String.class); } } private  RequestResponseUtils(); static String transformBody(Message obj); }
RequestResponseUtils { public static String transformBody(Message obj) { if (obj.getBody() == null) { return ""; } if (obj.getBody() instanceof String) { return (String) obj.getBody(); } else if (obj.getBody() instanceof byte[]) { String result = obj.getBody(String.class) == null ? new String((byte[]) obj.getBody()) : obj.getBody(String.class); if (result != null && result.trim().length() > 0 && result.trim().startsWith("<") && result.trim().endsWith(">")) { return result.trim(); } return Hex.encodeHexString((byte[]) obj.getBody()); } else if (obj.getBody() instanceof HumanReadable) { return ((HumanReadable) obj.getBody()).toHumanString(); } else { return obj.getBody(String.class); } } private  RequestResponseUtils(); static String transformBody(Message obj);  }