use of com.google.gson.JsonObject in project ion by koush.
the class GsonTests method testJunkPayload.
public void testJunkPayload() throws Exception {
AsyncHttpServer httpServer = new AsyncHttpServer();
try {
httpServer.get("/", new HttpServerRequestCallback() {
@Override
public void onRequest(AsyncHttpServerRequest request, final AsyncHttpServerResponse response) {
response.send("not json!");
}
});
httpServer.listen(5555);
Future<JsonObject> ret = Ion.with(getContext()).load("PUT", "http://localhost:5555/").asJsonObject();
ret.get();
fail();
} catch (ExecutionException e) {
assertTrue(e.getCause() instanceof JsonParseException);
} finally {
httpServer.stop();
AsyncServer.getDefault().stop();
}
}
use of com.google.gson.JsonObject in project ion by koush.
the class HeadersTests method testBustedJson.
public void testBustedJson() throws Exception {
AsyncHttpServer httpServer = new AsyncHttpServer();
try {
httpServer.get("/", new HttpServerRequestCallback() {
@Override
public void onRequest(AsyncHttpServerRequest request, AsyncHttpServerResponse response) {
response.send("hello");
}
});
httpServer.listen(Ion.getDefault(getContext()).getServer(), 5555);
Response<JsonObject> response = Ion.with(getContext()).load("http://localhost:5555/").asJsonObject().withResponse().get();
assertNull(response.getResult());
assertNotNull(response.getException());
} finally {
httpServer.stop();
Ion.getDefault(getContext()).getServer().stop();
}
}
use of com.google.gson.JsonObject in project ion by koush.
the class HttpTests method testGson.
public void testGson() throws Exception {
JsonObject dummy1 = new JsonObject();
dummy1.addProperty("foo", "bar");
JsonObject dummy2 = new JsonObject();
dummy2.addProperty("pong", "ping");
JsonArray array = new JsonArray();
array.add(dummy1);
array.add(dummy2);
final Semaphore semaphore = new Semaphore(0);
Ion.with(getContext()).load("https://koush.clockworkmod.com/test/echo").setHandler(null).setJsonArrayBody(array).as(new TypeToken<List<Dummy>>() {
}).setCallback(new FutureCallback<List<Dummy>>() {
@Override
public void onCompleted(Exception e, List<Dummy> result) {
assertEquals("bar", result.get(0).foo);
semaphore.release();
}
});
assertTrue(semaphore.tryAcquire(50000, TimeUnit.MILLISECONDS));
}
use of com.google.gson.JsonObject in project ion by koush.
the class HttpTests method testUrlEncodedFormBodyWithNull.
public void testUrlEncodedFormBodyWithNull() throws Exception {
JsonObject ret = Ion.with(getContext()).load("https://koush.clockworkmod.com/test/echo").setTimeout(3000000).setBodyParameter("blit", null).setBodyParameter("foo", "bar").asJsonObject().get();
assertTrue(!ret.has("blit"));
assertEquals("bar", ret.get("foo").getAsString());
}
use of com.google.gson.JsonObject in project bigbluebutton by bigbluebutton.
the class WhiteboardMessageReceiver method handleMessage.
@Override
public void handleMessage(String pattern, String channel, String message) {
if (channel.equalsIgnoreCase(MessagingConstants.TO_WHITEBOARD_CHANNEL)) {
JsonParser parser = new JsonParser();
JsonObject obj = (JsonObject) parser.parse(message);
if (obj.has("header") && obj.has("payload")) {
JsonObject header = (JsonObject) obj.get("header");
if (header.has("name")) {
String messageName = header.get("name").getAsString();
if (UndoWhiteboardRequest.UNDO_WHITEBOARD_REQUEST.equals(messageName)) {
UndoWhiteboardRequest msg = UndoWhiteboardRequest.fromJson(message);
bbbInGW.undoWhiteboard(msg.meetingId, msg.requesterId, msg.whiteboardId);
} else if (ClearWhiteboardRequestMessage.CLEAR_WHITEBOARD_REQUEST.equals(messageName)) {
ClearWhiteboardRequestMessage msg = ClearWhiteboardRequestMessage.fromJson(message);
bbbInGW.clearWhiteboard(msg.meetingId, msg.requesterId, msg.whiteboardId);
} else if (RequestWhiteboardAnnotationHistoryRequestMessage.REQUEST_WHITEBOARD_ANNOTATION_HISTORY_REQUEST.equals(messageName)) {
RequestWhiteboardAnnotationHistoryRequestMessage msg = RequestWhiteboardAnnotationHistoryRequestMessage.fromJson(message);
bbbInGW.requestWhiteboardAnnotationHistory(msg.meetingId, msg.requesterId, msg.whiteboardId, msg.replyTo);
} else if (IsWhiteboardEnabledRequestMessage.IS_WHITEBOARD_ENABLED_REQUEST.equals(messageName)) {
IsWhiteboardEnabledRequestMessage msg = IsWhiteboardEnabledRequestMessage.fromJson(message);
bbbInGW.isWhiteboardEnabled(msg.meetingId, msg.requesterId, msg.replyTo);
} else if (EnableWhiteboardRequestMessage.ENABLE_WHITEBOARD_REQUEST.equals(messageName)) {
EnableWhiteboardRequestMessage msg = EnableWhiteboardRequestMessage.fromJson(message);
bbbInGW.enableWhiteboard(msg.meetingId, msg.requesterId, msg.enable);
} else if (SendWhiteboardAnnotationRequestMessage.SEND_WHITEBOARD_ANNOTATION_REQUEST.equals(messageName)) {
SendWhiteboardAnnotationRequestMessage msg = SendWhiteboardAnnotationRequestMessage.fromJson(message);
bbbInGW.sendWhiteboardAnnotation(msg.meetingId, msg.requesterId, msg.annotation);
}
}
}
}
}
Aggregations