bug 11348: make content type for "json" files configurable

status 11348: resolved fixed
This commit is contained in:
alena 2011-09-07 14:19:13 -07:00
parent ba2c6695cc
commit b883b25a12
4 changed files with 13 additions and 3 deletions

View File

@ -120,6 +120,7 @@ public class ApiServer implements HttpRequestHandler {
public static final short RESOURCE_DOMAIN_ADMIN_COMMAND = 2;
public static final short USER_COMMAND = 8;
public static boolean encodeApiResponse = false;
public static String jsonContentType = "text/javascript";
private Properties _apiCommands = null;
private ApiDispatcher _dispatcher;
private ManagementServer _ms = null;
@ -233,6 +234,11 @@ public class ApiServer implements HttpRequestHandler {
}
encodeApiResponse = Boolean.valueOf(configDao.getValue(Config.EncodeApiResponse.key()));
String jsonType = configDao.getValue(Config.JavaScriptDefaultContentType.key());
if (jsonType != null) {
jsonContentType = jsonType;
}
ListenerThread listenerThread = new ListenerThread(this, apiPort);
listenerThread.start();
@ -773,7 +779,7 @@ public class ApiServer implements HttpRequestHandler {
BasicHttpEntity body = new BasicHttpEntity();
if (BaseCmd.RESPONSE_TYPE_JSON.equalsIgnoreCase(responseType)) {
// JSON response
body.setContentType("text/javascript");
body.setContentType(jsonContentType);
if (responseText == null) {
body.setContent(new ByteArrayInputStream("{ \"error\" : { \"description\" : \"Internal Server Error\" } }".getBytes("UTF-8")));
}

View File

@ -352,7 +352,7 @@ public class ApiServlet extends HttpServlet {
private void writeResponse(HttpServletResponse resp, String response, int responseCode, String responseType) {
try {
if (BaseCmd.RESPONSE_TYPE_JSON.equalsIgnoreCase(responseType)) {
resp.setContentType("text/javascript; charset=UTF-8");
resp.setContentType(ApiServer.jsonContentType + "; charset=UTF-8");
} else {
resp.setContentType("text/xml; charset=UTF-8");
}

View File

@ -273,7 +273,9 @@ public enum Config {
DnsBasicZoneUpdates("Advanced", NetworkManager.class, String.class, "network.dns.basiczone.updates", "all", "This parameter can take 2 values: all (default) and pod. It defines if DHCP/DNS requests have to be send to all dhcp servers in cloudstack, or only to the one in the same pod", "all,pod"),
ClusterMessageTimeOutSeconds("Advanced", ManagementServer.class, Integer.class, "cluster.message.timeout.seconds", "300", "Time (in seconds) to wait before a inter-management server message post times out.", null),
AgentLoadThreshold("Advanced", ManagementServer.class, Float.class, "agent.load.threshold", "0.7", "Percentage (as a value between 0 and 1) of connected agents after which agent load balancing will start happening", null);
AgentLoadThreshold("Advanced", ManagementServer.class, Float.class, "agent.load.threshold", "0.7", "Percentage (as a value between 0 and 1) of connected agents after which agent load balancing will start happening", null),
JavaScriptDefaultContentType("Advanced", ManagementServer.class, String.class, "json.content.type", "text/javascript", "Http response content type for .js files (default is text/javascript)", null);
private final String _category;
private final Class<?> _componentClass;

View File

@ -6,3 +6,5 @@ ALTER TABLE `cloud`.`vm_template` ADD COLUMN `template_tag` varchar(255) COMMENT
UPDATE vm_instance SET state='Error' WHERE state='Creating' AND removed IS null;
INSERT IGNORE INTO configuration VALUES ('Advanced', 'DEFAULT', 'management-server', 'json.content.type', 'text/javascript', 'Http response content type for .js files (default is text/javascript)');