Invalid URL scheme name "http-remoting" occurring when running application jar - java

I am using one of the JBoss JMS quickstart projects (HelloWorld-JMS) which uses JMS to write to a message queue. The queue has been defined in the JBoss XML configuration file. Our application runs perfectly fine when we run it from the IDE. However, when we package it as a JAR, we start seeing the exception:
SEVERE: Exception NamingException: javax.naming.InvalidNameException: WFNAM00007: Invalid URL scheme name "http-remoting"
We have also tried:
http-remoting://127.0.0.1:8080
remoting+http://127.0.0.1:8080
But we get the same exception.
Here's the main part of my code:
private static final String DEFAULT_MESSAGE = "Hello, World!";
private static final String DEFAULT_CONNECTION_FACTORY = "jms/RemoteConnectionFactory";
private static final String DEFAULT_DESTINATION = "jms/queue/myqueue";
private static final String DEFAULT_MESSAGE_COUNT = "1";
private static final String DEFAULT_USERNAME = "john";
private static final String DEFAULT_PASSWORD = "doe";
private static final String INITIAL_CONTEXT_FACTORY = "org.wildfly.naming.client.WildFlyInitialContextFactory";
private static final String PROVIDER_URL = "http-remoting://127.0.0.1:8080";
Context namingContext = null;
String userName = System.getProperty("username", DEFAULT_USERNAME);
String password = System.getProperty("password", DEFAULT_PASSWORD);
// Set up the namingContext for the JNDI lookup
final Properties env = new Properties();
env.put(Context.INITIAL_CONTEXT_FACTORY, INITIAL_CONTEXT_FACTORY);
env.put(Context.PROVIDER_URL, System.getProperty(Context.PROVIDER_URL, PROVIDER_URL));
env.put(Context.SECURITY_PRINCIPAL, userName);
env.put(Context.SECURITY_CREDENTIALS, password);
namingContext = new InitialContext(env);
// Perform the JNDI lookups
String connectionFactoryString = System.getProperty("connection.factory", DEFAULT_CONNECTION_FACTORY);
log.info("Attempting to acquire connection factory \"" + connectionFactoryString + "\"");
ConnectionFactory connectionFactory = (ConnectionFactory) namingContext.lookup(connectionFactoryString);
log.info("Found connection factory \"" + connectionFactoryString + "\" in JNDI");
The exception occurs at this line:
ConnectionFactory connectionFactory = (ConnectionFactory) namingContext.lookup(connectionFactoryString);
These are the dependencies in pom.xml:
<dependency>
<groupId>org.jboss.eap</groupId>
<artifactId>wildfly-jms-client-bom</artifactId>
<version>7.3.4.GA</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.jboss.eap</groupId>
<artifactId>wildfly-ejb-client-bom</artifactId>
<version>7.3.4.GA</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.jboss.spec.javax.jms</groupId>
<artifactId>jboss-jms-api_2.0_spec</artifactId>
<version>1.0.0.Final-redhat-1</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.8.0</version>
</dependency>
<dependency>
<groupId>org.jboss</groupId>
<artifactId>jboss-ejb-client</artifactId>
<version>4.0.37.Final</version>
</dependency>
<dependency>
<groupId>org.wildfly.common</groupId>
<artifactId>wildfly-common</artifactId>
<version>1.5.4.Final</version>
</dependency>
<dependency>
<groupId>org.jboss.remotingjmx</groupId>
<artifactId>remoting-jmx</artifactId>
<version>3.0.4.Final</version>
</dependency>

It looks to me like your classpath has overlapping classes on it. I see the same thing in your pom.xml. This will cause the wrong classes to be loaded at runtime.
For example, if you look at the pom.xml of the HelloWorld-JMS project you'll see that it only uses the wildfly-jms-client-bom. In fact, the whole point of such a "bom" (i.e. bill of materials) is to incorporate all the required dependencies into a single dependency. Therefore, I recommend you just use this in your pom.xml:
<dependency>
<groupId>org.jboss.eap</groupId>
<artifactId>wildfly-jms-client-bom</artifactId>
<version>7.3.4.GA</version>
<type>pom</type>
</dependency>
Likewise, on your application's classpath you should only have the dependencies of wildfly-jms-client-bom on your classpath (or aggregated equivalents).

