com.google.api.client.googleapis.json.GoogleJsonErrorContainer Java Examples

The following examples show how to use com.google.api.client.googleapis.json.GoogleJsonErrorContainer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BatchRequestTest.java    From google-api-java-client with Apache License 2.0 6 votes vote down vote up
public void subTestExecuteWithVoidCallback(boolean testServerError) throws IOException {
  MockTransport transport = new MockTransport(testServerError, false,false, false, false);
  MockGoogleClient client = new MockGoogleClient.Builder(
      transport, ROOT_URL, SERVICE_PATH, null, null).setApplicationName("Test Application")
      .build();
  MockGoogleClientRequest<String> jsonHttpRequest1 =
      new MockGoogleClientRequest<String>(client, METHOD1, URI_TEMPLATE1, null, String.class);
  MockGoogleClientRequest<String> jsonHttpRequest2 =
      new MockGoogleClientRequest<String>(client, METHOD2, URI_TEMPLATE2, null, String.class);
  ObjectParser parser = new JsonObjectParser(new JacksonFactory());
  BatchRequest batchRequest =
      new BatchRequest(transport, null).setBatchUrl(new GenericUrl(TEST_BATCH_URL));
  HttpRequest request1 = jsonHttpRequest1.buildHttpRequest();
  request1.setParser(parser);
  HttpRequest request2 = jsonHttpRequest2.buildHttpRequest();
  request2.setParser(parser);
  batchRequest.queue(request1, MockDataClass1.class, GoogleJsonErrorContainer.class, callback1);
  batchRequest.queue(request2, Void.class, Void.class, callback3);
  batchRequest.execute();
  // Assert transport called expected number of times.
  assertEquals(1, transport.actualCalls);
}
 
Example #2
Source File: BigQueryServicesImplTest.java    From beam with Apache License 2.0 5 votes vote down vote up
/** A helper that generates the error JSON payload that Google APIs produce. */
private static GoogleJsonErrorContainer errorWithReasonAndStatus(String reason, int status) {
  ErrorInfo info = new ErrorInfo();
  info.setReason(reason);
  info.setDomain("global");
  // GoogleJsonError contains one or more ErrorInfo objects; our utiities read the first one.
  GoogleJsonError error = new GoogleJsonError();
  error.setErrors(ImmutableList.of(info));
  error.setCode(status);
  error.setMessage(reason);
  // The actual JSON response is an error container.
  GoogleJsonErrorContainer container = new GoogleJsonErrorContainer();
  container.setError(error);
  return container;
}
 
Example #3
Source File: BatchRequestTest.java    From google-api-java-client with Apache License 2.0 5 votes vote down vote up
@Override
public void onFailure(GoogleJsonErrorContainer e, HttpHeaders responseHeaders) {
  failureCalls++;
  GoogleJsonError error = e.getError();
  ErrorInfo errorInfo = error.getErrors().get(0);
  assertEquals(ERROR_DOMAIN, errorInfo.getDomain());
  assertEquals(ERROR_REASON, errorInfo.getReason());
  assertEquals(ERROR_MSG, errorInfo.getMessage());
  assertEquals(ERROR_CODE, error.getCode());
  assertEquals(ERROR_MSG, error.getMessage());
}
 
Example #4
Source File: BatchRequestTest.java    From google-api-java-client with Apache License 2.0 5 votes vote down vote up
@Override
public void onFailure(ErrorOutput.ErrorBody e, HttpHeaders responseHeaders) throws IOException {
  GoogleJsonErrorContainer errorContainer = new GoogleJsonErrorContainer();

  if (e.hasError()) {
    ErrorOutput.ErrorProto errorProto = e.getError();

    GoogleJsonError error = new GoogleJsonError();
    if (errorProto.hasCode()) {
      error.setCode(errorProto.getCode());
    }
    if (errorProto.hasMessage()) {
      error.setMessage(errorProto.getMessage());
    }

    List<ErrorInfo> errorInfos = new ArrayList<ErrorInfo>(errorProto.getErrorsCount());
    for (ErrorOutput.IndividualError individualError : errorProto.getErrorsList()) {
      ErrorInfo errorInfo = new ErrorInfo();
      if (individualError.hasDomain()) {
        errorInfo.setDomain(individualError.getDomain());
      }
      if (individualError.hasMessage()) {
        errorInfo.setMessage(individualError.getMessage());
      }
      if (individualError.hasReason()) {
        errorInfo.setReason(individualError.getReason());
      }
      errorInfos.add(errorInfo);
    }
    error.setErrors(errorInfos);
    errorContainer.setError(error);
  }
  callback.onFailure(errorContainer, responseHeaders);
}
 
