Skip to content

Commit d5333f4

Browse files
batya239sebgoa
authored andcommitted
cloudstack api post and ssl fix
Signed-off-by: Sebastien Goasguen <runseb@gmail.com>
1 parent fb498a4 commit d5333f4

7 files changed

Lines changed: 232 additions & 466 deletions

File tree

awsapi/src/com/cloud/bridge/util/JsonAccessor.java

Lines changed: 0 additions & 248 deletions
This file was deleted.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.cloud.bridge.util;
2+
3+
import com.google.gson.JsonElement;
4+
import com.google.gson.JsonObject;
5+
import com.google.gson.JsonPrimitive;
6+
7+
/**
8+
* @author Dmitry Batkovich
9+
*
10+
* For more complex cases (JsonArrays or other) it can be rewrite to matcher pattern
11+
*/
12+
public final class JsonElementUtil {
13+
14+
private JsonElementUtil() {}
15+
16+
public static JsonElement getAsJsonElement(final JsonElement jsonElement, final String... path) {
17+
JsonElement currentElement = jsonElement;
18+
for (final String propertyName : path) {
19+
if (currentElement == null) {
20+
return null;
21+
}
22+
if (jsonElement.isJsonObject()) {
23+
currentElement = ((JsonObject) currentElement).get(propertyName);
24+
} else {
25+
return null;
26+
}
27+
}
28+
return currentElement;
29+
}
30+
31+
public static Integer getAsInt(final JsonElement jsonElement, final String... path) {
32+
final JsonElement targetElement = getAsJsonElement(jsonElement, path);
33+
if (targetElement == null || !targetElement.isJsonPrimitive()) {
34+
return null;
35+
}
36+
final JsonPrimitive asPrimitive = (JsonPrimitive) targetElement;
37+
return asPrimitive.getAsInt();
38+
}
39+
40+
public static String getAsString(final JsonElement jsonElement, final String... path) {
41+
final JsonElement targetElement = getAsJsonElement(jsonElement, path);
42+
return targetElement == null ? null : targetElement.getAsString();
43+
}
44+
45+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.cloud.stack;
2+
3+
/**
4+
* @author Dmitry Batkovich
5+
*/
6+
public class CloudStackClientException extends Exception {
7+
public CloudStackClientException() {
8+
}
9+
10+
public CloudStackClientException(final String s) {
11+
super(s);
12+
}
13+
14+
public CloudStackClientException(final String s, final Throwable throwable) {
15+
super(s, throwable);
16+
}
17+
18+
public CloudStackClientException(final Throwable throwable) {
19+
super(throwable);
20+
}
21+
}

0 commit comments

Comments
 (0)