Related

Unable to use full text search with oak lucene

I am trying out jackrabbit oak with lucene in a file node store. The index definition record is created successfully but it seems the index record is not created.
The full project I am working on is here
What I am doing in the code is initializa a repository, create the lucene index definition, add a test data with a single property "name" with value "foo".
Sleep for 5 second for async indexing to complete, then perform the following query in a retry loop
select * from [nt:base] where contains(., 'foo').
No result is returned.
I have tried oak-run console to retrieve lc info on oak:index/lucene directory, it displays no result as well.
This is the main part of the code
public static void main( String[] args ) throws Exception
{
init();
createLuceneIndex();
createTestData();
performQuery();
}
private static void init() throws InvalidFileStoreVersionException, IOException {
LuceneIndexProvider provider = new LuceneIndexProvider();
FileStore fs = FileStoreBuilder.fileStoreBuilder(new File("repository")).build();
nodestore = SegmentNodeStoreBuilders.builder(fs).build();
repository = new Jcr(new Oak(nodestore))
.withAsyncIndexing("async", 3)
.with(new LuceneIndexEditorProvider())
.with((QueryIndexProvider) provider)
.with((Observer)provider)
.withAsyncIndexing()
.createRepository();
}
private static void createLuceneIndex() throws RepositoryException {
Session session = createAdminSession();
Node indexesNode = session.getRootNode().getNode("oak:index");
IndexDefinitionBuilder idxBuilder = new IndexDefinitionBuilder();
IndexRule indexRules = idxBuilder.indexRule("nt:unstructured");
indexRules.sync();
indexRules.property("name").analyzed().nodeScopeIndex();
idxBuilder.async("async");
idxBuilder.includedPaths("/");
Node documentIndex = indexesNode.addNode("lucene", "oak:QueryIndexDefinition");
idxBuilder.build(documentIndex);
session.save();
session.logout();
}
private static void createTestData() throws LoginException, RepositoryException {
Session session = createAdminSession();
Node test = session.getRootNode().addNode("test");
test.setProperty("name", "foo");
session.save();
session.logout();
}
private static void performQuery() throws Exception {
final Session session = createAdminSession();
TimeUnit.MICROSECONDS.sleep(5);
QueryManager qm = session.getWorkspace().getQueryManager();
final Query q = qm.createQuery("select * from [nt:base] where contains(., 'foo')", Query.JCR_SQL2);
new RetryLoop(new RetryLoop.Condition() {
public String getDescription() {
return "Full text query";
}
public boolean isTrue() throws Exception {
QueryResult r = q.execute();
return r.getNodes().hasNext();
}
}, 20, 500);
}
the pom file dependencies
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.jcr</groupId>
<artifactId>jcr</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>org.apache.jackrabbit</groupId>
<artifactId>oak-jcr</artifactId>
<version>1.21-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.jackrabbit</groupId>
<artifactId>oak-core</artifactId>
<version>1.21-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.jackrabbit</groupId>
<artifactId>oak-jcr</artifactId>
<version>1.21-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.jackrabbit</groupId>
<artifactId>oak-segment-tar</artifactId>
<version>1.21-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.jackrabbit</groupId>
<artifactId>oak-lucene</artifactId>
<version>1.21-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.30</version>
</dependency>
<dependency>
<groupId>com.codahale.metrics</groupId>
<artifactId>metrics-core</artifactId>
<version>3.0.2</version>
</dependency>

Programmatically connect LDAP and authenticate credentials in AEM

