diff --git a/src/main/java/io/mosip/print/service/impl/PrintServiceImpl.java b/src/main/java/io/mosip/print/service/impl/PrintServiceImpl.java index 2e3b1f13..eb843270 100644 --- a/src/main/java/io/mosip/print/service/impl/PrintServiceImpl.java +++ b/src/main/java/io/mosip/print/service/impl/PrintServiceImpl.java @@ -645,8 +645,11 @@ private void setTemplateAttributes(String jsonString, Map attrib * @throws Exception */ private String getPassword(org.json.JSONObject jsonObject) throws ApisResourceAccessException, IOException { - - String[] attributes = env.getProperty(UINCARDPASSWORD).split("\\|"); + String propertyValue = Objects.requireNonNull( + env.getProperty(UINCARDPASSWORD), + "Environment property '" + UINCARDPASSWORD + "' is missing." + ); + String[] attributes = propertyValue.split("\\|"); List list = new ArrayList<>(Arrays.asList(attributes)); Iterator it = list.iterator(); String uinCardPd = ""; @@ -660,16 +663,16 @@ private String getPassword(org.json.JSONObject jsonObject) throws ApisResourceAc } catch (Exception e) { obj = object; } - } - if (obj instanceof JSONArray) { - JsonValue[] jsonValues = JsonUtil.mapJsonNodeToJavaObject(JsonValue.class, (JSONArray) obj); - uinCardPd = uinCardPd.concat(getFormattedPasswordAttribute(getParameter(jsonValues, templateLang))); - - } else if (object instanceof org.json.simple.JSONObject) { - org.json.simple.JSONObject json = (org.json.simple.JSONObject) object; - uinCardPd = uinCardPd.concat(getFormattedPasswordAttribute((String) json.get(VALUE))); - } else { - uinCardPd = uinCardPd.concat(getFormattedPasswordAttribute(object.toString())); + if (obj instanceof JSONArray) { + JsonValue[] jsonValues = JsonUtil.mapJsonNodeToJavaObject(JsonValue.class, (JSONArray) obj); + uinCardPd = uinCardPd.concat(getFormattedPasswordAttribute(getParameter(jsonValues, templateLang))); + + } else if (object instanceof org.json.simple.JSONObject) { + org.json.simple.JSONObject json = (org.json.simple.JSONObject) object; + uinCardPd = uinCardPd.concat(getFormattedPasswordAttribute((String) json.get(VALUE))); + } else { + uinCardPd = uinCardPd.concat(getFormattedPasswordAttribute(object.toString())); + } } } return uinCardPd; diff --git a/src/main/java/io/mosip/print/util/RestApiClient.java b/src/main/java/io/mosip/print/util/RestApiClient.java index 6d510947..7e9f43fb 100644 --- a/src/main/java/io/mosip/print/util/RestApiClient.java +++ b/src/main/java/io/mosip/print/util/RestApiClient.java @@ -3,6 +3,8 @@ import java.io.IOException; import java.net.URI; import java.util.Iterator; +import java.util.List; + import org.slf4j.Logger; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; @@ -117,8 +119,12 @@ private HttpEntity setRequestHeader(Object requestType, MediaType mediaT Iterator iterator = httpHeader.keySet().iterator(); while (iterator.hasNext()) { String key = iterator.next(); - if (!(headers.containsKey("Content-Type") && key.equals("Content-Type"))) - headers.add(key, httpHeader.get(key).get(0)); + if (!(headers.containsKey("Content-Type") && key.equals("Content-Type"))) { + List values = httpHeader.get(key); + if (values != null && !values.isEmpty()) { + headers.add(key, values.getFirst()); + } + } } return new HttpEntity(httpEntity.getBody(), headers); } catch (ClassCastException | NullPointerException e) {