Fix GroupKey interpretation in REST
Input string from REST should not be converted into byte array directly.
Before: "1" -> ascii 49 -> 0x31
After: "0x01" -> 0x01
GroupKey is a byte array with arbitrary length and represented by hex string
Change-Id: If27101f0e5522212c7e434fab58b66e67e9676d7
diff --git a/core/common/src/main/java/org/onosproject/codec/impl/GroupCodec.java b/core/common/src/main/java/org/onosproject/codec/impl/GroupCodec.java
index 60ef0cf..10ddd4d 100644
--- a/core/common/src/main/java/org/onosproject/codec/impl/GroupCodec.java
+++ b/core/common/src/main/java/org/onosproject/codec/impl/GroupCodec.java
@@ -18,6 +18,7 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
+import org.onlab.util.HexString;
import org.onosproject.codec.CodecContext;
import org.onosproject.codec.JsonCodec;
import org.onosproject.core.ApplicationId;
@@ -118,7 +119,11 @@
// parse group key (appCookie)
String groupKeyStr = nullIsIllegal(json.get(APP_COOKIE),
APP_COOKIE + MISSING_MEMBER_MESSAGE).asText();
- GroupKey groupKey = new DefaultGroupKey(groupKeyStr.getBytes());
+ if (!groupKeyStr.startsWith("0x")) {
+ throw new IllegalArgumentException("APP_COOKIE must be a hex string starts with 0x");
+ }
+ GroupKey groupKey = new DefaultGroupKey(HexString.fromHexString(
+ groupKeyStr.split("0x")[1], ""));
// parse device id
DeviceId deviceId = DeviceId.deviceId(nullIsIllegal(json.get(DEVICE_ID),