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.
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.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.jarpackage 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:
pas de probl�me mais lorsque de utilise ce param�tr� j'ai un probl�me de passage des param�tr�s aux entity.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
les param�tr�s sont null au lieu de 2553636 et ooooooooo.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