@@ -253,33 +253,39 @@ private String getSubscriptionField(String fieldName, JsonNode subscriptionJson)
253
253
* @param subscriptionJson
254
254
* @return
255
255
*/
256
- private MultiValueMap <String , String > mapNotificationMessage (String aggregatedObject , JsonNode subscriptionJson ) {
257
- MultiValueMap <String , String > mapNotificationMessage = new LinkedMultiValueMap <>();
258
- ArrayNode arrNode = (ArrayNode ) subscriptionJson .get ("notificationMessageKeyValues" );
259
-
260
- if (subscriptionJson .has ("authenticationType" )) {
261
- String authType = subscriptionJson .get ("authenticationType" ).asText ();
262
-
263
- if (authType .equals ("BASIC_AUTH" )) {
264
- String username = subscriptionJson .get ("userName" ).asText ();
265
- String password = subscriptionJson .get ("password" ).asText ();
266
- String encoding = Base64 .getEncoder ().encodeToString ((username + ":" + password ).getBytes ());
267
-
268
- key = "Authorization" ;
269
- val = "Basic " + encoding ;
270
-
271
- }
272
- }
273
-
274
- if (arrNode .isArray ()) {
275
- for (final JsonNode objNode : arrNode ) {
276
- mapNotificationMessage .add (objNode .get ("formkey" ).toString ().replaceAll (REGEX , "" ), jmespath
277
- .runRuleOnEvent (objNode .get ("formvalue" ).toString ().replaceAll (REGEX , "" ), aggregatedObject )
278
- .toString ().replaceAll (REGEX , "" ));
279
- }
280
- }
281
- return mapNotificationMessage ;
282
- }
256
+ private MultiValueMap <String , String > mapNotificationMessage (String aggregatedObject , JsonNode subscriptionJson ) {
257
+ MultiValueMap <String , String > mapNotificationMessage = new LinkedMultiValueMap <>();
258
+ ArrayNode arrNode = (ArrayNode ) subscriptionJson .get ("notificationMessageKeyValues" );
259
+
260
+ if (subscriptionJson .has ("authenticationType" )) {
261
+ String authType = subscriptionJson .get ("authenticationType" ).asText ();
262
+
263
+ if (authType .equals ("BASIC_AUTH" )) {
264
+ boolean userNameFieldExists = subscriptionJson .has ("userName" ) && subscriptionJson .get ("userName" ) != null ;
265
+ boolean passwordFieldExists = subscriptionJson .has ("password" ) && subscriptionJson .get ("password" ) != null ;
266
+
267
+ if (userNameFieldExists && passwordFieldExists ) {
268
+ String username = subscriptionJson .get ("userName" ).asText ();
269
+ String password = subscriptionJson .get ("password" ).asText ();
270
+ String encoding = Base64 .getEncoder ().encodeToString ((username + ":" + password ).getBytes ());
271
+
272
+ key = "Authorization" ;
273
+ val = "Basic " + encoding ;
274
+ } else {
275
+ LOGGER .error ("userName/password field in subscription is missing. Make sure all subscriptions are up to date and has all required fields." );
276
+ }
277
+ }
278
+ }
279
+
280
+ if (arrNode .isArray ()) {
281
+ for (final JsonNode objNode : arrNode ) {
282
+ mapNotificationMessage .add (objNode .get ("formkey" ).toString ().replaceAll (REGEX , "" ), jmespath
283
+ .runRuleOnEvent (objNode .get ("formvalue" ).toString ().replaceAll (REGEX , "" ), aggregatedObject )
284
+ .toString ().replaceAll (REGEX , "" ));
285
+ }
286
+ }
287
+ return mapNotificationMessage ;
288
+ }
283
289
284
290
/**
285
291
* This method is responsible to display the configurable application properties
0 commit comments