How to lookup ejb on JBoss AS 7.x - ejb

I try ejb lookup for jndi name.
That ejb is same jboss server then is success. But ejb is other jboss server then is failed.
My source code:
Hashtable<String, String> env = new Hashtable<String, String>();
env.put("java.naming.provider.url","jnp://192.168.100.10:8484");
env.put("java.naming.factory.initial",
"org.jboss.as.naming.InitialContextFactory");
env.put("java.naming.factory.url.pkgs",
"org.jboss.as.naming.interfaces.java");
env.put("java.naming.security.principal", "Admin");
env.put("java.naming.security.credentials",
"password");
Context context = new InitialContext(env);
IMyLogic infoLogic = (IMyLogic) context.lookUp("java:global/MyApplication/MyModule/MyLogic!org.test.interfaces.IMyLogic");
IMyLogic ejb 192.168.100.10 jboss as 7.1 deployed.
I try lookup 192.168.100.15 jboss as 7.1.
Thanks.

You should use this guide to make remote invocations to an EJB from a standalone client:
https://docs.jboss.org/author/display/AS71/EJB+invocations+from+a+remote+client+using+JNDI
Or if you are in another JBoss instance, then use the accompanying article:
https://docs.jboss.org/author/display/AS71/EJB+invocations+from+a+remote+server+instance

Related

Lookup Remote EJBs on Liberty (wlp-javaee8.21.0.0.8)

