@AsyncThread void handleHttpRequest(HttpEntity<String> e, HttpServletResponse rsp) { Message msg = CloudBusGson.fromJson(e.getBody()); Map raw = JSONObjectUtil.toObject(e.getBody(), LinkedHashMap.class); try { restoreFromSchema(msg, raw); } catch (ClassNotFoundException e1) { throw new CloudRuntimeException(e1); } new MessageSender(msg).localSend(); rsp.setStatus(HttpStatus.OK.value()); } }
private void eventSend() { buildSchema(msg); localSend(); destMaker.getAllNodeInfo().forEach(node -> { if (!node.getNodeUuid().equals(Platform.getManagementServerId())) { httpSend(node.getNodeIP()); } }); }
void send() { try { doSend(); } catch (Throwable th) { replyErrorIfNeeded(operr(th.getMessage())); } }
private void httpSend(String ip) { String url = CloudBusGlobalProperty.HTTP_CONTEXT_PATH.isEmpty() ? String.format("http://%s:%s%s", ip, CloudBusGlobalProperty.HTTP_PORT, HTTP_BASE_URL) : String.format("http://%s:%s/%s/%s", ip, CloudBusGlobalProperty.HTTP_PORT, CloudBusGlobalProperty.HTTP_CONTEXT_PATH, HTTP_BASE_URL); HttpHeaders headers = new HttpHeaders(); HttpEntity<String> req = new HttpEntity<>(CloudBusGson.toJson(msg), headers); try { ResponseEntity<String> rsp = new Retry<ResponseEntity<String>>() { { interval = 2; } @Override @RetryCondition(onExceptions = {IOException.class, RestClientException.class, HttpClientErrorException.class}) protected ResponseEntity<String> call() { return http.exchange(url, HttpMethod.POST, req, String.class); } }.run(); if (!rsp.getStatusCode().is2xxSuccessful()) { replyErrorIfNeeded(operr("HTTP ERROR, status code: %s, body: %s", rsp.getStatusCode(), rsp.getBody())); } } catch (OperationFailureException e) { replyErrorIfNeeded(e.getErrorCode()); } catch (Throwable e) { replyErrorIfNeeded(operr(e.getMessage())); } }
private void httpSend() { buildSchema(msg); String ip = destMaker.getNodeInfo(managementNodeId).getNodeIP(); httpSend(ip); }
private void doSend(Message msg) { evalThreadContextToMessage(msg); if (logger.isTraceEnabled() && islogMessage(msg)) { logger.trace(String.format("[msg send]: %s", dumpMessage(msg))); } new MessageSender(msg).send(); }
private void doPublish(Event evt) { evalThreadContextToMessage(evt); if (logger.isTraceEnabled() && islogMessage(evt)) { logger.trace(String.format("[event publish]: %s", dumpMessage(evt))); } new MessageSender(evt).send(); }