Java API
HSM Dinamo
Loading...
Looking for...
No entries found
PostPutGetDeletePIX.java

Example of the use of POST, PUT, GET and DELETE HTTP operations for submissions in the PIX standard defined in SPI (Instant Payment System).

See Note on examples.
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"; //Nome da chave no HSM
String strCertChainId ="key_cert"; //Nome do certificado no HSM
String strPIXCertChainId ="peer_chain"; //Nome da cadeia de certificados do PIX no HSM
String strURL = "https://127.0.0.1:8000"; //URL de acesso ao PIX
String straRequestHeaderList[] = { "Content-Type: application/xml; charset=utf-8"}; //Headers HTTP
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()));
/*
* Chamada opcional de recuperação de detalhes da operação.
* */
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()));
/*
* Chamada opcional de recuperação de detalhes da operação.
* */
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.");
}
}