2014-01-24 140 views
-2

在jboss 4中,我们使用了dom4j SAX解析器来读取server.xml。它工作正常,但它不是在JBoss的EAP 6。下面的情况下,工作在JBoss的4更改JBoss EAP 6端口号

public static Document modifyAttributeValue(Document document, String elementName, String attributeName, String attributeValue) { 
    if (document == null) 
     return document; 
    try { 
     Element element = (Element) document.selectSingleNode(elementName); 
     if (element != null) { 
      Attribute attribute = element.attribute(attributeName); 
      attribute.setValue(attributeValue); 
     } 
    } catch (Exception e) { 
     logger.error("Failed to modify attribute.", e); 
    } 
    return document; 
} 

我得到元素作为空值使用的代码。

+0

因此,无论您尝试选择哪个元素都不在该文件中,并且可能已移至其他文件。通过实际执行研究来修复它。 – Gimby

+0

我正在使用此代码获取节点 – Rajesh

+0

modifyAttributeValue(document,“// socketbinding [@ name ='http']”,“port”,“8080”); – Rajesh

回答

2

拉杰什,

正如EIS刚才指出,JBoss的EAP 6.x的是基于在JBoss AS 7.x的代码的基础上,其比早期版本显著不同(的JBoss AS 4.x中,5.x的,6.x,JBoss EAP 5.x)

端口在server.xml中没有像以前的版本那样定义,而是在JBOSS_HOME/standalone/configuration/standalone.xml中定义。

尝试使用Eclipse(或您最喜欢的IDE)调试您的代码,放置很少的断点并逐行执行代码。看看为什么你得到NULL,我的猜测是你的文档通过了NULL,因此你的modifyAttributeValue()方法也返回NULL

现在,如果您希望以编程方式更改端口,那么执行此操作的方法很少。

最简单的是使用JBoss CLI(本地接口):

JBOSS_HOME/bin/jboss-cli.sh --connect 

/socket-binding-group=standard-sockets/socket-binding=http:write-attribute(name=port,value=8081) 

希望有所帮助。