import com.att.eelf.configuration.EELFManager;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
+import java.util.Arrays;
import java.util.HashSet;
import java.util.Map;
import java.util.Properties;
public class IntermediateMessageSenderImpl implements IntermediateMessageSender {
+ private final EELFLogger logger = EELFManager.getInstance().getLogger(IntermediateMessageSenderImpl.class);
- private Producer producer;
-
- private Configuration configuration;
+ private static final String PARAM_MESSAGE = "message";
+ private static final String ATTR_REQUEST_ID = "input.common-header.request-id";
- private final EELFLogger logger = EELFManager.getInstance().getLogger(IntermediateMessageSenderImpl.class);
+ private Producer producer;
private static final String STATUS = "STATUS";
private static final String FAILURE = "FAILURE";
private static final String MSO = "MSO";
public void init() {
- configuration = ConfigurationFactory.getConfiguration();
- Properties properties = configuration.getProperties();
+ Properties properties = ConfigurationFactory.getConfiguration().getProperties();
String writeTopic = properties.getProperty("appc.LCM.topic.write");
String apiKey = properties.getProperty("appc.LCM.client.key");
Set<String> pool = new HashSet<>();
if (!StringUtils.isEmpty(hostNames)) {
- for (String name : hostNames.split(",")) {
- pool.add(name);
- }
+ pool.addAll(Arrays.asList(hostNames.split(",")));
}
BundleContext ctx = FrameworkUtil.getBundle(IntermediateMessageSenderImpl.class).getBundleContext();
private void validateInputs(Map<String, String> params, SvcLogicContext context) throws APPCException {
String code = params.get("code");
- String message = params.get("message");
+ String message = params.get(PARAM_MESSAGE);
if (StringUtils.isEmpty(code) || StringUtils.isEmpty(message)) {
throw new APPCException("code or message is empty");
}
- String requestId = context.getAttribute("input.common-header.request-id");
+ String requestId = context.getAttribute(ATTR_REQUEST_ID);
if (StringUtils.isEmpty(requestId)) {
throw new APPCException("requestId is empty");
}
}
private String getCorrelationId(SvcLogicContext context) {
- String requestId = context.getAttribute("input.common-header.request-id");
+ String requestId = context.getAttribute(ATTR_REQUEST_ID);
String subRequestId = context.getAttribute("input.common-header.sub-request-id");
return requestId + (StringUtils.isEmpty(subRequestId) ? "" : ("-" + subRequestId));
}
ObjectMapper objectMapper = new ObjectMapper();
ObjectNode status = objectMapper.createObjectNode();
status.put("code", params.get("code"));
- status.put("message", params.get("message"));
+ status.put(PARAM_MESSAGE, params.get(PARAM_MESSAGE));
return status;
}
commonHeader.put("api-ver", context.getAttribute("input.common-header.api-ver"));
commonHeader.put("timestamp", context.getAttribute("input.common-header.timestamp"));
commonHeader.put("originator-id", context.getAttribute("input.common-header.originator-id"));
- commonHeader.put("request-id", context.getAttribute("input.common-header.request-id"));
+ commonHeader.put("request-id", context.getAttribute(ATTR_REQUEST_ID));
commonHeader.put("sub-request-id", context.getAttribute("input.common-header.sub-request-id"));
return commonHeader;
}