Example #5
Source File: JsonBatchCallback.java    From google-api-java-client with Apache License 2.0 4 votes vote down vote up
public final void onFailure(GoogleJsonErrorContainer e, HttpHeaders responseHeaders)
    throws IOException {
  onFailure(e.getError(), responseHeaders);
}
 
Example #6
Source File: BatchRequestTest.java    From google-api-java-client with Apache License 2.0 4 votes vote down vote up
@Override
public void onFailure(GoogleJsonErrorContainer e, HttpHeaders responseHeaders) {
  fail("Should not be invoked in this test");
}
 
Example #7
Source File: BatchRequestTest.java    From google-api-java-client with Apache License 2.0 4 votes vote down vote up
protected TestCallbackBaseAdapter(
    BatchCallback<OutputType, GoogleJsonErrorContainer> callback) {
  this.callback = callback;
}
 
Example #8
Source File: BatchRequestTest.java    From google-api-java-client with Apache License 2.0 4 votes vote down vote up
private BatchRequest getBatchPopulatedWithRequests(boolean testServerError,
    boolean testAuthenticationError,
    boolean returnSuccessAuthenticatedContent,
    boolean testRedirect,
    boolean testBinary,
    boolean testMissingLength) throws IOException {
  transport = new MockTransport(testServerError,
      testAuthenticationError,
      testRedirect,
      testBinary,
      testMissingLength);
  MockGoogleClient client = new MockGoogleClient.Builder(
      transport, ROOT_URL, SERVICE_PATH, null, null).setApplicationName("Test Application")
      .build();
  MockGoogleClientRequest<String> jsonHttpRequest1 =
      new MockGoogleClientRequest<String>(client, METHOD1, URI_TEMPLATE1, null, String.class);
  MockGoogleClientRequest<String> jsonHttpRequest2 =
      new MockGoogleClientRequest<String>(client, METHOD2, URI_TEMPLATE2, null, String.class);
  credential = new MockCredential();

  ObjectParser parser =
      testBinary ? new ProtoObjectParser() : new JsonObjectParser(new JacksonFactory());
  BatchRequest batchRequest =
      new BatchRequest(transport, credential).setBatchUrl(new GenericUrl(TEST_BATCH_URL));
  HttpRequest request1 = jsonHttpRequest1.buildHttpRequest();
  request1.setParser(parser);
  HttpRequest request2 = jsonHttpRequest2.buildHttpRequest();
  request2.setParser(parser);
  if (testAuthenticationError) {
    request2.setUnsuccessfulResponseHandler(
        new MockUnsuccessfulResponseHandler(transport, returnSuccessAuthenticatedContent));
  }

  if (testBinary) {
    batchRequest.queue(request1, MockData.Class1.class, ErrorOutput.ErrorBody.class,
        new TestCallback1Adapter(callback1));
    batchRequest.queue(request2, MockData.Class2.class, ErrorOutput.ErrorBody.class,
        new TestCallback2Adapter(callback2));
  } else {
    batchRequest.queue(request1, MockDataClass1.class, GoogleJsonErrorContainer.class, callback1);
    batchRequest.queue(request2, MockDataClass2.class, GoogleJsonErrorContainer.class, callback2);
  }
  return batchRequest;
}
 
Example #9
Source File: AbstractGoogleJsonClientRequest.java    From google-api-java-client with Apache License 2.0 votes vote down vote up
/**
 * Queues the request into the specified batch request container.
 *
 * <p>
 * Batched requests are then executed when {@link BatchRequest#execute()} is called.
 * </p>
 * <p>
 * Example usage:
 * </p>
 *
 * <pre>
   request.queue(batchRequest, new JsonBatchCallback&lt;SomeResponseType&gt;() {

     public void onSuccess(SomeResponseType content, HttpHeaders responseHeaders) {
       log("Success");
     }

     public void onFailure(GoogleJsonError e, HttpHeaders responseHeaders) {
       log(e.getMessage());
     }
   });
 * </pre>
 *
 *
 * @param batchRequest batch request container
 * @param callback batch callback
 */
public final void queue(BatchRequest batchRequest, JsonBatchCallback<T> callback)
    throws IOException {
  super.queue(batchRequest, GoogleJsonErrorContainer.class, callback);
}