Java Code Examples for javax.ws.rs.core.Response#toString()

The following examples show how to use javax.ws.rs.core.Response#toString() . 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: SnomedClientRest.java    From SNOMED-in-5-minutes with Apache License 2.0 6 votes vote down vote up
/**
 * Returns description matches for the specified description id.
 *
 * @param descriptionId the description id
 * @return the matches for description id
 * @throws Exception the exception
 */
public MatchResults findByDescriptionId(String descriptionId)
  throws Exception {
  Logger.getLogger(getClass()).debug(
      "Snomed Client - find description matches by description id "
          + descriptionId);

  validateNotEmpty(descriptionId, "descriptionId");

  final Client client = ClientBuilder.newClient();
  final WebTarget target =
      client.target(getUrl() + "/descriptions/" + descriptionId);
  final Response response = target.request(MediaType.APPLICATION_JSON).get();
  final String resultString = response.readEntity(String.class);
  if (response.getStatusInfo().getFamily() == Family.SUCCESSFUL) {
    // n/a
  } else {
    throw new Exception(response.toString());
  }

  // converting to object
  return Utility.getGraphForJson(resultString, MatchResults.class);
}
 
Example 2
Source File: SnomedClientRest.java    From SNOMED-in-5-minutes with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the concept for the specified concept id.
 *
 * @param conceptId the concept id
 * @return the concept for id
 * @throws Exception the exception
 */
public Concept findByConceptId(String conceptId) throws Exception {
  Logger.getLogger(getClass()).debug(
      "Snomed Client - find concept by concept id " + conceptId);

  validateNotEmpty(conceptId, "conceptId");

  final Client client = ClientBuilder.newClient();
  final WebTarget target = client.target(getUrl() + "/concepts/" + conceptId);
  final Response response = target.request(MediaType.APPLICATION_JSON).get();
  final String resultString = response.readEntity(String.class);
  if (response.getStatusInfo().getFamily() == Family.SUCCESSFUL) {
    // n/a
  } else {
    throw new Exception(response.toString());
  }

  // converting to object
  return Utility.getGraphForJson(resultString, Concept.class);
}
 
Example 3
Source File: SnomedClientRest.java    From SNOMED-in-5-minutes with Apache License 2.0 5 votes vote down vote up
/**
 * Returns description matches for the specified query.
 *
 * @param query the query
 * @return the matches for query
 * @throws Exception the exception
 */
public MatchResults findByQuery(String query) throws Exception {
  Logger.getLogger(getClass()).debug(
      "Snomed Client - get description matches by query " + query);

  validateNotEmpty(query, "query");

  final Client client = ClientBuilder.newClient();
  final WebTarget target =
      client.target(getUrl()
          + "/descriptions?query="
          + URLEncoder.encode(query == null ? "" : query, "UTF-8")
              .replaceAll("\\+", "%20")
          + "&limit=50&searchMode=partialMatching"
          + "&lang=english&statusFilter=activeOnly&skipTo=0"
          + "&returnLimit=100&normalize=true");

  final Response response = target.request(MediaType.APPLICATION_JSON).get();
  final String resultString = response.readEntity(String.class);
  if (response.getStatusInfo().getFamily() == Family.SUCCESSFUL) {
    // n/a
  } else {
    throw new Exception(response.toString());
  }

  // converting to object
  return Utility.getGraphForJson(resultString, MatchResults.class);
}
 
Example 4
Source File: SnomedClientRest.java    From SNOMED-in-5-minutes with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the matches for query.
 *
 * @param query the query
 * @param semanticFilter the semantic filter
 * @return the matches for query
 * @throws Exception the exception
 */
public MatchResults findByQueryWithFilter(String query, String semanticFilter)
  throws Exception {
  Logger.getLogger(getClass()).debug(
      "Snomed Client - find description matches for query and filter " + query + ", "
          + semanticFilter);

  validateNotEmpty(query, "query");
  validateNotEmpty(semanticFilter, "semanticFilter");

  final Client client = ClientBuilder.newClient();
  final WebTarget target =
      client.target(getUrl()
          + "/descriptions?query="
          + URLEncoder.encode(query == null ? "" : query, "UTF-8")
              .replaceAll("\\+", "%20")
          + "&limit=50&searchMode=partialMatching"
          + "&lang=english&statusFilter=activeOnly&skipTo=0"
          + "&returnLimit=100&normalize=true&semanticFilter="
          + URLEncoder.encode(semanticFilter == null ? "" : semanticFilter,
              "UTF-8").replaceAll("\\+", "%20"));

  final Response response = target.request(MediaType.APPLICATION_JSON).get();
  final String resultString = response.readEntity(String.class);
  if (response.getStatusInfo().getFamily() == Family.SUCCESSFUL) {
    // n/a
  } else {
    throw new Exception(response.toString());
  }

  // converting to object
  return Utility.getGraphForJson(resultString, MatchResults.class);
}
 
Example 5
Source File: SnomedClientRest.java    From SNOMED-in-5-minutes with Apache License 2.0 4 votes vote down vote up
/**
 * Returns description matches for the specified parameters.
 *
 * @param query the query
 * @param limit the limit
 * @param searchMode the search mode
 * @param lang the lang
 * @param statusFilter the status filter
 * @param skipTo the skip to
 * @param returnLimit the return limit
 * @param normalize the normalize
 * @param semanticFilter the semantic filter
 * @return the matches for query
 * @throws Exception the exception
 */
public MatchResults findByQuery(String query, Long limit, String searchMode,
  String lang, String statusFilter, Long skipTo, Long returnLimit,
  Boolean normalize, String semanticFilter) throws Exception {
  Logger.getLogger(getClass()).debug(
      "Snomed Client - get description matches by query " + query);

  validateNotEmpty(query, "query");

  // Use defaults if null is passed
  final long localLimit = limit == null ? 50L : limit;
  final String localSearchMode =
      searchMode == null ? "partialMatching" : searchMode;
  final String localLang = lang == null ? "english" : lang;
  final String localStatusFilter =
      statusFilter == null ? "activeOnly" : statusFilter;
  final long localSkipTo = skipTo == null ? 0L : skipTo;
  final long localReturnLimit = returnLimit == null ? 100L : returnLimit;
  final boolean localNormalize = normalize == null ? true : normalize;
  final String localSemanticFilter =
      semanticFilter == null ? "" : "&semanticFilter=" + semanticFilter;

  final Client client = ClientBuilder.newClient();
  final WebTarget target =
      client.target(getUrl()
          + "/descriptions?query="
          + URLEncoder.encode(query == null ? "" : query, "UTF-8")
              .replaceAll("\\+", "%20") + "&limit=" + localLimit
          + "&searchMode=" + localSearchMode + "&lang=" + localLang
          + "&statusFilter=" + localStatusFilter + "&skipTo=" + localSkipTo
          + "&returnLimit=" + localReturnLimit + "&normalize="
          + localNormalize + localSemanticFilter);

  final Response response = target.request(MediaType.APPLICATION_JSON).get();
  final String resultString = response.readEntity(String.class);
  if (response.getStatusInfo().getFamily() == Family.SUCCESSFUL) {
    // n/a
  } else {
    throw new Exception(response.toString());
  }

  // converting to object
  return Utility.getGraphForJson(resultString, MatchResults.class);
}
 
Example 6
Source File: ConnectorResponseErrorException.java    From pay-publicapi with MIT License 4 votes vote down vote up
public ConnectorResponseErrorException(Response response) {
    super(response.toString());
    this.status = response.getStatus();
    this.error = readError(response);
    response.close();
}