我有一个成功使用嵌入式glassfish来测试JCA部署的测试。
然而,与已经使用端口3700的GlassFish 2.1的运行版本存在冲突。
如何将嵌入式GlassFish对象配置为使用命名服务的备用端口?理想情况下,这可以在测试中进行配置。
这是当前的测试代码,
GlassFishRuntime gfRuntime = GlassFishRuntime.bootstrap();
GlassFish glassfish = gfRuntime.newGlassFish();
glassfish.start();
deployJca(glassfish);
// Do tests on object acquired from JNDI.
glassfish.stop();
gfRuntime.shutdown();
例外是,
Caused by: org.omg.CORBA.COMM_FAILURE: SEVERE: IOP00410016: Unable to create IIOP listener on the specified host all interfaces and port 3,700 vmcid: OMG minor code: 16 completed: No
Caused by: java.net.BindException: Address already in use: bind
答案 0 :(得分:2)
javadoc for GlassFishRutime.newGlassFish(GlassFishProperties)和javadoc for GlassFishRuntime.bootstrap(BootstrapProperties)有点想要细节...
the asadmin create-domain reference page上描述了'--domainproperties'选项。您可以设置的其中一个属性称为“orb.listener.port”......这可能有助于解决此问题。我还注意到domain.xml文件利用端口定义的系统属性(打开domain.xml文件并搜索“IIOP_LISTENER_PORT”)。我猜这两个字符串中的一个将是BootstrapProperties或GlassFishProperties属性的关键,它将做你想要的。
答案 1 :(得分:1)
我得到了以下解决方案(以及一些有用的方法):
public synchronized CommandResult runCommand(String command, String... parameters)
throws GlassFishException {
CommandRunner runner = this.gfInstance.getCommandRunner();
CommandResult result = runner.run(command, parameters);
checkCommandResult(command, result);
return result;
}
private void checkCommandResult(String cmd, CommandResult result) {
LOG.info("Command: {}\n Result.status:\n {}\n Result.out:\n {}\n Result.failCause:\n {}\n",
new Object[] {cmd, result.getExitStatus(), result.getOutput(), result.getFailureCause()});
if (result.getExitStatus().ordinal() != 0) {
throw new IllegalStateException("Command '" + cmd + "' was unsuccessful: "
+ result.getOutput(),
result.getFailureCause());
}
然后我可以调用几乎任何东西,就像使用asadmin命令一样: 例如:
runCommand("list", "configs.config.server-config.iiop-service.iiop-listener");
生成日志:
Result.status:
SUCCESS
Result.out:
PlainTextActionReporterSUCCESSDescription: list AdminCommandnull
configs.config.server-config.iiop-service.iiop-listener.SSL
configs.config.server-config.iiop-service.iiop-listener.SSL_MUTUALAUTH
configs.config.server-config.iiop-service.iiop-listener.orb-listener-1
Result.failCause:
null
然后再次查看domain.xml并设置您想要的任何内容: http://embedded-glassfish.java.net/domain.xml 例如,在我的EGF初始化中,我在部署之前和实例启动之后调用它:
runCommand("set",
"configs.config.server-config.iiop-service.iiop-listener.orb-listener-1.port=" + 50000);
runCommand("set",
"configs.config.server-config.iiop-service.iiop-listener.SSL.port=" + 50001);
runCommand("set",
"configs.config.server-config.iiop-service.iiop-listener.SSL_MUTUALAUTH.port=" + 50002);