As the title says. I have some EJBs in an EAR and I have a client jar providing remote methods to a JSF app also sitting in liberty (different server/machine). The client jar tries to access the remote EJBs via lookup.
This is breaking my heart for two days now. As the title says...
I am aware of other stackoverflow questions from the past and I am aware of the following resources:
https://www.ibm.com/docs/en/was-liberty/core?topic=liberty-using-enterprise-javabeans-remote-interfaces
https://github.com/OpenLiberty/open-liberty/blob/release/dev/com.ibm.ws.ejbcontainer.remote_fat/test-applications/RemoteClientWeb.war/src/com/ibm/ws/ejbcontainer/remote/client/web/RemoteTxAttrServlet.java
I have tried every combination provided in the above but no joy.
I use (wlp-javaee8.21.0.0.8) with javaee8 feature enabled, this enables everything else I need e.g. ejb-3.2, ejbRemote-3.2, jndi-1.0 and a few others)
I have an EAR my-ear that contains a module my-module-1.0.4-SNAPSHOT.jar which contains my beans. I am using gradle/liberty plugin and IntelliJ.
I am using tests from within IntelliJ in the client jar module to try to access the remote beans.
My myEAR deploys fine and starts up fine and the app shows running in admincenter. In messages.log I see my EJB bindings. Just picking one example.
[16/08/21 10:58:42:384 IST] 00000022
com.ibm.ws.ejbcontainer.osgi.internal.NameSpaceBinderImpl I
CNTR0167I: The server is binding the
my.org.functiona.ejb.advance.MyAdvance interface of the MyAdvanceBean
enterprise bean in the my-module-1.0.4-SNAPSHOT.jar module of the
my-ear application. The binding location is:
ejb/my-ear/my-module-1.0.4-SNAPSHOT.jar/MyAdvanceBean#my.org.functiona.ejb.advance.MyAdvance
[16/08/21 10:58:42:385 IST] 00000022
com.ibm.ws.ejbcontainer.osgi.internal.NameSpaceBinderImpl I
CNTR0167I: The server is binding the
my.org.functiona.ejb.advance.MyAdvance interface of the MyAdvanceBean
enterprise bean in the my-module-1.0.4-SNAPSHOT.jar module of the
my-ear application. The binding location is:
my.org.functiona.ejb.advance.MyAdvance [16/08/21 10:58:42:385 IST]
00000022 com.ibm.ws.ejbcontainer.runtime.AbstractEJBRuntime
I CNTR0167I: The server is binding the
my.org.functiona.ejb.advance.MyAdvance interface of the MyAdvanceBean
enterprise bean in the my-module-1.0.4-SNAPSHOT.jar module of the
my-ear application. The binding location is:
java:global/my-ws-ear/my-module-1.0.4-SNAPSHOT.jar/MyAdvanceBean!my.org.functiona.ejb.advance.MyAdvance
This is my corresponding interface:
package my.org.functiona.ejb.advance;
import javax.ejb.Remote;
#Remote
public interface MyAdvance {
This is my corresponding implementation:
package my.org.functiona.ejb.advance;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
#Stateless(mappedName = "MyAdvance")
#TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public class MyAdvanceBean implements MyAdvance {
Like I said, its breaking my heart. I tried every combination of provided in the (patchy) documentation and other sources. The most progress I made was by accessing "corbaname::localhost:2809/NameService" through a default InitialContext().lookup. So at least I was able to confirm I can gwet through to the NameService. But any subsequent bean lookup using that context with any combination of the names provided in messages.log or in the code snippets from documentation all fail with the exception below.
javax.naming.NameNotFoundException [Root exception is org.omg.CosNaming.NamingContextPackage.NotFound: IDL:omg.org/CosNaming/NamingContext/NotFound:1.0]
Same for InitialContext() lookups where I prefix the names with "corbaname::localhost:2809/NameService#".
I tried
ejb/my-ear/my-module-1.0.4-SNAPSHOT.jar/MyAdvanceBean#my.org.functiona.ejb.advance.MyAdvance
ejb/global/my-ear/my-module-1.0.4-SNAPSHOT.jar/MyAdvanceBean#my.org.functiona.ejb.advance.MyAdvance
ejb/my-ear/my-module-1.0.4-SNAPSHOT.jar/MyAdvance#my.org.functiona.ejb.advance.MyAdvance
ejb/global/my-ear/my-module-1.0.4-SNAPSHOT.jar/MyAdvance#my.org.functiona.ejb.advance.MyAdvance
java:global/my-ear/my-module-1.0.4-SNAPSHOT.jar/MyAdvance#my.org.functiona.ejb.advance.MyAdvance
java:global/my-ear/my-module-1.0.4-SNAPSHOT.jar/MyAdvanceBean#my.org.functiona.ejb.advance.MyAdvance
my.org.functiona.ejb.advance.MyAdvance
and probably a few others
I replaced the # sign with an exclamation mark in all of the above. And went through it again.
I tried corbaloc:: and corbaloc:iiop: for context. Nothing.
I am no web dev expert but this feels very try and error and I dont feel it should be like that. I understand in websphere proper I could identify the names in the admin console but then I'm not even certain websphere proper and liberty behave the same way.
Sine accessing EJBs from remote seems bread & butter stuff I assume I am overlooking something basic and silly due to my inexperience.
Any pointers anyone? Thank you so much for your time reading this.
Carsten
Edit: server.xml
<server description="disbCoreServer">
<featureManager>
<feature>javaee-8.0</feature>
<feature>adminCenter-1.0</feature>
<feature>websocket-1.1</feature>
</featureManager>
<quickStartSecurity userName="admin" userPassword="carsten" />
<!-- To access this server from a remote client add a host attribute to the following element, e.g. host="*" -->
<httpEndpoint id="defaultHttpEndpoint"
host="${hostname}"
httpPort="${default.http.port}"
httpsPort="${default.https.port}">
<accessLogging filepath="${com.ibm.ws.logging.log.directory}/accessLog.log" logFormat='%h %i %u %t "%r" %s %b %{R}W' />
<tcpOptions soReuseAddr="true" />
</httpEndpoint>
<include location="appConfXML/disb_core_jndi.xml"/>
<include location="appConfXML/disb_core_jdbc.xml"/>
<include location="appConfXML/disb_core_jms.xml"/>
<include location="appConfXML/disb_core_mail.xml"/>
</server>
The example provided through the FAT test (remoteLookup) works just fine. I just didnt have all my ducks in a row.
https://github.com/OpenLiberty/open-liberty/blob/release/dev/com.ibm.ws.ejbcontainer.remote_fat/test-applications/RemoteClientWeb.war/src/com/ibm/ws/ejbcontainer/remote/client/web/RemoteTxAttrServlet.java
My scenario is serverA hosting EJBs and serverB running the remote client calling serverA's EJBs.
Steps on serverB are:
Get (local) InitialContext with no properties: InitialContext initialContext = new InitialContext();
With the above lookup the remote Context: Context remoteContext = (Context) initialContext.lookup("corbaname::remotehost:remotePort/NameService");
With the remoteContext lookup the EJB remote interfaces and 'narrow' and cast them to appropriate type
String lookupName = "ejb/global" + "/" + "MyAppName" + "/" + "MyModuleName" + "/" + jndiName;
Object remoteObj = remoteContext.lookup(lookupName);
return interfaceClass.cast(PortableRemoteObject.narrow(remoteObj, interfaceClass));
Where
"MyAppName" is my apps name, the name of the EAR in my case (without .jar)
"MyModuleName" is the name of the EJB module within my EAR (without .jar)
and jndiName is the bean name / fully qualified interface name separated by exclamation mark e.g. "MyBean!myorg.ejb.interfaces.MyBeanIfc"
Call the interfaces to remotely execute serverA EJB code
Note: When running serverA and serverB on the same machine (e.g. localhost) ensure they are not operating on the same port for NameService.
Thanks to everyone who tried to help!

Wildfly not crating JNDI bindings for beans implementing 2 interfaces

I am having an issues with Wildfly 15.0.0 that it's not crating a JNDI for an EJB that is implementing both local and remote interfaces. My classes are as follows:
Local interface:
#Local
public interface BlockingManagerRemote{
}
Remote interface:
#Remote
public interface BlockingManagerLocal{
}
implementation:
#Remote({BlockingManagerRemote.class})
#Local({BlockingManagerLocal.class})
#Stateless
public class BlockingManager
implements BlockingManagerRemote, BlockingManagerLocal {
}
I get the following message first:
2019-03-13 12:09:57,459 INFO [org.jboss.as.ejb3.deployment] (MSC service thread 1-3) WFLYEJB0111: No jndi bindings will be created for EJB BlockingManager since no views are exposed
And When trying to inject this EJB in another class as follows:
#Remote({BusinessUserManagerRemote.class})
#Local({BusinessUserManagerLocal.class})
#Stateless
public class BusinessUserManager
implements BusinessUserManagerLocal, BusinessUserManagerRemote {
#EJB
private BlockingManagerLocal blockingManager;
}
I get this exception:
2019-03-13 12:09:58,469 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-1) MSC000001: Failed to start service jboss.deployment.subunit."mpaymentapp-ear.ear"."mpaymentapp-service-1.0.3-SNAPSHOT.jar".INSTALL: org.jboss.msc.service.StartException in service jboss.deployment.subunit."mpaymentapp-ear.ear"."mpaymentapp-service-1.0.3-SNAPSHOT.jar".INSTALL: WFLYSRV0153: Failed to process phase INSTALL of subdeployment "mpaymentapp-service-1.0.3-SNAPSHOT.jar" of deployment "mpaymentapp-ear.ear"
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:151)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1738)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.execute(ServiceControllerImpl.java:1700)
at org.jboss.msc.service.ServiceControllerImpl$ControllerTask.run(ServiceControllerImpl.java:1558)
at org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
at org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1985)
at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1487)
at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1364)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: WFLYEE0052: Failed to install component BusinessUserManager
at org.jboss.as.ee.component.deployers.ComponentInstallProcessor.deploy(ComponentInstallProcessor.java:109)
at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:144)
... 8 more
Caused by: org.jboss.as.server.deployment.DeploymentUnitProcessingException: WFLYEJB0406: No EJB found with interface of type 'com.cit.mpaymentapp.common.blocking.BlockingManagerLocal' for binding com.cit.mpaymentapp.service.registration.BusinessUserManager/blockingManager
at org.jboss.as.ejb3.deployment.processors.EjbInjectionSource.getResourceValue(EjbInjectionSource.java:90)
at org.jboss.as.ee.component.deployers.ComponentInstallProcessor.processBindings(ComponentInstallProcessor.java:263)
at org.jboss.as.ee.component.deployers.ComponentInstallProcessor.access$000(ComponentInstallProcessor.java:80)
at org.jboss.as.ee.component.deployers.ComponentInstallProcessor$1.handle(ComponentInstallProcessor.java:215)
at org.jboss.as.ee.component.ClassDescriptionTraversal.run(ClassDescriptionTraversal.java:54)
at org.jboss.as.ee.component.deployers.ComponentInstallProcessor.deployComponent(ComponentInstallProcessor.java:218)
at org.jboss.as.ee.component.deployers.ComponentInstallProcessor.deploy(ComponentInstallProcessor.java:101)
... 9 more
The same code was working on JBOSS EAP6. Why Wildfly is not recognizing the local interface BlockingManagerLocal?
I think you should implement your Interfaces as plain java interfaces and add the annotation #LocalBean instead of #Local to your bean implementation.
Remote EJBs should be avoided. I recommend using Rest interfaces instead.

