PIX Ejemplo de uso de las operaciones HTTP POST, PUT, GET y DELETE para envíos en el estándar definido en SPI (Sistema de Pago Instantáneo).
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.PIXHTTPReqDetails;
import com.dinamonetworks.PIXResponse;
public class PostPutGetDeletePIX {
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\\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 ="peer_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,
0);
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()));
PIXHTTPReqDetails details = api.getPIXHTTPReqDetails();
System.out.println("Total time (ms): " + details.getTotalTime());
System.out.println("HTTP response: " + details.getHttpResponseCode());
response = api.putPIX(strPrivKeyId,
strCertChainId,
strPIXCertChainId,
strURL,
straRequestHeaderList,
xml,
0,
0);
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()));
details = api.getPIXHTTPReqDetails();
System.out.println("Total time (ms): " + details.getTotalTime());
System.out.println("HTTP response: " + details.getHttpResponseCode());
response = api.getPIX(strPrivKeyId,
strCertChainId,
strPIXCertChainId,
strURL,
straRequestHeaderList,
0,
0);
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,
0);
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.");
}
}