CliConfigImpl config = new CliConfigImpl();
BufferedInputStream input = null;
try {
final XMLMapper mapper = XMLMapper.Factory.create();
mapper.registerRootElement(new QName("urn:jboss:cli:1.0", "jboss-cli"), new XMLElementReader<CliConfigImpl>(){
@Override
public void readElement(XMLExtendedStreamReader reader, CliConfigImpl config) throws XMLStreamException {
boolean jbossCliEnded = false;
while (reader.hasNext() && jbossCliEnded == false) {
int tag = reader.nextTag();
if(tag == XMLStreamConstants.START_ELEMENT) {
final String localName = reader.getLocalName();
if (localName.equals("ssl")) {
SslConfig sslConfig = new SslConfig();
readSSLElement(reader, sslConfig);
config.sslConfig = sslConfig;
}
} else if(tag == XMLStreamConstants.END_ELEMENT) {
final String localName = reader.getLocalName();
if (localName.equals("jboss-cli")) {
jbossCliEnded = true;
}
}
}
}
public void readSSLElement(XMLExtendedStreamReader reader, SslConfig config) throws XMLStreamException {
while (reader.hasNext() && reader.nextTag() != END_ELEMENT) {
final String localName = reader.getLocalName();
if ("keyStore".equals(localName)) {
config.setKeyStore(reader.getElementText());
} else if ("keyStorePassword".equals(localName)) {
config.setKeyStorePassword(reader.getElementText());
} else if ("trustStore".equals(localName)) {
config.setTrustStore(reader.getElementText());
} else if ("trustStorePassword".equals(localName)) {
config.setTrustStorePassword(reader.getElementText());
} else if ("modifyTrustStore".equals(localName)) {
config.setModifyTrustStore(Boolean.getBoolean(reader.getElementText()));
}
}
}
});
FileInputStream is = new FileInputStream(f);
input = new BufferedInputStream(is);
XMLStreamReader streamReader = XMLInputFactory.newInstance().createXMLStreamReader(input);
mapper.parseDocument(config, streamReader);
streamReader.close();
} catch(Throwable t) {
throw new CliInitializationException("Failed to parse " + f.getAbsolutePath(), t);
} finally {
StreamUtils.safeClose(input);