终止连接时JBoss AS 7.2 CLI API中的异常

时间:2013-07-22 07:12:28

标签: jboss jboss7.x

我们最近从JBoss 7.1.3-Final升级到7.2.0-Final。由于我们升级了一个使用Java CLI公共API的应用程序,因此每次通过CLI API终止连接时都会抛出NullPointerExceptions。

以下是我们设置和关闭JBoss CLI连接的代码:

private CommandContext ctx;
private ModelControllerClient client; 

public JBossCLITool() {
   try {
        ctx = CommandContextFactory.getInstance().newCommandContext();
    } catch(CliInitializationException e) {
        throw new IllegalStateException("Failed to initialize CLI context", e);
    }
}

public void establishConnection() {
    try {
        ctx.connectController("localhost", 9999);
        client = ctx.getModelControllerClient();
    } catch (CommandLineException e) {
        LOG.debug(e.toString());
    }
} 

public void terminateConnection() {
    try {
        if (!ctx.isTerminated()){
            ctx.terminateSession();
        }
    } catch (Exception e) {
        LOG.debug(e.toString());
    }
}

调用ctx.terminateSession()时会抛出以下异常:

13:46:58,691 ERROR [org.jboss.remoting.handler-errors] (Remoting "cli-client" read-1) Close handler threw an exception: java.lang.NullPointerException
at org.jboss.as.cli.impl.CommandContextImpl.handleClose(CommandContextImpl.java:1206) [org-jboss-as-jboss-as-cli-7.2.0.Final.jar:7.2.0.Final]
at org.jboss.as.cli.impl.CLIModelControllerClient$4.handleClose(CLIModelControllerClient.java:156) [org-jboss-as-jboss-as-cli-7.2.0.Final.jar:7.2.0.Final]
at org.jboss.as.cli.impl.CLIModelControllerClient$4.handleClose(CLIModelControllerClient.java:153) [org-jboss-as-jboss-as-cli-7.2.0.Final.jar:7.2.0.Final]
at org.jboss.remoting3.spi.SpiUtils.safeHandleClose(SpiUtils.java:54) [org-jboss-remoting3-jboss-remoting-3.2.14.GA.jar:3.2.14.GA]
at org.jboss.remoting3.spi.AbstractHandleableCloseable$CloseHandlerTask.run(AbstractHandleableCloseable.java:501) [org-jboss-remoting3-jboss-remoting-3.2.14.GA.jar:3.2.14.GA]
at org.jboss.remoting3.spi.AbstractHandleableCloseable.runCloseTask(AbstractHandleableCloseable.java:406) [org-jboss-remoting3-jboss-remoting-3.2.14.GA.jar:3.2.14.GA]
at org.jboss.remoting3.spi.AbstractHandleableCloseable.closeComplete(AbstractHandleableCloseable.java:277) [org-jboss-remoting3-jboss-remoting-3.2.14.GA.jar:3.2.14.GA]
at org.jboss.remoting3.ConnectionImpl.access$000(ConnectionImpl.java:38) [org-jboss-remoting3-jboss-remoting-3.2.14.GA.jar:3.2.14.GA]
at org.jboss.remoting3.ConnectionImpl$1.handleClose(ConnectionImpl.java:55) [org-jboss-remoting3-jboss-remoting-3.2.14.GA.jar:3.2.14.GA]
at org.jboss.remoting3.ConnectionImpl$1.handleClose(ConnectionImpl.java:53) [org-jboss-remoting3-jboss-remoting-3.2.14.GA.jar:3.2.14.GA]
at org.jboss.remoting3.spi.SpiUtils.safeHandleClose(SpiUtils.java:54) [org-jboss-remoting3-jboss-remoting-3.2.14.GA.jar:3.2.14.GA]
at org.jboss.remoting3.spi.AbstractHandleableCloseable$CloseHandlerTask.run(AbstractHandleableCloseable.java:501) [org-jboss-remoting3-jboss-remoting-3.2.14.GA.jar:3.2.14.GA]
at org.jboss.remoting3.spi.AbstractHandleableCloseable.runCloseTask(AbstractHandleableCloseable.java:406) [org-jboss-remoting3-jboss-remoting-3.2.14.GA.jar:3.2.14.GA]
at org.jboss.remoting3.spi.AbstractHandleableCloseable.closeComplete(AbstractHandleableCloseable.java:277) [org-jboss-remoting3-jboss-remoting-3.2.14.GA.jar:3.2.14.GA]
at org.jboss.remoting3.remote.RemoteConnectionHandler.handleConnectionClose(RemoteConnectionHandler.java:117) [org-jboss-remoting3-jboss-remoting-3.2.14.GA.jar:3.2.14.GA]
at org.jboss.remoting3.remote.RemoteReadListener.handleEvent(RemoteReadListener.java:78) [org-jboss-remoting3-jboss-remoting-3.2.14.GA.jar:3.2.14.GA]
at org.jboss.remoting3.remote.RemoteReadListener.handleEvent(RemoteReadListener.java:45) [org-jboss-remoting3-jboss-remoting-3.2.14.GA.jar:3.2.14.GA]
at org.xnio.ChannelListeners.invokeChannelListener(ChannelListeners.java:72) [org-jboss-xnio-xnio-api-3.0.7.GA.jar:3.0.7.GA]
at org.xnio.channels.TranslatingSuspendableChannel.handleReadable(TranslatingSuspendableChannel.java:189) [org-jboss-xnio-xnio-api-3.0.7.GA.jar:3.0.7.GA]
at org.xnio.channels.TranslatingSuspendableChannel$1.handleEvent(TranslatingSuspendableChannel.java:103) [org-jboss-xnio-xnio-api-3.0.7.GA.jar:3.0.7.GA]
at org.xnio.ChannelListeners.invokeChannelListener(ChannelListeners.java:72) [org-jboss-xnio-xnio-api-3.0.7.GA.jar:3.0.7.GA]
at org.xnio.channels.TranslatingSuspendableChannel.handleReadable(TranslatingSuspendableChannel.java:189) [org-jboss-xnio-xnio-api-3.0.7.GA.jar:3.0.7.GA]
at org.xnio.ssl.JsseConnectedSslStreamChannel.handleReadable(JsseConnectedSslStreamChannel.java:180) [org-jboss-xnio-xnio-api-3.0.7.GA.jar:3.0.7.GA]
at org.xnio.channels.TranslatingSuspendableChannel$1.handleEvent(TranslatingSuspendableChannel.java:103) [org-jboss-xnio-xnio-api-3.0.7.GA.jar:3.0.7.GA]
at org.xnio.ChannelListeners.invokeChannelListener(ChannelListeners.java:72) [org-jboss-xnio-xnio-api-3.0.7.GA.jar:3.0.7.GA]
at org.xnio.nio.NioHandle.run(NioHandle.java:90) [org-jboss-xnio-xnio-nio-3.0.7.GA.jar:3.0.7.GA]
at org.xnio.nio.WorkerThread.run(WorkerThread.java:187) [org-jboss-xnio-xnio-nio-3.0.7.GA.jar:3.0.7.GA]

使用7.1.3 API和JBoss AS相同的代码可以正常工作。即使使用7.2,连接似乎也正确关闭(在调用terminateSession()之后,在建立新连接之前不能再进行CLI调用。)

我在JBoss社区问了同样的问题,只是重复一遍,希望别人看到它。这是链接:https://community.jboss.org/message/828608

1 个答案:

答案 0 :(得分:0)

嗯,我遇到了同样的问题。

说实话,我没有详细分析过。似乎它与复合DMR的​​执行有关 - 可能与需要重新加载相结合。

CommandContext类中的parsedCommandLine为null。 close处理程序方法不会检查它。

作为第一个解决方法,我在关闭上下文之前添加了一个非侵入性命令。我在close方法中添加了以下行:

// Workaround for a strange NPE by jboss-cli I do not completely understand...
if (cmdCtx.getParsedCommandLine() == null
  || cmdCtx.getParsedCommandLine().getFormat() == null) {
  cmdCtx.handle("/:read-attribute(name=launch-type)");
}
if (!cmdCtx.isTerminated()) {
  cmdCtx.terminateSession();
}

也许不是最好的解决方案,但第一次尝试......