use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonParser in project syndesis by syndesisio.
the class JsonRecordSupport method jsonStreamToRecords.
public static void jsonStreamToRecords(Set<String> indexes, String dbPath, InputStream is, Consumer<JsonRecord> consumer) throws IOException {
try (JsonParser jp = new JsonFactory().createParser(is)) {
jsonStreamToRecords(indexes, jp, dbPath, consumer);
JsonToken jsonToken = jp.nextToken();
if (jsonToken != null) {
throw new JsonParseException(jp, "Document did not terminate as expected.");
}
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonParser in project build-info by JFrogDev.
the class ArtifactoryHttpClient method getVersion.
public ArtifactoryVersion getVersion() throws IOException {
String versionUrl = artifactoryUrl + VERSION_INFO_URL;
PreemptiveHttpClient client = getHttpClient();
HttpGet httpGet = new HttpGet(versionUrl);
HttpResponse response = client.execute(httpGet);
int statusCode = response.getStatusLine().getStatusCode();
if (statusCode == HttpStatus.SC_NOT_FOUND) {
HttpEntity httpEntity = response.getEntity();
if (httpEntity != null) {
EntityUtils.consume(httpEntity);
}
return ArtifactoryVersion.NOT_FOUND;
}
if (statusCode != HttpStatus.SC_OK) {
if (response.getEntity() != null) {
EntityUtils.consume(response.getEntity());
}
throw new IOException(response.getStatusLine().getReasonPhrase());
}
HttpEntity httpEntity = response.getEntity();
if (httpEntity != null) {
InputStream content = httpEntity.getContent();
JsonParser parser;
try {
parser = createJsonParser(content);
EntityUtils.consume(httpEntity);
JsonNode result = parser.readValueAsTree();
log.debug("Version result: " + result);
String version = result.get("version").asText();
JsonNode addonsNode = result.get("addons");
boolean hasAddons = (addonsNode != null) && addonsNode.iterator().hasNext();
return new ArtifactoryVersion(version, hasAddons);
} finally {
if (content != null) {
content.close();
}
}
}
return ArtifactoryVersion.NOT_FOUND;
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonParser in project build-info by JFrogDev.
the class ArtifactoryHttpClient method execute.
public ArtifactoryUploadResponse execute(HttpPut httpPut) throws IOException {
HttpResponse response = getHttpClient().execute(httpPut);
ArtifactoryUploadResponse artifactoryResponse = null;
if (response.getEntity() != null && response.getEntity().getContent() != null) {
InputStream in = response.getEntity().getContent();
String content = IOUtils.toString(in, "UTF-8");
if (StringUtils.isNotEmpty(content)) {
try {
JsonParser parser = createJsonParser(content);
artifactoryResponse = parser.readValueAs(ArtifactoryUploadResponse.class);
} catch (Exception e) {
// Displays the response received from the client and the stacktrace in case an Exception caught.
log.info("Response received: \n\n" + content + "\n\n");
log.error("Failed while reading the response from: " + httpPut, e);
} finally {
in.close();
}
}
}
if (artifactoryResponse == null) {
artifactoryResponse = new ArtifactoryUploadResponse();
}
StatusLine statusLine = response.getStatusLine();
artifactoryResponse.setStatusLine(statusLine);
return artifactoryResponse;
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonParser in project build-info by JFrogDev.
the class ArtifactoryDependenciesClient method readResponse.
/**
* Reads HTTP response and converts it to object of the type specified.
*
* @param response response to read
* @param valueType response object type
* @param errorMessage error message to throw in case of error
* @param <T> response object type
* @return response object converted from HTTP Json reponse to the type specified.
* @throws java.io.IOException if reading or converting response fails.
*/
private <T> T readResponse(HttpResponse response, TypeReference<T> valueType, String errorMessage, boolean ignorMissingFields) throws IOException {
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
HttpEntity entity = response.getEntity();
if (entity == null) {
return null;
}
InputStream content = null;
try {
content = entity.getContent();
JsonParser parser = httpClient.createJsonParser(content);
if (ignorMissingFields) {
((ObjectMapper) parser.getCodec()).configure(FAIL_ON_UNKNOWN_PROPERTIES, false);
}
// http://wiki.fasterxml.com/JacksonDataBinding
return parser.readValueAs(valueType);
} finally {
if (content != null) {
IOUtils.closeQuietly(content);
}
}
} else {
HttpEntity httpEntity = response.getEntity();
if (httpEntity != null) {
IOUtils.closeQuietly(httpEntity.getContent());
}
throw new IOException(errorMessage + ": " + response.getStatusLine());
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonParser in project build-info by JFrogDev.
the class BuildInfoExtractorUtils method jsonStringToGeneric.
public static <T extends Serializable> T jsonStringToGeneric(String json, Class<T> clazz) throws IOException {
JsonFactory jsonFactory = createJsonFactory();
JsonParser parser = jsonFactory.createJsonParser(new StringReader(json));
return jsonFactory.getCodec().readValue(parser, clazz);
}
Aggregations