mirror of https://github.com/apache/cloudstack.git
CLOUDSTACK-9358: StringIndexOutOfBoundsException on events
Fixes JSON deserialization of cmdInfo (current process fails with StringIndexOutOfBoundsException when cmdEventType is the last parameter in the JSON string.
This commit is contained in:
parent
e762e27054
commit
61d2692597
|
|
@ -19,6 +19,7 @@ package com.cloud.api;
|
|||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InterruptedIOException;
|
||||
import java.lang.reflect.Type;
|
||||
import java.net.InetAddress;
|
||||
import java.net.ServerSocket;
|
||||
import java.net.Socket;
|
||||
|
|
@ -176,6 +177,7 @@ import com.cloud.utils.db.TransactionLegacy;
|
|||
import com.cloud.utils.db.UUIDManager;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.cloud.utils.exception.ExceptionProxyObject;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
@Component
|
||||
public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiServerService {
|
||||
|
|
@ -264,10 +266,11 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer
|
|||
String info = job.getCmdInfo();
|
||||
String cmdEventType = "unknown";
|
||||
if (info != null) {
|
||||
String marker = "\"cmdEventType\"";
|
||||
int begin = info.indexOf(marker);
|
||||
if (begin >= 0) {
|
||||
cmdEventType = info.substring(begin + marker.length() + 2, info.indexOf(",", begin) - 1);
|
||||
Type type = new TypeToken<Map<String, String>>(){}.getType();
|
||||
Map<String, String> cmdInfo = ApiGsonHelper.getBuilder().create().fromJson(info, type);
|
||||
String eventTypeObj = cmdInfo.get("cmdEventType");
|
||||
if (eventTypeObj != null) {
|
||||
cmdEventType = eventTypeObj;
|
||||
|
||||
if (s_logger.isDebugEnabled())
|
||||
s_logger.debug("Retrieved cmdEventType from job info: " + cmdEventType);
|
||||
|
|
|
|||
Loading…
Reference in New Issue