private String buildApiString(String apiNs, String actionNs, String remotingApiVar, String pollingUrlsVar,
String sseVar, String routerUrl, String basePollUrl, String baseSseUrl, String group, boolean debug,
boolean doc) {
RemotingApi remotingApi = new RemotingApi(routerController.getConfiguration().getProviderType(), routerUrl,
actionNs);
remotingApi.setTimeout(routerController.getConfiguration().getTimeout());
remotingApi.setMaxRetries(routerController.getConfiguration().getMaxRetries());
Object enableBuffer = routerController.getConfiguration().getEnableBuffer();
if (enableBuffer instanceof String && StringUtils.hasText((String) enableBuffer)) {
String enableBufferString = (String) enableBuffer;
if (enableBufferString.equalsIgnoreCase("true")) {
remotingApi.setEnableBuffer(true);
} else if (enableBufferString.equalsIgnoreCase("false")) {
remotingApi.setEnableBuffer(false);
} else {
Integer enableBufferMs = NumberUtils.parseNumber(enableBufferString, Integer.class);
remotingApi.setEnableBuffer(enableBufferMs);
}
} else if (enableBuffer instanceof Number || enableBuffer instanceof Boolean) {
remotingApi.setEnableBuffer(enableBuffer);
}
buildRemotingApi(remotingApi, group);
StringBuilder sb = new StringBuilder();
if (StringUtils.hasText(apiNs)) {
sb.append("Ext.ns('");
sb.append(apiNs);
sb.append("');");
}
if (debug) {
sb.append("\n\n");
}
if (StringUtils.hasText(actionNs)) {
sb.append("Ext.ns('");
sb.append(actionNs);
sb.append("');");
if (debug) {
sb.append("\n\n");
}
}
String jsonConfig;
if (!doc) {
jsonConfig = routerController.getJsonHandler().writeValueAsString(remotingApi, debug);
} else {
ObjectMapper mapper = new ObjectMapper();
mapper.addMixInAnnotations(RemotingApi.class, RemotingApiMixin.class);
try {
jsonConfig = mapper.writer().withDefaultPrettyPrinter().writeValueAsString(remotingApi);
} catch (JsonProcessingException e) {
jsonConfig = null;
LogFactory.getLog(ApiController.class).info("serialize object to json", e);
}
}
if (StringUtils.hasText(apiNs)) {
sb.append(apiNs).append(".");
}
sb.append(remotingApiVar).append(" = ");
sb.append(jsonConfig);
sb.append(";");
List<PollingProvider> pollingProviders = remotingApi.getPollingProviders();
if (!pollingProviders.isEmpty()) {
if (debug) {
sb.append("\n\n");
}
if (StringUtils.hasText(apiNs)) {
sb.append(apiNs).append(".");
}
sb.append(pollingUrlsVar).append(" = {");
if (debug) {
sb.append("\n");
}
for (int i = 0; i < pollingProviders.size(); i++) {
if (debug) {
sb.append(" ");
}
sb.append("\"");
sb.append(pollingProviders.get(i).getEvent());
sb.append("\"");
sb.append(" : \"").append(basePollUrl).append("/");
sb.append(pollingProviders.get(i).getBeanName());
sb.append("/");
sb.append(pollingProviders.get(i).getMethod());
sb.append("/");
sb.append(pollingProviders.get(i).getEvent());
sb.append("\"");
if (i < pollingProviders.size() - 1) {
sb.append(",");
if (debug) {
sb.append("\n");
}
}
}
if (debug) {
sb.append("\n");
}
sb.append("};");
}
Map<String, List<String>> sseProviders = remotingApi.getSseProviders();
if (!sseProviders.isEmpty()) {
if (debug) {
sb.append("\n\n");
}