response.sendError(HttpServletResponse.SC_FORBIDDEN);
return;
}
final JSONRenderer renderer = new JSONRenderer();
context.setRenderer(renderer);
final JSONObject ret = new JSONObject();
renderer.setJSONObject(ret);
try {
final JSONObject requestJSONObject = Requests.parseRequestJSONObject(request, response);
final JSONObject broadcast = requestJSONObject.getJSONObject("broadcast");
final JSONObject preference = preferenceQueryService.getPreference();
final String b3logKey = preference.getString(Preference.KEY_OF_SOLO);
final String email = preference.getString(Preference.ADMIN_EMAIL);
final String clientName = "B3log Solo";
final String clientVersion = SoloServletListener.VERSION;
final String clientTitle = preference.getString(Preference.BLOG_TITLE);
final String clientRuntimeEnv = Latkes.getRuntimeEnv().name();
final JSONObject broadcastRequest = new JSONObject();
broadcastRequest.put("b3logKey", b3logKey);
broadcastRequest.put("email", email);
broadcastRequest.put("broadcast", broadcast);
broadcastRequest.put("clientRuntimeEnv", clientRuntimeEnv);
broadcastRequest.put("clientTitle", clientTitle);
broadcastRequest.put("clientVersion", clientVersion);
broadcastRequest.put("clientName", clientName);
broadcastRequest.put("clientHost", Latkes.getServePath());
final HTTPRequest httpRequest = new HTTPRequest();
httpRequest.setURL(ADD_BROADCAST_URL);
httpRequest.setRequestMethod(HTTPRequestMethod.POST);
httpRequest.setPayload(broadcastRequest.toString().getBytes("UTF-8"));
@SuppressWarnings("unchecked")
final Future<HTTPResponse> future = (Future<HTTPResponse>) urlFetchService.fetchAsync(httpRequest);
final HTTPResponse result = future.get();
if (HttpServletResponse.SC_OK == result.getResponseCode()) {
ret.put(Keys.STATUS_CODE, true);
optionMgmtService.removeOption(Option.ID_C_BROADCAST_CHANCE_EXPIRATION_TIME);
LOGGER.info("Submits broadcast successfully");
return;
}
ret.put(Keys.STATUS_CODE, false);
} catch (final Exception e) {
LOGGER.log(Level.ERROR, "Submits broadcast failed", e);
final JSONObject jsonObject = QueryResults.defaultResult();
renderer.setJSONObject(jsonObject);
jsonObject.put(Keys.MSG, e.getMessage());
}
}