【发布时间】:2014-05-15 14:35:42
【问题描述】:
我在我的 RMI 上发送对象,但我发现一个空值。
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");
我的界面:
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface InterfaceMathML extends Remote{
public int Create(Object unObject,String user, String unType)throws RemoteException;
}
我的服务器:
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;
那么为什么我的对象不能在服务器上为空?
请帮忙。
编辑 在我的 MAINTestServer.java 中(在我的 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);
成功了
我的 RMI 服务器
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();
}
}
我的客户RMI: 我使用多态性来启动类检测我的类:
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();
它的工作,例如我的类“CreateFichierAction”,我可以发送字符串它的工作,但不是我的对象
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;
}
}
这是可行的,但是如果我的 RMI CLIENT 则不行
【问题讨论】:
标签: java object null rmi remote-access