+ /**
+ * Returns parameters from the parameter map.
+ *
+ * @param paramMap parameter map
+ * @param p parameters instance
+ * @return parameters filed instance
+ * @throws SvcLogicException when svc logic exception occurs
+ */
+ public static Parameters getParameters(Map<String, String> paramMap,
+ Parameters p)
+ throws SvcLogicException {
+ p.templateFileName = parseParam(paramMap, "templateFileName",
+ false, null);
+ p.requestBody = parseParam(paramMap, "requestBody", false, null);
+ p.restapiUrl = parseParam(paramMap, restapiUrlString, true, null);
+ validateUrl(p.restapiUrl);
+ p.restapiUser = parseParam(paramMap, "restapiUser", false, null);
+ p.restapiPassword = parseParam(paramMap, "restapiPassword", false,
+ null);
+ p.oAuthConsumerKey = parseParam(paramMap, "oAuthConsumerKey",
+ false, null);
+ p.oAuthConsumerSecret = parseParam(paramMap, "oAuthConsumerSecret",
+ false, null);
+ p.oAuthSignatureMethod = parseParam(paramMap, "oAuthSignatureMethod",
+ false, null);
+ p.oAuthVersion = parseParam(paramMap, "oAuthVersion", false, null);
+ p.contentType = parseParam(paramMap, "contentType", false, null);
+ p.format = Format.fromString(parseParam(paramMap, "format", false,
+ "json"));
+ p.authtype = fromString(parseParam(paramMap, "authType", false,
+ "unspecified"));
+ p.httpMethod = HttpMethod.fromString(parseParam(paramMap, "httpMethod",
+ false, "post"));
+ p.responsePrefix = parseParam(paramMap, responsePrefix, false, null);
+ p.listNameList = getListNameList(paramMap);
+ String skipSendingStr = paramMap.get(skipSendingMessage);
+ p.skipSending = "true".equalsIgnoreCase(skipSendingStr);
+ p.convertResponse = valueOf(parseParam(paramMap, "convertResponse",
+ false, "true"));
+ p.trustStoreFileName = parseParam(paramMap, "trustStoreFileName",
+ false, null);
+ p.trustStorePassword = parseParam(paramMap, "trustStorePassword",
+ false, null);
+ p.keyStoreFileName = parseParam(paramMap, "keyStoreFileName",
+ false, null);
+ p.keyStorePassword = parseParam(paramMap, "keyStorePassword",
+ false, null);
+ p.ssl = p.trustStoreFileName != null && p.trustStorePassword != null
+ && p.keyStoreFileName != null && p.keyStorePassword != null;
+ p.customHttpHeaders = parseParam(paramMap, "customHttpHeaders",
+ false, null);
+ p.partner = parseParam(paramMap, "partner", false, null);
+ p.dumpHeaders = valueOf(parseParam(paramMap, "dumpHeaders",
+ false, null));
+ p.returnRequestPayload = valueOf(parseParam(
+ paramMap, "returnRequestPayload", false, null));
+ p.accept = parseParam(paramMap, "accept",
+ false, null);
+ p.multipartFormData = valueOf(parseParam(paramMap, "multipartFormData",
+ false, "false"));
+ p.multipartFile = parseParam(paramMap, "multipartFile",
+ false, null);
+ return p;
+ }
+
+ /**
+ * Validates the given URL in the parameters.
+ *
+ * @param restapiUrl rest api URL
+ * @throws SvcLogicException when URL validation fails
+ */
+ private static void validateUrl(String restapiUrl)
+ throws SvcLogicException {
+ try {
+ URI.create(restapiUrl);
+ } catch (IllegalArgumentException e) {
+ throw new SvcLogicException("Invalid input of url "
+ + e.getLocalizedMessage(), e);
+ }
+ }
+
+ /**
+ * Returns the list of list name.
+ *
+ * @param paramMap parameters map
+ * @return list of list name
+ */
+ private static Set<String> getListNameList(Map<String, String> paramMap) {
+ Set<String> ll = new HashSet<>();
+ for (Map.Entry<String, String> entry : paramMap.entrySet()) {
+ if (entry.getKey().startsWith("listName")) {
+ ll.add(entry.getValue());
+ }
+ }
+ return ll;
+ }
+
+ /**
+ * Parses the parameter string map of property, validates if required,
+ * assigns default value if present and returns the value.
+ *
+ * @param paramMap string param map
+ * @param name name of the property
+ * @param required if value required
+ * @param def default value
+ * @return value of the property
+ * @throws SvcLogicException if required parameter value is empty
+ */
+ public static String parseParam(Map<String, String> paramMap, String name,
+ boolean required, String def)
+ throws SvcLogicException {
+ String s = paramMap.get(name);
+
+ if (s == null || s.trim().length() == 0) {
+ if (!required) {
+ return def;
+ }
+ throw new SvcLogicException("Parameter " + name + " is required in RestapiCallNode");
+ }
+
+ s = s.trim();
+ StringBuilder value = new StringBuilder();
+ int i = 0;
+ int i1 = s.indexOf('%');
+ while (i1 >= 0) {
+ int i2 = s.indexOf('%', i1 + 1);
+ if (i2 < 0) {
+ break;
+ }
+
+ String varName = s.substring(i1 + 1, i2);
+ String varValue = System.getenv(varName);
+ if (varValue == null) {
+ varValue = "%" + varName + "%";
+ }
+
+ value.append(s.substring(i, i1));
+ value.append(varValue);
+
+ i = i2 + 1;
+ i1 = s.indexOf('%', i);
+ }
+ value.append(s.substring(i));
+
+ log.info("Parameter {}: [{}]", name, value);
+ return value.toString();
+ }
+
+ public RetryPolicyStore getRetryPolicyStore() {
+ return retryPolicyStore;
+ }
+
+ public void setRetryPolicyStore(RetryPolicyStore retryPolicyStore) {
+ this.retryPolicyStore = retryPolicyStore;
+ }
+
+ /**