_stateReuse.switchToRegisterResponseError();
}
else
{
InputStream bodyStream = Channels.newInputStream(_decorated);
ObjectMapper mapper = new ObjectMapper();
int registerResponseVersion = 3; // either 2 or 3 would suffice here; we care only about 4
if (_registerResponseVersionHdr != null)
{
try
{
registerResponseVersion = Integer.parseInt(_registerResponseVersionHdr);
}
catch (NumberFormatException e)
{
throw new RuntimeException("Could not parse /register response protocol version: " +
_registerResponseVersionHdr);
}
if (registerResponseVersion < 2 || registerResponseVersion > 4)
{
throw new RuntimeException("Out-of-range /register response protocol version: " +
_registerResponseVersionHdr);
}
}
if (registerResponseVersion == 4) // DDSDBUS-2009
{
HashMap<String, List<Object>> responseMap =
mapper.readValue(bodyStream, new TypeReference<HashMap<String, List<Object>>>() {});
// Look for mandatory SOURCE_SCHEMAS_KEY.
Map<Long, List<RegisterResponseEntry>> sourcesSchemasMap = RegisterResponseEntry.createFromResponse(responseMap,
RegisterResponseEntry.SOURCE_SCHEMAS_KEY,
false);
// Look for optional KEY_SCHEMAS_KEY
// Key schemas, if they exist, should correspond to source schemas, but it's not
// a one-to-one mapping. The same version of a key schema may be used for several
// versions of a source schema, or vice versa. (The IDs must correspond.)
//
// TODO (DDSDBUS-xxx): support key schemas on the relay side, too
Map<Long, List<RegisterResponseEntry>> keysSchemasMap = RegisterResponseEntry.createFromResponse(responseMap,
RegisterResponseEntry.KEY_SCHEMAS_KEY,
true);
// Look for optional METADATA_SCHEMAS_KEY
List<RegisterResponseMetadataEntry> metadataSchemasList = RegisterResponseMetadataEntry.createFromResponse(responseMap,
RegisterResponseMetadataEntry.METADATA_SCHEMAS_KEY,
true);
_stateReuse.switchToRegisterSuccess(sourcesSchemasMap, keysSchemasMap, metadataSchemasList);
}
else // version 2 or 3
{
List<RegisterResponseEntry> schemasList =
mapper.readValue(bodyStream, new TypeReference<List<RegisterResponseEntry>>() {});
Map<Long, List<RegisterResponseEntry>> sourcesSchemasMap = RegisterResponseEntry.convertSchemaListToMap(schemasList);
_stateReuse.switchToRegisterSuccess(sourcesSchemasMap, null, null);
}