Wildfly 14 JNDI http-remoting request to port 8080 not working with ear and more than 61 jars in it

We are currently migrating from JBoss AS 7 to Wildfly 14. Now we have the strange behavior that our JNDI http-remtoing requests do not work if we have more than 61 jars in our ear (Needed for Authetification and Permissions-Lookup). We can remove any jar (that do not have any dependencies to other artifacts) and if we start our Wildfly it works. It just has to be less than 61 jars in our ear-File (I'm referencing to the modules in the ear, not the libs). No Error-Message on Wildfly appears, it seams that the request never arrives to wildfly, but the client still waits. I tried also with different ports, but nothing.
Our code is compiled with Maven src 1.6 to target 1.7. Running JRE on Wildfly is 1.8.
Do anyone has experienced same problems with migrating from JBoss AS 7 to Wildfly?
We also tried with a older version of Wildfly (Wildfly 11) and had the same Problem. I really don't want to have to debug the server, so if somebody has a clue, experienced the same or any idea why this behaviour can behave, then please help me :-)
At the moment we are trying to set up the Wildfly in Standalone-Mode, target is to let it run in Domain-Mode as a Cluster-Server. When this will work, we want to update our project first to Java 8 and after that to a higher version like Java 10 or 11.
This is the Test-Lookup and -Call that I fire
final Hashtable<String, String> jndiProperties = new Hashtable<>();
//jndiProperties.put(Context.INITIAL_CONTEXT_FACTORY, "org.wildfly.naming.client.WildFlyInitialContextFactory");
jndiProperties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
jndiProperties.put(Context.PROVIDER_URL, "http-remoting://localhost:8080");
jndiProperties.put(Context.SECURITY_PRINCIPAL, "user-name");
jndiProperties.put(Context.SECURITY_CREDENTIALS, "xxxxxxxxxxx");
jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
final Context ctx = new InitialContext(jndiProperties);
final DistServer ds = (DistServer) ctx.lookup(
"ejb:our-server/distribution-server/DistServerBean!com.someenterprise.common.DistServer");
System.out.println("Calling canIAccess returns " + ds.canIAccess());

Websphere 7 and EJB 2.1 - JNDI name not specified

Environment - WAS 7.0 and EJB 2.1
I have a EAR with EJB jar file. It has some remote EJB's (EJB 2.1) that I want to convert to local EJB. Hence i had to modify ejb-jar.xml as per my understanding.
My modified ejb-jar xml file is as follows:
<ejb-jar id="ejb-jar_ID" version="2.1" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd">
....
...
<session id="Manager">
<ejb-name>Manager</ejb-name>
<home>com.aa.bb.ManagerHome</home>
<remote>com.aa.bb.ManagerRemote</remote>
<ejb-class>com.aa.bb.Manager</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
<local-home>com.aa.bb.ManagerLocalHome</local-home>
<local>com.aa.bb.ManagerLocal</local>
<ejb-local-ref id="EJBLocalRef_1139997836094">
<ejb-ref-name>ejb/ManagerLocalHome</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<local-home>com.aa.bb.ManagerLocalHome</local-home>
<local>com.aa.bb.ManagerLocal</local>
<ejb-link>Manager</ejb-link>
</ejb-local-ref>
, and are newly added tags for the local ejb.
And my Bindings file is as follows -
<ejbbnd:EJBJarBinding xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:ejb="ejb.xmi" xmlns:ejbbnd="ejbbnd.xmi" xmi:id="EJBJarBinding_1107442316219">
<ejbJar href="META-INF/ejb-jar.xml#ejb-jar_ID"/>
.....
.....
<ejbBindings xmi:id="EnterpriseBeanBinding_1142021363669" jndiName="ejb/ManagerLocalHome">
<enterpriseBean xmi:type="ejb:Session" href="META-INF/ejb-jar.xml#Manager"/>
<resRefBindings xmi:id="ResourceRefBinding_1315855161720" jndiName="OraDataSource">
<bindingResourceRef href="META-INF/ejb-jar.xml#ResourceRef_1142023723001"/>
</resRefBindings>
</ejbBindings>
During deploy of the EAR file I get the following error -
com.ibm.websphere.management.application.client.AppDeploymentException:
ADMA0014E: Validation failed. ADMA0007E: A Validation error occurred in task Mapping EJB references to enterprise beans.
The Java Naming and Directory Interface (JNDI) name is not specified for reference binding ejb/ManagerLocalHome in module ZZZZZ with EJB name Manager.
Any idea why it would complain about JNDI when it has been defined ?
Am I missing something?
It seems like the jndiName should jndiName="ejb/Manager" in the bindings file and it started working for me.
Had to run it rhought rmic but the lookup is now working.

Hosting .Net Core Web API as Guest Service in Service Fabric

Hi Please can anyone help, I'm trying to get Service Fabric to Host a .Net Core Web API Restful service as a Guest Executable.
I'm guessing possibly incorrectly that I should be able to run the exe once I have done the full publish, but it fails when I do.
I have done the following...
Ensured the main Web API assembly and all referenced .NET Core assemblies are set to x64 Targets
Set the Output type to be an exe and have a program.cs as below...
public static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.UseApplicationInsights()
.Build();
host.Run();
}
Done the command line stuff...
dotnet restore
dotnet publish -c release -r win10-x64
Made a Referenced to "Microsoft.AspNetCore.Server.Kestrel": "1.0.0"
in Project.deps.json in the resultant win10-x64 publish folder.
However when I execute the thing directly the console window reports a problem with the StartUp Constructor, i.e. when performing builder.build.
public Startup(IHostingEnvironment env)
{
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
//.AddServiceFabricConfig("Config") // Add Service Fabric configuration settings.
.AddEnvironmentVariables();
Configuration = builder.Build();
}
I feel close to getting this stuff working and have added a Service Fabric Guest Host project to host the exe, but needless to say the node fails with the error shown below...
Error event: SourceId='System.Hosting', Property='CodePackageActivation:Code:EntryPoint'.
There was an error during CodePackage activation.The service host terminated with exit code:2147516556
What am I doing wrong?

Resources