RMI Zugriff zwischen zwei WAR Projekten

RMInoob

Neues Mitglied
Moin, ich habe zwei WAR Projekte welche auf einem Glassfish Server liegen und möchte mittels RMI/JNDI auf Methoden des einen Projekts zugreifen.
Das Binden scheint zu funktionieren, jedoch bekommen wir bei dem Lookup folgenden Fehler:
java.lang.ClassCastException: com.sun.proxy.$Proxy290 cannot be cast to projekt2014.dao.IUserDao

Server:
IUserDao
Java:
public interface IUserDao extends Remote {
    void testRMI()throws RemoteException;
    
}

UserDaoImpl
Java:
@Stateless
public class UserDaoImpl extends UnicastRemoteObject implements IUserDao{

    private static final long serialVersionUID = 7288416492240640633L;
    
    public UserDaoImpl() throws RemoteException{
        super();
    }

    @Override
    public Class[] value() {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public Class<? extends Annotation> annotationType() {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void testRMI() throws RemoteException {
        System.out.println("RMI GEHT");
        
    }
}

Binden
Java:
        try {

            LocateRegistry.createRegistry(1099);
            rmiRegister = new UserDaoImpl();
            Naming.bind("rmi://localhost/rmifi", rmiRegister);
            System.out.println("RMI-Facade wurde registriert!");

        } catch (RemoteException e) {
            e.printStackTrace();
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (AlreadyBoundException ex) {
            Logger.getLogger(Jndi.class.getName()).log(Level.SEVERE, null, ex);
        }



Client:
IUserDao
Java:
public interface IUserDao extends Remote {
    void testRMI()throws RemoteException;
}

UserDaoImpl
Java:
public class UserDaoImpl  {

    private static UserDaoImpl instance = null;
    private static String adress = "rmi://localhost:1099/rmifi";
    private static IUserDao udl = null;

    public static UserDaoImpl getInstance() {
        if (instance == null) {
            try {
                instance = new UserDaoImpl();
                System.out.println("LOOKUPP;:"+Naming.lookup(adress));
                udl = (IUserDao) Naming.lookup(adress);
                
            } catch (NotBoundException ex) {
                Logger.getLogger(Mp3ArtistDao.class.getName()).log(Level.SEVERE, null, ex);
            } catch (MalformedURLException ex) {
                Logger.getLogger(Mp3ArtistDao.class.getName()).log(Level.SEVERE, null, ex);
            } catch (RemoteException ex) {
                Logger.getLogger(Mp3ArtistDao.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        return null;
    }

    public IUserDao getRmiFacade() {
        return udl;
    }
}

Methodenaufruf
Java:
        try {        
            IUserDao udl = UserDaoImpl.getInstance().getRmiFacade();
            udl.testRMI();
        } catch (RemoteException ex) {
            Logger.getLogger(Mp3ArtistDao.class.getName()).log(Level.SEVERE, null, ex);
        }

Ich hoffe jemand hat eine Idee parat die mir helfen könnte. :toll:

Mfg
 
Zuletzt bearbeitet:
Könntest du schreiben die Deklaration von: rmiRegister ?

Moin, ich habe zwei WAR Projekte welche auf einem Glassfish Server liegen und möchte mittels RMI/JNDI auf Methoden des einen Projekts zugreifen.
Das Binden scheint zu funktionieren, jedoch bekommen wir bei dem Lookup folgenden Fehler:


Server:
IUserDao
Java:
public interface IUserDao extends Remote {
    void testRMI()throws RemoteException;
    
}

UserDaoImpl
Java:
@Stateless
public class UserDaoImpl extends UnicastRemoteObject implements IUserDao{

    private static final long serialVersionUID = 7288416492240640633L;
    
    public UserDaoImpl() throws RemoteException{
        super();
    }

    @Override
    public Class[] value() {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public Class<? extends Annotation> annotationType() {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void testRMI() throws RemoteException {
        System.out.println("RMI GEHT");
        
    }
}

Binden
Java:
        try {

            LocateRegistry.createRegistry(1099);
            rmiRegister = new UserDaoImpl();
            Naming.bind("rmi://localhost/rmifi", rmiRegister);
            System.out.println("RMI-Facade wurde registriert!");

        } catch (RemoteException e) {
            e.printStackTrace();
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (AlreadyBoundException ex) {
            Logger.getLogger(Jndi.class.getName()).log(Level.SEVERE, null, ex);
        }



Client:
IUserDao
Java:
public interface IUserDao extends Remote {
    void testRMI()throws RemoteException;
}

UserDaoImpl
Java:
public class UserDaoImpl  {

    private static UserDaoImpl instance = null;
    private static String adress = "rmi://localhost:1099/rmifi";
    private static IUserDao udl = null;

    public static UserDaoImpl getInstance() {
        if (instance == null) {
            try {
                instance = new UserDaoImpl();
                System.out.println("LOOKUPP;:"+Naming.lookup(adress));
                udl = (IUserDao) Naming.lookup(adress);
                
            } catch (NotBoundException ex) {
                Logger.getLogger(Mp3ArtistDao.class.getName()).log(Level.SEVERE, null, ex);
            } catch (MalformedURLException ex) {
                Logger.getLogger(Mp3ArtistDao.class.getName()).log(Level.SEVERE, null, ex);
            } catch (RemoteException ex) {
                Logger.getLogger(Mp3ArtistDao.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        return null;
    }

    public IUserDao getRmiFacade() {
        return udl;
    }
}

Methodenaufruf
Java:
        try {        
            IUserDao udl = UserDaoImpl.getInstance().getRmiFacade();
            udl.testRMI();
        } catch (RemoteException ex) {
            Logger.getLogger(Mp3ArtistDao.class.getName()).log(Level.SEVERE, null, ex);
        }

Ich hoffe jemand hat eine Idee parat die mir helfen könnte. :toll:

Mfg
 

Neue Themen


Zurück
Oben