| Title: Clients |
| |
| <a name="Clients-LocalClient(embeddedcontainer)"></a> |
| ### Local Client (embedded container) |
| |
| |
| Properties p = new Properties(); |
| p.put("java.naming.factory.initial", "org.apache.openejb.client.LocalInitialContextFactory"); |
| |
| InitialContext ctx = new InitialContext(p); |
| |
| MyBean myBean = (MyBean) ctx.lookup("MyBeanRemote"); |
| |
| |
| <a name="Clients-LocalClient(non-defaultrealmname)"></a> |
| ### Local Client (non-default realm name) |
| |
| <a name="Clients-Loginconfigurationfile(conf/login.config)"></a> |
| ### Login configuration file (conf/login.config) |
| |
| |
| PropertiesLogin { |
| org.apache.openejb.core.security.jaas.PropertiesLoginModule required |
| Debug=true |
| UsersFile="users.properties" |
| GroupsFile="groups.properties"; |
| }; |
| MyApp { |
| org.apache.openejb.core.security.jaas.SQLLoginModule required |
| dataSourceName="MyDataSource" |
| userSelect="SELECT username, password FROM users WHERE username=?" |
| groupSelect="SELECT username, grp FROM users WHERE username=?"; |
| }; |
| |
| |
| <a name="Clients-Programcode"></a> |
| ### Code |
| |
| |
| Properties p = new Properties(); |
| p.put("java.naming.factory.initial", "org.apache.openejb.client.LocalInitialContextFactory"); |
| p.put("openejb.authentication.realmName", "MyApp"); |
| |
| InitialContext ctx = new InitialContext(p); |
| |
| MyBean myBean = (MyBean) ctx.lookup("MyBeanRemote"); |
| |
| |
| <a name="Clients-RemoteClient(openejbstandalone)"></a> |
| ### Remote Client (openejb standalone) |
| |
| |
| Properties p = new Properties(); |
| p.put("java.naming.factory.initial", "org.apache.openejb.client.RemoteInitialContextFactory"); |
| p.put("java.naming.provider.url", "ejbd://localhost:4201"); |
| // user and pass optional |
| p.put("java.naming.security.principal", "myuser"); |
| p.put("java.naming.security.credentials", "mypass"); |
| |
| InitialContext ctx = new InitialContext(p); |
| |
| MyBean myBean = (MyBean) ctx.lookup("MyBeanRemote"); |
| |
| |
| <a name="Clients-RemoteClientwithHTTP(openejbstandalone)"></a> |
| ### Remote Client with HTTP (openejb standalone) |
| |
| |
| Properties p = new Properties(); |
| p.put("java.naming.factory.initial", "org.apache.openejb.client.RemoteInitialContextFactory"); |
| p.put("java.naming.provider.url", "http://localhost:4204/ejb"); |
| // user and pass optional |
| p.put("java.naming.security.principal", "myuser"); |
| p.put("java.naming.security.credentials", "mypass"); |
| |
| InitialContext ctx = new InitialContext(p); |
| |
| MyBean myBean = (MyBean) ctx.lookup("MyBeanRemote"); |
| |
| |
| |
| <a name="Clients-RemoteClientwithHTTP(intomcat)"></a> |
| ### Remote Client with HTTP (in TomEE) |
| |
| |
| Properties p = new Properties(); |
| p.put("java.naming.factory.initial", "org.apache.openejb.client.RemoteInitialContextFactory"); |
| p.put("java.naming.provider.url", "http://127.0.0.1:8080/tomee/ejb"); |
| // user and pass optional |
| p.put("java.naming.security.principal", "myuser"); |
| p.put("java.naming.security.credentials", "mypass"); |
| |
| InitialContext ctx = new InitialContext(p); |
| |
| MyBean myBean = (MyBean) ctx.lookup("MyBeanRemote"); |
| |
| <a name="RemoteClientUsingEjbInjection)"></a> |
| ### Remote Client using @EJB Injection |
| see here: |
| <a href="http://tomee.apache.org/ejb-refs.html">ejb-refs</a> |
| |