API Java
HSM Dinamo
Carregando...
Procurando...
Nenhuma entrada encontrado
PostPutGetDeletePIX.java

Exemplo de uso das operações POST, PUT, GET e DELETE HTTP para envios no padrão PIX definido no SPI(Sistema de Pagamentos Instantâneos).

Veja Nota sobre os exemplos.
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.");
}
}