I send object on my RMI but , i find a null value.
Client.java :
service.InterfaceMathML stub = (service.InterfaceMathML) Naming.lookup("rmi://localhost:1099/BK");
System.out.println("id : " +this.MTI_creerFichier.getId()); // Show 10
int ValRetour = stub.Create(this.MTI_creerFichier, this.MTI_creerFichier.getId(), "CreateFichier");
My Interface :
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface InterfaceMathML extends Remote{
public int Create(Object unObject,String user, String unType)throws RemoteException;
}
My Server :
public int Create(Object unObject, String user, String unType) throws RemoteException {
// TODO Auto-generated method stub
switch(unType)
{
case "CreateFichier" :
System.out.println("Create Fichier");
System.out.println((CreateFichier)unObject.getId()); // show Null
ystem.out.println(user); // show userTest
FichierImpl = new JDBCDAO_Fichier();
this.validation = FichierImpl.Validation_ADD((CreateFichier)unObject, user);
if ( this.validation == 1) { this.entier = FichierImpl.add((CreateFichier)unObject, user); }
else { this.entier = this.validation; }
break;
so Why I can't my Object is null on the server ?
Please for help.
EDIT In my MAINTestServer.java ( on my serverRMI)
od = new MathMLServiceImpl() CreateFichier fi = new CreateFichier();
fi.setLogin("test"); fi.setDossierParent("dossierparenttest");
fi.setNomFichier("nomfichiertest");
fi.setContenuFichier("essaie");
int val = od.Create(fi, "test", "CreateFichier"); System.out.println(val);
It's work
my RMI Server
public static void main(String[] args) {
// TODO Auto-generated method stub
String url = "rmi://localhost:1099/BK";
try {
LocateRegistry.createRegistry(1099);
MathMLServiceImpl od = new MathMLServiceImpl();
// je met a dispo un objet dans un url
Naming.rebind("rmi://localhost:1099/BK", od);
System.out.println("Service pret");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
My CLientRMI : I use Polymorphism to lanch class detect my class :
Class<?> actionClass = Class.forName("metierToInte." + nomDto + "Action");
System.out.println(actionClass);
Constructor<?> actionConstructe = actionClass.getConstructor(dto.getClass()); //dto.getClass()
System.out.println("constructeur : " + actionConstructe.toString());
ActionInteToMetier uneActione = (ActionInteToMetier) actionConstructe.newInstance(dto);
System.out.println("action : " + uneActione.toString());
//System.out.println("action : " + uneActione.toString());
uneActione.executer();
It's work , for exemple my class "CreateFichierAction", I can send String it's work, but not my object
this.MTI_creerFichier = creerFichier;
service.InterfaceMathML stub = (service.InterfaceMathML) Naming.lookup("rmi://localhost:1099/BK");
System.out.println("id : " +this.MTI_creerFichier.getId()); // Show 10
int ValRetour = stub.Create(this.MTI_creerFichier, this.MTI_creerFichier.getLogin(), "CreateFichier");
System.out.println("valeur retour rmi " + ValRetour);
soucr : CreerFichier
package dto.metierToInte;
import java.io.Serializable;
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "")
@XmlRootElement(name = "CreateFichier")
public class CreateFichier
extends Fichier
implements Serializable
{
private static final long serialVersionUID = 1L;
@XmlAttribute(name = "id")
protected int id;
public String getId() {
return id;
}
}
It's work but , Not if my RMI CLIENT
Your object is not null only the id you are getting out of it is null
System.out.println((CreateFichier)unObject.getId());
if unObject was null then you must have got a NullPointerException. So check the getId() part.