Salut,
J'ai commencé à créer un projet maven de type ear sous netbeans 6.9 Le projet contient un module EJB,un module web, un projet Assembly, et un projet "Enterprise Application".
Le but principal de mon projet est d'envoyer une requete POST vers une service REST(une resource qui existe sour le module web) . Ce dernier dépend du module ejb et il doit creer une ligne dans une table à travers la ressource Rest.
Mon module ejb contient une interface Remote ISessionFacade et un Stateless session Bean SessionFacade.
Mon pom.xml du projet web contient les dependances suivantes:
<!-- appserv-rt.jar -->
<dependency>
<groupId>org.glassfish.extras</groupId>
<artifactId>appserv-rt.jar</artifactId>
<version>LATEST</version>
<scope>system</scope>
<systemPath>${glassfish.home}/lib/appserv-rt.jar</systemPath>
</dependency>
<!-- Javaee API -->
<dependency>
<groupId>org.glassfish.extras</groupId>
<artifactId>javaee</artifactId>
<version>LATEST</version>
<scope>system</scope>
<systemPath>${glassfish.home}/lib/javaee.jar</systemPath>
</dependency>
<!-- Jndi properties -->
<dependency>
<groupId>jndi</groupId>
<artifactId>jndi-properties.jar</artifactId>
<version>LATEST</version>
<scope>system</scope>
<systemPath>${glassfish.home}/lib/jndi-properties.jar</systemPath>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>${javax.javaee.version}</version>
<scope>provided</scope>
</dependency>
La classe Resource Rest SessionsResource est sous la forme
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package resource;
import facade.remote.IArmariusWordspottingSessionFacade;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.EJB;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.restlet.data.Status;
import org.restlet.representation.Representation;
import org.restlet.resource.Post;
import org.restlet.resource.Get;
import org.restlet.resource.ServerResource;
/**
*
* @author Administrateur
*/
//@Stateless
public class SessionsResource extends ServerResource {
/**
* cq: create a new item.
*/
@Post
public Representation acceptItem(Representation entity) throws NamingException {
Representation result = null;
ISessionFacade ejbFaçade = lookupFacadeRemote1();
System.out.println("sessionFacade =" + sessionFacade.getOkString());
return result;
}
private ISessionFacade lookupFacadeRemote1() {
try {
// Properties properties = new Properties();
// properties.setProperty("java.naming.factory.initial", "com.sun.enterprise.naming.SerialInitContextFactory");
// properties.setProperty("java.naming.factory.url.pkgs", "com.sun.enterprise.naming");
// properties.setProperty("java.naming.factory.state", "com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl");
// properties.setProperty("java.naming.provider.url", "localhost:1099");
// properties.setProperty("org.omg.CORBA.ORBInitialHost", "localhost");
Context c = new InitialContext();
//Context c = new InitialContext(properties);
return (ISessionFacade) c.lookup("java:global/webService-ejb_ejb_1.0-SNAPSHOT/SessionFacade!facade.remote.ISessionFacade");
} catch (NamingException ne) {
Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", ne);
throw new RuntimeException(ne);
}
}
}
Mais le problème c'est qu'en exécutant mon code sous glassFish 3.0.1 une exception est générée
javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:645)
Meme si je définie les propriétés pour initialiser le context je me trouve avec l'exception suivante :
javax.naming.NoInitialContextException: Need to specify class name in environment or system property,
or as an applet parameter, or in an application resource file: java.naming.factory.initial
Je suis reconnaissante a tout ce qui peut m'aider à résoudre mon problème.
Merci d'avance
Partager