Skip to content

Commit a5f50d2

Browse files
author
Kris McQueen
committed
Rearranging how response objects work since we need the response name when doing serialization. Now there's a base class that implements the getResponseName method, all responses extend this base class
1 parent 4a73639 commit a5f50d2

47 files changed

Lines changed: 337 additions & 343 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎core/src/com/cloud/serializer/SerializerHelper.java‎

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,6 @@ public static String toSerializedStringOld(Object result) {
4848
return null;
4949
}
5050

51-
// FIXME: what about XML response?
52-
public static String toSerializedString(Object result) {
53-
if (result != null) {
54-
Gson gson = GsonHelper.getBuilder().create();
55-
56-
return gson.toJson(result);
57-
}
58-
return null;
59-
}
60-
6151
public static Object fromSerializedString(String result) {
6252
try {
6353
if(result != null && !result.isEmpty()) {
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
11
package com.cloud.api;
22

33
public interface ResponseObject {
4+
/**
5+
* Get the name of the API response
6+
* @return the name of the API response
7+
*/
8+
String getResponseName();
9+
10+
/**
11+
* Set the name of the API response
12+
* @param name
13+
*/
14+
void setResponseName(String name);
415
}

‎server/src/com/cloud/api/commands/GetCloudIdentifierCmd.java‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import com.cloud.api.Implementation;
2828
import com.cloud.api.Parameter;
2929
import com.cloud.api.ServerApiException;
30+
import com.cloud.api.response.ApiResponseSerializer;
3031
import com.cloud.api.response.CloudIdentifierResponse;
3132
import com.cloud.serializer.SerializerHelper;
3233

@@ -60,9 +61,10 @@ public String getName() {
6061
return s_name;
6162
}
6263

63-
@Override
64+
@Override @SuppressWarnings("unchecked")
6465
public String getResponse() {
6566
CloudIdentifierResponse response = new CloudIdentifierResponse();
67+
response.se
6668
ArrayList<String> responseObject = (ArrayList<String>)getResponseObject();
6769
if (responseObject != null) {
6870
response.setCloudIdentifier(responseObject.get(0));
@@ -71,6 +73,6 @@ public String getResponse() {
7173
} else {
7274
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to add config");
7375
}
74-
return SerializerHelper.toSerializedString(responseObject);
76+
return ApiResponseSerializer.toSerializedString(responseObject);
7577
}
7678
}

‎server/src/com/cloud/api/response/AccountResponse.java‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@
1717
*/
1818
package com.cloud.api.response;
1919

20-
import com.cloud.api.ResponseObject;
2120
import com.cloud.serializer.Param;
2221

23-
public class AccountResponse implements ResponseObject {
22+
public class AccountResponse extends BaseResponse {
2423
@Param(name="id")
2524
private Long id;
2625

‎server/src/com/cloud/api/response/AlertResponse.java‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@
1919

2020
import java.util.Date;
2121

22-
import com.cloud.api.ResponseObject;
2322
import com.cloud.serializer.Param;
2423

25-
public class AlertResponse implements ResponseObject {
24+
public class AlertResponse extends BaseResponse {
2625
@Param(name="type")
2726
private Short alertType;
2827

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.cloud.api.response;
2+
3+
import com.cloud.api.ResponseObject;
4+
import com.cloud.serializer.GsonHelper;
5+
import com.google.gson.Gson;
6+
7+
public class ApiResponseSerializer {
8+
// FIXME: what about XML response?
9+
public static String toSerializedString(ResponseObject result) {
10+
if (result != null) {
11+
Gson gson = GsonHelper.getBuilder().create();
12+
13+
return gson.toJson(result);
14+
}
15+
return null;
16+
}
17+
}

‎server/src/com/cloud/api/response/AsyncJobResponse.java‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@
1919

2020
import java.util.Date;
2121

22-
import com.cloud.api.ResponseObject;
2322
import com.cloud.serializer.Param;
2423

25-
public class AsyncJobResponse implements ResponseObject {
24+
public class AsyncJobResponse extends BaseResponse {
2625
@Param(name="id")
2726
private Long id;
2827

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.cloud.api.response;
2+
3+
import com.cloud.api.ResponseObject;
4+
5+
public class BaseResponse implements ResponseObject {
6+
private String responseName;
7+
8+
@Override
9+
public String getResponseName() {
10+
return responseName;
11+
}
12+
13+
@Override
14+
public void setResponseName(String responseName) {
15+
this.responseName = responseName;
16+
}
17+
18+
}

‎server/src/com/cloud/api/response/CapacityResponse.java‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,9 @@
1717
*/
1818
package com.cloud.api.response;
1919

20-
import com.cloud.api.ResponseObject;
2120
import com.cloud.serializer.Param;
2221

23-
public class CapacityResponse implements ResponseObject {
22+
public class CapacityResponse extends BaseResponse {
2423
@Param(name="type")
2524
private Short capacityType;
2625

‎server/src/com/cloud/api/response/CloudIdentifierResponse.java‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
package com.cloud.api.response;
22

3-
import com.cloud.api.ResponseObject;
43
import com.cloud.serializer.Param;
54

6-
public class CloudIdentifierResponse implements ResponseObject{
5+
public class CloudIdentifierResponse extends BaseResponse {
76

87
@Param(name="userid")
98
private Long userId;

0 commit comments

Comments
 (0)