public Properties checkNodeConfig(Properties nodeConfig) { for (NodeProperties property : getRequiredProperties()) { if (nodeConfig.getProperty(property.getKey()) == null) { LOG.warn("-- checkNodeConfig(..): node property '{}' not set; reverting to " + "default value '{}'", property.getKey(), property.getDefaultValue()); nodeConfig.setProperty(property.getKey(), property.getDefaultValue()); } } this.nodeConfig = nodeConfig; return nodeConfig; }
private String getCredentials(String authScheme) { if (authScheme.equals(HttpConstants.AUTH_SCHEME_NONE)) { return Constants.STRING_EMPTY; } else if (authScheme.equals(HttpConstants.AUTH_SCHEME_BASIC)) { return Base64.encodeBase64String((nodeConfig.getProperty(NodeProperties.RPC_USER.getKey()) + ":" + nodeConfig.getProperty(NodeProperties.RPC_PASSWORD.getKey())).getBytes()); } throw new IllegalArgumentException(Errors.ARGS_HTTP_AUTHSCHEME_UNSUPPORTED.getDescription()); }
private void buildMonitors(Properties nodeConfig) { int alertPort = Integer.parseInt(nodeConfig.getProperty(NodeProperties.ALERT_PORT.getKey())); monitors.put(Notifications.ALERT, new NotificationMonitor(Notifications.ALERT, alertPort, null)); int blockPort = Integer.parseInt(nodeConfig.getProperty(NodeProperties.BLOCK_PORT.getKey())); monitors.put(Notifications.BLOCK, new NotificationMonitor(Notifications.BLOCK, blockPort, client)); int walletPort = Integer.parseInt(nodeConfig.getProperty(NodeProperties.WALLET_PORT.getKey())); monitors.put(Notifications.WALLET, new NotificationMonitor(Notifications.WALLET, walletPort, client)); monitorPool = Executors.newFixedThreadPool(monitors.size()); }
public Properties toProperties(Object... values) { Properties properties = new Properties(); List<NodeProperties> requiredProperties = new ArrayList<NodeProperties>( getRequiredProperties()); for (int i = 0; i < requiredProperties.size(); i++) { if (values[i] != null) { String key = requiredProperties.get(i).getKey(); properties.setProperty(key, values[i].toString()); } } return properties; } }
private HttpRequestBase getNewRequest(String reqMethod, String reqPayload) throws URISyntaxException, UnsupportedEncodingException { HttpRequestBase request; if (reqMethod.equals(HttpConstants.REQ_METHOD_POST)) { HttpPost postRequest = new HttpPost(); postRequest.setEntity(new StringEntity(reqPayload, ContentType.create( DataFormats.JSON.getMediaType(), Constants.UTF_8))); request = postRequest; } else { throw new IllegalArgumentException(Errors.ARGS_HTTP_METHOD_UNSUPPORTED.getDescription()); } request.setURI(new URI(String.format("%s://%s:%s/", nodeConfig.getProperty(NodeProperties.RPC_PROTOCOL.getKey()), nodeConfig.getProperty(NodeProperties.RPC_HOST.getKey()), nodeConfig.getProperty(NodeProperties.RPC_PORT.getKey())))); String authScheme = nodeConfig.getProperty(NodeProperties.HTTP_AUTH_SCHEME.getKey()); request.addHeader(resolveAuthHeader(authScheme)); LOG.debug("<< getNewRequest(..): returning a new HTTP '{}' request with target endpoint " + "'{}' and headers '{}'", reqMethod, request.getURI(), request.getAllHeaders()); return request; }