public IotHubMessageResult execute(Message msg, Object context) { Counter counter = (Counter) context; System.out.println( "Received message " + counter.toString() + " with content: " + new String(msg.getBytes(), Message.DEFAULT_IOTHUB_MESSAGE_CHARSET)); for (MessageProperty messageProperty : msg.getProperties()) { System.out.println(messageProperty.getName() + " : " + messageProperty.getValue()); } counter.increment(); return IotHubMessageResult.COMPLETE; } }
/** * Returns a copy of the message properties. * * @return a copy of the message properties. */ public MessageProperty[] getProperties() { // Codes_SRS_HTTPSSINGLEMESSAGE_11_013: [The function shall return a copy of the message properties.] int propertiesSize = this.properties.length; MessageProperty[] propertiesCopy = new MessageProperty[propertiesSize]; for (int i = 0; i < propertiesSize; ++i) { MessageProperty property = this.properties[i]; MessageProperty propertyCopy = new MessageProperty(property.getName(), property.getValue()); propertiesCopy[i] = propertyCopy; } return propertiesCopy; }
/** * Gets the values of user-defined properties of this Message. * @param name Name of the user-defined property to search for. * @return The value of the property if it is set, or null otherwise. */ public String getProperty(String name) { MessageProperty messageProperty = null; for (MessageProperty currentMessageProperty: this.properties) { if (currentMessageProperty.hasSameName(name)) { messageProperty = currentMessageProperty; break; } } // Codes_SRS_MESSAGE_11_034: [If no value associated with the property name is found, the function shall return null.] if (messageProperty == null) { return null; } // Codes_SRS_MESSAGE_11_032: [The function shall return the value associated with the message property name, where the name can be either the HTTPS or AMQPS property name.] return messageProperty.getValue(); }
private static boolean isErrorInjectionMessage(MessageAndResult messageAndResult) { MessageProperty[] properties = messageAndResult.message.getProperties(); for (int i = 0; i < properties.length; i++) { if (properties[i].getValue().equals(ErrorInjectionHelper.FaultCloseReason_Boom.toString()) || properties[i].getValue().equals(ErrorInjectionHelper.FaultCloseReason_Bye.toString())) { return true; } } return false; }
/** * Equivalent to property.getName().equalsIgnoreCase(name). * * @param name the property name. * * @return true if the given name is the property name. */ public boolean hasSameName(String name) { boolean nameMatches = false; // Codes_SRS_MESSAGEPROPERTY_11_006: [The function shall return true if and only if the property has the given name, where the names are compared in a case-insensitive manner.] if (this.getName().equalsIgnoreCase(name)) { nameMatches = true; } return nameMatches; }
if (currentMessageProperty.hasSameName(name)) this.properties.add(new MessageProperty(name, value));
/** * Returns whether the property name and value constitute a valid HTTPS * application property. The property is valid if it is a valid application * property and its name begins with 'iothub-app-'. * * @param name the property name. * @param value the property value. * * @return whether the property is a valid HTTPS property. */ private static boolean isValidHttpsAppProperty(String name, String value) { String lowercaseName = name.toLowerCase(); return (MessageProperty.isValidAppProperty(name.toLowerCase(), value) && lowercaseName.startsWith(HTTPS_APP_PROPERTY_PREFIX)); }
/** * Returns whether the property name and value constitute a valid HTTPS * system property. The property is valid if it is a reserved * property and its name begins with 'iothub-'. * * @param name the property name. * @param value the property value. * * @return whether the property is a valid HTTPS property. */ private static boolean isValidHttpsSystemProperty(String name, String value) { String lowercaseName = name.toLowerCase(); return (MessageProperty.isValidSystemProperty(name.toLowerCase(), value) && lowercaseName.startsWith(HTTPS_SYSTEM_PROPERTY_PREFIX) && !lowercaseName.startsWith(HTTPS_APP_PROPERTY_PREFIX)); }
properties.add(new MessageProperty(propertyName, propertyValue));
public IotHubMessageResult execute(Message msg, Object context) { Counter counter = (Counter) context; System.out.println( "Received message " + counter.toString() + " with content: " + new String(msg.getBytes(), Message.DEFAULT_IOTHUB_MESSAGE_CHARSET)); for (MessageProperty messageProperty : msg.getProperties()) { System.out.println(messageProperty.getName() + " : " + messageProperty.getValue()); } counter.increment(); return IotHubMessageResult.COMPLETE; } }
httpsMsg.properties[countProperty] = new MessageProperty( HTTPS_APP_PROPERTY_PREFIX + property.getName(), property.getValue());
public IotHubMessageResult execute(Message msg, Object context) { Counter counter = (Counter) context; System.out.println( "Received message " + counter.toString() + " with content: " + new String(msg.getBytes(), Message.DEFAULT_IOTHUB_MESSAGE_CHARSET)); for (MessageProperty messageProperty : msg.getProperties()) { System.out.println(messageProperty.getName() + " : " + messageProperty.getValue()); } counter.increment(); return IotHubMessageResult.COMPLETE; } }
public IotHubTransportMessage(byte[] data, MessageType messageType, String messageId, String correlationId, MessageProperty[] messageProperties) { //Codes_SRS_IOTHUBTRANSPORTMESSAGE_34_017: [This constructor shall return an instance of IotHubTransportMessage with provided bytes, messagetype, correlationid, messageid, and application properties.] super(data); super.setMessageType(messageType); this.setMessageId(messageId); this.setCorrelationId(correlationId); for (MessageProperty messageProperty : messageProperties) { this.setProperty(messageProperty.getName(), messageProperty.getValue()); } }
public IotHubMessageResult execute(Message msg, Object context) { Counter counter = (Counter) context; System.out.println( "Device Client " + msg.getIotHubConnectionString().getDeviceId() + " received message " + counter.toString() + " with content: " + new String(msg.getBytes(), Message.DEFAULT_IOTHUB_MESSAGE_CHARSET)); for (MessageProperty messageProperty : msg.getProperties()) { System.out.println(messageProperty.getName() + " : " + messageProperty.getValue()); } IotHubMessageResult res = IotHubMessageResult.COMPLETE; System.out.println( "Responding to message " + counter.toString() + " with " + res.name()); counter.increment(); return res; } }