/** * Convert a BytesMessage to a Java Object with the specified type. * @param message the input message * @param targetJavaType the target type * @return the message converted to an object * @throws JMSException if thrown by JMS * @throws IOException in case of I/O errors */ protected Object convertFromBytesMessage(BytesMessage message, JavaType targetJavaType) throws JMSException, IOException { String encoding = this.encoding; if (this.encodingPropertyName != null && message.propertyExists(this.encodingPropertyName)) { encoding = message.getStringProperty(this.encodingPropertyName); } byte[] bytes = new byte[(int) message.getBodyLength()]; message.readBytes(bytes); try { String body = new String(bytes, encoding); return this.objectMapper.readValue(body, targetJavaType); } catch (UnsupportedEncodingException ex) { throw new MessageConversionException("Cannot convert bytes to String", ex); } }
@Test public void fromBytesMessage() throws Exception { BytesMessage bytesMessageMock = mock(BytesMessage.class); Map<String, String> unmarshalled = Collections.singletonMap("foo", "bar"); byte[] bytes = "{\"foo\":\"bar\"}".getBytes(); final ByteArrayInputStream byteStream = new ByteArrayInputStream(bytes); given(bytesMessageMock.getStringProperty("__typeid__")).willReturn(Object.class.getName()); given(bytesMessageMock.propertyExists("__encoding__")).willReturn(false); given(bytesMessageMock.getBodyLength()).willReturn(new Long(bytes.length)); given(bytesMessageMock.readBytes(any(byte[].class))).willAnswer( new Answer<Integer>() { @Override public Integer answer(InvocationOnMock invocation) throws Throwable { return byteStream.read((byte[]) invocation.getArguments()[0]); } }); Object result = converter.fromMessage(bytesMessageMock); assertEquals("Invalid result", result, unmarshalled); }
private static org.jboss.narayana.blacktie.jatmibroker.core.transport.Message convertFromBytesMessage(BytesMessage message) throws JMSException { String controlIOR = message.getStringProperty("messagecontrol"); String replyTo = message.getStringProperty("messagereplyto"); int len = (int) message.getBodyLength(); String serviceName = message.getStringProperty("servicename"); int flags = new Integer(message.getStringProperty("messageflags")); int cd = new Integer(message.getStringProperty("messagecorrelationId")); String type = message.getStringProperty("messagetype"); String subtype = message.getStringProperty("messagesubtype"); log.debug("type: " + type + " subtype: " + subtype);
public MailSignedDocumentTaskMessage(Message message) { if (false == message instanceof BytesMessage) { throw new RuntimeException("message should be BytesMessage"); } BytesMessage bytesMessage = (BytesMessage) message; try { this.email = bytesMessage.getStringProperty("email"); this.language = bytesMessage.getStringProperty("language"); this.mimetype = bytesMessage.getStringProperty("mimetype"); int documentLength = (int) bytesMessage.getBodyLength(); this.document = new byte[documentLength]; if (documentLength != bytesMessage.readBytes(this.document)) { throw new JMSException("could not read entire JMS message body"); } } catch (JMSException e) { throw new RuntimeException("JMS error: " + e.getMessage(), e); } }
@Override @SuppressWarnings("rawtypes") public long getCommittedWindowId(String appId, int operatorId) { logger.debug("Getting committed windowId appId {} operatorId {}", appId, operatorId); try { beginTransaction(); BytesMessage message = (BytesMessage)consumer.receive(); logger.debug("Retrieved committed window messageId: {}, messageAppOperatorIdProp: {}", message.getJMSMessageID(), message.getStringProperty(APP_OPERATOR_ID)); long windowId = message.readLong(); writeWindowId(appId, operatorId, windowId); commitTransaction(); logger.debug("metaQueueName: " + metaQueueName); logger.debug("Retrieved windowId {}", windowId); return windowId; } catch (JMSException ex) { throw new RuntimeException(ex); } }
/** * Convert a {@link BytesMessage} to {@link CamelKapuaMessage} * * @param jmsMessage * @throws JMSException * @throws KapuaException */ public static CamelKapuaMessage<?> convertToKapuaMessage(ConnectorDescriptor connectorDescriptor, MessageType messageType, BytesMessage jmsMessage, KapuaId connectionId, String clientId) throws JMSException, KapuaException { String jmsTopic = jmsMessage.getStringProperty(MessageConstants.PROPERTY_ORIGINAL_TOPIC); Date queuedOn = new Date(jmsMessage.getLongProperty(MessageConstants.PROPERTY_ENQUEUED_TIMESTAMP)); return convertToKapuaMessage(connectorDescriptor, connectorDescriptor.getDeviceClass(messageType), connectorDescriptor.getKapuaClass(messageType), jmsMessage, jmsTopic, queuedOn, connectionId, clientId); }
/** * Convert a BytesMessage to a Java Object with the specified type. * @param message the input message * @param targetJavaType the target type * @return the message converted to an object * @throws JMSException if thrown by JMS * @throws IOException in case of I/O errors */ protected Object convertFromBytesMessage(BytesMessage message, JavaType targetJavaType) throws JMSException, IOException { String encoding = this.encoding; if (this.encodingPropertyName != null && message.propertyExists(this.encodingPropertyName)) { encoding = message.getStringProperty(this.encodingPropertyName); } byte[] bytes = new byte[(int) message.getBodyLength()]; message.readBytes(bytes); try { String body = new String(bytes, encoding); return this.objectMapper.readValue(body, targetJavaType); } catch (UnsupportedEncodingException ex) { throw new MessageConversionException("Cannot convert bytes to String", ex); } }
/** * Convert a BytesMessage to a Java Object with the specified type. * @param message the input message * @param targetJavaType the target type * @return the message converted to an object * @throws JMSException if thrown by JMS * @throws IOException in case of I/O errors */ protected Object convertFromBytesMessage(BytesMessage message, JavaType targetJavaType) throws JMSException, IOException { String encoding = this.encoding; if (this.encodingPropertyName != null && message.propertyExists(this.encodingPropertyName)) { encoding = message.getStringProperty(this.encodingPropertyName); } byte[] bytes = new byte[(int) message.getBodyLength()]; message.readBytes(bytes); try { String body = new String(bytes, encoding); return this.objectMapper.readValue(body, targetJavaType); } catch (UnsupportedEncodingException ex) { throw new MessageConversionException("Cannot convert bytes to String", ex); } }
/** * Convert a BytesMessage to a Java Object with the specified type. * @param message the input message * @param targetJavaType the target type * @return the message converted to an object * @throws javax.jms.JMSException if thrown by JMS * @throws java.io.IOException in case of I/O errors */ protected Object convertFromBytesMessage(BytesMessage message, JavaType targetJavaType) throws JMSException, IOException { String encoding = this.encoding; if (this.encodingPropertyName != null && message.propertyExists(this.encodingPropertyName)) { encoding = message.getStringProperty(this.encodingPropertyName); } byte[] bytes = new byte[(int) message.getBodyLength()]; message.readBytes(bytes); try { String body = new String(bytes, encoding); return this.objectMapper.readValue(body, targetJavaType); } catch (UnsupportedEncodingException ex) { throw new MessageConversionException("Cannot convert bytes to String", ex); } }
byte[] bytes = new byte[(int) length]; message.readBytes(bytes); String version = message.getStringProperty(BocaSerializationConstants.version); NotificationUpdateHandler handler = new NotificationUpdateHandler(session, version); synchronized (userDestinations) {
try contentType = message.getStringProperty("contentType");
try contentType = message.getStringProperty("contentType");
try contentType = message.getStringProperty("contentType");