Bonjour,
je travaille sous eclipse LUNA et ai créé un projet Entreprise Application Project. J'ai ajouté un serveur JBOSS eap 6.2
Voici la structure de mon projet
J'ai créé un remote EJB stateless dans le module EJBTutorialEJB
LibrarySessionBeanRemote.java
LibrarySessionBean.java
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14 package com.tutorialspoint.sessionbean.stateless; import java.util.List; import javax.ejb.Remote; @Remote public interface LibrarySessionBeanRemote { void addBook(String bookname); List<String> getBooks(); }
Dans le module EJBTutorialClient, j'ai une classe main qui appelle cet EJB remote stateless
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 package com.tutorialspoint.sessionbean.stateless; import java.util.ArrayList; import java.util.List; import javax.ejb.Stateless; /** * Session Bean implementation class LibrarySessionBean */ @Stateless public class LibrarySessionBean implements LibrarySessionBeanRemote { private List<String> bookShelf; /** * Default constructor. */ public LibrarySessionBean() { // TODO Auto-generated constructor stub bookShelf = new ArrayList<String>(); } public void addBook(String bookname) { bookShelf.add(bookname); } public List<String> getBooks() { return bookShelf; } }
Quand Je fais un "run as Java Application" sur la classe Main, il y a plusieurs comportement innatendu
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113 import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.List; import java.util.Properties; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; import com.tutorialspoint.sessionbean.stateless.LibrarySessionBeanRemote; public class Main { BufferedReader brConsoleReader = null; Properties jndiProperties = new Properties(); Context ctx = null; public void initializeStandardJNDIContext() { // Context.URL_PKG_PREFIXES = "java.naming.factory.url.pkgs" jndiProperties.put(Context.URL_PKG_PREFIXES,"org.jboss.ejb.client.naming"); // Context.INITIAL_CONTEXT_FACTORY = "java.naming.factory.initial" jndiProperties.put(Context.INITIAL_CONTEXT_FACTORY,"org.jboss.naming.remote.client.InitialContextFactory"); // Context.PROVIDER_URL = "java.naming.provider.url" jndiProperties.put(Context.PROVIDER_URL, "remote://localhost:4447"); jndiProperties.put("jboss.naming.client.ejb.context", true); try { ctx = new InitialContext(jndiProperties); } catch (NamingException ex) { ex.printStackTrace(); } } public static void main(String[] args) { // TODO Auto-generated method stub Main ejbTester = new Main(); ejbTester.initializeStandardJNDIContext(); ejbTester.testStatelessEjb(); } /* * (non-Java-doc) * * @see java.lang.Object#Object() */ public Main() { super(); brConsoleReader = new BufferedReader(new InputStreamReader(System.in)); } private void showGUI() { System.out.println("**********************"); System.out.println("Welcome to Book Store"); System.out.println("**********************"); System.out.print("Options \n1. Add Book\n2. Exit \nEnter Choice: "); } private void testStatelessEjb() { try { int choice = 1; String viewClassName = LibrarySessionBeanRemote.class.getName(); LibrarySessionBeanRemote libraryBean = (LibrarySessionBeanRemote) ctx.lookup("EJBTutorial/EJBTutorialEJB//LibrarySessionBean!"+ viewClassName); while (choice != 2) { String bookName; showGUI(); String strChoice = brConsoleReader.readLine(); choice = Integer.parseInt(strChoice); if (choice == 1) { System.out.print("Enter book name: "); bookName = brConsoleReader.readLine(); libraryBean.addBook(bookName); } else if (choice == 2) { break; } } List<String> booksList = libraryBean.getBooks(); System.out.println("Book(s) entered so far: " + booksList.size()); for (int i = 0; i < booksList.size(); ++i) { System.out.println((i + 1) + ". " + booksList.get(i)); } LibrarySessionBeanRemote libraryBean1 = (LibrarySessionBeanRemote) ctx .lookup("EJBTutorial/EJBTutorialEJB//LibrarySessionBean!" + viewClassName); List<String> booksList1 = libraryBean1.getBooks(); System.out.println("***Using second lookup to get library stateless object***"); System.out.println("Book(s) entered so far: " + booksList1.size()); for (int i = 0; i < booksList1.size(); ++i) { System.out.println((i + 1) + ". " + booksList1.get(i)); } } catch (Exception e) { System.out.println(e.getMessage()); e.printStackTrace(); } finally { try { if (brConsoleReader != null) { brConsoleReader.close(); } ctx.close(); } catch (IOException | NamingException ex) { System.out.println(ex.getMessage()); } } } }
Voici ce qu'il y a en console
1) premièrement je rentre 2 livres: "La source et le delta" et "Struts"
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
39 INFO: JBoss EJB Client version 1.0.24.Final-redhat-1 ********************** Welcome to Book Store ********************** Options 1. Add Book 2. Exit Enter Choice: 1 Enter book name: La source et le delta ********************** Welcome to Book Store ********************** Options 1. Add Book 2. Exit Enter Choice: 1 Enter book name: Struts ********************** Welcome to Book Store ********************** Options 1. Add Book 2. Exit Enter Choice: 2 Book(s) entered so far: 2 1. La source et le delta 2. Struts ***Using second lookup to get library stateless object*** Book(s) entered so far: 2 1. La source et le delta 2. Struts sept. 27, 2014 6:04:26 PM org.jboss.naming.remote.protocol.v1.RemoteNamingStoreV1$MessageReceiver handleEnd ERROR: Channel end notification received, closing channel Channel ID 8d6f21a9 (outbound) of Remoting connection 65694ee6 to localhost/127.0.0.1:4447 sept. 27, 2014 6:04:26 PM org.jboss.ejb.client.remoting.ChannelAssociation$ResponseReceiver handleEnd INFO: EJBCLIENT000016: Channel Channel ID a531a3da (outbound) of Remoting connection 65694ee6 to localhost/127.0.0.1:4447 can no longer process messages sept. 27, 2014 6:04:26 PM org.jboss.remoting3.spi.SpiUtils safeHandleClose ERROR: Close handler threw an exception java.util.concurrent.RejectedExecutionException: Task java.util.concurrent.FutureTask@241f0670 rejected from java.util.concurrent.ThreadPoolExecutor@70dfb596[Terminated, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 1]
Quand je choisis Exit ensuite il y a un comportement attendu au départ
Jusqu'ici, tout va bien
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4 Book(s) entered so far: 2 1. La source et le delta 2. Struts
Seulement après, il m'affiche
Et là ça ne va pas car cette liste est obtenu à l'aide d'un nouveau lookup (LibrarySessionBeanRemote libraryBean1 = (LibrarySessionBeanRemote) ctx.lookup("EJBTutorial/EJBTutorialEJB//LibrarySessionBean!"+ viewClassName)
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5 ***Using second lookup to get library stateless object*** Book(s) entered so far: 2 1. La source et le delta 2. Struts
Comme j'ai un stateless remote Bean, la liste des 2 livre que j'ai rentré auparavant ne devrait pas être stocké et retrouvé avec ce nouveau lookup. J'en profite pour vous demander la chose suivante (à mon avis je dirais oui): est-ce que quand on fait un lookup, cela crée une nouvelle session ?
2) deuxièmement: quand j'essaye de fermer mon context (en bleu à la fin de ma classe main), il y a l'erreur suivante
Je ne comprends pas quelle est l'erreur.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3 sept. 27, 2014 6:04:26 PM org.jboss.naming.remote.protocol.v1.RemoteNamingStoreV1$MessageReceiver handleEnd ERROR: Channel end notification received, closing channel Channel ID 8d6f21a9 (outbound) of Remoting connection 65694ee6 to localhost/127.0.0.1:4447
Merci d'avance pour vos réponses
Partager