use of com.google.api.client.json.JsonFactory in project beam by apache.
the class PackageUtilTest method googleJsonResponseException.
/**
* Builds a fake GoogleJsonResponseException for testing API error handling.
*/
private static GoogleJsonResponseException googleJsonResponseException(final int status, final String reason, final String message) throws IOException {
final JsonFactory jsonFactory = new JacksonFactory();
HttpTransport transport = new MockHttpTransport() {
@Override
public LowLevelHttpRequest buildRequest(String method, String url) throws IOException {
ErrorInfo errorInfo = new ErrorInfo();
errorInfo.setReason(reason);
errorInfo.setMessage(message);
errorInfo.setFactory(jsonFactory);
GenericJson error = new GenericJson();
error.set("code", status);
error.set("errors", Arrays.asList(errorInfo));
error.setFactory(jsonFactory);
GenericJson errorResponse = new GenericJson();
errorResponse.set("error", error);
errorResponse.setFactory(jsonFactory);
return new MockLowLevelHttpRequest().setResponse(new MockLowLevelHttpResponse().setContent(errorResponse.toPrettyString()).setContentType(Json.MEDIA_TYPE).setStatusCode(status));
}
};
HttpRequest request = transport.createRequestFactory().buildGetRequest(HttpTesting.SIMPLE_GENERIC_URL);
request.setThrowExceptionOnExecuteError(false);
HttpResponse response = request.execute();
return GoogleJsonResponseException.from(jsonFactory, response);
}
use of com.google.api.client.json.JsonFactory in project beam by apache.
the class BigqueryMatcher method newBigqueryClient.
@VisibleForTesting
Bigquery newBigqueryClient(String applicationName) {
HttpTransport transport = Transport.getTransport();
JsonFactory jsonFactory = Transport.getJsonFactory();
Credentials credential = getDefaultCredential();
return new Bigquery.Builder(transport, jsonFactory, new HttpCredentialsAdapter(credential)).setApplicationName(applicationName).build();
}
use of com.google.api.client.json.JsonFactory in project gatk by broadinstitute.
the class ReferenceAPISource method writeObject.
// TODO: Move these to a CustomCoder. That will allow us to do something else (possibly better) for Spark.
// TODO: See Issue #849.
// implement methods for Java serialization, since Reference does not implement Serializable
private void writeObject(ObjectOutputStream stream) throws IOException {
JsonFactory jsonFactory = com.google.api.client.googleapis.util.Utils.getDefaultJsonFactory();
stream.writeInt(referenceMap.size());
for (Map.Entry<String, Reference> e : referenceMap.entrySet()) {
stream.writeUTF(e.getKey());
stream.writeUTF(jsonFactory.toString(e.getValue()));
}
stream.writeObject(referenceNameToIdTable);
stream.writeObject(apiKey);
}
Aggregations