Github user olegz commented on a diff in the pull request:
https://github.com/apache/nifi/pull/305#discussion_r57714484
--- Diff:
nifi-nar-bundles/nifi-amqp-bundle/nifi-amqp-processors/src/main/java/org/apache/nifi/amqp/processors/AMQPUtils.java
---
@@ -141,4 +142,101 @@ private static String
extractPropertyNameFromMethod(Method method) {
c[0] = Character.toLowerCase(c[0]);
return AMQP_PROP_PREFIX + new String(c);
}
+
+ /**
+ * Will validate if provided amqpPropValue can be converted to a
{@link Map}.
+ *
+ * @param amqpPropValue
+ * the value of the property
+ * @return {@link Map} if valid otherwise null
+ */
+ public static Map<String, Object> validateAMQPHeaderProperty(String
amqpPropValue){
+ String[] strEntries = amqpPropValue.split(",");
+ Map<String, Object> headers = new HashMap<>();
+ for (String strEntry : strEntries) {
+ String[] kv = strEntry.split("=");
+ if (kv.length == 2) {
+ headers.put(kv[0].trim(), kv[1].trim());
+ } else {
+ logger.warn("Malformed key value pair for AMQP header
property: " + amqpPropValue);
+ }
+ }
+
+ return headers;
+ }
+
+ /**
+ * Will validate if provided amqpPropValue can be converted to an
{@link Integer}, and that its
+ * value is 1 or 2.
+ *
+ * @param amqpPropValue
+ * the value of the property
+ * @return {@link Integer} if valid otherwise null
+ */
+ public static Integer validateAMQPDeliveryModeProperty(String
amqpPropValue){
+ Integer deliveryMode = null;
+
+ try {
+ deliveryMode = Integer.parseInt(amqpPropValue);
+ } catch (NumberFormatException aE){
+ //we will deal with the error below instead of having
duplicate logger code
+ }
--- End diff --
Consider ```private static Integer toInt(String strVal)``` method, since
the same logic is repeated in the next one. Just trying to avoid duplication as
much as possible.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---