I got this up and running to a degree, Wildfly now instantiates and binds an InitialContext for me to use - cool! But I still can't inject queues or topics. What I have so far ...
<subsystem xmlns="urn:jboss:domain:naming:2.0">
<bindings>
<external-context name="java:global/hornetq" module="org.jboss.jnp-client" class="javax.naming.InitialContext" cache="true">
<environment>
<property name="java.naming.factory.initial" value="org.jnp.interfaces.NamingContextFactory" />
<property name="java.naming.provider.url" value="jnp://host:port" />
<property name="java.naming.factory.url.pkgs" value="org.jboss.naming:org.jnp.interfaces" />
</environment>
</external-context>
</bindings>
<remote-naming/>
</subsystem>
Where I just created the org.jboss.jnp-client module myself: Place into WILDFLY_HOME/modules/system/layers/base/org/jboss/jnp-client/main jnp-client-4.2.2.GA.jar and the following module.xml:
<module xmlns="urn:jboss:module:1.3" name="org.jboss.jnp-client">
<properties>
<property name="jboss.api" value="private"/>
</properties>
<resources>
<resource-root path="jnp-client-4.2.2.GA.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="org.hornetq"/>
<module name="org.jboss.invocation"/>
<module name="org.jboss.logging"/>
</dependencies>
</module>
This then binds an InitialContext to java:global/hornetq which I can successfully inject
@Resource(mappedName = "java:global/hornetq")
InitialContext ic;
...
private void walkJNDI(String name) {
try {
NamingEnumeration ne = ic.list(name);
while (ne.hasMoreElements()) {
NameClassPair ncp = (NameClassPair) ne.nextElement();
System.out.println(name + "/" + ncp.getName());
if (ncp.getClassName().equals("org.jnp.interfaces.NamingContext")) {
walkJNDI(name + "/" + ncp.getName());
}
}
} catch (NamingException e) {
e.printStackTrace();
}
}
06:35:00,952 INFO [stdout] (default task-3) /comp
06:35:00,952 INFO [stdout] (default task-3) /ConnectionFactory
06:35:00,952 INFO [stdout] (default task-3) /ThroughputConnectionFactory
06:35:00,953 INFO [stdout] (default task-3) /XAThroughputConnectionFactory
06:35:00,953 INFO [stdout] (default task-3) /topic
06:35:00,955 INFO [stdout] (default task-3) /topic/exampleTopic
06:35:00,955 INFO [stdout] (default task-3) /XAConnectionFactory
06:35:00,956 INFO [stdout] (default task-3) /queue
06:35:00,958 INFO [stdout] (default task-3) /queue/ExpiryQueue
06:35:00,958 INFO [stdout] (default task-3) /queue/DLQ
Is there a way to ask Wildfly to add the bindings from the remote JNDI provider to it's own set of bindings? What I really want to be able to do is simply:
@Resource(mappedName = "java:global/hornetq/topic/exampleTopic")
Topic topic;
When I try and do this anyway, I get the following exception:
Caused by: javax.naming.InvalidNameException: Not a compound name: topic/exampleTopic
at javax.naming.CompoundName.addAll(CompoundName.java:462)
at org.jnp.interfaces.NamingContext.composeName(NamingContext.java:1018)
at org.jnp.interfaces.NamingContext.getAbsoluteName(NamingContext.java:1612)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:658)
at javax.naming.InitialContext.lookup(InitialContext.java:415)
at javax.naming.InitialContext.lookup(InitialContext.java:415)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.jboss.as.naming.ExternalContextObjectFactory$CachedContext.invoke(ExternalContextObjectFactory.java:144)
at javax.naming.InitialContext$$$$Proxy1.lookup(Unknown Source)
at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:236)
at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:184)
at org.jboss.as.naming.InitialContext$DefaultInitialContext.lookup(InitialContext.java:237)
at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:193)
at org.jboss.as.naming.NamingContext.lookup(NamingContext.java:189)
at javax.naming.InitialContext.lookup(InitialContext.java:411)
at javax.naming.InitialContext.lookup(InitialContext.java:411)
at org.jboss.as.weld.services.bootstrap.WeldResourceInjectionServices.resolveResource(WeldResourceInjectionServices.java:209)
at org.jboss.as.weld.services.bootstrap.WeldResourceInjectionServices$1.createResource(WeldResourceInjectionServices.java:157)
at org.jboss.weld.injection.AbstractResourceInjection.getResourceReference(AbstractResourceInjection.java:44)
at org.jboss.weld.injection.AbstractResourceInjection.injectResourceReference(AbstractResourceInjection.java:53)
at org.jboss.weld.util.Beans.injectEEFields(Beans.java:348)
at org.jboss.weld.injection.producer.ResourceInjector$1.proceed(ResourceInjector.java:69)
at org.jboss.weld.injection.InjectionContextImpl.run(InjectionContextImpl.java:48)
at org.jboss.weld.injection.producer.ResourceInjector.inject(ResourceInjector.java:72)
at org.jboss.weld.injection.producer.BasicInjectionTarget.inject(BasicInjectionTarget.java:121)
at org.jboss.weld.bean.ManagedBean.create(ManagedBean.java:159)
at org.jboss.weld.context.AbstractContext.get(AbstractContext.java:96)
at org.jboss.weld.bean.ContextualInstanceStrategy$DefaultContextualInstanceStrategy.get(ContextualInstanceStrategy.java:101)
at org.jboss.weld.bean.ContextualInstanceStrategy$ApplicationScopedContextualInstanceStrategy.get(ContextualInstanceStrategy.java:141)
at org.jboss.weld.bean.ContextualInstance.get(ContextualInstance.java:50)
at org.jboss.weld.manager.BeanManagerImpl.getReference(BeanManagerImpl.java:761)
at org.jboss.weld.manager.BeanManagerImpl.getInjectableReference(BeanManagerImpl.java:861)
at org.jboss.weld.injection.FieldInjectionPoint.inject(FieldInjectionPoint.java:92)
... 57 more
Am I going about this the right way? Once again, any help would be appreciated.