Using InitialContext for lookups on Liberty - ejb

I am working on migrating ear application from WebSphere 8.5 to WebSphere Liberty.
There are 2 EJB Applications A and B deployed on different systems.
In the code , whenever B has to talk with A, the steps were
a) Create InitialContext and pass the EJB URL of A
Hashtable<String, String> env = new Hashtable<String, String>();
env.put(Context.INITIAL_CONTEXT_FACTORY,"com.ibm.websphere.naming.WsnInitialContextFactory");
env.put(Context.PROVIDER_URL, url);
InitialContext ic = new InitialContext(env)
b) Use this InitialContext to then do JNDI lookup
To migrate this code to Liberty , I need to replace all JNDI lookups for EJB Interfaces with java namespace.
The migration tool also suggests using default InitialContext and not passing the INITIAL_CONTEXT_FACTORY and PROVIDER_URL on Liberty
InitialContext context = new InitialContext();
My question is how will this work in case of liberty for the above scenario where A and B are on remote systems ?
Don't we require the EJB Url to be provided?
Another related question is whether this change is backward compatible with Websphere 8.5

On Liberty, the java: namespace lookups are only available when looking up beans within the same server process. To lookup beans between server processes, you must use a corbaname lookup, where the corbaname would include the host and IP address of the target server. Details about this may be found here:
https://www.ibm.com/support/knowledgecenter/SSD28V_liberty/com.ibm.websphere.wlp.core.doc/ae/twlp_ejb_remote.html
Also, an example of this may be found in the open-liberty source test project that explicitly tests different ways of looking up remote EJBs between processes:
https://github.com/OpenLiberty/open-liberty/blob/integration/dev/com.ibm.ws.ejbcontainer.remote_fat/fat/src/com/ibm/ws/ejbcontainer/remote/fat/tests/Server2ServerTests.java
And the actual servlet for that test (running on one of the two servers) is found here:
https://github.com/OpenLiberty/open-liberty/blob/integration/dev/com.ibm.ws.ejbcontainer.remote_fat/test-applications/RemoteClientWeb.war/src/com/ibm/ws/ejbcontainer/remote/client/web/RemoteTxAttrServlet.java
The test is using localhost since both servers are on the same system, so that would need to be replaced if they are on separate systems.
As for being portable with WebSphere traditional 8.5, the answer is no. WebSphere traditional and Liberty would both support looking up remote interfaces in the java: name spaces for beans that are co-located in the same server process, however the behavior for looking up EJBs between processes is not compatible.

Related

EJB: What is remote client?

I am going through EJB specification(ejb-3_1-pfd-spec). I am not able to completely grasp concept of remote client:
Spec document states following:
"The interface used by a remote client of a session bean is implemented by the container as a remote business interface (or a remote EJBObject interface), and the remote client view of a session bean is location-independent. A client running in the same JVM as the session object uses the same API as a client running in a different JVM on the same or different machine"
This suggests that remote client can run in same JVM or different JVM from session object.
But different discussion threads suggest that a remote client is one which runs in JVM different from session bean.
So which definition is more accurate.
Any guidance would be of great value.
This is a bit reflexive - a remote client on JVM A on machine A is connecting through to an EJB component on JVM B on machine B, that's all either side is aware of. In some situations, it may be that machine A and machine B are the same machine. It may also happen that JVM A and JVM B are the same JVM.
The important thing is that remote clients are location agnostic - they must behave the same regardless of where they are on the network. As a programmer, this means your code must not assume they are in the same place. As a deployer, it means that you can choose to deploy them on one machine or on several, without any code changes.

Remote EJB in Domain mode WildFly

We are trying to lookup a remote EJB across wildfly running in domain mode with two nodes.
The setup is like this:
Wildfly Node 1:
Module A: EJB Client
Module B: Remote EJB
Wildfly Node 2:
Module A: EJB Client
Module B: Remote EJB
The wildfly nodes are part of a single domain.
Now, if we lookup the remote EJB across the nodes, it should return the EJB from the same node first, if it is available. Only if, it is not available, should the lookup return EJB from other node.
We have configured the EJB as clustered.
The problem is that even if we use "java:global" binding, the lookup is always returning the EJB from other node.
What configuration are we missing?
Have you tried configuring the JNDI properties for your InitialContext before doing the lookup? You can create a properties file and load at the moment to instantiate your InitialContext, in this file you can define the primary and secondary host that will be used to get the proxy, you can define this by a properties file or programmatically.
https://docs.jboss.org/author/display/AS71/EJB+invocations+from+a+remote+client+using+JNDI

Kettle client to invoke EJBs deployed in JBoss

I'm just starting with Kettle (PDI).
I want to know if it is possible to deploy EJB3 in JBoss AS 5.1.0, and then invoke EJBs from a remote client through KETTLE by using the JNDI API to first lookup the bean proxy and then invoke on that proxy?
Basically, I want to extract, transform and load data that was deployed to the application server through Kettle.
Thanks
Generally speaking you'd like to implement a normal stand-alone remote EJB client. This client is to be integrated into an (open source) ETL tool.
I would be very surprised if this does not work. If you managed to have a stand-alone remote client (sometimes tough enough), there could be one problem: Conflicting libraries: Normally a JBoss clients use jboss-client.jar, and its content may conflict with libraries provided by Kettle. But Kettle is open source, so with a little effort you could resolve this as well.

How to configure a Message Driven Bean to subscribe to a remote JMS Topic

I am trying to get a MessageDriven (EJB 3) bean to subscribe to a JMS Topic on another glassfish instance on another host. Is this possible?
In the Glassfish console you can modify the JMS server and point it to another Glassfish instance or a standalone OpenMQ broker. Although you can configure several JMS hosts to my knowledge Glassfish will always use the one called default_JMS_host so that's the one you want to edit.
Just one thing: in such a setup the two server instances will share queues and topics, which may not be what you want if the two servers are for example running the same application but don't want to share e.g a particular queue. This can easily be solved via the Destination Resources configuration, by specifying different physical names for that queue.

Call to EJB method from a remote jboss server(servlet)

case 1:
I'm having war in one jboss server and ejb jar in another jboss server.
I want to call my ejb from my servlet which is present in another server.
How to call it. can any one help me with a working sample and required configurations.
case 2:
Message Driven Bean(MDB) in my transaction jboss server and business method in another jboss server. How to call my business method from my transaction server.
kindly help me to solve this case
Thanks in advance
I can't (won't) help with a working example, but this is what you have to do:
Your EJBs (session beans) must be configured in a way to support remote access, RMI.
You have to export your EJB client classes into a separate JAR file; those are the interfaces and base classes required to perform an RMI call (stubs). This is required as clients (your WAR) must understand how to deserialize/serialize the RMI communication between your servlets and the remote EJBs.
Make the exported EJB client JAR available to your WAR file
Define an initial context pointing to your remote EJB server as described here.
Deploy and run it...
BTW: A personal opinion, RMI communication is painful and you should try to avoid it as it tightly couples the client (your WAR) to the remote EJBs.
EDIT: Which EJB version and which IDE do you use?

Resources