Issue
by using Java, i am trying to download pact contract on provider side. Please suggest any way or tool to Download contract from pact broker on provider side.
Solution
by using below dependency in java project (i have used gradle)
implementation group: 'au.com.dius', name: 'pact-jvm-provider-junit_2.11', version: '2.4.3'
compile group: 'com.google.code.gson', name: 'gson', version: '2.8.6'
and use below code for contract
PactLoader loader = new au.com.dius.pact.provider.junit.loader.PactBrokerLoader("localhost", 8101,"http");
List<Pact> icd10 = loader.load("YourProviderName");
String json = new Gson().toJson(icd10);
JSONObject jsonObject;
JSONParser parser = new JSONParser();
JSONArray jsonArray = (JSONArray) parser.parse(json);
jsonObject = (JSONObject) jsonArray.get(0);
try {
FileWriter file = new FileWriter("\\ContractDownloadDemo\\Contract.json");
file.write(jsonObject.toJSONString());
file.close();
} catch (IOException e) {
e.printStackTrace();
}
Answered By - KB1
Answer Checked By - Clifford M. (JavaFixing Volunteer)