I want to connect to LDAP programmatically in AEM using maven dependency which resolves in OSGi
Approaches and subsequent issues faced:-
1. Cannot use
#Reference
private ExternalIdentityProviderManager externalIdentityProviderManager;
final String externalId = request.getParameter("externalId");
final String externalPassword = request.getParameter("externalPassword");
final ExternalIdentityProvider idap = externalIdentityProviderManager.getProvider("ldap");
final SimpleCredentials credentials = new SimpleCredentials(externalId, externalPassword.toCharArray());
final ExternalUser externalUser = idap.authenticate(credentials);
as this Identity provider config is only present in author environment and not in publish servers(as per req).
2. Trying to use
<dependency>
<groupId>org.apache.directory.api</groupId>
<artifactId>api-ldap-client-api</artifactId>
<version>2.0.0.AM4</version>
</dependency>
to resolve dependencies. It resolve my compile time errors but this is not an 'osgi ready' library, hence couldn't be installed in OSGi. If done so manually it has further unresolved dependencies.
Code reference for this approach -
https://directory.apache.org/api/user-guide/2.1-connection-disconnection.html
&
https://directory.apache.org/api/user-guide/2.10-ldap-connection-template.html
3. I've also tried to use
String rootDN = "uid=admin,ou=system";
String rootPWD = "secret";
Hashtable < String, String > environment = new Hashtable < String, String > ();
environment.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
environment.put(Context.PROVIDER_URL, "ldap://localhost:10389");
environment.put(Context.SECURITY_AUTHENTICATION, "simple");
environment.put(Context.SECURITY_PRINCIPAL, rootDN);
environment.put(Context.SECURITY_CREDENTIALS, rootPWD);
DirContext dirContext = null;
NamingEnumeration < ? > results = null;
dirContext = new InitialDirContext(environment);
SearchControls controls = new SearchControls();
controls.setSearchScope(SearchControls.SUBTREE_SCOPE);
String userId = "abhishek";
String userPwd = "{SSHA}ip/DD+zUhv22NH3wE1dvJN7oauYE4TYQ3ziRtg=="; //"apple";
String filter = "(&(objectclass=person)(uid=" + userId + ")(userPassword=" + userPwd + "))";
results = dirContext.search("", filter, controls);
if(results.hasMore()) {
System.out.println("User found");
} else {
System.out.println("User not found");
}
It has 2 issues -
a) It works fine when tested as plain Java class in main method on class load, but when attempted to integrate in AEM/osgi service class, it throws -
javax.naming.NotContextException: Not an instance of DirContext at javax.naming.directory.InitialDirContext.getURLOrDefaultInitDirCtx(InitialDirContext.java:111) at javax.naming.directory.InitialDirContext.search(InitialDirContext.java:267)
b) Even in plain Java class, i had to provide the hashed password to validate, which would be difficult to integrate.
String userPwd = "{SSHA}ip/DD+zUhv22NH3wE1dvJN7oauYE4TYQ3ziRtg==";//"apple";
Can someone provide me any maven dependency/library that can integrate with osgi and resolve dependency as well as i don't need to provide hashed password to validate user credentials? Any approach that may resolve these issues?
Step 1:
Add these dependencies in project pom
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
<version>2.6.2</version>
</dependency>
<dependency>
<groupId>org.apache.directory.api</groupId>
<artifactId>api-all</artifactId>
<version>1.0.0-RC2</version>
</dependency>
<dependency>
<groupId>org.apache.mina</groupId>
<artifactId>mina-core</artifactId>
<version>2.1.3</version>
</dependency>
<dependency>
<groupId>commons-pool</groupId>
<artifactId>commons-pool</artifactId>
<version>1.6</version>
</dependency>
<dependency>
<groupId>antlr</groupId>
<artifactId>antlr</artifactId>
<version>2.7.7</version>
</dependency>
Step 2:
Add them to bundle pom
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-pool2</artifactId>
</dependency>
<dependency>
<groupId>org.apache.directory.api</groupId>
<artifactId>api-all</artifactId>
</dependency>
<dependency>
<groupId>org.apache.mina</groupId>
<artifactId>mina-core</artifactId>
</dependency>
<dependency>
<groupId>commons-pool</groupId>
<artifactId>commons-pool</artifactId>
</dependency>
<dependency>
<groupId>antlr</groupId>
<artifactId>antlr</artifactId>
</dependency>
Step 3:
In bundle pom at the plugin description
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Import-Package>!net.sf.cglib.proxy, javax.inject;version=0.0.0,*</Import-Package>
<Export-Package />
<Sling-Model-Packages></Sling-Model-Packages>
<Bundle-SymbolicName></Bundle-SymbolicName>
<Embed-Dependency>antlr, mina-core, api-all, commons-pool, commons-pool2</Embed-Dependency>
</instructions>
</configuration>
</plugin>
Use these for the above mentioned plugin
<Import-Package>!net.sf.cglib.proxy</Import-Package>
<Embed-Dependency>antlr, mina-core, api-all, commons-pool, commons-pool2</Embed-Dependency>
Step 4:
Imports are specifics and works only when
<dependency>
<groupId>org.apache.directory.api</groupId>
<artifactId>api-all</artifactId>
<version>1.0.0-RC2</version>
</dependency>
is used. As there are some other dependencies which provides packages/class but they don't work at some point or the other.
import org.apache.directory.api.ldap.model.message.SearchScope;
import org.apache.directory.ldap.client.api.DefaultPoolableLdapConnectionFactory;
import org.apache.directory.ldap.client.api.LdapConnectionConfig;
import org.apache.directory.ldap.client.api.LdapConnectionPool;
import org.apache.directory.ldap.client.template.LdapConnectionTemplate;
import org.apache.directory.ldap.client.template.PasswordWarning;
import org.apache.directory.ldap.client.template.exception.PasswordException;
private String ldapAuthenticationApacheDsFlow(final SlingHttpServletRequest request) {
String status = "";
try {
LdapConnectionConfig config = new LdapConnectionConfig();
config.setLdapHost("localhost");
config.setLdapPort(10389);
config.setName("uid=admin,ou=system");
config.setCredentials("secret");
final DefaultPoolableLdapConnectionFactory factory = new DefaultPoolableLdapConnectionFactory(config);
final LdapConnectionPool pool = new LdapConnectionPool(factory);
pool.setTestOnBorrow(true);
final LdapConnectionTemplate ldapConnectionTemplate = new LdapConnectionTemplate(pool);
final String uid = request.getParameter("externalId");
final String password = request.getParameter("externalPassword");
final PasswordWarning warning = ldapConnectionTemplate.authenticate(
"ou=Users,dc=example,dc=com", "(uid=" + uid +")", SearchScope.SUBTREE, password.toCharArray());
status = "User credentials authenticated";
if(warning != null) {
status = status + " \n Warning!!" +warning.toString();
}
} catch(final PasswordException e) {
status = e.toString();
e.printStackTrace();
}
return status;
}
If no error is thrown at final PasswordWarning warning = user credentials are successfully validated.

