<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">

<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>

                                <td>

                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="http://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">JBoss Community</a></h1>
                                                                </td>

                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px;  -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
    Re: AS 7 demos
</h3>
<span style="margin-bottom: 10px;">
    created by <a href="http://community.jboss.org/people/kabir.khan%40jboss.com">Kabir Khan</a> in <i>JBoss AS7 Development</i> - <a href="http://community.jboss.org/message/568056#568056">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">

<div class="jive-rendered-content"><p><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">I think the previous post can be ignored, I messed up my branches somehow&#8230;&#160; </div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"> </div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">Trying out a JMS example I didn't see the ConnectionFactory and queue from standalone.xml getting bound in JNDI. JMSServerManagerImpl.bindToJndi() ignores the requests to bind to JNDI because no context has been set yet. If I modify this it gets bound in JNDI</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">+++ b/messaging/src/main/java/org/jboss/as/messaging/jms/JMSService.java</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">@@ -23,6 +23,8 @@</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"> package org.jboss.as.messaging.jms;</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"> </div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"> import javax.naming.Context;</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">+import javax.naming.InitialContext;</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">+import javax.naming.NamingException;</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"> </div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"> import org.hornetq.core.server.HornetQServer;</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"> import org.hornetq.jms.server.JMSServerManager;</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">@@ -31,10 +33,10 @@ import org.jboss.as.messaging.MessagingSubsystemElement;</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"> import org.jboss.logging.Logger;</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"> import org.jboss.msc.service.BatchBuilder;</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"> import org.jboss.msc.service.Service;</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">-import org.jboss.msc.service.ServiceController.Mode;</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"> import org.jboss.msc.service.StartContext;</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"> import org.jboss.msc.service.StartException;</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"> import org.jboss.msc.service.StopContext;</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">+import org.jboss.msc.service.ServiceController.Mode;</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"> import org.jboss.msc.value.InjectedValue;</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"> </div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"> /**</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">@@ -49,10 +51,15 @@ public class JMSService implements Service&lt;JMSServerManager&gt; {</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&#160;&#160;&#160;&#160; private JMSServerManager jmsServer;</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"> </div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&#160;&#160;&#160;&#160; public static void addService(final BatchBuilder builder) {</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">-&#160;&#160;&#160;&#160;&#160;&#160;&#160; final JMSService service = new JMSService();</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">-&#160;&#160;&#160;&#160;&#160;&#160;&#160; builder.addService(JMSSubsystemElement.JMS_MANAGER, service)</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">-&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; .addDependency(MessagingSubsystemElement.JBOSS_MESSAGING, HornetQServer.class, service.getHornetQServer())</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">-&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; .setInitialMode(Mode.ACTIVE);</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">+&#160;&#160;&#160;&#160;&#160;&#160;&#160; try {</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">+&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; final JMSService service = new JMSService();</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">+&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; builder.addService(JMSSubsystemElement.JMS_MANAGER, service)</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">+&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; .addDependency(MessagingSubsystemElement.JBOSS_MESSAGING, HornetQServer.class, service.getHornetQServer())</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">+&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; .addInjection(service.getContextInjector(), (Context)new InitialContext())</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">+&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; .setInitialMode(Mode.ACTIVE);</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">+&#160;&#160;&#160;&#160;&#160;&#160;&#160; } catch (NamingException e) {</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">+&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; throw new RuntimeException(e);</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">+&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&#160;&#160;&#160;&#160; }</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"> </div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&#160;&#160;&#160;&#160; protected JMSService() {</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">@@ -65,7 +72,7 @@ public class JMSService implements Service&lt;JMSServerManager&gt; {</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; final JMSServerManager jmsServer = new JMSServerManagerImpl(hornetQServer.getValue());</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"> </div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; final Context jndiContext = contextInjector.getOptionalValue();</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">-&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if(context != null) {</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">+&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if(jndiContext != null) {</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; jmsServer.setContext(jndiContext);</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"> </div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">~</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"> </div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">Next when I try to look up 'ConnectionFactory' from my example I get the following error:</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"> </div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">00:12:02,953 ERROR [deployment] Caught exception handling update (param is 643db326-7dd6-4da3-97ca-f1ea0d2de596): org.jboss.msc.service.StartException in service service jboss.mbean.service.jboss:name=test,type=jms.start: Failed to execute legacy service start</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">at org.jboss.as.service.StartStopService.start(StartStopService.java:62)</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:923)</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [:1.6.0_20]</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [:1.6.0_20]</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">at java.lang.Thread.run(Thread.java:637) [:1.6.0_20]</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">Caused by: java.lang.reflect.InvocationTargetException</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [:1.6.0_20]</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [:1.6.0_20]</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [:1.6.0_20]</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">at java.lang.reflect.Method.invoke(Method.java:597) [:1.6.0_20]</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">at org.jboss.as.service.StartStopService.start(StartStopService.java:59)</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">... 4 more</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">Caused by: java.lang.ClassCastException: javax.naming.Reference cannot be cast to javax.jms.QueueConnectionFactory</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">at org.jboss.as.demos.jms.mbean.Test.start(Test.java:58)</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">... 9 more</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"> </div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">It appears to happen because in this path ObjectFactoryBuilder.factoryFromReference()'s contextCl is null, resulting in an exception, which returns 'this' i.e. the original Reference and not the ObjectFactory. Since the reference is a not a ModularReference we are trying the TCL.</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"> </div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">ObjectFactoryBuilder.factoryFromReference(Reference, Hashtable&lt;?,?&gt;) line: 104</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">ObjectFactoryBuilder.createObjectFactory(Object, Hashtable&lt;?,?&gt;) line: 58</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">NamingManager.getObjectInstance(Object, Name, Context, Hashtable&lt;?,?&gt;) line: 282</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">NamingContext.getObjectInstance(Object, Name, Hashtable) line: 430</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">NamingContext.lookup(Name) line: 163</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">NamingContext.lookup(String) line: 173</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">InitialContext.lookup(String) line: 392</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">Test.start() line: 58</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"> </div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">The object that is originally passed in to NamingContext.rebind() is HornetQConectionFactory which is an instance of Referenceable and whose getReference() method returns a plain Reference:</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"> </div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&#160;&#160; public Reference getReference() throws NamingException</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&#160;&#160; {</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&#160;&#160;&#160;&#160;&#160; return new Reference(this.getClass().getCanonicalName(),</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; new SerializableObjectRefAddr("HornetQ-CF", this),</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ConnectionFactoryObjectFactory.class.getCanonicalName(),</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; null);</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&#160;&#160; }</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">this then is what bound in JNDI, I don't think there is a way to override this to create a ModularReference. I can see queue/test and topic/test getting bound the same way so there will probably be a similar exception looking this up. Putting in some debug statements</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"> </div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; InitialContext ctx = new InitialContext();</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"> </div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; System.out.println(ctx.lookup("ConnectionFactory"));</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">&#160;&#160;&#160;&#160;&#160;&#160;&#160; System.out.println(ctx.lookup("queue/test"));</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"> </div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">Shows this:</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">09:27:22,965 INFO&#160; [stdout] Reference Class Name: org.hornetq.jms.client.HornetQConnectionFactory</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">09:27:22,966 INFO&#160; [stdout] Type: HornetQ-CF</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">09:27:22,966 INFO&#160; [stdout] Content: [B@f4b2263</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">09:27:22,967 INFO&#160; [stdout] </div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">09:27:22,968 INFO&#160; [stdout] Reference Class Name: org.hornetq.jms.client.HornetQQueue</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">09:27:22,968 INFO&#160; [stdout] Type: HornetQ-DEST</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">09:27:22,968 INFO&#160; [stdout] Content: [B@60da5686</div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;">09:27:22,969 INFO&#160; [stdout] </div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"> </div><div id="_mcePaste" style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;"> </div><p>I think the previous post can be ignored, I messed up my branches somehow&#8230;&#160; </p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Trying out a JMS example I didn't see the ConnectionFactory and queue from standalone.xml getting bound in JNDI. JMSServerManagerImpl.bindToJndi() ignores the requests to bind to JNDI because no context has been set yet. If I modify this it gets bound in JNDI</p><p>+++ b/messaging/src/main/java/org/jboss/as/messaging/jms/JMSService.java</p><p>@@ -23,6 +23,8 @@</p><p> package org.jboss.as.messaging.jms;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p> import javax.naming.Context;</p><p>+import javax.naming.InitialContext;</p><p>+import javax.naming.NamingException;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p> import org.hornetq.core.server.HornetQServer;</p><p> import org.hornetq.jms.server.JMSServerManager;</p><p>@@ -31,10 +33,10 @@ import org.jboss.as.messaging.MessagingSubsystemElement;</p><p> import org.jboss.logging.Logger;</p><p> import org.jboss.msc.service.BatchBuilder;</p><p> import org.jboss.msc.service.Service;</p><p>-import org.jboss.msc.service.ServiceController.Mode;</p><p> import org.jboss.msc.service.StartContext;</p><p> import org.jboss.msc.service.StartException;</p><p> import org.jboss.msc.service.StopContext;</p><p>+import org.jboss.msc.service.ServiceController.Mode;</p><p> import org.jboss.msc.value.InjectedValue;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p> /**</p><p>@@ -49,10 +51,15 @@ public class JMSService implements Service&lt;JMSServerManager&gt; {</p><p>&#160;&#160;&#160;&#160; private JMSServerManager jmsServer;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160;&#160; public static void addService(final BatchBuilder builder) {</p><p>-&#160;&#160;&#160;&#160;&#160;&#160;&#160; final JMSService service = new JMSService();</p><p>-&#160;&#160;&#160;&#160;&#160;&#160;&#160; builder.addService(JMSSubsystemElement.JMS_MANAGER, service)</p><p>-&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; .addDependency(MessagingSubsystemElement.JBOSS_MESSAGING, HornetQServer.class, service.getHornetQServer())</p><p>-&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; .setInitialMode(Mode.ACTIVE);</p><p>+&#160;&#160;&#160;&#160;&#160;&#160;&#160; try {</p><p>+&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; final JMSService service = new JMSService();</p><p>+&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; builder.addService(JMSSubsystemElement.JMS_MANAGER, service)</p><p>+&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; .addDependency(MessagingSubsystemElement.JBOSS_MESSAGING, HornetQServer.class, service.getHornetQServer())</p><p>+&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; .addInjection(service.getContextInjector(), (Context)new InitialContext())</p><p>+&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; .setInitialMode(Mode.ACTIVE);</p><p>+&#160;&#160;&#160;&#160;&#160;&#160;&#160; } catch (NamingException e) {</p><p>+&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; throw new RuntimeException(e);</p><p>+&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p><p>&#160;&#160;&#160;&#160; }</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160;&#160; protected JMSService() {</p><p>@@ -65,7 +72,7 @@ public class JMSService implements Service&lt;JMSServerManager&gt; {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; final JMSServerManager jmsServer = new JMSServerManagerImpl(hornetQServer.getValue());</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; final Context jndiContext = contextInjector.getOptionalValue();</p><p>-&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if(context != null) {</p><p>+&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; if(jndiContext != null) {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; jmsServer.setContext(jndiContext);</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>~</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Next when I try to look up 'ConnectionFactory' from my example I get the following error:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>00:12:02,953 ERROR [deployment] Caught exception handling update (param is 643db326-7dd6-4da3-97ca-f1ea0d2de596): org.jboss.msc.service.StartException in service service jboss.mbean.service.jboss:name=test,type=jms.start: Failed to execute legacy service start</p><p><span style="white-space: pre;"> </span>at org.jboss.as.service.StartStopService.start(StartStopService.java:62)</p><p><span style="white-space: pre;"> </span>at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:923)</p><p><span style="white-space: pre;"> </span>at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [:1.6.0_20]</p><p><span style="white-space: pre;"> </span>at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [:1.6.0_20]</p><p><span style="white-space: pre;"> </span>at java.lang.Thread.run(Thread.java:637) [:1.6.0_20]</p><p>Caused by: java.lang.reflect.InvocationTargetException</p><p><span style="white-space: pre;"> </span>at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [:1.6.0_20]</p><p><span style="white-space: pre;"> </span>at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [:1.6.0_20]</p><p><span style="white-space: pre;"> </span>at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [:1.6.0_20]</p><p><span style="white-space: pre;"> </span>at java.lang.reflect.Method.invoke(Method.java:597) [:1.6.0_20]</p><p><span style="white-space: pre;"> </span>at org.jboss.as.service.StartStopService.start(StartStopService.java:59)</p><p><span style="white-space: pre;"> </span>... 4 more</p><p>Caused by: java.lang.ClassCastException: javax.naming.Reference cannot be cast to javax.jms.QueueConnectionFactory</p><p><span style="white-space: pre;"> </span>at org.jboss.as.demos.jms.mbean.Test.start(Test.java:58)</p><p><span style="white-space: pre;"> </span>... 9 more</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>It appears to happen because in this path ObjectFactoryBuilder.factoryFromReference()'s contextCl is null, resulting in an exception, which returns 'this' i.e. the original Reference and not the ObjectFactory. Since the reference is a not a ModularReference we are trying the TCL.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>ObjectFactoryBuilder.factoryFromReference(Reference, Hashtable&lt;?,?&gt;) line: 104<span style="white-space: pre;"> </span></p><p>ObjectFactoryBuilder.createObjectFactory(Object, Hashtable&lt;?,?&gt;) line: 58<span style="white-space: pre;"> </span></p><p>NamingManager.getObjectInstance(Object, Name, Context, Hashtable&lt;?,?&gt;) line: 282<span style="white-space: pre;"> </span></p><p>NamingContext.getObjectInstance(Object, Name, Hashtable) line: 430<span style="white-space: pre;"> </span></p><p>NamingContext.lookup(Name) line: 163<span style="white-space: pre;"> </span></p><p>NamingContext.lookup(String) line: 173<span style="white-space: pre;"> </span></p><p>InitialContext.lookup(String) line: 392<span style="white-space: pre;"> </span></p><p>Test.start() line: 58<span style="white-space: pre;"> </span></p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>The object that is originally passed in to NamingContext.rebind() is HornetQConectionFactory which is an instance of Referenceable and whose getReference() method returns a plain Reference:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160; public Reference getReference() throws NamingException</p><p>&#160;&#160; {</p><p>&#160;&#160;&#160;&#160;&#160; return new Reference(this.getClass().getCanonicalName(),</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; new SerializableObjectRefAddr("HornetQ-CF", this),</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; ConnectionFactoryObjectFactory.class.getCanonicalName(),</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; null);</p><p>&#160;&#160; }</p><p>this then is what bound in JNDI, I don't think there is a way to override this to create a ModularReference. I can see queue/test and topic/test getting bound the same way so there will probably be a similar exception looking this up. Putting in some debug statements</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; InitialContext ctx = new InitialContext();</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; System.out.println(ctx.lookup("ConnectionFactory"));</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; System.out.println(ctx.lookup("queue/test"));</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Shows this:</p><p>09:27:22,965 INFO&#160; [stdout] Reference Class Name: org.hornetq.jms.client.HornetQConnectionFactory</p><p>09:27:22,966 INFO&#160; [stdout] Type: HornetQ-CF</p><p>09:27:22,966 INFO&#160; [stdout] Content: [B@f4b2263</p><p>09:27:22,967 INFO&#160; [stdout] </p><p>09:27:22,968 INFO&#160; [stdout] Reference Class Name: org.hornetq.jms.client.HornetQQueue</p><p>09:27:22,968 INFO&#160; [stdout] Type: HornetQ-DEST</p><p>09:27:22,968 INFO&#160; [stdout] Content: [B@60da5686</p><p>09:27:22,969 INFO&#160; [stdout] </p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p></p></div>

<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
    <p style="margin: 0;">Reply to this message by <a href="http://community.jboss.org/message/568056#568056">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in JBoss AS7 Development at <a href="http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2225">Community</a></p>
</div></td>
                        </tr>
                    </tbody>
                </table>


                </td>
            </tr>
        </tbody>
    </table>

</div>

</body>
</html>