return getServerDefinition( is, file.getAbsolutePath() );
}
public static ServerDefinition getServerDefinition( InputStream is, String resourceIdentifier )
throws ConfigException, IOException {
ServerDefinitionDocument doc = null;
StringBuffer inputStr = new StringBuffer();
try {
// First read the response into a buffer; that way, we can print it on error.
int c;
while ( ( c = is.read() ) != -1 )
{
inputStr.append( ( char ) c );
}
XmlOptions loadOptions = new XmlOptions();
loadOptions.setLoadLineNumbers();
doc = ServerDefinitionDocument.Factory.parse( inputStr.toString(), loadOptions );
}
catch ( XmlException e ) {
log.fatal( "test recorder parse exception while parsing this document: " + inputStr.toString(), e );
ConfigException ex = new ConfigException( "ERROR: failed parsing test recorder server definition XML, file( " +
resourceIdentifier + " )", e );
log.fatal( ex );
throw ex;
}
finally {
if ( is != null ) {
try {
is.close();
}
catch ( IOException e ) {
log.error( "ERROR: failed to close stream for file( " + resourceIdentifier + " )" );
}
}
}
assert doc != null;
try {
validate( doc, resourceIdentifier,
"ERROR: test recorder server definition XML document is not valid against the schema" );
}
catch ( ConfigException e ) {
log.fatal( "test recorder failed validating server definition file( " + resourceIdentifier + " )", e );
throw e;
}
ServerDefinition server = new ServerDefinition( doc.getServerDefinition().getName(),
doc.getServerDefinition().getHostname(), doc.getServerDefinition().getPort() );
populateServerDefinition( server, doc );
return server;
}