Tabnine Logo
EmoResponse
Code IndexAdd Tabnine to your IDE (free)

How to use
EmoResponse
in
com.bazaarvoice.emodb.client

Best Java code snippets using com.bazaarvoice.emodb.client.EmoResponse (Showing top 20 results out of 315)

origin: bazaarvoice/emodb

protected RuntimeException convertException(EmoClientException e) {
  EmoResponse response = e.getResponse();
  String exceptionType = response.getFirstHeader("X-BV-Exception");
  if (response.getStatus() == Response.Status.BAD_REQUEST.getStatusCode() &&
      IllegalArgumentException.class.getName().equals(exceptionType)) {
    return new IllegalArgumentException(response.getEntity(String.class), e);
  } else if (response.getStatus() == Response.Status.NOT_FOUND.getStatusCode() &&
      UnknownMoveException.class.getName().equals(exceptionType)) {
    return response.getEntity(UnknownMoveException.class);
  } else if (response.getStatus() == Response.Status.FORBIDDEN.getStatusCode() &&
      UnauthorizedException.class.getName().equals(exceptionType)) {
    if (response.hasEntity()) {
      return (RuntimeException) response.getEntity(UnauthorizedException.class).initCause(e);
    } else {
      return (RuntimeException) new UnauthorizedException().initCause(e);
    }
  } else if (response.getStatus() == Response.Status.SERVICE_UNAVAILABLE.getStatusCode() &&
      ServiceUnavailableException.class.getName().equals(exceptionType)) {
    if (response.hasEntity()) {
      return (RuntimeException) response.getEntity(ServiceUnavailableException.class).initCause(e);
    } else {
      return (RuntimeException) new ServiceUnavailableException().initCause(e);
    }
  }
  return e;
}
origin: bazaarvoice/emodb

private EmoApiKey getApiKeyFromResponse(EmoResponse response) {
  if (response.getStatus() == Response.Status.OK.getStatusCode()) {
    return response.getEntity(EmoApiKey.class);
  } else if (response.getStatus() == Response.Status.NOT_FOUND.getStatusCode()) {
    return null;
  }
  throw convertException(new EmoClientException(response));
}
origin: com.bazaarvoice.emodb/emodb-blob-client-common

/** Parses HTTP headers into a {@link BlobMetadata} object. */
private BlobMetadata parseMetadataHeaders(String blobId, EmoResponse response) {
  // The server always sets X-BV-Length.  It's similar to Content-Length but proxies etc. shouldn't mess with it.
  String lengthString = response.getFirstHeader(X_BV_PREFIX + "Length");
  checkState(lengthString != null, "BlobStore request is missing expected required X-BV-Length header.");
  long length = Long.parseLong(lengthString);
  // Extract signature hash values.
  String md5 = base64ToHex(response.getFirstHeader(HttpHeaders.CONTENT_MD5));
  String sha1 = stripQuotes(response.getFirstHeader(HttpHeaders.ETAG));
  // Extract attribute map specified when the blob was first uploaded.
  Map<String, String> attributes = Maps.newHashMap();
  for (Map.Entry<String, List<String>> entry : response.getHeaders()) {
    if (entry.getKey().startsWith(X_BVA_PREFIX)) {
      attributes.put(entry.getKey().substring(X_BVA_PREFIX.length()), entry.getValue().get(0));
    }
  }
  return new DefaultBlobMetadata(blobId, response.getLastModified(), length, md5, sha1, attributes);
}
origin: com.bazaarvoice.emodb/emodb-blob-client-common

@Override
public boolean getTableExists(String apiKey, String table) {
  checkNotNull(table, "table");
  URI uri = _blobStore.clone()
      .segment("_table", table)
      .build();
  EmoResponse response = _client.resource(uri)
      .accept(MediaType.APPLICATION_JSON_TYPE)
      .header(ApiKeyRequest.AUTHENTICATION_HEADER, apiKey)
      .head();
  if (response.getStatus() == Response.Status.OK.getStatusCode()) {
    return true;
  } else if (response.getStatus() == Response.Status.NOT_FOUND.getStatusCode() &&
      UnknownTableException.class.getName().equals(response.getFirstHeader("X-BV-Exception"))) {
    return false;
  } else {
    throw convertException(new EmoClientException(response));
  }
}
origin: bazaarvoice/emodb

@Override
public PollResult poll(String apiKey, @PartitionKey String subscription, Duration claimTtl, int limit) {
  checkNotNull(subscription, "subscription");
  checkNotNull(claimTtl, "claimTtl");
  URI uri = getPollUriBuilder(subscription, claimTtl, limit).build();
  EmoResponse response = _client.resource(uri)
      .queryParam("includeTags", "true")
      .accept(MediaType.APPLICATION_JSON_TYPE)
      .header(ApiKeyRequest.AUTHENTICATION_HEADER, apiKey)
      .get(EmoResponse.class);
  if (response.getStatus() != Response.Status.OK.getStatusCode()) {
    throw convertException(new EmoClientException(response));
  }
  Iterator<Event> events = response.getEntity(new TypeReference<Iterator<Event>>() {});
  boolean moreEvents;
  String databusEmpty = response.getFirstHeader(POLL_DATABUS_EMPTY_HEADER);
  if (databusEmpty != null) {
    // Use the header value from the server to determine if the databus subscription is empty
    moreEvents = !Boolean.parseBoolean(databusEmpty);
  } else {
    // Must be polling an older version of Emo which did not include this header.  Infer whether the queue
    // is empty based on whether any results were returned.
    moreEvents = events.hasNext();
  }
  return new PollResult(events, limit, moreEvents);
}
origin: com.bazaarvoice.emodb/emodb-blob-client-common

@Override
public boolean isRetriableException(Exception e) {
  return (e instanceof EmoClientException &&
      ((EmoClientException) e).getResponse().getStatus() >= 500) ||
      e instanceof JsonStreamingEOFException;
}
origin: com.bazaarvoice.emodb/emodb-sor-client-common

@Override
public void setTableTemplate(String apiKey, String table, Map<String, ?> template, Audit audit) {
  checkNotNull(table, "table");
  checkNotNull(template, "template");
  checkNotNull(audit, "audit");
  URI uri = _dataStore.clone()
      .segment("_table", table, "template")
      .queryParam("audit", RisonHelper.asORison(audit))
      .build();
  for (int attempt = 0; ; attempt++) {
    try {
      _client.resource(uri)
          .type(MediaType.APPLICATION_JSON_TYPE)
          .header(ApiKeyRequest.AUTHENTICATION_HEADER, apiKey)
          .put(template);
      return;
    } catch (EmoClientException e) {
      // The SoR returns a 301 response when we need to make this request against a different data center.
      // Follow the redirect a few times but don't loop forever.
      if (e.getResponse().getStatus() == Response.Status.MOVED_PERMANENTLY.getStatusCode() && attempt < 5) {
        uri = e.getResponse().getLocation();
        continue;
      }
      throw convertException(e);
    }
  }
}
origin: com.bazaarvoice.emodb/emodb-blob-client-common

    .get(EmoResponse.class);
