You would need to create a simple JAVA RPC client and use the authentication header in the HTTP request to pass the authentication attributes. Please find a sample below:
public JSONObject invokeRPC(String id, String method, List<Object> params) {
DefaultHttpClient httpclient = new DefaultHttpClient();
JSONObject json = new JSONObject();
json.put("id", id);
json.put("chain_name", chain_name);
json.put("method", method);
if (null != params) {
json.put("params", params);
}
JSONObject responseJsonObj = null;
try {
httpclient.getCredentialsProvider().setCredentials(new AuthScope(ip, port),
new UsernamePasswordCredentials(uName, pwd));
StringEntity myEntity = new StringEntity(json.toJSONString());
HttpPost httppost = new HttpPost("http://"+ip+":"+port);
httppost.setEntity(myEntity);
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
System.out.println("----------------------------------------");
System.out.println(response.getStatusLine());
if (entity != null) {
System.out.println("Response content length: " + entity.getContentLength());
}
JSONParser parser = new JSONParser();
responseJsonObj = (JSONObject) parser.parse(EntityUtils.toString(entity));
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (org.json.simple.parser.ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
// When HttpClient instance is no longer needed,
// shut down the connection manager to ensure
// immediate deallocation of all system resources
httpclient.getConnectionManager().shutdown();
}
return responseJsonObj;
}
All you have to do is create a class with the variables ip, port , uname and password. IP is the IP of the system when Multichain daemon is running. Port is the RPC port assigned. uname is the user name which is by default multichain. password is the password for the RPC user. The user name and password are present in the multichain.conf file in the chain named directory. To check the RPC port check the value in params.dat.
By default Multichain only accepts request from local host, since you are using a different system you would need to add the IP of the system from the RPC calls are to be made by editing the multichain.conf file.
Append rpcallowip=192.168.1.0/24 at the end of the multichain.conf. The example will allow all IP's in the range of 192.168.1.*. However you can add multiple entries with associated IP's as well. For example if your system IP is 192.168.1.12, it could be done by adding rpcallowip=192.168.1.12
The response from the method shall be a JSON object similar to the way we see the output using the Multichain-Cli . Use the params to pass extra info as required by a method.
After making any changes to the multichain.conf file, to make the change effective, a restart of the multichain daemon is required.