-
1. Re: AS 7.1.0 Final calling remote ejb without using property file?
wdfink Mar 8, 2012 11:07 AM (in response to sekobey)You might use this:
{code}
Hashtable<String, String> p = new Hashtable<String, String>();
p.put(InitialContext.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
p.put(InitialContext.PROVIDER_URL, "remote://localhost:4447");
p.put(Context.SECURITY_PRINCIPAL,"user");
p.put(Context.SECURITY_CREDENTIALS, "user123");
new InitialContext(p);
{code}
Also you have to add the user with add-user.sh to the ApplicationRealm.
But notice this is deprecated and the 'ejb:' lookup is the recommended one.
-
2. Re: AS 7.1.0 Final calling remote ejb without using property file?
rafaelri Mar 8, 2012 8:25 PM (in response to wdfink)I sincerely could not without the jboss-ejb-client.properties file, it throws the following exception:
Caused by: java.lang.IllegalStateException: No EJBReceiver available for node name netbooksony
at org.jboss.ejb.client.EJBClientContext.requireNodeEJBReceiver(EJBClientContext.java:559)
at org.jboss.ejb.client.EJBClientContext.requireNodeEJBReceiverContext(EJBClientContext.java:594)
at org.jboss.ejb.client.ReceiverInterceptor.handleInvocation(ReceiverInterceptor.java:54)
at org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:175)
at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:136)
at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:121)
at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:104)
at $Proxy0.create(Unknown Source)
... 9 more
btw I am calling an SFSB with a RemoteHome and an Init method.
-
3. Re: AS 7.1.0 Final calling remote ejb without using property file?
wdfink Mar 9, 2012 1:57 AM (in response to rafaelri)Can be an issue AS7-4110. Could you try a nightly build (solved last night ) or 7.1.1.Final?
-
4. Re: AS 7.1.0 Final calling remote ejb without using property file?
sekobey Mar 9, 2012 3:03 AM (in response to sekobey)Hi Wolf-Dieter Fink,
You might use this:
{code}
Hashtable<String, String> p = new Hashtable<String, String>();
p.put(InitialContext.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
p.put(InitialContext.PROVIDER_URL, "remote://localhost:4447");
p.put(Context.SECURITY_PRINCIPAL,"user");
p.put(Context.SECURITY_CREDENTIALS, "user123");
new InitialContext(p);
{code}
Also you have to add the user with add-user.sh to the ApplicationRealm.
But notice this is deprecated and the 'ejb:' lookup is the recommended one.
I tried this piece of code many times before you suggest, but it doesn't work.
I think I found solution.
At post "How to call a remote EJB without a property file?" Jakiran gives an example for calling a remote ejb without a property file. However, property setup part of that example is left blank. When i tried that example it has worked. Code is below:
Properties pr = new Properties();
pr.put("endpoint.name", "client-endpoint");
pr.put("remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED", "false");
pr.put("remote.connections", "default");
pr.put("remote.connection.default.port", "4447");
pr.put("remote.connection.default.host", "localhost");
pr.put("remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS", "false");
// Username and password is not needed if security-realm attribute is omitted from remoting-connector
// pr.put("remote.connection.default.username", "testuser2");
// pr.put("remote.connection.default.password", "1");
EJBClientConfiguration cc = new PropertiesBasedEJBClientConfiguration(pr);
ContextSelector < EJBClientContext > selector = new ConfigBasedEJBClientContextSelector(cc);
EJBClientContext.setSelector(selector);
Properties props = new Properties();
props.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
try {
Context c = new InitialContext(props);
c.lookup("ejb:<jndi-name-of-the-ejb>");
}
catch (NamingException ex) {
ex.printStackTrace();
}