JBoss AS 7 JNDI 的常见异常

  1、对于jnp包的使用,jboss5中使用jnp,实现类是org.jnp.interfaces.NamingContextFactory,需要引 入jnp-client.jar。在AS7中客户端只需要引入一个jboss-client.jar的包使用的 java.naming.factory.initial改成了这个包下面的 org.jboss.naming.remote.client.InitialContextFactory。

                      jboss5下面的initialContext的实例化方法是

                                         Properties prop = new Properties();

                                         prop.put("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");

                                         prop.put("java.naming.provider.url","localhost:1099")

                                         prop.put("java.naming.factory.url.pkgs","org.jboss.naming")

                      jboss7中改成了

                                        Properties prop = new Properties();

                                        prop.put(Context.PROVIDER_URL, "remote://127.0.0.1:4447");

                                        prop.put(Context.SECURITY_PRINCIPAL, System.getProperty("username","appname"));

                                        prop.put(Context.SECURITY_CREDENTIALS, System.getProperty("password","12345"));

                                        prop.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");

                    否则会抛出Caused by: java.lang.ClassNotFoundException: org.jnp.interfaces.NamingContextFactory
                                      at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
                                      at java.security.AccessController.doPrivileged(Native Method)
                                      at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
                                      at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
                                      at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
                                      at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
                                      at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
                                      at java.lang.Class.forName0(Native Method)
                                      at java.lang.Class.forName(Class.java:247)

                    2、注意到上面那个remote:127.0.0.1:4447,没有使用5.1里默认的localhost:1099,因为这个localhost和 127.0.0.1的区别访问不到JNDI,搞了好半天,这个banding IP可以在standalone/configration/standalone.xml文件里<integerface>配置

否则抛出

javax.naming.NamingException: Failed to create remoting connection [Root exception is java.lang.RuntimeException: Operation failed with status WAITING]
at org.jboss.naming.remote.client.ClientUtil.namingException(ClientUtil.java:36)
at org.jboss.naming.remote.client.InitialContextFactory.getInitialContext(InitialContextFactory.java:121)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:667)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
at javax.naming.InitialContext.init(InitialContext.java:223)
at javax.naming.InitialContext.<init>(InitialContext.java:197)
at ClientTest.main(ClientTest.java:27)
Caused by: java.lang.RuntimeException: Operation failed with status WAITING
at org.jboss.naming.remote.protocol.IoFutureHelper.get(IoFutureHelper.java:89)
at org.jboss.naming.remote.client.NamingStoreCache.getRemoteNamingStore(NamingStoreCache.java:56)
at org.jboss.naming.remote.client.InitialContextFactory.getOrCreateCachedNamingStore(InitialContextFactory.java:166)
at org.jboss.naming.remote.client.InitialContextFactory.getOrCreateNamingStore(InitialContextFactory.java:139)
at org.jboss.naming.remote.client.InitialContextFactory.getInitialContext(InitialContextFactory.java:104)
... 5 more

                    3、用户名密码,在jboss7里必须使用用户名和密码的验证,而且需要自己添加一个用户,一般用add-user.bat添加,选择Application User

                         Realm输入默认的ApplicationRealm

                          最后输入一行what roles do you want this user to belong to?

                          这里的输入与standalone.xml的内容匹配。我的项目是用到guest的

                          否则抛出

