|
@@ -19,12 +19,13 @@ import java.io.ByteArrayOutputStream;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
import java.io.OutputStream;
|
|
import java.io.OutputStream;
|
|
|
|
|
|
|
|
+import org.apache.commons.text.StringEscapeUtils;
|
|
import org.codelibs.core.lang.StringUtil;
|
|
import org.codelibs.core.lang.StringUtil;
|
|
import org.codelibs.fess.Constants;
|
|
import org.codelibs.fess.Constants;
|
|
|
|
+import org.codelibs.fess.util.EsUtil;
|
|
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
|
|
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
|
|
import org.elasticsearch.cluster.health.ClusterHealthStatus;
|
|
import org.elasticsearch.cluster.health.ClusterHealthStatus;
|
|
-import org.elasticsearch.common.xcontent.ToXContent;
|
|
|
|
-import org.elasticsearch.common.xcontent.XContentFactory;
|
|
|
|
|
|
+import org.elasticsearch.common.xcontent.XContentType;
|
|
|
|
|
|
public class PingResponse {
|
|
public class PingResponse {
|
|
private final int status;
|
|
private final int status;
|
|
@@ -39,10 +40,13 @@ public class PingResponse {
|
|
status = response.getStatus() == ClusterHealthStatus.RED ? 1 : 0;
|
|
status = response.getStatus() == ClusterHealthStatus.RED ? 1 : 0;
|
|
clusterName = response.getClusterName();
|
|
clusterName = response.getClusterName();
|
|
clusterStatus = response.getStatus().toString();
|
|
clusterStatus = response.getStatus().toString();
|
|
- try (OutputStream out = response.toXContent(XContentFactory.jsonBuilder(), ToXContent.EMPTY_PARAMS).getOutputStream()) {
|
|
|
|
|
|
+ try (OutputStream out = EsUtil.getXContentOutputStream(response, XContentType.JSON)) {
|
|
message = ((ByteArrayOutputStream) out).toString(Constants.UTF_8);
|
|
message = ((ByteArrayOutputStream) out).toString(Constants.UTF_8);
|
|
|
|
+ if (StringUtil.isBlank(message)) {
|
|
|
|
+ message = "{}";
|
|
|
|
+ }
|
|
} catch (final IOException e) {
|
|
} catch (final IOException e) {
|
|
- message = "{ \"error\" : \"" + e.getMessage() + "\"}";
|
|
|
|
|
|
+ message = "{ \"error\" : \"" + StringEscapeUtils.escapeJson(e.getMessage()) + "\"}";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|