findbugs fixes for ApiServer, ApiSerializerHelper and ApiXmlDocWriter

This commit is contained in:
Daan Hoogland 2014-01-26 13:27:37 +01:00
parent 9a1b882d0e
commit 9aced41d70
7 changed files with 40 additions and 16 deletions

View File

@ -24,7 +24,7 @@ import org.apache.cloudstack.api.ResponseObject;
public class ApiSerializerHelper {
public static final Logger s_logger = Logger.getLogger(ApiSerializerHelper.class.getName());
public static String token = "/";
private static String token = "/";
public static String toSerializedString(Object result) {
if (result != null) {

View File

@ -159,9 +159,9 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer
private static final Logger s_logger = Logger.getLogger(ApiServer.class.getName());
private static final Logger s_accessLogger = Logger.getLogger("apiserver." + ApiServer.class.getName());
public static boolean encodeApiResponse = false;
public static String jsonContentType = "text/javascript";
public static String controlCharacters = "[\000-\011\013-\014\016-\037\177]"; // Non-printable ASCII characters - numbers 0 to 31 and 127 decimal
private static boolean encodeApiResponse = false;
private static String jsonContentType = "text/javascript";
private static String controlCharacters = "[\000-\011\013-\014\016-\037\177]"; // Non-printable ASCII characters - numbers 0 to 31 and 127 decimal
@Inject ApiDispatcher _dispatcher;
@Inject private AccountManager _accountMgr;
@ -237,7 +237,7 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer
_apiNameCmdClassMap.put(apiName, cmdClass);
}
encodeApiResponse = Boolean.valueOf(_configDao.getValue(Config.EncodeApiResponse.key()));
setEncodeApiResponse(Boolean.valueOf(_configDao.getValue(Config.EncodeApiResponse.key())));
String jsonType = _configDao.getValue(Config.JavaScriptDefaultContentType.key());
if (jsonType != null) {
jsonContentType = jsonType;
@ -375,7 +375,7 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer
buildAuditTrail(auditTrailSb, command[0], response);
} else {
if (!command[0].equalsIgnoreCase("login") && !command[0].equalsIgnoreCase("logout")) {
String errorString = "Unknown API command: " + ((command == null) ? "null" : command[0]);
String errorString = "Unknown API command: " + command[0];
s_logger.warn(errorString);
auditTrailSb.append(" " + errorString);
throw new ServerApiException(ApiErrorCode.UNSUPPORTED_ACTION_ERROR, errorString);
@ -1115,4 +1115,16 @@ public class ApiServer extends ManagerBase implements HttpRequestHandler, ApiSer
public void setApiAccessCheckers(List<APIChecker> _apiAccessCheckers) {
this._apiAccessCheckers = _apiAccessCheckers;
}
public static boolean isEncodeApiResponse() {
return encodeApiResponse;
}
private static void setEncodeApiResponse(boolean encodeApiResponse) {
ApiServer.encodeApiResponse = encodeApiResponse;
}
public static String getJsonContentType() {
return jsonContentType;
}
}

View File

@ -34,6 +34,7 @@ import javax.servlet.http.HttpSession;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;
import org.springframework.web.context.support.SpringBeanAutowiringSupport;
import org.apache.cloudstack.api.ApiErrorCode;
import org.apache.cloudstack.api.BaseCmd;
import org.apache.cloudstack.api.ServerApiException;
@ -366,7 +367,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(ApiServer.jsonContentType + "; charset=UTF-8");
resp.setContentType(ApiServer.getJsonContentType() + "; charset=UTF-8");
} else {
resp.setContentType("text/xml; charset=UTF-8");
}

View File

@ -36,7 +36,7 @@ public class EncodedStringTypeAdapter implements JsonSerializer<String>{
}
private static String encodeString(String value) {
if (!ApiServer.encodeApiResponse) {
if (!ApiServer.isEncodeApiResponse()) {
return value;
}
try {

View File

@ -16,9 +16,15 @@
// under the License.
package com.cloud.api.doc;
public class Alert {
private String type;
private int value;
import java.io.Serializable;
public class Alert implements Serializable{
/**
*
*/
private static final long serialVersionUID = 960408026527837920L;
private final String type;
private final int value;
public Alert(String type, int value) {
this.type = type;

View File

@ -16,11 +16,16 @@
// under the License.
package com.cloud.api.doc;
import java.io.Serializable;
import java.util.ArrayList;
public class Command {
public class Command implements Serializable{
private String name;
/**
*
*/
private static final long serialVersionUID = -4318310162503004975L;
private String name;
private String description;
private String usage;
private boolean isAsync;
@ -84,7 +89,7 @@ public class Command {
}
public Argument getReqArgByName(String name){
for (Argument a : this.getRequest()) {
for (Argument a : getRequest()) {
if (a.getName().equals(name)) {
return a;
}
@ -93,7 +98,7 @@ public class Command {
}
public Argument getResArgByName(String name){
for (Argument a : this.getResponse()) {
for (Argument a : getResponse()) {
if (a.getName().equals(name)) {
return a;
}

View File

@ -277,7 +277,7 @@ public class ApiResponseSerializer {
}
private static String encodeParam(String value) {
if (!ApiServer.encodeApiResponse) {
if (!ApiServer.isEncodeApiResponse()) {
return value;
}
try {