javax.naming.NamingException: Failed to create remoting connection [Root exception is java.lang.RuntimeException:javax.security.sasl.SaslException: Authentication failed: all available authentication mechanisms failed]
at org.jboss.naming.remote.client.ClientUtil.namingException(ClientUtil.java:36)
at org.jboss.naming.remote.client.InitialContextFactory.getInitialContext(InitialContextFactory.java:121)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:667)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
at javax.naming.InitialContext.init(InitialContext.java:223)
at javax.naming.InitialContext.<init>(InitialContext.java:197)
at ClientTest.main(ClientTest.java:27)
Caused by: java.lang.RuntimeException: javax.security.sasl.SaslException: Authentication failed: all available authentication mechanisms failed
at org.jboss.naming.remote.protocol.IoFutureHelper.get(IoFutureHelper.java:87)
at org.jboss.naming.remote.client.NamingStoreCache.getRemoteNamingStore(NamingStoreCache.java:56)
at org.jboss.naming.remote.client.InitialContextFactory.getOrCreateCachedNamingStore(InitialContextFactory.java:166)
at org.jboss.naming.remote.client.InitialContextFactory.getOrCreateNamingStore(InitialContextFactory.java:139)
at org.jboss.naming.remote.client.InitialContextFactory.getInitialContext(InitialContextFactory.java:104)
... 5 more
Caused by: javax.security.sasl.SaslException: Authentication failed: all available authentication mechanisms failed
at org.jboss.remoting3.remote.ClientConnectionOpenListener$Capabilities.handleEvent(ClientConnectionOpenListener.java:365)
at org.jboss.remoting3.remote.ClientConnectionOpenListener$Capabilities.handleEvent(ClientConnectionOpenListener.java:214)
at org.xnio.ChannelListeners.invokeChannelListener(ChannelListeners.java:72)
at org.xnio.channels.TranslatingSuspendableChannel.handleReadable(TranslatingSuspendableChannel.java:189)
at org.xnio.channels.TranslatingSuspendableChannel$1.handleEvent(TranslatingSuspendableChannel.java:103)
at org.xnio.ChannelListeners.invokeChannelListener(ChannelListeners.java:72)
at org.xnio.nio.NioHandle.run(NioHandle.java:90)
at org.xnio.nio.WorkerThread.run(WorkerThread.java:184)
at ...asynchronous invocation...(Unknown Source)
at org.jboss.remoting3.EndpointImpl.doConnect(EndpointImpl.java:270)
at org.jboss.remoting3.EndpointImpl.doConnect(EndpointImpl.java:251)
at org.jboss.remoting3.EndpointImpl.connect(EndpointImpl.java:349)
at org.jboss.remoting3.EndpointImpl.connect(EndpointImpl.java:333)
at org.jboss.naming.remote.client.EndpointCache$EndpointWrapper.connect(EndpointCache.java:105)
at org.jboss.naming.remote.client.NamingStoreCache.getRemoteNamingStore(NamingStoreCache.java:55)
... 8 more

                     4、jndi命名,JBoss7使用了更加严格的JNDI命名比如 JMS的jms-connection-factories使用的是java:jboss/exported/jms /RemoteConnectionFactory而不是以前的/RemoteConnectionFactory我以为是 initialcontext.lookup的时候查找的内容是java:jboss/exported/jms /RemoteConnectionFactory,试了几次发现错了,应该是配置文件中的命名为java:jboss/exported/jms /RemoteConnectionFactory查找的时候用jms/RemoteConnectionFactory。同理查找Queue的时候在 standalone.xml中配置

                <jms-destinations>
                    <jms-queue name="myQueue">
                        <entry name="java:jboss/exported/queue/MyQueue"/>
                    </jms-queue>
                    <jms-queue name="SyslogQueue">
                        <entry name="java:jboss/exported/queue/SYSLOG"/>
                    </jms-queue>
                    <jms-queue name="TrapQueue">
                        <entry name="java:jboss/exported/queue/TRAP"/>
                    </jms-queue>
                    <jms-queue name="ICMPPingQueue">
                        <entry name="java:jboss/exported/queue/ICMPPING"/>
                    </jms-queue>
                </jms-destinations>

查找的时候用initialcontext.lookup("queue/MyQueue");

否则抛出

javax.naming.NameNotFoundException: jms/RemoteConnectionFactory -- service jboss.naming.context.java.jboss.exported.jms.RemoteConnectionFactory
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$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)

ps:发现一个问题上面说的第四点 我理解错了,我原来以为entry name="XXX/XXX"就是用来查找的所以把原来的<entry name="queue/SYSLOG"/>直接改成了<entry name="java:jboss/exported/queue/SYSLOG"/>然后启动时候没有报错但是会有几行提示信息

10:05:54,884 INFO  [org.hornetq.ra.inflow.HornetQActivation] (default-short-running-threads-threads - 3) Attempting to reconnect org.hornetq.ra.inflow.HornetQActivationSpec(ra=org.hornetq.ra.HornetQResourceAdapter@175c39c3 destination=queue/ICMPPING destinationType=javax.jms.Queue ack=Auto-acknowledge durable=false clientID=null user=null maxSession=15)
10:05:54,900 INFO  [org.hornetq.ra.inflow.HornetQActivation] (default-short-running-threads-threads - 2) Attempting to reconnect org.hornetq.ra.inflow.HornetQActivationSpec(ra=org.hornetq.ra.HornetQResourceAdapter@175c39c3 destination=queue/SYSLOG destinationType=javax.jms.Queue ack=Auto-acknowledge durable=false clientID=null user=null maxSession=15)
10:05:54,900 INFO  [org.hornetq.ra.inflow.HornetQActivation] (default-short-running-threads-threads - 3) awaiting topic/queue creation queue/ICMPPING

原来系统是根据entry name="XXX/XXX"来创建Queue的 所以entry name="XXX/XXX"(也就是<entry name="queue/SYSLOG">是不能去掉滴,否则提示找不到对应的Queue)要保留。

你可能感兴趣的:(jboss)