@Test public void testGetTextWithUnknownEncodedDataThrowsJMSException() throws Exception { String encodedString = "myEncodedString"; byte[] encodedBytes = encodedString.getBytes(Charset.forName("UTF-16")); Message message = Message.Factory.create(); message.setBody(new Data(new Binary(encodedBytes))); AmqpJmsTextMessageFacade amqpTextMessageFacade = createReceivedTextMessageFacade(createMockAmqpConsumer(), message); try { amqpTextMessageFacade.getText(); fail("expected exception not thrown"); } catch (JMSException ise) { } }
@Override public String getText() throws JMSException { Section body = getBody(); if (body == null) { return null; } else if (body instanceof Data) { Data data = (Data) body; if (data.getValue() == null || data.getValue().getLength() == 0) { return ""; } else { Binary b = data.getValue(); ByteBuffer buf = ByteBuffer.wrap(b.getArray(), b.getArrayOffset(), b.getLength()); try { CharBuffer chars = charset.newDecoder().decode(buf); return String.valueOf(chars); } catch (CharacterCodingException e) { throw JmsExceptionSupport.create("Cannot decode String in " + charset.displayName(), e); } } } else if (body instanceof AmqpValue) { Object value = ((AmqpValue) body).getValue(); if (value == null || value instanceof String) { return (String) value; } else { throw new IllegalStateException("Unexpected amqp-value body content type: " + value.getClass().getSimpleName()); } } else { throw new IllegalStateException("Unexpected message body type: " + body.getClass().getSimpleName()); } }
AmqpJmsTextMessageFacade extends AmqpJmsMessageFacade implements JmsTextMessageFacade { @Override public String getText() throws JMSException { Section body = getBody(); if (body == null) { return null; } else if (body instanceof Data) { Data data = (Data) body; if (data.getValue() == null || data.getValue().getLength() == 0) { return ""; } else { Binary b = data.getValue(); ByteBuffer buf = ByteBuffer.wrap(b.getArray(), b.getArrayOffset(), b.getLength()); try { CharBuffer chars = charset.newDecoder().decode(buf); return String.valueOf(chars); } catch (CharacterCodingException e) { throw JmsExceptionSupport.create("Cannot decode String in " + charset.displayName(), e); } } } else if (body instanceof AmqpValue) { Object value = ((AmqpValue) body).getValue(); if (value == null || value instanceof String) { return (String) value; } else { throw new IllegalStateException("Unexpected amqp-value body content type: " + value.getClass().getSimpleName()); } } else { throw new IllegalStateException("Unexpected message body type: " + body.getClass().getSimpleName()); } } }
AmqpJmsTextMessageFacade extends AmqpJmsMessageFacade implements JmsTextMessageFacade { @Override public String getText() throws JMSException { Section body = getBody(); if (body == null) { return null; } else if (body instanceof Data) { Data data = (Data) body; if (data.getValue() == null || data.getValue().getLength() == 0) { return ""; } else { Binary b = data.getValue(); ByteBuffer buf = ByteBuffer.wrap(b.getArray(), b.getArrayOffset(), b.getLength()); try { CharBuffer chars = charset.newDecoder().decode(buf); return String.valueOf(chars); } catch (CharacterCodingException e) { throw JmsExceptionSupport.create("Cannot decode String in " + charset.displayName(), e); } } } else if (body instanceof AmqpValue) { Object value = ((AmqpValue) body).getValue(); if (value == null || value instanceof String) { return (String) value; } else { throw new IllegalStateException("Unexpected amqp-value body content type: " + value.getClass().getSimpleName()); } } else { throw new IllegalStateException("Unexpected message body type: " + body.getClass().getSimpleName()); } } AmqpJmsTextMessageFacade();   AmqpJmsTextMessageFacade(Charset charset); }
AmqpJmsTextMessageFacade extends AmqpJmsMessageFacade implements JmsTextMessageFacade { @Override public String getText() throws JMSException { Section body = getBody(); if (body == null) { return null; } else if (body instanceof Data) { Data data = (Data) body; if (data.getValue() == null || data.getValue().getLength() == 0) { return ""; } else { Binary b = data.getValue(); ByteBuffer buf = ByteBuffer.wrap(b.getArray(), b.getArrayOffset(), b.getLength()); try { CharBuffer chars = charset.newDecoder().decode(buf); return String.valueOf(chars); } catch (CharacterCodingException e) { throw JmsExceptionSupport.create("Cannot decode String in " + charset.displayName(), e); } } } else if (body instanceof AmqpValue) { Object value = ((AmqpValue) body).getValue(); if (value == null || value instanceof String) { return (String) value; } else { throw new IllegalStateException("Unexpected amqp-value body content type: " + value.getClass().getSimpleName()); } } else { throw new IllegalStateException("Unexpected message body type: " + body.getClass().getSimpleName()); } } AmqpJmsTextMessageFacade();   AmqpJmsTextMessageFacade(Charset charset); @Override byte getJmsMsgType(); @Override AmqpJmsTextMessageFacade copy(); @Override String getText(); @Override void setText(String value); @Override void clearBody(); @Override boolean hasBody(); @Override JmsTextMessage asJmsMessage(); }
AmqpJmsTextMessageFacade extends AmqpJmsMessageFacade implements JmsTextMessageFacade { @Override public String getText() throws JMSException { Section body = getBody(); if (body == null) { return null; } else if (body instanceof Data) { Data data = (Data) body; if (data.getValue() == null || data.getValue().getLength() == 0) { return ""; } else { Binary b = data.getValue(); ByteBuffer buf = ByteBuffer.wrap(b.getArray(), b.getArrayOffset(), b.getLength()); try { CharBuffer chars = charset.newDecoder().decode(buf); return String.valueOf(chars); } catch (CharacterCodingException e) { throw JmsExceptionSupport.create("Cannot decode String in " + charset.displayName(), e); } } } else if (body instanceof AmqpValue) { Object value = ((AmqpValue) body).getValue(); if (value == null || value instanceof String) { return (String) value; } else { throw new IllegalStateException("Unexpected amqp-value body content type: " + value.getClass().getSimpleName()); } } else { throw new IllegalStateException("Unexpected message body type: " + body.getClass().getSimpleName()); } } AmqpJmsTextMessageFacade();   AmqpJmsTextMessageFacade(Charset charset); @Override byte getJmsMsgType(); @Override AmqpJmsTextMessageFacade copy(); @Override String getText(); @Override void setText(String value); @Override void clearBody(); @Override boolean hasBody(); @Override JmsTextMessage asJmsMessage();  }