-
1. Re: ejb remote client with java:global
sfcoy Sep 4, 2013 8:32 PM (in response to chamtem)1 of 1 people found this helpfulJNDI java:global references are only available within the same application server instance as your JBossAS/WildFly. Therefore you will need to stick with the ejb: notation.
From the §EE5.2.2 of the spec:
java:global – Names in this namespace are shared by all applications deployed in an application server instance. Note that an application server instance may represent a single server, a cluster of servers, an administrative domain containing many servers, or even more. The scope of an application server instance is product-dependent, but it must be possible to deploy multiple applications to a single application server instance.
-
2. Re: ejb remote client with java:global
chamtem Sep 5, 2013 12:28 AM (in response to sfcoy)1 of 1 people found this helpfulThanks Stephen,
-
3. Re: ejb remote client with java:global
jaysensharma Sep 5, 2013 2:06 AM (in response to chamtem)Hi,
In Addition to Stephen Coy comment, The following error which you are getting indicates that you have not included the "$JBOSS_HOME/bin/client/jboss-client.jar" file in your Client's classpath .
Exception in thread "main" 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:662)
AND
Exception in thread "main" javax.naming.NoInitialContextException: Cannot instantiate class: org.jboss.naming.remote.client.InitialContextFactory [Root exception is java.lang.ClassNotFoundException: org.jboss.naming.remote.client.InitialContextFactory]
You need to correct your pom in order to make sure that the jboss-client jar dependency is added while running the client code.
JNDI name and lookup is a secondary issue here because the exception indicates that your client code is not even able to create the InitialContext properly and failing there only. So that need to be fixed first.
-
4. Re: ejb remote client with java:global
chamtem Sep 5, 2013 2:33 AM (in response to jaysensharma)Thanks Jay,
I will check and post in here.
Best Regards,
-
5. Re: ejb remote client with java:global
chamtem Sep 5, 2013 3:35 AM (in response to jaysensharma)But my question is how it works for ejb:xxx if jboss-client.jar is not in the path.
Regards,
-
6. Re: ejb remote client with java:global
jaysensharma Sep 5, 2013 4:48 AM (in response to chamtem)HI,
If you have placed the jboss-client.jar file in clients classpath And Suppose if your EJBs global JNDI name is as following:
java:global/TestEJBAppp/remoteEJB/IntCalculatorBean!ejb3.InterestCalculatorRemote";
java:jboss/exported/TestEJBAppp/remoteEJB/IntCalculatorBean!ejb3.InterestCalculatorRemote";
Then you can lookup the EJB remotely using the following JNDI name while using JBOss EJB Client API(non Remoting API)
JNDI_NAME="ejb:TestEJBAppp/remoteEJB/IntCalculatorBean!ejb3.InterestCalculatorRemote";
package client;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import java.util.*;
import java.util.Locale;
// EJB Client API related imports
import org.jboss.ejb.client.remoting.ConfigBasedEJBClientContextSelector;
import org.jboss.ejb.client.remoting.ReconnectHandler;
import org.jboss.ejb.client.remoting.RemotingConnectionEJBReceiver;
import org.jboss.remoting3.Connection;
import org.jboss.ejb.client.ContextSelector;
import org.jboss.ejb.client.EJBClient;
import org.jboss.ejb.client.EJBClientConfiguration;
import org.jboss.ejb.client.EJBClientContext;
import org.jboss.ejb.client.PropertiesBasedEJBClientConfiguration;
public class JBossEJBClientAPIBased
{
Context context=null;
static String JNDI_NAME="ejb:TestEJBAppp/remoteEJB/IntCalculatorBean!ejb3.InterestCalculatorRemote";
public static void main(String ar[]) throws Exception
{
JBossEJBClientAPIBased client=new JBossEJBClientAPIBased();
test();
}
public void test()
{
Properties p = new Properties ();
try
{
p.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
p.put("remote.connections", "default");
p.put("remote.connection.default.port", "4447"); // the default remoting port, replace if necessary
p.put("remote.connection.default.host", "localhost"); // the host, replace if necessary
p.put("jboss.naming.client.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT","false");
p.put("remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED","false");
p.put("remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS","false");
p.put("remote.connection.default.username","ejbUser");
p.put("remote.connection.default.password", "ejbPassword");
EJBClientConfiguration cc = new PropertiesBasedEJBClientConfiguration(p);
ContextSelector<EJBClientContext> selector = new ConfigBasedEJBClientContextSelector(cc);
EJBClientContext.setSelector(selector);
Properties props = new Properties();
props.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
context = new InitialContext(props);
InterestCalculatorRemote remote=(InterestCalculatorRemote)context.lookup(JNDI_NAME);
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
-
7. Re: ejb remote client with java:global
shsarma Oct 29, 2013 3:28 AM (in response to jaysensharma)hi jay/stephon coy,
i am getting exception for the deployed application and could you please help me in resolving this for the same,and while executing the service client i am getting the
exception in server
09:14:50,812 ERROR [org.jboss.remoting.remote.connection] (Remoting "us-pc" read
-1) JBREM000200: Remote connection failed: java.io.IOException: Received an inva
lid message length of 369295616
and on the client side
Oct 29, 2013 9:14:50 AM org.jboss.remoting3.remote.RemoteConnection handleExcept
ion
ERROR: JBREM000200: Remote connection failed: javax.net.ssl.SSLException: Unreco
gnized SSL message, plaintext connection?
Oct 29, 2013 9:14:50 AM org.jboss.ejb.client.remoting.ConfigBasedEJBClientContex
tSelector setupEJBReceivers
WARN: Could not register a EJB receiver for connection to remote://localhost:444
7
- java.lang.RuntimeException: javax.net.ssl.SSLException: Unrecognized SSL message
, plaintext connection?
at org.jboss.ejb.client.remoting.IoFutureHelper.get(IoFutureHelper.java:
91)
at org.jboss.ejb.client.remoting.ConfigBasedEJBClientContextSelector.set
upEJBReceivers(ConfigBasedEJBClientContextSelector.java:115)
at org.jboss.ejb.client.remoting.ConfigBasedEJBClientContextSelector.<in
it>(ConfigBasedEJBClientContextSelector.java:77)
at org.jboss.ejb.client.EJBClientContext.<clinit>(EJBClientContext.java:
76)
at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandl
- er.java:120)
at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler
.java:104)
at com.sun.proxy.$Proxy0.add(Unknown Source)
at org.jboss.as.quickstarts.ejb.remote.client.MyRemoteEJBClient.invokeSt
atelessBean(MyRemoteEJBClient.java:78)
at org.jboss.as.quickstarts.ejb.remote.client.MyRemoteEJBClient.main(MyR
- emoteEJBClient.java:60)
Caused by: javax.net.ssl.SSLException: Unrecognized SSL message, plaintext conne
ction?
at sun.security.ssl.EngineInputRecord.bytesInCompletePacket(Unknown Sour
ce)
at sun.security.ssl.SSLEngineImpl.readNetRecord(Unknown Source)
at sun.security.ssl.SSLEngineImpl.unwrap(Unknown Source)
at javax.net.ssl.SSLEngine.unwrap(Unknown Source)
at org.xnio.ssl.JsseConnectedSslStreamChannel.unwrap(JsseConnectedSslStr
- eamChannel.java:443)
at org.xnio.ssl.JsseConnectedSslStreamChannel.read(JsseConnectedSslStrea
- mChannel.java:484)
at org.xnio.ssl.JsseConnectedSslStreamChannel.read(JsseConnectedSslStrea
- mChannel.java:449)
at org.xnio.channels.FramedMessageChannel.receive(FramedMessageChannel.j
ava:88)
at org.jboss.remoting3.remote.ClientConnectionOpenListener$Greeting.hand
leEvent(ClientConnectionOpenListener.java:138)
at org.jboss.remoting3.remote.ClientConnectionOpenListener$Greeting.hand
leEvent(ClientConnectionOpenListener.java:130)
at org.xnio.ChannelListeners.invokeChannelListener(ChannelListeners.java
:72)
at org.xnio.channels.TranslatingSuspendableChannel.handleReadable(Transl
- atingSuspendableChannel.java:189)
at org.xnio.channels.TranslatingSuspendableChannel$1.handleEvent(Transla
- tingSuspendableChannel.java:103)
at org.xnio.ChannelListeners.invokeChannelListener(ChannelListeners.java
:72)
at org.xnio.channels.TranslatingSuspendableChannel.handleReadable(Transl
- atingSuspendableChannel.java:189)
at org.xnio.ssl.JsseConnectedSslStreamChannel.handleReadable(JsseConnect
- edSslStreamChannel.java:180)
at org.xnio.channels.TranslatingSuspendableChannel$1.handleEvent(Transla
- tingSuspendableChannel.java:103)
at org.xnio.ChannelListeners.invokeChannelListener(ChannelListeners.java
:72)
at org.xnio.nio.NioHandle.run(NioHandle.java:90)
at org.xnio.nio.WorkerThread.safeRun(WorkerThread.java:205)
at org.xnio.nio.WorkerThread.run(WorkerThread.java:121)
at ...asynchronous invocation...(Unknown Source)
at org.jboss.remoting3.EndpointImpl.doConnect(EndpointImpl.java:270)
at org.jboss.remoting3.EndpointImpl.doConnect(EndpointImpl.java:251)
at org.jboss.remoting3.EndpointImpl.connect(EndpointImpl.java:349)
at org.jboss.remoting3.EndpointImpl.connect(EndpointImpl.java:333)
at org.jboss.ejb.client.remoting.ConfigBasedEJBClientContextSelector.set
upEJBReceivers(ConfigBasedEJBClientContextSelector.java:113)
... 7 more
Exception in thread "main" java.lang.IllegalStateException: No EJB receiver avai
lable for handling [appName:,modulename:jboss-as-ejb-remote-app,distinctname:] c
ombination
at org.jboss.ejb.client.EJBClientContext.requireEJBReceiver(EJBClientCon
- text.java:530)
at org.jboss.ejb.client.ReceiverInterceptor.handleInvocation(ReceiverInt
- erceptor.java:84)
at org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClient
- InvocationContext.java:175)
at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandl
- er.java:136)
at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandl
- er.java:121)
at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler
.java:104)
at com.sun.proxy.$Proxy0.add(Unknown Source)
at org.jboss.as.quickstarts.ejb.remote.client.MyRemoteEJBClient.invokeSt
atelessBean(MyRemoteEJBClient.java:78)
at org.jboss.as.qui
---------------------------------------------------------------------------------------------------------------------------
and my client program an propeties file i will put so could you help me what properties or jars required to get resolve this exception
package org.jboss.as.quickstarts.ejb.remote.client;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import java.security.Security;
import java.util.Hashtable;import org.jboss.as.quickstarts.ejb.remote.stateless.CalculatorBean;
import org.jboss.as.quickstarts.ejb.remote.stateless.RemoteCalculator;
import org.jboss.sasl.JBossSaslProvider;
import org.jboss.naming.remote.client.InitialContextFactory;
import java.util.Properties;
import java.io.IOException;
import java.util.*;// EJB Client API related imports
import org.jboss.ejb.client.remoting.ConfigBasedEJBClientContextSelector;
import org.jboss.ejb.client.remoting.ReconnectHandler;
import org.jboss.ejb.client.remoting.RemotingConnectionEJBReceiver;
import org.jboss.remoting3.Connection;
import org.jboss.ejb.client.ContextSelector;
import org.jboss.ejb.client.EJBClient;
import org.jboss.ejb.client.EJBClientConfiguration;
import org.jboss.ejb.client.EJBClientContext;
import org.jboss.ejb.client.PropertiesBasedEJBClientConfiguration;
/**
* A sample program which acts a remote client for a EJB deployed on AS7 server.
* This program shows how to lookup stateful and stateless beans via JNDI and then invoke on them
*
* @author Jaikiran Pai
*/
public class MyRemoteEJBClient{
static String JNDI_NAME="ejb:/jboss-as-ejb-remote-app/CalculatorBean!org.jboss.as.quickstarts.ejb.remote.stateless.RemoteCalculator";
private static Context initialContext;
private static final String PKG_INTERFACES = "org.jboss.ejb.client.naming";
public static Context getInitialContext() throws NamingException {
if (initialContext == null) {
Properties properties = new Properties();
properties.put(Context.URL_PKG_PREFIXES, PKG_INTERFACES);
properties.put(Context.PROVIDER_URL, "remote://localhost:4447");
properties.put(Context.SECURITY_PRINCIPAL, "shanmukha3");
properties.put(Context.SECURITY_CREDENTIALS, "shannu2004");
initialContext = new InitialContext(properties);
}
return initialContext;
}
public static void main(String[] args) throws Exception {
// Invoke a stateless bean
invokeStatelessBean();
}
/**
* Looks up a stateless bean and invokes on it
*
* @throws NamingException
*/
private static void invokeStatelessBean() throws NamingException,IOException {
// Let's lookup the remote stateless calculator
final RemoteCalculator statelessRemoteCalculator = lookupRemoteStatelessCalculator();
System.out.println("Obtained a remote stateless calculator for invocation");
// invoke on the remote calculator
int a = 204;
int b = 340;
System.out.println("Adding " + a + " and " + b + " via the remote stateless calculator deployed on the server");
int sum = statelessRemoteCalculator.add(a, b);
System.out.println("Remote calculator returned sum = " + sum);
if (sum != a + b) {
throw new RuntimeException("Remote stateless calculator returned an incorrect sum " + sum + " ,expected sum was " + (a + b));
}
// try one more invocation, this time for subtraction
int num1 = 3434;
int num2 = 2332;
System.out.println("Subtracting " + num2 + " from " + num1 + " via the remote stateless calculator deployed on the server");
int difference = statelessRemoteCalculator.subtract(num1, num2);
System.out.println("Remote calculator returned difference = " + difference);
if (difference != num1 - num2) {
throw new RuntimeException("Remote stateless calculator returned an incorrect difference " + difference + " ,expected difference was " + (num1 - num2));
}
}
/**
* Looks up and returns the proxy to remote stateless calculator bean
*
* @return
* @throws NamingException
*/
private static RemoteCalculator lookupRemoteStatelessCalculator() throws NamingException, IOException {
getInitialContext();
System.out.println("context initated ");/* // The app name is the application name of the deployed EJBs. This is typically the ear name
// without the .ear suffix. However, the application name could be overridden in the application.xml of the
// EJB deployment on the server.
// Since we haven't deployed the application as a .ear, the app name for us will be an empty string
final String appName = "";
// This is the module name of the deployed EJBs on the server. This is typically the jar name of the
// EJB deployment, without the .jar suffix, but can be overridden via the ejb-jar.xml
// In this example, we have deployed the EJBs in a jboss-as-ejb-remote-app.jar, so the module name is
// jboss-as-ejb-remote-app
final String moduleName = "jboss-as-ejb-remote-app";
// AS7 allows each deployment to have an (optional) distinct name. We haven't specified a distinct name for
// our EJB deployment, so this is an empty string
final String distinctName = "";
// The EJB name which by default is the simple class name of the bean implementation class
final String beanName = CalculatorBean.class.getSimpleName();
// the remote view fully qualified class name
final String viewClassName = RemoteCalculator.class.getName();
System.out.println("ejb:" + appName + "/" + moduleName + "/" + distinctName + "/" + beanName + "!" + viewClassName);
// let's do the lookup
*/return (RemoteCalculator)initialContext.lookup(JNDI_NAME);
}
}----------------------------------------------------------------
propeties file is
remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false
remote.connections=default
remote.connection.default.host=localhost
remote.connection.default.port = 4447
remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false
remote.connection.default.username=shanmukha3
remote.connection.default.password=shannu2004and classpath is in bat file is
set classpath=%classpath%;E:\examples\jars\jboss-client-7.1.0.Final.jar;
set classpath=%classpath%;E:\examples\jars\jboss-ejb-api_3.1_spec-1.0.1.Final.jar;
set classpath=%classpath%;E:\examples\jars\jboss-ejb-client-1.0.2.Final.jar;
set classpath=%classpath%;E:\examples\jars\jboss-logging-3.1.0.GA.jar;
set classpath=%classpath%;E:\examples\jars\jboss-marshalling-1.3.9.GA.jar;
set classpath=%classpath%;E:\examples\jars\jboss-marshalling-river-1.3.9.GA.jar;
set classpath=%classpath%;E:\examples\jars\jboss-remoting-3.2.2.GA.jar;
set classpath=%classpath%;E:\examples\jars\jboss-sasl-1.0.0.Final.jar
set classpath=%classpath%;E:\examples\jars\jboss-transaction-api_1.1_spec-1.0.0.Final.jar
set classpath=%classpath%;E:\examples\jars\xnio-api-3.0.3.GA.jar;
set classpath=%classpath%;E:\examples\jars\xnio-nio-3.0.3.GA.jar;
set classpath=%classpath%;E:\examples\jbossExamples\ejbExample\resources\jboss-ejb-client.properties;
javac -sourcepath src -classpath %classpath% src\org\jboss\as\quickstarts\ejb\remote\stateless\*.java -d classes
javac -sourcepath src -classpath %classpath% src\org\jboss\as\quickstarts\ejb\remote\client\*.java -d classesjava -classpath %classpath%;classes org.jboss.as.quickstarts.ejb.remote.client.MyRemoteEJBClient
pause
with regards
shanmukha sarma
-
8. Re: ejb remote client with java:global
wdfink Oct 29, 2013 4:05 AM (in response to shsarma)Hi Shanmukha,
it looks like you mix remote-naming and ejb-client approach and the connection get's confused with SSL.
Read this documentation EJB-client and Remote-naming.
Also your issue is different and you should not use an already answered thread for this as your question might be overlooked.
So please start a new thread if you have still problems with the appropriate informations