Example of the use of HTTP POST, PUT, GET and DELETE operations for submissions in the PIX standard defined in SPI (Instant Payment System) with basic abstractions.
package doxy.examples;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import com.dinamonetworks.Dinamo;
import com.dinamonetworks.PIXResponse;
public class BasicPostPutGetDeletePIX {
public static void main(String[] args) throws IOException {
String strAddr = "127.0.0.1";
String strUsrId = "master";
String strPwd = "12345678";
int nPort = 4433;
int nFlags = 0;
Path currentRelativePath = Paths.get("c:\\tmp\\pix.xml");
byte[] xml = Files.readAllBytes(currentRelativePath);
Dinamo api = new Dinamo();
try {
api.openSession(strAddr, strUsrId, strPwd, nPort, nFlags);
System.out.println("Conectado.");
String strPrivKeyId ="key";
String strCertChainId ="key_cert";
String strPIXCertChainId ="pix_chain";
String strURL = "https://127.0.0.1:8000";
String straRequestHeaderList[] = { "Content-Type: application/xml; charset=utf-8"};
PIXResponse response = api.postPIX(strPrivKeyId,
strCertChainId,
strPIXCertChainId,
strURL,
straRequestHeaderList,
xml,
0,
true,
false);
System.out.println("POST");
System.out.println("Head");
System.out.println(new String(response.getHead()));
System.out.println("Body");
System.out.println(new String(response.getBody()));
response = api.putPIX(strPrivKeyId,
strCertChainId,
strPIXCertChainId,
strURL,
straRequestHeaderList,
xml,
0,
true,
false);
System.out.println("PUT");
System.out.println("Head");
System.out.println(new String(response.getHead()));
System.out.println("Body");
System.out.println(new String(response.getBody()));
response = api.getPIX(strPrivKeyId,
strCertChainId,
strPIXCertChainId,
strURL,
straRequestHeaderList,
0,
true,
false);
System.out.println("GET");
System.out.println("Head");
System.out.println(new String(response.getHead()));
System.out.println("Body");
System.out.println(new String(response.getBody()));
response = api.deletePIX( strPrivKeyId,
strCertChainId,
strPIXCertChainId,
strURL,
straRequestHeaderList,
0,
true,
false);
System.out.println("DELETE");
System.out.println("Head");
System.out.println(new String(response.getHead()));
System.out.println("Body");
System.out.println(new String(response.getBody()));
api.closeSession();
} catch (br.com.trueaccess.TacException e) {
e.printStackTrace();
}
System.out.println("Finalizado.");
}
}