Bonsoir a tous!
j'ai deux projets un projet JavaEE utilisant le framework Spring boot et un autre JavaFx
cote serveur tous fonctionnes j'ai fait une teste avec RestController et les methodes repondent correctement. J'exporte un service avec RmiServiceExporter. dans mon projet client je recupere le service avec Naming.lookup()
Lorsque j'appel une methode d'insertion de donnee sa fonctionne bien les donnees sont enregistres en base de donnee mais lorsque je recupere ces donnees j'obtient cette erreur:
voici mon interface rmi:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7 java.rmi.UnmarshalException: error unmarshalling return; nested exception is: java.io.WriteAbortedException: writing aborted;java.io.NotSerializableException: java.util.Optional at sun.rmi.server.UnicastRef.invoke(Unknown Source) at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(Unknown Source) at java.rmi.server.RemoteObjectInvocationHandler.invoke(Unknown Source) at com.sun.proxy.$Proxy6.getUser(Unknown Source) ...
la classe user service:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8 public interface UserRemote extends Remote{ public User saveUser(User user) throws RemoteException; public boolean connexion(String username, String password) throws RemoteException; public long countUsers(Role role) throws RemoteException; public boolean userExist(String username) throws RemoteException; public Optional<User> getUser(Long id) throws RemoteException; }
la classe d'export des services:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38 @Service public class UserService { @Autowired private UserRepository userRepo; public User saveUser(User user){ return this.userRepo.save(user); } public void deleteUser(Long id){ this.userRepo.deleteById(id); } public void deleteUser(User user){ this.userRepo.delete(user); } public User updateUser(User user){ return this.userRepo.save(user); } public User getUser(String username,String password){ return this.userRepo.getUserByUsernameAndPassword(username,password); } public Optional<User> getUser(Long id){ return userRepo.findById(id); } public long countUser(Role role){ return this.userRepo.count(); } public boolean exist(String username){ return (this.userRepo.getUserByUsername(username) != null); } }
en fin voici le code pour l'appel du service
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 @Configuration public class ServiceRMIExporter { private int port = 5400; public SimpleJaxWsServiceExporter jaxWsServiceExporter(){ return new SimpleJaxWsServiceExporter(); } @Bean @Autowired public RmiServiceExporter getUserRemoteService(UserRemote userService){ RmiServiceExporter exporter = new RmiServiceExporter(); exporter.setService(userService); exporter.setServiceName("userservice"); exporter.setRegistryPort(port); return exporter; } }
Une aide sera la bienvenue!!!
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 public class TestRmi { public static void main(String[] args) { try { UserRemote stub = (UserRemote) Naming.lookup("rmi://localhost:5400/userservice"); Optional<User> usr = stub.getUser(1L); System.out.println(usr.toString()); } catch (MalformedURLException | NotBoundException | RemoteException e) { e.printStackTrace(); } } }Merci
Partager