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

Example of the use of HTTP POST, PUT, GET and DELETE operations for submissions in the PIX standard defined in the 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("Connected.");
String strPrivKeyId ="key"; //Name of key in HSM
String strCertChainId ="key_cert"; //Name of certificate in HSM
String strPIXCertChainId ="peer_chain"; //Name of the PIX certificate chain in the HSM
String strURL = " https://127.0.0.1:8000"; //URL to access the 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()));
/*
* Optional recall of operation details.
* */
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()));
/*
* Optional recall of operation details.
* */
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("Finished.");
}
}