final Pattern simpleKeyDelimiterPattern,
final Pattern keyValueDelimiterPattern)
throws RoutingException
{
String[] simpleKeys = simpleKeyDelimiterPattern.split(urlString.trim());
CompoundKey compoundKey = new CompoundKey();
for (String simpleKey : simpleKeys)
{
String[] nameValuePair = keyValueDelimiterPattern.split(simpleKey.trim());
if (simpleKey.trim().length() == 0 || nameValuePair.length != 2)
{
errorMessageBuilder.append("Bad key format '");
errorMessageBuilder.append(urlString);
errorMessageBuilder.append("'");
return null;
}
// Simple key names and values are URL-encoded prior to being included in the URL on
// the client, to prevent collision with any of the delimiter characters (bulk,
// compound key and simple key-value). So, must decode them
String name;
try
{
name = URLDecoder.decode(nameValuePair[0], RestConstants.DEFAULT_CHARSET_NAME);
}
catch (UnsupportedEncodingException e)
{
//should not happen, since we are using "UTF-8" as the encoding
throw new RestLiInternalException(e);
}
// Key is not found in the set defined for the resource
Key currentKey = getKeyWithName(keys, name);
if (currentKey == null)
{
errorMessageBuilder.append("Unknown key part named '");
errorMessageBuilder.append(name);
errorMessageBuilder.append("'");
return null;
}
String decodedStringValue;
try
{
decodedStringValue =
URLDecoder.decode(nameValuePair[1], RestConstants.DEFAULT_CHARSET_NAME);
}
catch (UnsupportedEncodingException e)
{
//should not happen, since we are using "UTF-8" as the encoding
throw new RestLiInternalException(e);
}
compoundKey.append(name, convertSimpleValue(decodedStringValue, currentKey.getDataSchema(), currentKey.getType()));
}
return compoundKey;
}