I am using jboss-5.0.1 GA.
I am trying to invoke EJB deployed on remote JBoss server from my local EJB using JNDI.
I have included the remote interfaces jar file in my local EJB project's class path. I have as well added jnp-client.jar, jboss-ejb3-client.jar in my class path.
I have started JBoss on remote machine with -b 0.0.0.0 flags to ensure it accepts remote connections.
Here is the code.
SatheBeanRemote sbr = null; //Is the remote interface for the remote bean
Properties p = new Properties();
p.put(Context.PROVIDER_URL, "jnp://10.73.17.76:1099"); //remote Jboss IP
p.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
p.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
Context context;
try {
context = new InitialContext(p);
sbr = (SatheBeanRemote) context.lookup("RemoteEAR/SatheBean/remote");
} catch (NamingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
I am getting the below exception.
javax.ejb.EJBException: Unexpected Error
java.lang.NoClassDefFoundError: com/netapp/beans/SatheBeanRemote
at com.netapp.balaji.greeting.GreetingBean.sayGreeting(GreetingBean.java:78)
Can anyone help me point out the issue ?
Probably, You have to add EJB Project in your client folder's class path, It may resolve the problem
Related
I'm trying to do Remote EJB calls to my Wildfly 10/JBoss 7 EAP server, but keep getting Invalid User error messages on my Wildfly server (my EJB is called LoginManager):
23:04:02,872 ERROR [org.jboss.as.ejb3.invocation] (default task-6) WFLYEJB0034: EJB Invocation failed on component LoginManager for method public abstract java.lang.String ejbs.LoginManagerRemote.echo(java.lang.String): javax.ejb.EJBAccessException: WFLYSEC0027: Invalid User
at org.jboss.as.ejb3.security.SecurityContextInterceptor$1.run(SecurityContextInterceptor.java:69)
at org.jboss.as.ejb3.security.SecurityContextInterceptor$1.run(SecurityContextInterceptor.java:49)
at org.jboss.as.ejb3.security.SecurityContextInterceptor.processInvocation(SecurityContextInterceptor.java:97)
I've added my user to the application-users.properties file using the add-user.sh/bat scripts.
I've tried putting in breakpoints in the Wildfly server itself in the SecurityContextInterceptor class on line 54 and see that the principal is null:
if (holder.skipAuthentication == false) {
holder.securityManager.authenticate(holder.runAs, holder.runAsPrincipal, holder.extraRoles);
I'm not entirely sure if this runAs or runAsPrincipal is the principal/credentials passed by the remote EJB invocation, but I suspect it might be responsible for my problem.
I'm calling the remote ejb as:
Properties p = new Properties();
p.setProperty(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
final Context context = new InitialContext(p);
LoginManagerRemote ejb = (LoginManagerRemote) context.lookup("ejb:ear-1.0/ejbs-1.0//LoginManager!ejbs.LoginManagerRemote");
return ejb.echo("test");
with my jboss-ejb-client.properties as:
remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false
remote.connections=default
remote.connection.default.host=localhost
remote.connection.default.port=8080
remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false
remote.conncetion.default.connect.options.org.xnio.Options.SASL_DISALLOWED_MECHANISMS=JBOSS-LOCAL-USER
remote.connection.default.username=test
remote.connection.default.password=test
Am I doing something wrong? Am I missing something obvious somewhere? What do I need to do to successfully call a remote EJB?
There's a typo in your jboss-ejb-client.properties
remote.conncetion.default.connect.options.org.xnio.Options.SASL_DISALLOWED_MECHANISMS=JBOSS-LOCAL-USER
Should be remote.connection.default.connect.options etc etc
I already have a integration-test phase, when I ran the selenium tests. I also want to run some unit tests in this phase, because the app is too much complex and have a lot of dependencies between his modules (a hell), so, after a week fighting against OpenEJB and Arquillian, I believe that this would be easier.
The thing is: how do I made it work?
I have the instance already running, if I instantiate an InitialContext and try to lookup some bean, I got an exception telling me that I have not set the java.naming.initial.factory, and I don't know what to put in there.
I'm also complaining about the annotated beans.
Suppose a Bean like this:
#Stateless
public class ABeanImpl implements ABean {
#EJB
private BBean;
}
Will the container automatically get right the BBean?
Thanks in advance
How to connect to JBoss 7.1 remote JNDI:
Here is the code snippet that I use for JBoss 7.1:
Properties props = new Properties();
String JBOSS_CONTEXT = "org.jboss.naming.remote.client.InitialContextFactory";
props.put("jboss.naming.client.ejb.context", true);
props.put(Context.INITIAL_CONTEXT_FACTORY, JBOSS_CONTEXT);
props.put(Context.PROVIDER_URL, "remote://localhost:4447");
props.put(Context.SECURITY_PRINCIPAL, "jboss");
props.put(Context.SECURITY_CREDENTIALS, "jboss123");
InitialContext ctx = new InitialContext(props);
Resolution of ambiguous ejb references:
According to JBoss EJB 3 reference, if at any level of your EJB environment (EJB/EAR/Server) are duplicates in used interfaces, exception will be thrown during resolution of injected beans.
Based on above, if you have got a reference to EJB bean which interface:
has two implementations in your EJB module (JAR/WAR) - exception will be thrown
has two implementations in your application (other EJB JAR's in same EAR) - exception will be thrown
has two implementations, one in module with bean ABeanImpl, second somewhere else - implemetation from current module is used.
after quite a while I made the remote access to a stateless EJB run under JBoss 7.1.1. using Properties object:
Properties jndiProps = new Properties();
jndiProps.put(Context.INITIAL_CONTEXT_FACTORY,
"org.jboss.naming.remote.client.InitialContextFactory");
jndiProps.put(Context.PROVIDER_URL,"remote://localhost:4447");
jndiProps.put(Context.SECURITY_PRINCIPAL, "remote");
jndiProps.put(Context.SECURITY_CREDENTIALS, "remotepwd");
jndiProps.put("jboss.naming.client.ejb.context", true);
Context ctx = new InitialContext(jndiProps);
String lookupString = "//HelloWorld/HelloWorldBean!org.acme.test.HelloWorld";
HelloWorld hw = (HelloWorld) ctx.lookup(lookupString);
System.out.println("Response: "+ hw.sayHello("Hi there"));
So this works fine but now I want to put the JNDI thing into jndi.properties file but failed, this is how the file looks like:
java.naming.factory.initial=org.jboss.naming.remote.client.InitialContextFactory
java.naming.factory.url.pkgs=org.jboss.ejb.client.naming
java.naming.provider.url=remote://localhost:4447
java.naming.security.principal=remote
java.naming.security.credentials=remotepwd
The exception:
Exception in thread "main" java.lang.IllegalStateException: No EJB receiver available for handling [appName:,modulename:HelloWorld,distinctname:] combination for invocation context org.jboss.ejb.client.EJBClientInvocationContext#108c175
at org.jboss.ejb.client.EJBClientContext.requireEJBReceiver(EJBClientContext.java:584)
at org.jboss.ejb.client.ReceiverInterceptor.handleInvocation(ReceiverInterceptor.java:119)
at org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:181)
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.sayHello(Unknown Source)
at de.brockhaus.test.client.TestClient.main(TestClient.java:35)
I already went through several doco but failed, so how does it have to look like then?
OK, so I found the answer myself ...
First you need to have two properties files, jndi.properties plus jboss-ejb-client.properties.
jndi.properties:
#
# jndi.properties
#
java.naming.factory.initial=org.jboss.naming.remote.client.InitialContextFactory
java.naming.factory.url.pkgs=org.jboss.ejb.client.naming
java.naming.provider.url=remote://localhost:4447
java.naming.security.principal=remote
java.naming.security.credentials=remotepwd
jboss-ejb-client.properties:
#
# jboss-ejb-client.properties
#
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
Having both of them on the classpath will make the code run like a charm even without specifying the properties within the code.
Still confusing is the construction of the lookup string ...
I've followed the instructions here to create a client to a remote SessionBean. I run the client on the same machine that Glassfish 3.1.2 beta is running on. When I use the gf-client.jar from the 3.1.2 beta Glassfish I get the following Exception which is the same Exception if I leave the gf-client.jar out of the classpath:
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
If I use a 3.1.1 gf-client.jar from a Maven repository I get a huge stack trace with complaints about it not being able to find some .jar files from Derby which I'm not even using. Apparently a version mismatch problem.
Has anyone gotten a standalone client to connect to Glassfish 3.1.2 beta? Did this change in JavaEE 6?
Here's the code:
#Stateless
public class LockTestDeadlockService implements LockTestDeadlockServiceI {
public int getP1Id() throws SQLException {
int parentId = -1;
return parentId;
}
}
#Remote
public interface LockTestDeadlockServiceI {
public int getP1Id() throws SQLException;
public void insertChildUpdateParent(int parentId) throws SQLException;
}
Here's my client:
public class LoadTestClient {
static Logger logger = Logger.getLogger(LoadTestClient.class);
public static void main(String[] args) {
String jndiName = "java:global/locktest-0.0.1-SNAPSHOT/LockTestDeadlockService";
try {
LockTestDeadlockServiceI lockTestService =
(LockTestDeadlockServiceI) new InitialContext().lookup(jndiName);
logger.info("Got lockTestService Remote Interface");
} catch (NamingException e) {
logger.info("Failed to get lockTestService Remote Interface: " + e);
}
}
}
The short answer is that to connect to GF 3.x from a client, you need a mini-glassfish install via the Application Client Container (ACC) using either webstart or the package-appclient script. Open up the gf-client.jar and look at its classpath in the manifest file. There are a ton of files listed in there. This was similar in GF 2.x, but it seemed to need less dependencies on the client (though it was 15MB with that version).
See these:
Create an "Application Client" with Maven in Java EE
With which maven dependencies can i create a standalone JMS client for Glassfish?
http://docs.oracle.com/cd/E18930_01/html/821-2418/beakt.html#scrolltoc
http://docs.oracle.com/cd/E18930_01/html/821-2418/beakv.html#beakz
First of all, I'd like to underline that I've already read other posts in StackOverflow (example) with similar questions, but unfortunately I didn't manage to solve this problem with the answers I saw on those posts. I have no intention to repost a question that has already been answered, so if that's the case, I apologize and I'd be thankful to whom points out where the solution is posted.
Here is my question:
I'm trying to deploy an EJB in WebLogic 10.3.2. The purpose is to use a specific WorkManager to execute work produced in the scope of this component.
With this in mind, I've set up a WorkManager (named ResponseTimeReqClass-0) on my WebLogic configuration, using the web-based interface (Environment > Work Managers > New). Here is a screenshot:
Here is my session bean definition and descriptors:
OrquestratorRemote.java
package orquestrator;
import javax.ejb.Remote;
#Remote
public interface OrquestratorRemote {
public void initOrquestrator();
}
OrquestratorBean.java
package orquestrator;
import javax.ejb.Stateless;
import com.siemens.ecustoms.orchestration.eCustomsOrchestrator;
#Stateless(name = "OrquestratorBean", mappedName = "OrquestratorBean")
public class OrquestratorBean implements OrquestratorRemote {
public void initOrquestrator(){
eCustomsOrchestrator orquestrator = new eCustomsOrchestrator();
orquestrator.run();
}
}
META-INF\ejb-jar.xml
<?xml version='1.0' encoding='UTF-8'?>
<ejb-jar xmlns='http://java.sun.com/xml/ns/javaee'
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
metadata-complete='true'>
<enterprise-beans>
<session>
<ejb-name>OrquestradorEJB</ejb-name>
<mapped-name>OrquestratorBean</mapped-name>
<business-remote>orquestrator.OrquestratorRemote</business-remote>
<ejb-class>orquestrator.OrquestratorBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
</session>
</enterprise-beans>
<assembly-descriptor></assembly-descriptor>
</ejb-jar>
META-INF\weblogic-ejb-jar.xml
(I've placed work manager configuration in this file, as I've seen on a tutorial on the internet)
<weblogic-ejb-jar xmlns="http://www.bea.com/ns/weblogic/90"
xmlns:j2ee="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.bea.com/ns/weblogic/90
http://www.bea.com/ns/weblogic/90/weblogic-ejb-jar.xsd">
<weblogic-enterprise-bean>
<ejb-name>OrquestratorBean</ejb-name>
<jndi-name>OrquestratorBean</jndi-name>
<dispatch-policy>ResponseTimeReqClass-0</dispatch-policy>
</weblogic-enterprise-bean>
</weblogic-ejb-jar>
I've compiled this into a JAR and deployed it on WebLogic, as a library shared by administrative server and all cluster nodes on my solution (it's in "Active" state).
As I've seen in several tutorials and examples, I'm using this code on my application, in order to call the bean:
InitialContext ic = null;
try {
Hashtable<String,String> env = new Hashtable<String,String>();
env.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
env.put(Context.PROVIDER_URL, "t3://localhost:7001");
ic = new InitialContext(env);
}
catch(Exception e) {
System.out.println("\n\t Didn't get InitialContext: "+e);
}
//
try {
Object obj = ic.lookup("OrquestratorBean");
OrquestratorRemote remote =(OrquestratorRemote)obj;
System.out.println("\n\n\t++ Remote => "+ remote.getClass());
System.out.println("\n\n\t++ initOrquestrator()");
remote.initOrquestrator();
}
catch(Exception e) {
System.out.println("\n\n\t WorkManager Exception => "+ e);
e.printStackTrace();
}
Unfortunately, this don't work. It throws an exception on runtime, as follows:
WorkManager Exception =>
javax.naming.NameNotFoundException:
Unable to resolve 'OrquestratorBean'.
Resolved '' [Root exception is
javax.naming.NameNotFoundException:
Unable to resolve 'OrquestratorBean'.
Resolved '']; remaining name
'OrquestratorBean'
After seeing this, I've even tried changing this line
Object obj = ic.lookup("OrquestratorBean");
to this:
Object obj = ic.lookup("OrquestratorBean#orquestrator.OrquestratorBean");
but the result was the same runtime exception.
Can anyone please help me detecting what am I doing wrong here? I'm having a bad time debugging this, as I don't know how to check out what may be causing this issue...
Thanks in advance for your patience and help.
Your EJB gets bound under the following JNDI name (when deployed as EJB module):
Object obj = ic.lookup("OrquestratorBean#orquestrator.OrquestratorRemote");
Note that I deployed your code (without the weblogic-ejb-jar.xml) as an EJB module, not as a shared library.
seems like your mapped-name in ejb-jar.xml "Orquestrator" may be overriding the mappedName=OrquestratorBean setting of the Bean.
Have you tried ic.lookup for "Orquestrator" ?