When invoke Java Sparkcontext constructor my Maven web app stops without exceptions or other messages

i have a problem with Maven WebApp with following dependences :
` <dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-core_2.10</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-sql_2.10</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>3.4.0-rc1</version>
</dependency>
<dependency>
<groupId>org.mongodb.spark</groupId>
<artifactId>mongo-spark-connector_2.10</artifactId>
<version>2.0.0-rc1</version>
</dependency>`
In a EJB (#stateless with local interface, called from a servlet) i have :
public void callSpark(QParams qp){
String uri = "mongodb://localhost:27017/admin.EventCollection";
try {
SparkConf conf = new SparkConf()
.setMaster("local")
.setAppName("BigDataEvent")
.set("spark.mongodb.input.partitioner",
"MongoPaginateBySizePartitioner")
.set("spark.app.id", "BigDataAnalysis")
.set("spark.mongodb.input.uri", uri)
.set("spark.mongodb.output.uri", uri);
JavaSparkContext jsc = new JavaSparkContext(conf);
SparkSession sparkSession = SparkSession.builder().getOrCreate();
SQLContext sqlc = new org.apache.spark.sql.SQLContext(jsc);
Dataset<Row> df = MongoSpark.load(jsc).toDF();
df.createOrReplaceTempView("EventCollection");
postCodeQuery(df,qp); //my method
eventTypeQuery(sparkSession, eventType); //my method
} catch (Exception ex){Logger.getLogger(SparkContext.class.getName()).log(Level.SEVERE, null, ex);
}
This code works very well in a Java Client Maven application but in this situation (Maven Web APP) the application crashes (without exception and error message) when I call :
JavaSparkContext jsc = new JavaSparkContext(conf);
The application make build and deploy (on GlassFish 4.1.1) without errors or exception.
Anyone Had Similar Experiences with this configuration?
Thanks...

JBoss EJB Client handler missing argument

I am trying to set a new InitialContext in the following manner (which is pretty standard I believe):
private static InitialContext getInitialContext() throws NamingException {
InitialContext context = null;
try {
Properties properties = new Properties();
properties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
properties.put(Context.PROVIDER_URL, "remote://localhost:4447");
properties.put(Context.SECURITY_PRINCIPAL, "username");
properties.put(Context.SECURITY_CREDENTIALS, "password");
context = new InitialContext(properties);
System.out.println("\n\tGot initial Context: " + context);
}
catch (Exception e) {
e.printStackTrace();
}
return context;
}
public static void sendMessage(RoboticsParameters object_msg) throws Exception {
InitialContext context = getInitialContext();
// other code
}
The code "fails" at the line where the new InitialContext is created using the properties and i get a java.lang.NullPointerException. I suspect I am missing an argument. Here is the stack trace:
WARN: EJB client integration will not be available due to a problem setting up the EJB client handler java.lang.NullPointerException
at org.jboss.naming.remote.client.InitialContextFactory.<clinit>(InitialContextFactory.java:118)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:72)
at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:61)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:672)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:313)
at javax.naming.InitialContext.init(InitialContext.java:244)
at javax.naming.InitialContext.<init>(InitialContext.java:216)
Any suggestions?
I am running JBoss EAP 6.4 and using EJB 3. I have jboss-client.jar in the class path.
I checked the source code for:
jboss-remote-naming/src/main/java/org/jboss/naming/remote/client/InitialContextFactory.java
and found where the log message was coming from:
public class InitialContextFactory implements javax.naming.spi.InitialContextFactory {
// code
private static final String REMOTE_NAMING_EJB_CLIENT_HANDLER_CLASS_NAME = "org.jboss.naming.remote.client.ejb.RemoteNamingStoreEJBClientHandler";
// code
try {
klass = classLoader.loadClass(REMOTE_NAMING_EJB_CLIENT_HANDLER_CLASS_NAME);
method = klass.getMethod("setupEJBClientContext", new Class<?>[] {Properties.class, List.class});
} catch (Throwable t) {
logger.warn("EJB client integration will not be available due to a problem setting up the EJB client handler", t);
}
// other code
}
The class org.jboss.naming.remote.client.ejb.RemoteNamingStoreEJBClientHandler was in the jar that I added to the class path but for some reason there were problems loading the class.
Then I stumbled upon this small README-EJB-JMS.txt file in the [jboss_home]/bin/client folder which states the following:
"Maven users should not use this jar, but should use the following BOM dependencies instead
<dependencies>
<dependency>
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-ejb-client-bom</artifactId>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-jms-client-bom</artifactId>
<type>pom</type>
</dependency>
</dependencies>
This is because using maven with a shaded jar has a very high chance of causing class version conflicts, which is why
we do not publish this jar to the maven repository."
So, I added the maven dependency instead of having the jar in my class path and VOILA! It works!

