Beberapa alternatif pengganti XML diataranya:
- Simple Outline XML: SOX
- YAML Ain't Markup Language (YAML™)
- SLiP, a "Sorta Like Python" shorthand for XML
- PYX
java.io.Serializable
baik secara langsung ataupun tidak langsung (maksudnya secara hirarki object tersebutimport java.io.Serializable;
import java.util.Date;
import java.util.Calendar;
public class PersistentTime implements Serializable {
private Date time;
public PersistentTime() {
time = Calendar.getInstance().getTime();
}
public Date getTime() {
return time;
}
}
ObjectOutputStream.writeObject(Object obj)
.ObjectOutputStream
merupakan sebuah filter stream class yang dapat kita gunakan untuk menyimpan byte stream menjadi file atau ditransfer lewat networkimport java.io.ObjectOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
public class FlattenTime {
public static void main(String [] args) {
PersistentTime time = new PersistentTime();
FileOutputStream fos = null;
ObjectOutputStream out = null;
try {
fos = new FileOutputStream("time.obj");
out = new ObjectOutputStream(fos);
out.writeObject(time);
out.close();
} catch(IOException ex) {
ex.printStackTrace();
}
}
}
import java.io.ObjectInputStream;contoh diatas membuat object dari file bernama time.obj
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Calendar;
public class InflateTime {
public static void main(String [] args) {
PersistentTime time = null;
FileInputStream fis = null;
ObjectInputStream in = null;
try {
fis = new FileInputStream("time.obj");
in = new ObjectInputStream(fis);
// Recreate object
time = (PersistentTime)in.readObject();
in.close();
} catch(IOException ex) {
ex.printStackTrace();
} catch(ClassNotFoundException ex) {
ex.printStackTrace();
}
}
PersistentTime
.Thread, Socket, OutputStream
dan subclass-nya.private void readObject(java.io.ObjectInputStream in)- Contoh :
throws IOException, ClassNotFoundException;
public class MyObject implements Serializable {
public MyObject() {
initialization();
}
private void initialization() {
// code constructor disini
}
private void readObject(java.io.ObjectInputStream in)
throws IOException, ClassNotFoundException {
in.defaultReadObject();
initialization();
}
}
private void writeObject(java.io.ObjectOutputStream out)
throws IOException
readObject()
dan writeObject()
juga dapat digunakan untuk memastikan suatu proses dilakukan pada saat serialize atau deserialize.writeObject()
.throw new NotSerializableException("This object cannot be serialize");- Saat object di-serialize, maka dibuat sebuah "fingerprint" yang disebut serialVersionUID berupa 64-bit data.
serialVersionUID
sendiri dari awal pada serializable object dengan menambahkan field long bernilai sembarang seperti ini:static final long serialVersionUID = 4070409649129120458L;- Jika suatu file dari persistance object disimpan kemudian object tersebut mengalami perubahan kecil, misalnya penambahan field (java code berubah), dan kita dapat mengatakan bahwa file dari persistance object yang disimpan masih kompatibel dengan object yang baru maka object baru tersebut harus diberikan
serialVersionUID
yang sama object yang lama.java.io.InvalidClassException
.soapclient
dapat mendukung DIME attachment. Class ini dibuat seperti class soapclientmime
pada file nusoapdime.php
yang dibuat oleh Scott Nichol. Karena PEAR::SOAP sudah mendukung DIME attachment, maka dengan bantuan class Net_DIME dari PEAR maka pekerjaan ini jadi lebih mudah.Selanjutnya agar NuSOAP support DIME attachment kita perlu penambahan kapabilitas untuk menerima response DIME message dan kapabilitas pada WSDL.
function &_makeDIMEMessage(&$xml) {
// See class nusoap_base
$namespaces = 'http://schemas.xmlsoap.org/soap/envelope/';
// encode any attachments using DIME (see this link)
// now we have to DIME encode the message
$dime =& new Net_DIME_Message();
$msg =& $dime->encodeData($xml,$namespaces,NULL,NET_DIME_TYPE_URI);
// add the attachements
$c = count($this->requestAttachments);
for ($i=0; $i < $c; $i++) {
$attachment =& $this->requestAttachments[$i];
if ($attachment['data'] == '' && $attachment['filename'] <> '') {
if ($fd = fopen($attachment['filename'], 'rb')) {
$data = fread($fd, filesize($attachment['filename']));
fclose($fd);
} else {
$data = '';
}
$attachment['data'] = $data;
}
$msg .= $dime->encodeData($attachment['data'],
$attachment['contenttype'],
$attachment['cid'],
NET_DIME_TYPE_MEDIA);
}
$msg .= $dime->endMessage();
return $msg;
}
<html>
<head>
<title>DJP SOAP test</title>
</head>
<body>
<?
require_once('nusoap.er.php');
$soapclient = new soapclient('https://eFiling:1208/certReqWs/RegistrationService.asmx?WSDL','wsdl');
$username="";
$password="";
$certparams = array('cainfofile' => '/home/ejlp/htdocs/.cert/CADJP.cert',
'sslcertfile' => '/home/ejlp/htdocs/.cert/korupsipajak.cert.pem',
'sslkeyfile' => '/home/ejlp/htdocs/.cert/korupsipajak.key.pem',
'passphrase' => 'password');
$soapclient->setCredentials($username,$password,'certificate', $certparams);
ini_set("soap.wsdl_cache_enabled", "1");
$soapclient->create();
$err = $soapclient->getError();
if ($err) {
echo '<p><b>Create soapclient error: ' . $err . '</b></p>';
}
$proxy = $soapclient->getproxy();
$params = array( 'UserName' => 'test' , 'Password' => 'testpassword');
$results = $proxy->GetNPWP($params);
echo '<h3>Request:</h3> <xmp>'.$proxy->request.'</xmp>';
echo '<h3>Response:</h3> <xmp>'.$proxy->response.'</xmp>';
echo '<h3>Debug:</h3> <xmp>'.$proxy->debug_str.'</xmp>';
?>
</body>
</html>