Source Code SSL Untuk TTE

import org.apache.hc.client5.http.impl.classic.HttpClients;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.client5.http.ssl.SSLConnectionSocketFactory;
import org.apache.hc.client5.http.ssl.TrustAllStrategy;
import org.apache.hc.client5.http.ssl.NoopHostnameVerifier;
import org.apache.hc.core5.ssl.SSLContextBuilder;
import org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManagerBuilder;
import org.apache.hc.client5.http.io.HttpClientConnectionManager;

private void BtnSimpanTandaTanganActionPerformed(java.awt.event.ActionEvent evt) {
R4.setSelected(true);
if (Phrase.getText().equals(“”)) {
Valid.textKosong(Phrase, “Phrase”);
} else {
try {
esign = true;
sertisign = false;
tampilPerawatan();
if (esign == true) {
File g = new File(“file.css”);
BufferedWriter bg = new BufferedWriter(new FileWriter(g));
bg.write(“.isi td{border-right: 1px solid #e2e7dd;font: 8.5px tahoma;height:12px;border-bottom: 1px solid #e2e7dd;background: #ffffff;color:#323232;}.isi a{text-decoration:none;color:#8b9b95;padding:0 0 0 0px;font-family: Tahoma;font-size: 8.5px;border: white;}”);
bg.close();

PdfWriter pdf = new PdfWriter(“RPP” + NoRawat.getText().trim().replaceAll(“/”, “”) + “.pdf”);
HtmlConverter.convertToPdf(
LoadHTMLRiwayatPerawatan.getText().replaceAll(“<head>”, “<head><link href=\”file.css\” rel=\”stylesheet\” type=\”text/css\” />”).
replaceAll(“<body>”,
“<body>”
+ “<table width=’100%’ align=’center’ border=’0′ class=’tbl_form’ cellspacing=’0′ cellpadding=’0′>”
+ “<tr>”
+ “<td width=’15%’ border=’0′>”
+ “<img width=’50’ height=’50’ src=’data:image/jpeg;base64,” + Base64.getEncoder().encodeToString(Sequel.cariGambar(“select setting.logo from setting”).readAllBytes()) + “‘/>”
+ “</td>”
+ “<td width=’85%’ border=’0′>”
+ “<center>”
+ “<font color=’000000′ size=’3′ face=’Tahoma’>” + akses.getnamars() + “</font><br>”
+ “<font color=’000000′ size=’1′ face=’Tahoma’>”
+ akses.getalamatrs() + “, ” + akses.getkabupatenrs() + “, ” + akses.getpropinsirs() + “<br/>”
+ akses.getkontakrs() + “, E-mail : ” + akses.getemailrs()
+ “<br>RIWAYAT PERAWATAN”
+ “</font> ”
+ “</center>”
+ “</td>”
+ “</tr>”
+ “</table><br>”
+ “<table width=’100%’ border=’0′ align=’center’ cellpadding=’3px’ cellspacing=’0′ class=’tbl_form’>”
+ “<tr class=’isi’>”
+ “<td valign=’top’ width=’20%’>No.RM</td>”
+ “<td valign=’top’ width=’1%’ align=’center’>:</td>”
+ “<td valign=’top’ width=’79%’>” + NoRM.getText().trim() + “</td>”
+ “</tr>”
+ “<tr class=’isi’>”
+ “<td valign=’top’ width=’20%’>Nama Pasien</td>”
+ “<td valign=’top’ width=’1%’ align=’center’>:</td>”
+ “<td valign=’top’ width=’79%’>” + NmPasien.getText() + “</td>”
+ “</tr>”
+ “<tr class=’isi’>”
+ “<td valign=’top’ width=’20%’>Alamat</td>”
+ “<td valign=’top’ width=’1%’ align=’center’>:</td>”
+ “<td valign=’top’ width=’79%’>” + Alamat.getText() + “</td>”
+ “</tr>”
+ “<tr class=’isi’>”
+ “<td valign=’top’ width=’20%’>Jenis Kelamin</td>”
+ “<td valign=’top’ width=’1%’ align=’center’>:</td>”
+ “<td valign=’top’ width=’79%’>” + Jk.getText().replaceAll(“L”, “Laki-Laki”).replaceAll(“P”, “Perempuan”) + “</td>”
+ “</tr>”
+ “<tr class=’isi’>”
+ “<td valign=’top’ width=’20%’>Tempat & Tanggal Lahir</td>”
+ “<td valign=’top’ width=’1%’ align=’center’>:</td>”
+ “<td valign=’top’ width=’79%’>” + TempatLahir.getText() + ” ” + TanggalLahir.getText() + “</td>”
+ “</tr>”
+ “<tr class=’isi’>”
+ “<td valign=’top’ width=’20%’>Ibu Kandung</td>”
+ “<td valign=’top’ width=’1%’ align=’center’>:</td>”
+ “<td valign=’top’ width=’79%’>” + IbuKandung.getText() + “</td>”
+ “</tr>”
+ “<tr class=’isi’>”
+ “<td valign=’top’ width=’20%’>Golongan Darah</td>”
+ “<td valign=’top’ width=’1%’ align=’center’>:</td>”
+ “<td valign=’top’ width=’79%’>” + GD.getText() + “</td>”
+ “</tr>”
+ “<tr class=’isi’>”
+ “<td valign=’top’ width=’20%’>Status Nikah</td>”
+ “<td valign=’top’ width=’1%’ align=’center’>:</td>”
+ “<td valign=’top’ width=’79%’>” + StatusNikah.getText() + “</td>”
+ “</tr>”
+ “<tr class=’isi’>”
+ “<td valign=’top’ width=’20%’>Agama</td>”
+ “<td valign=’top’ width=’1%’ align=’center’>:</td>”
+ “<td valign=’top’ width=’79%’>” + Agama.getText() + “</td>”
+ “</tr>”
+ “<tr class=’isi’>”
+ “<td valign=’top’ width=’20%’>Pendidikan Terakhir</td>”
+ “<td valign=’top’ width=’1%’ align=’center’>:</td>”
+ “<td valign=’top’ width=’79%’>” + Pendidikan.getText() + “</td>”
+ “</tr>”
+ “<tr class=’isi’>”
+ “<td valign=’top’ width=’20%’>Bahasa Dipakai</td>”
+ “<td valign=’top’ width=’1%’ align=’center’>:</td>”
+ “<td valign=’top’ width=’79%’>” + Bahasa.getText() + “</td>”
+ “</tr>”
+ “<tr class=’isi’>”
+ “<td valign=’top’ width=’20%’>Cacat Fisik</td>”
+ “<td valign=’top’ width=’1%’ align=’center’>:</td>”
+ “<td valign=’top’ width=’79%’>” + CacatFisik.getText() + “</td>”
+ “</tr>”
+ “</table>”
).
replaceAll((getClass().getResource(“/picture/”)) + “”, “./gambar/”), pdf
);
System.out.println(“Membuat ulang File RPP” + NoRawat.getText().trim().replaceAll(“/”, “”) + “.pdf untuk dikirim ke server”);
File f = new File(“RPP” + NoRawat.getText().trim().replaceAll(“/”, “”) + “.pdf”);
try {
CloseableHttpClient httpClient = createHttpClientWithSSL();
HttpPost post = new HttpPost(koneksiDB.URLAKSESFILEESIGN());
post.setHeader(“Content-Type”, “application/json”);
post.addHeader(“username”, koneksiDB.USERNAMEAPIESIGN());
post.addHeader(“password”, koneksiDB.PASSAPIESIGN());
post.addHeader(“url”, koneksiDB.URLAPIESIGN());

byte[] fileContent = Files.readAllBytes(f.toPath());

json = “{”
+ “\”file\”:\”” + Base64.getEncoder().encodeToString(fileContent) + “\”,”
+ “\”nik\”:\”” + Sequel.cariIsi(“select pegawai.no_ktp from pegawai where pegawai.nik=?”, akses.getkode()) + “\”,”
+ “\”passphrase\”:\”” + Phrase.getText() + “\”,”
+ “\”tampilan\”:\”visible\”,”
+ “\”image\”:\”false\”,”
+ “\”linkQR\”:\”Dikeluarkan di ” + akses.getnamars() + “, Kabupaten/Kota ” + akses.getkabupatenrs() + “. Ditandatangani secara elektronik oleh ” + dpjp + ” ID ” + kddpjp + ” Tanggal ” + Tanggal.getSelectedItem().toString() + “\”,”
+ “\”width\”:\”70\”,”
+ “\”height\”:\”70\”,”
+ “\”tag_koordinat\”:\”#\””
+ “}”;

System.out.println(“URL Akses file :” + koneksiDB.URLAKSESFILEESIGN());
post.setEntity(new StringEntity(json));
try ( CloseableHttpResponse response = httpClient.execute(post)) {
System.out.println(“Response Status : ” + response.getCode());
json = EntityUtils.toString(response.getEntity());
root = mapper.readTree(json);
if (response.getCode() == 200) {
try ( FileOutputStream fos = new FileOutputStream(new File(“RPP” + NoRawat.getText().trim().replaceAll(“/”, “”) + “.pdf”))) {
byte[] fileBytes = Base64.getDecoder().decode(root.path(“response”).asText());
fos.write(fileBytes);
WindowPhrase.dispose();
JOptionPane.showMessageDialog(null, “Proses tanda tangan berhasil…”);
Desktop.getDesktop().browse(new File(“RPP” + NoRawat.getText().trim().replaceAll(“/”, “”) + “.pdf”).toURI());
} catch (Exception e) {
WindowPhrase.dispose();
JOptionPane.showMessageDialog(null, “Gagal mengkonversi base64 ke file…”);
System.out.println(“Notif : ” + e);
}
} else {
WindowPhrase.dispose();
JOptionPane.showMessageDialog(null, “Code : ” + root.path(“metadata”).path(“code”).asText() + ” Pesan : ” + root.path(“metadata”).path(“message”).asText());
}
} catch (IOException a) {
WindowPhrase.dispose();
System.out.println(“Notifikasi : ” + a);
JOptionPane.showMessageDialog(null, “” + a);
}
} catch (Exception e) {
WindowPhrase.dispose();
System.out.println(“Notifikasi : ” + e);
JOptionPane.showMessageDialog(null, “” + e);
}
}
} catch (Exception e) {
System.out.println(“Notifikasi : ” + e);
}
}
}

// Method untuk membuat HTTP client yang menerima semua SSL certificate
private CloseableHttpClient createHttpClientWithSSL() throws Exception {
SSLContext sslContext = SSLContextBuilder.create()
.loadTrustMaterial(new TrustAllStrategy())
.build();

SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(
sslContext,
NoopHostnameVerifier.INSTANCE
);

HttpClientConnectionManager connectionManager = PoolingHttpClientConnectionManagerBuilder.create()
.setSSLSocketFactory(sslSocketFactory)
.build();

return HttpClients.custom()
.setConnectionManager(connectionManager)
.build();
}

Tulisan ini dipublikasikan di Tak Berkategori. Tandai permalink.
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments