}
private class ManagementHeaderMessageHandler implements MessageHandler {
public void handleMessage(Connection connection, InputStream dataStream) throws IOException {
final int workingVersion;
final ManagementRequestHeader requestHeader;
final ManagementOperationHandler handler;
ByteDataInput input = null;
try {
input = new SimpleByteDataInput(dataStream);
// Start by reading the request header
requestHeader = new ManagementRequestHeader(input);
// Work with the lowest protocol version
workingVersion = Math.min(ManagementProtocol.VERSION, requestHeader.getVersion());
byte handlerId = requestHeader.getOperationHandlerId();
if (handlerId == -1) {
throw new IOException("Management request failed. Invalid handler id");
}
handler = handlers.get(handlerId);
if (handler == null) {
String msg = null;
if (handlerId == DOMAIN_CONTROLLER_CLIENT_REQUEST) {
msg = "Management request failed. A request from a client " +
"wishing to communicate with a domain controller " +
"was received by this standalone server. Standalone " +
"servers do not support the domain client protocol";
}
else {
msg = "Management request failed. No handler found for id " + handlerId;
}
throw new IOException(msg);
}
connection.setMessageHandler(handler);
} catch (IOException e) {
throw e;
} catch (Throwable t) {
throw new IOException("Failed to read request header", t);
} finally {
safeClose(input);
safeClose(dataStream);
}
OutputStream dataOutput = null;
ByteDataOutput output = null;
try {
dataOutput = connection.writeMessage();
output = new SimpleByteDataOutput(dataOutput);
// Now write the response header
final ManagementResponseHeader responseHeader = new ManagementResponseHeader(workingVersion, requestHeader.getRequestId());
responseHeader.write(output);
output.close();
dataOutput.close();
} catch (IOException e) {