mirror of
https://github.com/apache/cloudstack.git
synced 2025-12-19 12:03:50 +01:00
Keep "encode.api.response" parameter in ApiServer class; initialize it as a part of init() method
This commit is contained in:
parent
da402fdd35
commit
d08abadc19
@ -84,6 +84,7 @@ import com.cloud.async.AsyncJob;
|
||||
import com.cloud.async.AsyncJobManager;
|
||||
import com.cloud.async.AsyncJobVO;
|
||||
import com.cloud.cluster.StackMaid;
|
||||
import com.cloud.configuration.Config;
|
||||
import com.cloud.configuration.ConfigurationVO;
|
||||
import com.cloud.configuration.dao.ConfigurationDao;
|
||||
import com.cloud.domain.Domain;
|
||||
@ -114,6 +115,7 @@ public class ApiServer implements HttpRequestHandler {
|
||||
public static final short DOMAIN_ADMIN_COMMAND = 4;
|
||||
public static final short RESOURCE_DOMAIN_ADMIN_COMMAND = 2;
|
||||
public static final short USER_COMMAND = 8;
|
||||
public static boolean encodeApiResponse = false;
|
||||
private Properties _apiCommands = null;
|
||||
private ApiDispatcher _dispatcher;
|
||||
private ManagementServer _ms = null;
|
||||
@ -225,6 +227,8 @@ public class ApiServer implements HttpRequestHandler {
|
||||
apiPort = Integer.parseInt(apiPortConfig.getValue());
|
||||
}
|
||||
|
||||
encodeApiResponse = Boolean.valueOf(configDao.getValue(Config.EncodeApiResponse.key()));
|
||||
|
||||
ListenerThread listenerThread = new ListenerThread(this, apiPort);
|
||||
listenerThread.start();
|
||||
}
|
||||
@ -886,4 +890,5 @@ public class ApiServer implements HttpRequestHandler {
|
||||
}
|
||||
return responseText;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -22,10 +22,6 @@ import java.lang.reflect.Type;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.configuration.Config;
|
||||
import com.cloud.configuration.dao.ConfigurationDao;
|
||||
import com.cloud.server.ManagementServer;
|
||||
import com.cloud.utils.component.ComponentLocator;
|
||||
import com.cloud.utils.encoding.URLEncoder;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
@ -34,18 +30,6 @@ import com.google.gson.JsonSerializer;
|
||||
|
||||
public class EncodedStringTypeAdapter implements JsonSerializer<String>{
|
||||
public static final Logger s_logger = Logger.getLogger(EncodedStringTypeAdapter.class.getName());
|
||||
private static final boolean encodeApiResponse = configure();
|
||||
|
||||
private static boolean configure() {
|
||||
ComponentLocator locator = ComponentLocator.getLocator(ManagementServer.Name);
|
||||
|
||||
ConfigurationDao configDao = locator.getDao(ConfigurationDao.class);
|
||||
if (configDao != null) {
|
||||
return Boolean.valueOf(configDao.getValue(Config.EncodeApiResponse.key()));
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonElement serialize(String src, Type typeOfResponseObj, JsonSerializationContext ctx) {
|
||||
@ -54,7 +38,7 @@ public class EncodedStringTypeAdapter implements JsonSerializer<String>{
|
||||
}
|
||||
|
||||
private static String encodeString(String value) {
|
||||
if (!encodeApiResponse) {
|
||||
if (!ApiServer.encodeApiResponse) {
|
||||
return value;
|
||||
}
|
||||
try {
|
||||
|
||||
@ -32,6 +32,7 @@ import org.apache.log4j.Logger;
|
||||
import com.cloud.api.ApiConstants;
|
||||
import com.cloud.api.ApiDBUtils;
|
||||
import com.cloud.api.ApiResponseGsonHelper;
|
||||
import com.cloud.api.ApiServer;
|
||||
import com.cloud.api.BaseCmd;
|
||||
import com.cloud.api.ResponseObject;
|
||||
import com.cloud.configuration.Config;
|
||||
@ -44,19 +45,6 @@ import com.google.gson.annotations.SerializedName;
|
||||
|
||||
public class ApiResponseSerializer {
|
||||
private static final Logger s_logger = Logger.getLogger(ApiResponseSerializer.class.getName());
|
||||
private static final boolean encodeApiResponse = configure();
|
||||
|
||||
private static boolean configure() {
|
||||
ComponentLocator locator = ComponentLocator.getCurrentLocator();
|
||||
|
||||
ConfigurationDao configDao = locator.getDao(ConfigurationDao.class);
|
||||
if (configDao != null) {
|
||||
return Boolean.valueOf(configDao.getValue(Config.EncodeApiResponse.key()));
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static String toSerializedString(ResponseObject result, String responseType) {
|
||||
if (BaseCmd.RESPONSE_TYPE_JSON.equalsIgnoreCase(responseType)) {
|
||||
@ -291,7 +279,7 @@ public class ApiResponseSerializer {
|
||||
}
|
||||
|
||||
private static String encodeParam(String value) {
|
||||
if (!encodeApiResponse) {
|
||||
if (!ApiServer.encodeApiResponse) {
|
||||
return value;
|
||||
}
|
||||
try {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user