com.flutterwave.rave.java.service.transferServices Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of Rave-Java Show documentation
Show all versions of Rave-Java Show documentation
A Java API wrapper for the Rave API
The newest version!
/*
* 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 com.flutterwave.rave.java.service;
import com.flutterwave.rave.java.config.raveConfig;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.Arrays;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.log4j.Logger;
/**
*
* @author cleopatradouglas
*/
public class transferServices {
private static final Logger LOG = Logger.getLogger(transferServices.class);
public String dotransfer(String params) {
StringBuilder result = new StringBuilder();
try (CloseableHttpClient client = HttpClientBuilder.create().build()) {
HttpPost post = new HttpPost((raveConfig.TRANSFER_URL+"create"));
StringEntity input = new StringEntity(params);
input.setContentType("application/json");
//System.out.println("input ===>" + input);
post.setEntity(input);
HttpResponse response = client.execute(post);
LOG.info("dotransfer response code ::: " + response.getStatusLine().getStatusCode());
BufferedReader rd = new BufferedReader(
new InputStreamReader(response.getEntity().getContent()));
String line;
while ((line = rd.readLine()) != null) {
result.append(line);
}
LOG.info("dotransfer request" + result.toString());
if (!String.valueOf(response.getStatusLine().getStatusCode()).startsWith("2") && !response.getEntity().getContentType().getValue().contains("json")) {
return null;
}
if (response.getStatusLine().getStatusCode() == 500) {
return "there is an error with the data";
} else {
return result.toString();
}
} catch (UnsupportedEncodingException ex) {
LOG.error(Arrays.toString(ex.getStackTrace()));
} catch (IOException ex) {
LOG.error(Arrays.toString(ex.getStackTrace()));
}
return null;
}
public String dobulktransfer(String params) {
StringBuilder result = new StringBuilder();
try (CloseableHttpClient client = HttpClientBuilder.create().build()) {
HttpPost post = new HttpPost((raveConfig.TRANSFER_URL +"create_bulk"));
StringEntity input = new StringEntity(params);
input.setContentType("application/json");
//System.out.println("input ===>" + input);
post.setEntity(input);
HttpResponse response = client.execute(post);
LOG.info("dobulktransfer response code ::: " + response.getStatusLine().getStatusCode());
BufferedReader rd = new BufferedReader(
new InputStreamReader(response.getEntity().getContent()));
String line;
while ((line = rd.readLine()) != null) {
result.append(line);
}
LOG.info("dobulktransfer request" + result.toString());
if (!String.valueOf(response.getStatusLine().getStatusCode()).startsWith("2") && !response.getEntity().getContentType().getValue().contains("json")) {
return null;
}
if (response.getStatusLine().getStatusCode() == 500) {
return "there is an error with the data";
} else {
return result.toString();
}
} catch (UnsupportedEncodingException ex) {
LOG.error(Arrays.toString(ex.getStackTrace()));
} catch (IOException ex) {
LOG.error(Arrays.toString(ex.getStackTrace()));
}
return null;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy