com.google.api.client.util.Objects Java Examples

The following examples show how to use com.google.api.client.util.Objects. 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: StringId.java    From catatumbo with Apache License 2.0 5 votes vote down vote up
@Override
public boolean equals(Object obj) {
  if (obj == null || !(obj instanceof StringId)) {
    return false;
  }
  StringId that = (StringId) obj;
  return Objects.equal(this.id, that.id) && Objects.equal(this.greetings, that.greetings);
}
 
Example #2
Source File: DeleteAll.java    From catatumbo with Apache License 2.0 5 votes vote down vote up
@Override
public boolean equals(Object obj) {
  if (obj == null || !(obj instanceof DeleteAll)) {
    return false;
  }
  DeleteAll that = (DeleteAll) obj;
  return this.id == that.id && Objects.equal(this.field1, that.field1);
}
 
Example #3
Source File: LongId.java    From catatumbo with Apache License 2.0 5 votes vote down vote up
@Override
public boolean equals(Object obj) {
  if (obj == null || !(obj instanceof LongId)) {
    return false;
  }
  LongId that = (LongId) obj;
  return this.id == that.id && Objects.equal(this.field1, that.field1);
}
 
Example #4
Source File: UserContact.java    From catatumbo with Apache License 2.0 5 votes vote down vote up
@Override
public boolean equals(Object obj) {
  if (this == obj) {
    return true;
  }
  if (obj == null || !this.getClass().equals(obj.getClass())) {
    return false;
  }
  UserContact that = (UserContact) obj;
  return Objects.equal(this.id, that.id) && Objects.equal(this.userKey, that.userKey)
      && Objects.equal(this.contactKey, that.contactKey)
      && Objects.equal(this.contactName, that.contactName);
}
 
Example #5
Source File: UrlEncodedParserTest.java    From google-http-java-client with Apache License 2.0 5 votes vote down vote up
@Override
public boolean equals(Object obj) {
  Simple other = (Simple) obj;
  return Objects.equal(a, other.a)
      && Objects.equal(b, other.b)
      && Objects.equal(c, other.c)
      && Objects.equal(q, other.q)
      && Arrays.equals(r, other.r)
      && Objects.equal(o, other.o);
}
 
Example #6
Source File: UrlEncodedParserTest.java    From google-http-java-client with Apache License 2.0 5 votes vote down vote up
@Override
public String toString() {
  return Objects.toStringHelper(this)
      .add("a", a)
      .add("b", b)
      .add("c", c)
      .add("q", q)
      .add("r", Arrays.asList(r))
      .add("o", o)
      .toString();
}
 
Example #7
Source File: StoredChannel.java    From google-api-java-client with Apache License 2.0 5 votes vote down vote up
@Override
public String toString() {
  return Objects.toStringHelper(StoredChannel.class)
      .add("notificationCallback", getNotificationCallback()).add("clientToken", getClientToken())
      .add("expiration", getExpiration()).add("id", getId()).add("topicId", getTopicId())
      .toString();
}
 
Example #8
Source File: AbstractNotification.java    From google-api-java-client with Apache License 2.0 5 votes vote down vote up
/** Returns the helper for {@link #toString()}. */
protected Objects.ToStringHelper toStringHelper() {
  return Objects.toStringHelper(this).add("messageNumber", messageNumber)
      .add("resourceState", resourceState).add("resourceId", resourceId)
      .add("resourceUri", resourceUri).add("channelId", channelId)
      .add("channelExpiration", channelExpiration).add("channelToken", channelToken)
      .add("changed", changed);
}
 
Example #9
Source File: StoredCredential.java    From google-oauth-java-client with Apache License 2.0 5 votes vote down vote up
@Override
public String toString() {
  return Objects.toStringHelper(StoredCredential.class)
      .add("accessToken", getAccessToken())
      .add("refreshToken", getRefreshToken())
      .add("expirationTimeMilliseconds", getExpirationTimeMilliseconds())
      .toString();
}
 
Example #10
Source File: StoredCredential.java    From google-oauth-java-client with Apache License 2.0 5 votes vote down vote up
@Override
public boolean equals(Object other) {
  if (this == other) {
    return true;
  }
  if (!(other instanceof StoredCredential)) {
    return false;
  }
  StoredCredential o = (StoredCredential) other;
  return Objects.equal(getAccessToken(), o.getAccessToken())
      && Objects.equal(getRefreshToken(), o.getRefreshToken())
      && Objects.equal(getExpirationTimeMilliseconds(), o.getExpirationTimeMilliseconds());
}
 
Example #11
Source File: JsonWebToken.java    From google-http-java-client with Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
  return Objects.toStringHelper(this).add("header", header).add("payload", payload).toString();
}
 
Example #12
Source File: Credential.java    From google-oauth-java-client with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 * <p>
 * Default implementation checks if {@code WWW-Authenticate} exists and contains a "Bearer" value
 * (see <a href="http://tools.ietf.org/html/rfc6750#section-3.1">rfc6750 section 3.1</a> for more
 * details). If so, it calls {@link #refreshToken} in case the error code contains
 * {@code invalid_token}. If there is no "Bearer" in {@code WWW-Authenticate} and the status code
 * is {@link HttpStatusCodes#STATUS_CODE_UNAUTHORIZED} it calls {@link #refreshToken}. If
 * {@link #executeRefreshToken()} throws an I/O exception, this implementation will log the
 * exception and return {@code false}. Subclasses may override.
 * </p>
 */
public boolean handleResponse(HttpRequest request, HttpResponse response, boolean supportsRetry) {
  boolean refreshToken = false;
  boolean bearer = false;

  List<String> authenticateList = response.getHeaders().getAuthenticateAsList();

  // TODO(peleyal): this logic should be implemented as a pluggable interface, in the same way we
  // implement different AccessMethods

  // if authenticate list is not null we will check if one of the entries contains "Bearer"
  if (authenticateList != null) {
    for (String authenticate : authenticateList) {
      if (authenticate.startsWith(BearerToken.AuthorizationHeaderAccessMethod.HEADER_PREFIX)) {
        // mark that we found a "Bearer" value, and check if there is a invalid_token error
        bearer = true;
        refreshToken = BearerToken.INVALID_TOKEN_ERROR.matcher(authenticate).find();
        break;
      }
    }
  }

  // if "Bearer" wasn't found, we will refresh the token, if we got 401
  if (!bearer) {
    refreshToken = response.getStatusCode() == HttpStatusCodes.STATUS_CODE_UNAUTHORIZED;
  }

  if (refreshToken) {
    try {
      lock.lock();
      try {
        // need to check if another thread has already refreshed the token
        return !Objects.equal(accessToken, method.getAccessTokenFromRequest(request))
            || refreshToken();
      } finally {
        lock.unlock();
      }
    } catch (IOException exception) {
      LOGGER.log(Level.SEVERE, "unable to refresh token", exception);
    }
  }
  return false;
}