|
@@ -1,13 +1,9 @@
|
|
|
package com.usthe.collector.collect.http;
|
|
package com.usthe.collector.collect.http;
|
|
|
|
|
|
|
|
-import com.google.gson.Gson;
|
|
|
|
|
import com.google.gson.JsonArray;
|
|
import com.google.gson.JsonArray;
|
|
|
import com.google.gson.JsonElement;
|
|
import com.google.gson.JsonElement;
|
|
|
import com.google.gson.JsonObject;
|
|
import com.google.gson.JsonObject;
|
|
|
-import com.jayway.jsonpath.Configuration;
|
|
|
|
|
-import com.jayway.jsonpath.Option;
|
|
|
|
|
-import com.jayway.jsonpath.spi.cache.CacheProvider;
|
|
|
|
|
-import com.jayway.jsonpath.spi.cache.LRUCache;
|
|
|
|
|
|
|
+import com.google.gson.JsonParser;
|
|
|
import com.usthe.collector.collect.AbstractCollect;
|
|
import com.usthe.collector.collect.AbstractCollect;
|
|
|
import com.usthe.collector.common.http.HttpClientPool;
|
|
import com.usthe.collector.common.http.HttpClientPool;
|
|
|
import com.usthe.collector.dispatch.DispatchConstants;
|
|
import com.usthe.collector.dispatch.DispatchConstants;
|
|
@@ -28,7 +24,6 @@ import org.apache.http.client.methods.CloseableHttpResponse;
|
|
|
import org.apache.http.client.methods.HttpUriRequest;
|
|
import org.apache.http.client.methods.HttpUriRequest;
|
|
|
import org.apache.http.client.methods.RequestBuilder;
|
|
import org.apache.http.client.methods.RequestBuilder;
|
|
|
import org.apache.http.client.protocol.HttpClientContext;
|
|
import org.apache.http.client.protocol.HttpClientContext;
|
|
|
-import org.apache.http.entity.StringEntity;
|
|
|
|
|
import org.apache.http.impl.client.BasicCredentialsProvider;
|
|
import org.apache.http.impl.client.BasicCredentialsProvider;
|
|
|
import org.apache.http.protocol.HttpContext;
|
|
import org.apache.http.protocol.HttpContext;
|
|
|
import org.apache.http.util.EntityUtils;
|
|
import org.apache.http.util.EntityUtils;
|
|
@@ -173,8 +168,7 @@ public class HttpCollectImpl extends AbstractCollect {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private void parseResponseByDefault(String resp, List<String> aliasFields, CollectRep.MetricsData.Builder builder) {
|
|
private void parseResponseByDefault(String resp, List<String> aliasFields, CollectRep.MetricsData.Builder builder) {
|
|
|
- Gson gson = new Gson();
|
|
|
|
|
- JsonElement element = gson.toJsonTree(resp);
|
|
|
|
|
|
|
+ JsonElement element = JsonParser.parseString(resp);
|
|
|
if (element.isJsonArray()) {
|
|
if (element.isJsonArray()) {
|
|
|
JsonArray array = element.getAsJsonArray();
|
|
JsonArray array = element.getAsJsonArray();
|
|
|
for (JsonElement jsonElement : array) {
|
|
for (JsonElement jsonElement : array) {
|
|
@@ -196,18 +190,15 @@ public class HttpCollectImpl extends AbstractCollect {
|
|
|
} else if (element.isJsonObject()) {
|
|
} else if (element.isJsonObject()) {
|
|
|
JsonObject object = element.getAsJsonObject();
|
|
JsonObject object = element.getAsJsonObject();
|
|
|
CollectRep.ValueRow.Builder valueRowBuilder = CollectRep.ValueRow.newBuilder();
|
|
CollectRep.ValueRow.Builder valueRowBuilder = CollectRep.ValueRow.newBuilder();
|
|
|
- StringBuilder instance = new StringBuilder();
|
|
|
|
|
for (String alias : aliasFields) {
|
|
for (String alias : aliasFields) {
|
|
|
JsonElement valueElement = object.get(alias);
|
|
JsonElement valueElement = object.get(alias);
|
|
|
if (valueElement != null) {
|
|
if (valueElement != null) {
|
|
|
String value = valueElement.getAsString();
|
|
String value = valueElement.getAsString();
|
|
|
valueRowBuilder.addColumns(value);
|
|
valueRowBuilder.addColumns(value);
|
|
|
- instance.append(value);
|
|
|
|
|
} else {
|
|
} else {
|
|
|
valueRowBuilder.addColumns(CommonConstants.NULL_VALUE);
|
|
valueRowBuilder.addColumns(CommonConstants.NULL_VALUE);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- valueRowBuilder.setInstance(instance.toString());
|
|
|
|
|
builder.addValues(valueRowBuilder.build());
|
|
builder.addValues(valueRowBuilder.build());
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|