int status = response.getStatus();
if (status != Response.Status.OK.getStatusCode() && status != HTTP_PARTIAL_CONTENT) {
  throw new EmoClientException(response);
InputStream input = response.getEntityInputStream();
boolean rangeApplied = true;
String contentRange = response.getFirstHeader(HttpHeaders.CONTENT_RANGE);
if (status == Response.Status.OK.getStatusCode()) {
  checkState(contentRange == null, "Unexpected HTTP 200 response with Content-Range header.");
origin: com.bazaarvoice.emodb/emodb-sor-client-common

@Override
public boolean getTableExists(String apiKey, String table) {
  checkNotNull(table, "table");
  URI uri = _dataStore.clone()
      .segment("_table", table)
      .build();
  EmoResponse response = _client.resource(uri)
      .accept(MediaType.APPLICATION_JSON_TYPE)
      .header(ApiKeyRequest.AUTHENTICATION_HEADER, apiKey)
      .head();
  if (response.getStatus() == Response.Status.OK.getStatusCode()) {
    return true;
  } else if (response.getStatus() == Response.Status.NOT_FOUND.getStatusCode() &&
      UnknownTableException.class.getName().equals(response.getFirstHeader("X-BV-Exception"))) {
    return false;
  } else {
    throw convertException(new EmoClientException(response));
  }
}
origin: bazaarvoice/emodb

@Override
public boolean isRetriableException(Exception e) {
  return (e instanceof EmoClientException &&
      ((EmoClientException) e).getResponse().getStatus() >= 500) ||
      e instanceof JsonStreamingEOFException;
}
origin: bazaarvoice/emodb

@Override
public void createTable(String apiKey, String table, TableOptions options, Map<String, ?> template, Audit audit) throws TableExistsException {
  checkNotNull(table, "table");
  checkNotNull(options, "options");
  checkNotNull(template, "template");
  checkNotNull(audit, "audit");
  URI uri = _dataStore.clone()
      .segment("_table", table)
      .queryParam("options", RisonHelper.asORison(options))
      .queryParam("audit", RisonHelper.asORison(audit))
      .build();
  for (int attempt = 0; ; attempt++) {
    try {
      _client.resource(uri)
          .type(MediaType.APPLICATION_JSON_TYPE)
          .header(ApiKeyRequest.AUTHENTICATION_HEADER, apiKey)
          .put(template);
      return;
    } catch (EmoClientException e) {
      // The SoR returns a 301 response when we need to make this request against a different data center.
      // Follow the redirect a few times but don't loop forever.
      if (e.getResponse().getStatus() == Response.Status.MOVED_PERMANENTLY.getStatusCode() && attempt < 5) {
        uri = e.getResponse().getLocation();
        continue;
      }
      throw convertException(e);
    }
  }
}
origin: bazaarvoice/emodb

    .get(EmoResponse.class);
int status = response.getStatus();
if (status != Response.Status.OK.getStatusCode() && status != HTTP_PARTIAL_CONTENT) {
  throw new EmoClientException(response);
InputStream input = response.getEntityInputStream();
boolean rangeApplied = true;
String contentRange = response.getFirstHeader(HttpHeaders.CONTENT_RANGE);
if (status == Response.Status.OK.getStatusCode()) {
  checkState(contentRange == null, "Unexpected HTTP 200 response with Content-Range header.");
origin: bazaarvoice/emodb

@Override
public EmoRole getRole(String apiKey, EmoRoleKey roleKey) {
  checkNotNull(roleKey, "roleKey");
  URI uri = _uac.clone()
      .segment("role")
      .segment(roleKey.getGroup())
      .segment(roleKey.getId())
      .build();
  EmoResponse response = _client.resource(uri)
      .accept(MediaType.APPLICATION_JSON_TYPE)
      .header(ApiKeyRequest.AUTHENTICATION_HEADER, apiKey)
      .get(EmoResponse.class);
  if (response.getStatus() == Response.Status.OK.getStatusCode()) {
    return response.getEntity(EmoRole.class);
  } else if (response.getStatus() == Response.Status.NOT_FOUND.getStatusCode()) {
    return null;
  }
  throw convertException(new EmoClientException(response));
}
origin: bazaarvoice/emodb

/** Parses HTTP headers into a {@link BlobMetadata} object. */
private BlobMetadata parseMetadataHeaders(String blobId, EmoResponse response) {
  // The server always sets X-BV-Length.  It's similar to Content-Length but proxies etc. shouldn't mess with it.
  String lengthString = response.getFirstHeader(X_BV_PREFIX + "Length");
  checkState(lengthString != null, "BlobStore request is missing expected required X-BV-Length header.");
  long length = Long.parseLong(lengthString);
  // Extract signature hash values.
  String md5 = base64ToHex(response.getFirstHeader(HttpHeaders.CONTENT_MD5));
  String sha1 = stripQuotes(response.getFirstHeader(HttpHeaders.ETAG));
  // Extract attribute map specified when the blob was first uploaded.
  Map<String, String> attributes = Maps.newHashMap();
  for (Map.Entry<String, List<String>> entry : response.getHeaders()) {
    if (entry.getKey().startsWith(X_BVA_PREFIX)) {
      attributes.put(entry.getKey().substring(X_BVA_PREFIX.length()), entry.getValue().get(0));
    }
  }
  return new DefaultBlobMetadata(blobId, response.getLastModified(), length, md5, sha1, attributes);
}
origin: bazaarvoice/emodb

@SuppressWarnings ("ThrowableResultOfMethodCallIgnored")
private RuntimeException convertException(EmoClientException e) {
  EmoResponse response = e.getResponse();
  String exceptionType = response.getFirstHeader("X-BV-Exception");
  if (response.getStatus() == Response.Status.BAD_REQUEST.getStatusCode() &&
      IllegalArgumentException.class.getName().equals(exceptionType)) {
    return new IllegalArgumentException(response.getEntity(String.class), e);
  } else if (response.getStatus() == Response.Status.NOT_FOUND.getStatusCode() &&
      UnknownSubscriptionException.class.getName().equals(exceptionType)) {
    if (response.hasEntity()) {
      return (RuntimeException) response.getEntity(UnknownSubscriptionException.class).initCause(e);
    } else {
      return (RuntimeException) new UnknownSubscriptionException().initCause(e);
  } else if (response.getStatus() == Response.Status.NOT_FOUND.getStatusCode() &&
      UnknownMoveException.class.getName().equals(exceptionType)) {
    return response.getEntity(UnknownMoveException.class);
  } else if (response.getStatus() == Response.Status.NOT_FOUND.getStatusCode() &&
      UnknownReplayException.class.getName().equals(exceptionType)) {
    return response.getEntity(UnknownReplayException.class);
  } else if (response.getStatus() == Response.Status.FORBIDDEN.getStatusCode() &&
      UnauthorizedSubscriptionException.class.getName().equals(exceptionType)) {
    if (response.hasEntity()) {
      return (RuntimeException) response.getEntity(UnauthorizedSubscriptionException.class).initCause(e);
    } else {
      return (RuntimeException) new UnauthorizedSubscriptionException().initCause(e);
  } else if (response.getStatus() == Response.Status.FORBIDDEN.getStatusCode() &&
origin: bazaarvoice/emodb

@Override
public boolean getTableExists(String apiKey, String table) {
  checkNotNull(table, "table");
  URI uri = _dataStore.clone()
      .segment("_table", table)
      .build();
  EmoResponse response = _client.resource(uri)
      .accept(MediaType.APPLICATION_JSON_TYPE)
      .header(ApiKeyRequest.AUTHENTICATION_HEADER, apiKey)
      .head();
  if (response.getStatus() == Response.Status.OK.getStatusCode()) {
    return true;
  } else if (response.getStatus() == Response.Status.NOT_FOUND.getStatusCode() &&
      UnknownTableException.class.getName().equals(response.getFirstHeader("X-BV-Exception"))) {
    return false;
  } else {
    throw convertException(new EmoClientException(response));
  }
}
origin: bazaarvoice/emodb

@Override
public boolean isRetriableException(Exception e) {
  return (e instanceof EmoClientException &&
      ((EmoClientException) e).getResponse().getStatus() >= 500);
}
origin: com.bazaarvoice.emodb/emodb-sor-client-common

@Override
public void createTable(String apiKey, String table, TableOptions options, Map<String, ?> template, Audit audit) throws TableExistsException {
  checkNotNull(table, "table");
  checkNotNull(options, "options");
  checkNotNull(template, "template");
  checkNotNull(audit, "audit");
  URI uri = _dataStore.clone()
      .segment("_table", table)
      .queryParam("options", RisonHelper.asORison(options))
      .queryParam("audit", RisonHelper.asORison(audit))
      .build();
  for (int attempt = 0; ; attempt++) {
    try {
      _client.resource(uri)
          .type(MediaType.APPLICATION_JSON_TYPE)
          .header(ApiKeyRequest.AUTHENTICATION_HEADER, apiKey)
          .put(template);
      return;
    } catch (EmoClientException e) {
      // The SoR returns a 301 response when we need to make this request against a different data center.
      // Follow the redirect a few times but don't loop forever.
      if (e.getResponse().getStatus() == Response.Status.MOVED_PERMANENTLY.getStatusCode() && attempt < 5) {
        uri = e.getResponse().getLocation();
        continue;
      }
      throw convertException(e);
    }
  }
}
origin: com.bazaarvoice.emodb/emodb-sor-client-common

@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
private RuntimeException convertException(EmoClientException e) {
  EmoResponse response = e.getResponse();
  String exceptionType = response.getFirstHeader("X-BV-Exception");
  if (response.getStatus() == Response.Status.BAD_REQUEST.getStatusCode()) {
    if (IllegalArgumentException.class.getName().equals(exceptionType)) {
      return new IllegalArgumentException(response.getEntity(String.class), e);
    } else if (JsonStreamProcessingException.class.getName().equals(exceptionType)) {
      return new JsonStreamProcessingException(response.getEntity(String.class));
    } else if (DeltaSizeLimitException.class.getName().equals(exceptionType)) {
      return response.getEntity(DeltaSizeLimitException.class);
    } else if (AuditSizeLimitException.class.getName().equals(exceptionType)) {
      return response.getEntity(AuditSizeLimitException.class);
  } else if (response.getStatus() == Response.Status.CONFLICT.getStatusCode() &&
      TableExistsException.class.getName().equals(exceptionType)) {
    if (response.hasEntity()) {
      return (RuntimeException) response.getEntity(TableExistsException.class).initCause(e);
    } else {
      return (RuntimeException) new TableExistsException().initCause(e);
  } else if (response.getStatus() == Response.Status.NOT_FOUND.getStatusCode() &&
      UnknownTableException.class.getName().equals(exceptionType)) {
    if (response.hasEntity()) {
      return (RuntimeException) response.getEntity(UnknownTableException.class).initCause(e);
    } else {
      return (RuntimeException) new UnknownTableException().initCause(e);
  } else if (response.getStatus() == Response.Status.NOT_FOUND.getStatusCode() &&
origin: bazaarvoice/emodb

@Override
public boolean getTableExists(String apiKey, String table) {
  checkNotNull(table, "table");
  URI uri = _blobStore.clone()
      .segment("_table", table)
      .build();
  EmoResponse response = _client.resource(uri)
      .accept(MediaType.APPLICATION_JSON_TYPE)
      .header(ApiKeyRequest.AUTHENTICATION_HEADER, apiKey)
      .head();
  if (response.getStatus() == Response.Status.OK.getStatusCode()) {
    return true;
  } else if (response.getStatus() == Response.Status.NOT_FOUND.getStatusCode() &&
      UnknownTableException.class.getName().equals(response.getFirstHeader("X-BV-Exception"))) {
    return false;
  } else {
    throw convertException(new EmoClientException(response));
  }
}
com.bazaarvoice.emodb.clientEmoResponse

Javadoc

Response class that can be returned as the entity for a API requests.

Most used methods

  • getEntity
  • getFirstHeader
  • getStatus
  • hasEntity
  • getLocation
  • getEntityInputStream
  • getHeaders
  • getLastModified

Popular in Java

  • Running tasks concurrently on multiple threads
  • onCreateOptionsMenu (Activity)
  • onRequestPermissionsResult (Fragment)
  • compareTo (BigDecimal)
  • IOException (java.io)
    Signals a general, I/O-related error. Error details may be specified when calling the constructor, a
  • URLConnection (java.net)
    A connection to a URL for reading or writing. For HTTP connections, see HttpURLConnection for docume
  • Path (java.nio.file)
  • Stack (java.util)
    Stack is a Last-In/First-Out(LIFO) data structure which represents a stack of objects. It enables u
  • JTable (javax.swing)
  • Options (org.apache.commons.cli)
    Main entry-point into the library. Options represents a collection of Option objects, which describ
  • Top 12 Jupyter Notebook Extensions
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyStudentsTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now