Bonjour
je suis en train de développer une application j2ee avec un client JAVASE.
je travail avec Glassfish3 ,EJB3.1,JPA2.0(EclipseLink 2.0) et IDE NetBeans7.0
voila un exemple simplifier de mon projet.
1)Code EJB+Entity bean.
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 package entity; /* * To change this template, choose Tools | Templates * and open the template in the editor. */ import java.io.Serializable; import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.Table; /** * * @author Herguem */ @Entity @Table(name = "tbRanch") public class Ranch implements Serializable { @Id private String name; private String premisesId; private String comment; public Ranch() { } public String getComment() { return comment; } public void setComment(String comment) { this.comment = comment; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getPremisesId() { return premisesId; } public void setPremisesId(String premisesId) { this.premisesId = premisesId; } }bien sur avec une interface Remote.
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 package ejb; import entity.Ranch; import javax.ejb.EJBException; import javax.ejb.Stateless; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; /** * * @author Herguem */ @Stateless public class HelloSessionBean implements HelloSessionBeanRemote { @PersistenceContext(unitName = "EJBModule1PU") private EntityManager em; @Override public String businessMethod() { return "Salut pour tt Md"; } @Override public String call(String parameter, String parameter1) { System.out.println(parameter); System.out.println(parameter1); return parameter + parameter1; } @Override public Ranch create(Ranch r) { if (r == null) { } System.out.println("vvvvvvvvvvvvvvvvvvvvvvvvv" + r.getName()); System.out.println("kkkkkkkkkkkkkkkkkkkkkkk" + r.getComment()); // em.persist(r); return r; } }
La 2eme Partie est le client JAVASE(Simple application de test)
j'ai ajouté le 2 jar Javaee.jar et appserv-rt.jar
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 package helloclient; import ejb.HelloSessionBeanRemote; import entity.Ranch; import java.util.Properties; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; import javax.swing.JOptionPane; import org.jdesktop.swingx.JXErrorPane; import org.jdesktop.swingx.error.ErrorInfo; import org.jdesktop.swingx.error.ErrorLevel; /** * * @author Herguem */ public class Client { /** * @param args the command line arguments */ public static Context initalContext; public static void main(String[] args) { try { Properties props = new Properties(); props.setProperty("java.naming.factory.initial", "com.sun.enterprise.naming.SerialInitContextFactory"); props.setProperty("java.naming.factory.url.pkgs", "com.sun.enterprise.naming"); props.setProperty("java.naming.factory.state", "com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl"); // optional. Defaults to localhost. Only needed if web server is running // on a different host than the appserver props.setProperty("org.omg.CORBA.ORBInitialHost", "192.168.1.20"); // optional. Defaults to 3700. Only needed if target orb port is not 3700. props.setProperty("org.omg.CORBA.ORBInitialPort", "3700"); initalContext = new InitialContext(props); HelloSessionBeanRemote cattle = (HelloSessionBeanRemote) initalContext.lookup("java:global/EJBModule1/HelloSessionBean!ejb.HelloSessionBeanRemote"); System.out.println(cattle.call("Bonjour", "Mr")); Ranch c = new Ranch(); c.setName("2553636"); c.setComment("ooooooooooooooo"); cattle.create(c); } catch (NamingException ex) { JXErrorPane.showDialog(null, new ErrorInfo("Error", ex.getMessage(), null, null, ex, ErrorLevel.SEVERE, null)); } } }
le problème et le suivant:
lorsque je execute mon client avec cette parametres: props.setProperty("org.omg.CORBA.ORBInitialHost", "localhost");
voila la resultat:
les paramétrés sont null au lieu de 2553636 et ooooooooo.
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 INFO: Glassfish-specific (Non-portable) JNDI names for EJB HelloSessionBean : [ejb.HelloSessionBeanRemote#ejb.HelloSessionBeanRemote, ejb.HelloSessionBeanRemote] INFO: EJBModule1 a été déployé en 204 ms. INFO: Bonjour INFO: Mr INFO: vvvvvvvvvvvvvvvvvvvvvvvvv2553636 INFO: kkkkkkkkkkkkkkkkkkkkkkkooooooooooooooo [/quote] pas de problème mais lorsque de utilise ce paramétré j'ai un problème de passage des paramétrés aux entity. [quote]INFO: Portable JNDI names for EJB HelloSessionBean : [java:global/EJBModule1/HelloSessionBean, java:global/EJBModule1/HelloSessionBean!ejb.HelloSessionBeanRemote] INFO: Glassfish-specific (Non-portable) JNDI names for EJB HelloSessionBean : [ejb.HelloSessionBeanRemote#ejb.HelloSessionBeanRemote, ejb.HelloSessionBeanRemote] INFO: EJBModule1 a été déployé en 204 ms. INFO: Bonjour INFO: Mr INFO: vvvvvvvvvvvvvvvvvvvvvvvvvnull INFO: kkkkkkkkkkkkkkkkkkkkkkknull
merci de votre aide.
Partager