Tenho um Cliente que faz uma busca no Servidor por nome, idade, sexo, cargo e faixa salarial. Consigo publicar o serviço pelo servidor o meu problema aparece quando vou rodar o meu Cliente
Exception in thread "main" java.lang.ClassCastException: com.sun.proxy.$Proxy0 cannot be cast to Cliente.IServico
public class Cliente {
public static void main(String[] args) throws RemoteException, NotBoundException {
List<Funcionario> func = new ArrayList();
Registry r = LocateRegistry.getRegistry("localhost", 1099);
IServico serv = (IServico) r.lookup("servico"); // aqui que dá erro
func = serv.buscarPorNome("Erick");;
System.out.println(func);
}
}
IServico:
public interface IServico extends Remote {
List<Funcionario> buscarPorNome(String nome) throws RemoteException;
List<Funcionario> buscarPorIdade(int idade) throws RemoteException;
List<Funcionario> buscarPorSexo(String sexo) throws RemoteException;
List<Funcionario> buscarPorCargo(String nome) throws RemoteException;
List<Funcionario> buscarPorSalario(int salMenor, int salMaior) throws RemoteException;
}
Servidor:
public class Servidor {
public static void main(String[] args) throws IOException {
//System.setProperty("java.rmi.server.hostname", "192.168.0.131");
List<Funcionario> list = Servidor.carregarFuncionarios("Arquivo.txt");
Registry r = LocateRegistry.createRegistry(1099);
r.rebind("servico", new Servico(list));
System.out.println("Servico Publicado");
}
public static List<Funcionario> carregarFuncionarios(String arquivo) throws IOException{
File file = new File(arquivo);
List<Funcionario> temp = new ArrayList();
try {
BufferedReader br = new BufferedReader(new FileReader(file));
String[] linha;
String aux;
while((aux = br.readLine()) != null){
linha = aux.split("\\s");
Funcionario func = new Funcionario(linha[0],
Integer.parseInt(linha[1]),
linha[2],
linha[3],
Double.parseDouble(linha[4]));
// for(String f : linha){
// System.out.println(f);
// }
temp.add(func);
}
} catch (FileNotFoundException ex) {
Logger.getLogger(Servidor.class.getName()).log(Level.SEVERE, null, ex);
}
return temp;
}
}
E implemento o metodo de buscar o nome, idade.. na classe Servico
Alguma sugestao?