kcb.billerengine.processors.CallJSON.java Source code

Java tutorial

Introduction

Here is the source code for kcb.billerengine.processors.CallJSON.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package kcb.billerengine.processors;

import java.io.IOException;
import java.math.BigDecimal;
import java.util.HashMap;
import kcb.billerengine.responses.BillerTransactionResponse;
import org.apache.http.HttpResponse;
import org.apache.http.ParseException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.util.EntityUtils;
import org.json.JSONObject;

/**
 *
 * @author NKSONGOK
 */
public class CallJSON {

    public BillerTransactionResponse callJSON(String trnxID, HashMap<String, String> serviceParams, String url) {
        BillerTransactionResponse response = new BillerTransactionResponse();
        JSONObject json = new JSONObject(serviceParams);

        return response;
    }

    private String getJson(HttpClient httpClient, String jsonURL, String body) {
        String sb = null;
        try {
            System.out.println("JSON REQUEST: " + body);
            StringEntity params = new StringEntity(body);

            HttpPost request = new HttpPost(jsonURL);
            request.addHeader("content-type", "application/text");
            request.setEntity(params);
            HttpResponse response = httpClient.execute(request);

            sb = EntityUtils.toString(response.getEntity(), "UTF-8");

        } catch (IOException | ParseException e) {
            e.printStackTrace();
        }
        System.out.println("ECITIZEN RESPONSE : " + sb);
        httpClient.getConnectionManager().shutdown();
        return sb;
    }

}