Not able to lookup Remote EJB in JBoss 7.x

I am trying to connect to a Remote EJB that is deployed in a JBoss 7 Server. I tried to figure out what the JNDI name is by looking at the JNDI dump that I got from the JBoss CLI.
No matter what I try I cannot lookup the EJB.
I think that the jndi name should be: java:global/XNet/api/ReceivingAPI_EJB!com.mycompany.receiving.api.ReceivingAPI_EJBRemote
Here is the client that I am using:
package com.mycompany.mavenproject1;
import com.mycompany.receiving.api.ReceivingAPI_EJBRemote;
import com.mycompany.receiving.api.ReceivingAPI;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import java.util.Properties;
/**
* Hello world!
*
*/
public class App
{
public static void main( String[] args ) throws NamingException
{
System.out.println( "Hello World!" );
//ReceivingAPI ejbRemote = DomainHelper.getHQApi(com.mycompany.receiving.api.ReceivingAPI.class);
ReceivingAPI_EJBRemote ejbRemote = App.lookupRemoteStatelessCalculator();
ejbRemote.getOpenRcvdocForSite(null, 7);
}
// private static ReceivingAPI_EJBRemote lookupRemoteStatelessReceiving() throws NamingException {
//
// }
//
private static ReceivingAPI_EJBRemote lookupRemoteStatelessCalculator() throws NamingException {
final Properties jndiProperties = new Properties();
jndiProperties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
jndiProperties.put(Context.PROVIDER_URL,"remote://someserver.xmx.com:1199");
// username
jndiProperties.put(Context.SECURITY_PRINCIPAL, "mycompany1");
// password
jndiProperties.put(Context.SECURITY_CREDENTIALS, "<removed>");
//final Context context = new InitialContext(jndiProperties);
jndiProperties.put("jboss.naming.client.ejb.context", true);
InitialContext context = new InitialContext( jndiProperties );
// 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 = "XNet";
// 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 = "api";
// 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 = "hq";
// The EJB name which by default is the simple class name of the bean implementation class
final String beanName = com.mycompany.receiving.api.ReceivingAPI.class.getSimpleName();
// the remote view fully qualified class name
final String viewClassName = ReceivingAPI_EJBRemote.class.getName();
// let's do the lookup
try {
ReceivingAPI test1 = (ReceivingAPI)context.lookup("java:global/XNet/api/" + beanName + "_EJB!" + viewClassName);
System.out.println("Test1 = " + test1.getClass().getName());
} catch(Throwable t) {
System.out.println(t);
}
try {
ReceivingAPI test = (ReceivingAPI)context.lookup("java:global/XNet/api/hq/" + beanName + "_EJB!com.mycompany.receiving.api.ReceivingAPI_EJBRemote");
System.out.println("Test = " + test.getClass().getName());
} catch(Throwable t) {
System.out.println(t);
}
try {
ReceivingAPI test = (ReceivingAPI)context.lookup("ejb:XNet/api/hq/" + beanName + "_EJB!com.mycompany.receiving.api.ReceivingAPI_EJBRemote");
System.out.println("Test = " + test.getClass().getName());
} catch(Throwable t) {
System.out.println(t);
}
return (ReceivingAPI_EJBRemote) context.lookup("ejb:" + appName + "/" + moduleName + "/" + distinctName + "/" + beanName + "_EJB!" + viewClassName);
}
}
The output from the run of the previous java class:
Hello World!
javax.naming.NameNotFoundException: global/XNet/api/ReceivingAPI_EJB!com.mycompany.receiving.api.ReceivingAPI_EJBRemote -- service jboss.naming.context.java.jboss.exported.global.XNet.api."ReceivingAPI_EJB!com.mycompany.receiving.api.ReceivingAPI_EJBRemote"
javax.naming.NameNotFoundException: global/XNet/api/hq/ReceivingAPI_EJB!com.mycompany.receiving.api.ReceivingAPI_EJBRemote -- service jboss.naming.context.java.jboss.exported.global.XNet.api.hq."ReceivingAPI_EJB!com.mycompany.receiving.api.ReceivingAPI_EJBRemote"
javax.naming.NameNotFoundException: ejb:XNet/api/hq/ReceivingAPI_EJB!com.mycompany.receiving.api.ReceivingAPI_EJBRemote -- service jboss.naming.context.java.jboss.exported.ejb:XNet.api.hq."ReceivingAPI_EJB!com.mycompany.receiving.api.ReceivingAPI_EJBRemote"
Exception in thread "main" javax.naming.NameNotFoundException: ejb:XNet/api/hq/ReceivingAPI_EJB!com.mycompany.receiving.api.ReceivingAPI_EJBRemote -- service jboss.naming.context.java.jboss.exported.ejb:XNet.api.hq."ReceivingAPI_EJB!com.mycompany.receiving.api.ReceivingAPI_EJBRemote"
at org.jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:97)
at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:178)
at org.jboss.naming.remote.protocol.v1.Protocol$1.handleServerMessage(Protocol.java:127)
at org.jboss.naming.remote.protocol.v1.RemoteNamingServerV1$MessageReciever$1.run(RemoteNamingServerV1.java:73)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:724)
Here is the dump of the JNDI CLI Command:
[jboss1#hmudev01 bin]$ ./jboss-cli.sh --connect controller=localhost:10099
[standalone#localhost:10099 /] /subsystem=naming:jndi-view
{
"outcome" => "success",
"result" => {
"java: contexts" => {
"java:global" => {
"XNet" => {
"class-name" => "javax.naming.Context",
"children" => {
"api" => {
"class-name" => "javax.naming.Context",
"children" => {
"ReceivingAPI_EJB!com.mycompany.receiving.api.ReceivingAPI_EJBLocal" => {
"class-name" => "com.mycompany.receiving.api.ReceivingAPI_EJBLocal$$$view46",
"value" => "Proxy for view class: com.mycompany.receiving.api.ReceivingAPI_EJBLocal of EJB: ReceivingAPI_EJB"
},
"ReceivingAPI_EJB!com.mycompany.receiving.api.ReceivingAPI_EJBRemote" => {
"class-name" => "com.sun.proxy.$Proxy272",
"value" => "Proxy for remote EJB StatelessEJBLocator{appName='XNet', moduleName='api', distinctName='hq', beanName='ReceivingAPI_EJB', view='interface com.mycompany.receiving.api.ReceivingAPI_EJBRemote'}"
},
}
}
}
}
}
}
...
}
}
[standalone#localhost:10099 /]
Any my maven deps are as follows:
<dependencies>
<dependency>
<groupId>com.mycompany.receiving</groupId>
<artifactId>xnet-domain-receiving-client</artifactId>
<version>2.5.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-naming</artifactId>
<version>7.1.3.Final</version>
</dependency>
<dependency>
<groupId>org.jboss.marshalling</groupId>
<artifactId>jboss-marshalling-river</artifactId>
<version>1.4.0.Final</version>
</dependency>
<dependency>
<groupId>org.jboss.client</groupId>
<artifactId>jbossall-client</artifactId>
<version>5.0.0.GA</version>
</dependency>
<dependency>
<groupId>org.jboss.spec.javax.ejb</groupId>
<artifactId>jboss-ejb-api_3.1_spec</artifactId>
<version>1.0.2.Final</version>
</dependency>
</dependencies>
In the comment above Rhys was right about the jndi string looking "funky". I tried everything I thought. Here is what worked for my situation.
The JNDI URL needs to look like this:
XNet/api/ReceivingAPI_EJB!com.mycompany.receiving.api.ReceivingAPI_EJBRemote
I also had to add add a dependency to the others shown in the question:
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
</dependency>

Categories

Resources