Utiliser seulement les interfaces locales avec les ejb
Bonjour
Je travaille actuellement sur un projet en ejb. J'ai le code suivant qui me permet de créer un ejb entité grâce à l'interface distante.
Code:
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
|
public class TestStudent {
Properties properties;
public TestStudent() {
properties = new Properties();
properties.put("java.naming.factory.initial",
"org.jnp.interfaces.NamingContextFactory");
properties.put("java.naming.factory.url.pkgs",
"org.jboss.naming:org.jnp.interfaces");
properties.put("java.naming.provider.url", "jnp://localhost:1099");
properties.put("jnp.disableDiscovery", "true");
}
public static void main(String[] args) {
TestStudent beanStudent = new TestStudent();
beanStudent.createBean();
}
public void createBean() throws EJBException {
try {
InitialContext context = new InitialContext(properties);
Object object = context.lookup(StudentHome.JNDI_NAME);
StudentHome studentHome = (StudentHome) PortableRemoteObject.narrow(object,
StudentHome.class);
Student student = studentHome.create();
student.setName("pirlouit");
System.out.println(student.getId());
System.out.println(student.getName());
} catch (NamingException e) {
throw new EJBException(e);
} catch (RemoteException e) {
throw new EJBException(e);
} catch (CreateException e) {
throw new EJBException(e);
}
}
} |
J'aimerais savoir comment faire exactement la même chose mais avec les interfaces locales. J'ai essayé de remplacer bêtement dans mon code les interfaces distantes par les interfaces locales mais ca ne marche pas.
Qd je fais ca, l'instruction suivante :
Code:
Object object = context.lookup(StudentLocalHome.JNDI_NAME);
me donne l'exception suivante :
Code:
1 2 3 4 5 6 7
|
Exception in thread "main" javax.ejb.EJBException: null; CausedByException is:
StudentLocal not bound
at fr.dauphine.test.TestStudent.createBean(TestStudent.java:54)
at fr.dauphine.test.TestStudent.main(TestStudent.java:33)
javax.naming.NameNotFoundException: StudentLocal not bound
at org.jnp.server.NamingServer.getBinding(NamingServer.java:514) |
J'ai trouvé sur le net qu'il fallait ajouter l'instruction suivante pour enlevé ce problème :
Code:
1 2 3 4 5
|
if (System.getSecurityManager() == null)
{
System.setSecurityManager(new RMISecurityManager());
} |
J'ai donc testé avec ca mais maintenant l'instruction contenant le lookup sort l'exception suivante :
Code:
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
|
Exception in thread "main" javax.ejb.EJBException: null; CausedByException is:
Could not obtain connection to any of these urls: localhost:1099
at fr.dauphine.test.TestStudent.createBean(TestStudent.java:58)
at fr.dauphine.test.TestStudent.main(TestStudent.java:37)
javax.naming.CommunicationException: Could not obtain connection to any of these urls: localhost:1099 [Root exception is javax.naming.CommunicationException: Failed to connect to server localhost:1099 [Root exception is java.security.AccessControlException: access denied (java.net.SocketPermission 127.0.0.1:1099 connect,resolve)]]
at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:1399)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:579)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:572)
at javax.naming.InitialContext.lookup(Unknown Source)
at fr.dauphine.test.TestStudent.createBean(TestStudent.java:50)
at fr.dauphine.test.TestStudent.main(TestStudent.java:37)
Caused by: javax.naming.CommunicationException: Failed to connect to server localhost:1099 [Root exception is java.security.AccessControlException: access denied (java.net.SocketPermission 127.0.0.1:1099 connect,resolve)]
at org.jnp.interfaces.NamingContext.getServer(NamingContext.java:254)
at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:1370)
... 5 more
Caused by: java.security.AccessControlException: access denied (java.net.SocketPermission 127.0.0.1:1099 connect,resolve)
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkConnect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at org.jnp.interfaces.TimedSocketFactory.createSocket(TimedSocketFactory.java:69)
at org.jnp.interfaces.TimedSocketFactory.createSocket(TimedSocketFactory.java:62)
at org.jnp.interfaces.NamingContext.getServer(NamingContext.java:224)
... 6 more |
Voilà je n'arrive pas à régler ce problème ....
Merci d'avance pour votre aide*
[Modéré par Didier] : ajout de tag dans le titre - Les règles du forum Java