Java 类javax.ws.rs.core.Response.Status.Family 实例源码

项目:InComb    文件:DBConnectionResponseInterceptor.java   
/**
 * Handles the {@link Connection} in the given {@link Message}.
 * @see DBConnectionResponseInterceptor
 */
@Override
public void handleMessage(final Message message) throws Fault {
    final Connection con = (Connection) message.getExchange().getInMessage().getContextualProperty(
            DBConnectionContextProvider.PROPERTY_CONNECTION);

    if(con != null) {
        try {
            final int responseCode = (int) message.get(Message.RESPONSE_CODE);

            if(Family.familyOf(responseCode).equals(Family.SERVER_ERROR)) {
                con.rollback();
            }
            else {
                con.commit();
            }

            con.close();
        }
        catch(final SQLException e) {
            LOGGER.error("Can't commit/rollback/close db connection because of an SQLException.", e);
        }
    }
}
项目:rest-jersey-utils    文件:RFCExceptionMapper.java   
@Override
public Response toResponse(@NonNull Exception exception) {
    ResponseBuilder builder;
    StatusType statusInfo;
    if (exception instanceof WebApplicationException) {
        Response response = ((WebApplicationException) exception).getResponse();
        builder = Response.fromResponse(response);
        statusInfo = response.getStatusInfo();
    } else {
        builder = Response.serverError();
        statusInfo = Status.INTERNAL_SERVER_ERROR;
    }

    SimpleExceptionJson simpleExceptionJson = new SimpleExceptionJson(statusInfo.getReasonPhrase(),
            statusInfo.getStatusCode(), exception.getMessage());
    builder.entity(simpleExceptionJson);
    builder.type("application/problem+json");

    if (statusInfo.getFamily() == Family.CLIENT_ERROR) {
        log.debug("Got client Exception", exception);
    } else {
        log.error("Sending error to client", exception);
    }

    return builder.build();
}
项目:rx-composer    文件:ErrorContent.java   
/**
 * Creates an ErrorContent for a HTTP {@link ErrorSource#CLIENT_ERROR client}- or
 * {@link ErrorSource#SERVER_ERROR server} error.
 *
 * @param position the content position
 * @param response the HTTP response. This must either by a client-error response or a server-error response.
 * @param startedTs the timestamp when fetching the content has started.
 * @return ErrorContent
 * @throws IllegalArgumentException if the response is not a client- or server error response.
 */
public static ErrorContent httpErrorContent(final String source,
                                            final Position position,
                                            final Response response,
                                            final long startedTs) {
    final StatusType statusInfo = response.getStatusInfo();
    final Family family = statusInfo.getFamily();

    checkArgument(HTTP_ERRORS.contains(family),
            "Response is not a HTTP client or server error");

    final ErrorSource errorSource = family == CLIENT_ERROR
            ? ErrorSource.CLIENT_ERROR
            : ErrorSource.SERVER_ERROR;

    return new ErrorContent(source, position, statusInfo.getReasonPhrase(), errorSource, startedTs);
}
项目:SNOMED-in-5-minutes    文件:SnomedClientRest.java   
/**
 * 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);
}
项目:SNOMED-in-5-minutes    文件:SnomedClientRest.java   
/**
 * 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);
}
项目:kt-ucloud-storage-client    文件:StorageClientIT.java   
protected static int assertStatus(final int actual, final Family family,
                                  final Status... expecteds) {
    if (family != null) {
        assertEquals(familyOf(actual), family);
    }
    if (expecteds != null && expecteds.length > 0) {
        boolean matched = false;
        for (final Status expected : expecteds) {
            if (actual == expected.getStatusCode()) {
                matched = true;
                break;
            }
        }
        if (!matched) {
            fail(actual + " \u2288 " + Arrays.toString(expecteds));
        }
    }
    return actual;
}
项目:kt-ucloud-storage-client    文件:StorageClientWsRsITs.java   
static void status(final StatusType statusInfo, final Family expectedFamily,
                   final Status... expectedStatuses) {
    requireNonNull(statusInfo, "null statusInfo");
    final Family actualFamily = statusInfo.getFamily();
    final int statusCode = statusInfo.getStatusCode();
    final String reasonPhrase = statusInfo.getReasonPhrase();
    logger.debug("-> response.status: {} {}", statusCode, reasonPhrase);
    if (expectedFamily != null) {
        assertEquals(actualFamily, expectedFamily);
    }
    if (expectedStatuses != null && expectedStatuses.length > 0) {
        assertTrue(
                Stream.of(expectedStatuses).map(Status::getStatusCode)
                .filter(v -> v == statusCode)
                .findAny()
                .isPresent()
        );
    }
}
项目:rest-maven-plugin    文件:Plugin.java   
private ErrorInfo processResponse( Response response, String outputFilename )
{
    if ( response.getStatusInfo().getFamily() == Family.SUCCESSFUL )
    {
        getLog().debug( String.format( "Status: [%d]", response.getStatus() ) );
        InputStream in = response.readEntity( InputStream.class );
        try
        {
            File of = new File( getOutputDir(), outputFilename );
            pipeToFile( in, of );
        }
        catch ( IOException ex )
        {
            getLog().debug( String.format( "IOException: [%s]", ex.toString() ) );
            return new ErrorInfo( String.format( "IOException: [%s]", ex.getMessage() ) );
        }

    }
    else
    {
        getLog().warn( String.format( "Error code: [%d]", response.getStatus() ) );
        getLog().debug( response.getEntity().toString() );
        return new ErrorInfo( response.getStatus(), response.getEntity().toString() );
    }
    return null;
}
项目:UMLS-Terminology-Server    文件:SecurityClientRest.java   
@Override
public void removeUserPreferences(Long id, String authToken) throws Exception {
  Logger.getLogger(getClass()).debug(
      "Security Client - remove user preferences " + id);
  validateNotEmpty(id, "id");
  Client client = ClientBuilder.newClient();
  WebTarget target =
      client.target(config.getProperty("base.url")
          + "/security/user/preferences/remove/" + id);
  Response response =
      target.request(MediaType.APPLICATION_XML)
          .header("Authorization", authToken).delete();

  if (response.getStatusInfo().getFamily() == Family.SUCCESSFUL) {
    // do nothing
  } else {
    throw new Exception(response.toString());
  }
}
项目:UMLS-Terminology-Server    文件:ContentClientRest.java   
@Override
public void removeConceptNote(Long noteId, String authToken)
  throws Exception {
  Logger.getLogger(getClass())
      .debug("Content Client - remove concept note for id " + noteId);

  validateNotEmpty(noteId, "note id");

  final Client client = ClientBuilder.newClient();
  final WebTarget target = client.target(
      config.getProperty("base.url") + "/content/concept/note/" + noteId);

  final Response response = target.request(MediaType.APPLICATION_XML)
      .header("Authorization", authToken).delete();
  if (response.getStatusInfo().getFamily() == Family.SUCCESSFUL) {
    // do nothing
  } else {
    throw new Exception(response.toString());
  }

}
项目:UMLS-Terminology-Server    文件:ContentClientRest.java   
@Override
public TreeList findConceptTreeChildren(String terminology, String version,
  String terminologyId, PfsParameterJpa pfs, String authToken)
  throws Exception {
  final Client client = ClientBuilder.newClient();
  final WebTarget target =
      client.target(config.getProperty("base.url") + "/content/" + "/concept"
          + "/" + terminology + "/" + version + "/trees/children");

  final String pfsString = ConfigUtility
      .getStringForGraph(pfs == null ? new PfsParameterJpa() : pfs);
  final Response response = target.request(MediaType.APPLICATION_XML)
      .header("Authorization", authToken).post(Entity.xml(pfsString));

  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 ConfigUtility.getGraphForString(resultString, TreeListJpa.class);

}
项目:UMLS-Terminology-Server    文件:ContentClientRest.java   
@Override
public Integer getEclExpressionResultCount(String query, String terminology,
  String version, String authToken) throws Exception {
  Logger.getLogger(getClass())
      .debug("Content Client - check if ECL expression for " + terminology
          + ", " + version + ", for query: " + query);

  validateNotEmpty(terminology, "terminology");
  validateNotEmpty(version, "version");
  validateNotEmpty(query, "query");

  final Client client = ClientBuilder.newClient();
  final WebTarget target = client
      .target(config.getProperty("base.url") + "/content/ecl/isExpression/"
          + terminology + "/" + version + "/" + query);

  final Response response = target.request(MediaType.APPLICATION_XML)
      .header("Authorization", authToken).get();

  Integer result = response.readEntity(Integer.class);
  if (response.getStatusInfo().getFamily() == Family.SUCCESSFUL) {
    return result;
  } else {
    throw new Exception(response.toString());
  }
}
项目:UMLS-Terminology-Server    文件:MetadataClientRest.java   
@Override
public Terminology getTerminology(String terminology, String version,
  String authToken) throws Exception {
  Logger.getLogger(getClass()).debug(
      "Metadata Client - get terminology " + terminology + ", " + version);
  validateNotEmpty(terminology, "terminology");
  validateNotEmpty(version, "version");

  Client client = ClientBuilder.newClient();
  WebTarget target = client.target(config.getProperty("base.url")
      + "/metadata/terminology/" + terminology + "/" + version);
  Response response = target.request(MediaType.APPLICATION_XML)
      .header("Authorization", authToken).get();

  String resultString = response.readEntity(String.class);
  if (response.getStatusInfo().getFamily() == Family.SUCCESSFUL) {
    // n/a
  } else {
    throw new Exception(response.toString());
  }
  // converting to object
  Terminology result =
      ConfigUtility.getGraphForString(resultString, TerminologyJpa.class);
  return result;
}
项目:UMLS-Terminology-Server    文件:ProcessClientRest.java   
@Override
public void removeAlgorithmConfig(Long projectId, Long id, String authToken)
  throws Exception {
  Logger.getLogger(getClass())
      .debug("Process Client - remove algorithmConfig " + id);
  validateNotEmpty(id, "id");
  Client client = ClientBuilder.newClient();
  WebTarget target = client.target(config.getProperty("base.url")
      + "/process/config/algo/" + id + "?projectId=" + projectId);

  if (id == null)
    return;

  Response response = target.request(MediaType.APPLICATION_XML)
      .header("Authorization", authToken).delete();

  if (response.getStatusInfo().getFamily() == Family.SUCCESSFUL) {
    // do nothing, successful
  } else {
    throw new Exception("Unexpected status - " + response.getStatus());
  }
}
项目:UMLS-Terminology-Server    文件:HistoryClientRest.java   
@Override
public ReleaseInfo addReleaseInfo(ReleaseInfoJpa releaseInfo,
  String authToken) throws Exception {
  Client client = ClientBuilder.newClient();
  WebTarget target =
      client.target(config.getProperty("base.url") + "/history/release");
  String riString = ConfigUtility.getStringForGraph(
      releaseInfo == null ? new ReleaseInfoJpa() : releaseInfo);
  Logger.getLogger(this.getClass()).debug(riString);
  Response response = target.request(MediaType.APPLICATION_XML)
      .header("Authorization", authToken).put(Entity.xml(riString));

  String resultString = response.readEntity(String.class);
  if (response.getStatusInfo().getFamily() == Family.SUCCESSFUL) {
    Logger.getLogger(this.getClass()).debug(
        resultString.substring(0, Math.min(resultString.length(), 3999)));
  } else {
    throw new Exception(response.toString());
  }

  // converting to object
  ReleaseInfoJpa info =
      ConfigUtility.getGraphForString(resultString, ReleaseInfoJpa.class);

  return info;
}
项目:UMLS-Terminology-Server    文件:WorkflowClientRest.java   
@Override
public void removeWorklistNote(Long projectId, Long noteId, String authToken)
  throws Exception {
  Logger.getLogger(getClass())
      .debug("Rest Client - remove note " + projectId + ", " + noteId);
  validateNotEmpty(projectId, "projectId");
  validateNotEmpty(noteId, "noteId");
  final Client client = ClientBuilder.newClient();
  final WebTarget target = client.target(config.getProperty("base.url")
      + "/worklist/note/" + noteId + "?projectId=" + projectId);

  final Response response = target.request(MediaType.APPLICATION_XML)
      .header("Authorization", authToken).delete();

  if (response.getStatusInfo().getFamily() == Family.SUCCESSFUL) {
    // do nothing, successful
  } else {
    throw new Exception("Unexpected status - " + response.getStatus());
  }
}
项目:UMLS-Terminology-Server    文件:MetadataClientRest.java   
@Override
public TerminologyList getCurrentTerminologies(String authToken)
  throws Exception {
  Logger.getLogger(getClass())
      .debug("Metadata Client - get all terminologyies versions");
  Client client = ClientBuilder.newClient();
  WebTarget target = client.target(
      config.getProperty("base.url") + "/metadata/terminology/current");
  Response response = target.request(MediaType.APPLICATION_XML)
      .header("Authorization", authToken).get();

  String resultString = response.readEntity(String.class);
  if (response.getStatusInfo().getFamily() == Family.SUCCESSFUL) {
    // n/a
  } else {
    throw new Exception(response.toString());
  }

  // converting to object
  return ConfigUtility.getGraphForString(resultString,
      TerminologyListJpa.class);

}
项目:UMLS-Terminology-Server    文件:ContentClientRest.java   
@Override
public StringList autocompleteConcepts(String terminology, String version,
  String searchTerm, String authToken) throws Exception {
  Logger.getLogger(getClass()).debug("Content Client - autocomplete concepts "
      + terminology + ", " + version + ", " + searchTerm);
  validateNotEmpty(searchTerm, "searchTerm");
  validateNotEmpty(terminology, "terminology");
  validateNotEmpty(version, "version");

  final Client client = ClientBuilder.newClient();
  final WebTarget target =
      client.target(config.getProperty("base.url") + "/content/concept/"
          + terminology + "/" + version + "/autocomplete/" + searchTerm);
  final Response response = target.request(MediaType.APPLICATION_XML)
      .header("Authorization", authToken).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 ConfigUtility.getGraphForString(resultString, StringList.class);
}
项目:UMLS-Terminology-Server    文件:ContentClientRest.java   
@Override
public void addDescriptorNote(Long id, String noteText, String authToken)
  throws Exception {

  Logger.getLogger(getClass())
      .debug("Content Client - add descriptor note for " + id + ", "
          + ", with text " + noteText);

  final Client client = ClientBuilder.newClient();
  final WebTarget target = client.target(
      config.getProperty("base.url") + "/content/descriptor/" + id + "/note");

  final Response response = target.request(MediaType.APPLICATION_XML)
      .header("Authorization", authToken).post(Entity.text(noteText));

  if (response.getStatusInfo().getFamily() == Family.SUCCESSFUL) {
    // do nothing
  } else {
    throw new Exception(response.toString());
  }
}
项目:UMLS-Terminology-Server    文件:ContentClientRest.java   
@Override
public ValidationResult validateAtom(Long projectId, AtomJpa atom,
  String authToken) throws Exception {
  Logger.getLogger(getClass())
      .debug("Content Client - validate atom " + atom);

  final Client client = ClientBuilder.newClient();
  final WebTarget target = client.target(config.getProperty("base.url")
      + "/content/validate/atom?projectId=" + projectId);

  final String atomString =
      (atom != null ? ConfigUtility.getStringForGraph(atom) : null);
  final Response response = target.request(MediaType.APPLICATION_XML)
      .header("Authorization", authToken).post(Entity.xml(atomString));

  final String resultString = response.readEntity(String.class);
  if (response.getStatusInfo().getFamily() == Family.SUCCESSFUL) {
    Logger.getLogger(getClass()).debug(resultString);
  } else {
    throw new Exception(resultString);
  }

  // converting to object
  return ConfigUtility.getGraphForString(resultString,
      ValidationResultJpa.class);
}
项目:UMLS-Terminology-Server    文件:IntegrationTestClientRest.java   
@Override
public Concept addConcept(ConceptJpa concept, String authToken)
  throws Exception {
  Logger.getLogger(getClass())
      .debug("Integration Test Client - add concept" + concept);

  final Client client = ClientBuilder.newClient();
  final WebTarget target =
      client.target(config.getProperty("base.url") + "/test/concept/add");

  final String conceptString = ConfigUtility
      .getStringForGraph(concept == null ? new ConceptJpa() : concept);
  final Response response = target.request(MediaType.APPLICATION_XML)
      .header("Authorization", authToken).put(Entity.xml(conceptString));

  final String resultString = response.readEntity(String.class);
  if (response.getStatusInfo().getFamily() == Family.SUCCESSFUL) {
    // n/a
  } else {
    throw new Exception("Unexpected status - " + response.getStatus());
  }

  // converting to object
  return ConfigUtility.getGraphForString(resultString, ConceptJpa.class);

}
项目:UMLS-Terminology-Server    文件:ContentClientRest.java   
@Override
public MapSetList getMapSets(String terminology, String version,
  String authToken) throws Exception {
  Logger.getLogger(getClass())
      .debug("Content Client - get mapsets " + terminology + ", " + version);
  validateNotEmpty(terminology, "terminology");
  validateNotEmpty(version, "version");

  final Client client = ClientBuilder.newClient();
  final WebTarget target = client.target(config.getProperty("base.url")
      + "/content/mapset/all/" + terminology + "/" + version);
  final Response response = target.request(MediaType.APPLICATION_XML)
      .header("Authorization", authToken).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 ConfigUtility.getGraphForString(resultString, MapSetListJpa.class);
}
项目:UMLS-Terminology-Server    文件:SecurityClientRest.java   
@Override
public User getUser(Long id, String authToken) throws Exception {
  Logger.getLogger(getClass()).debug("Security Client - get user " + id);
  validateNotEmpty(id, "id");
  Client client = ClientBuilder.newClient();
  WebTarget target =
      client.target(config.getProperty("base.url") + "/security/user/" + id);
  Response response =
      target.request(MediaType.APPLICATION_XML)
          .header("Authorization", authToken).get();

  if (response.getStatus() == 204)
    return null;

  String resultString = response.readEntity(String.class);
  if (response.getStatusInfo().getFamily() == Family.SUCCESSFUL) {
    // n/a
  } else {
    throw new Exception(response.toString());
  }

  // converting to object
  UserJpa user = ConfigUtility.getGraphForString(resultString, UserJpa.class);
  return user;
}
项目:UMLS-Terminology-Server    文件:SimpleEditClientRest.java   
@Override
public void updateAtom(Long projectId, Long conceptId, AtomJpa atom,
  String authToken) throws Exception {
  Logger.getLogger(getClass())
      .debug("Simple Edit Client - update atom " + projectId + ", " + atom);
  validateNotEmpty(projectId, "projectId");
  validateNotEmpty(conceptId, "conceptId");
  Client client = ClientBuilder.newClient();
  WebTarget target = client.target(config.getProperty("base.url")
      + "/simple/atom?projectId=" + projectId + "&conceptId=" + conceptId);
  String atomString =
      ConfigUtility.getStringForGraph(atom == null ? new AtomJpa() : atom);
  Response response = target.request(MediaType.APPLICATION_XML)
      .header("Authorization", authToken).post(Entity.xml(atomString));

  if (response.getStatusInfo().getFamily() == Family.SUCCESSFUL) {
    // n/a
  } else {
    throw new Exception(response.toString());
  }
}
项目:UMLS-Terminology-Server    文件:MetadataClientRest.java   
@Override
public AdditionalRelationshipType getAdditionalRelationshipType(String type,
  String terminology, String version, String authToken) throws Exception {
  Logger.getLogger(getClass()).debug("Metadata Client - get add rel type ");

  Client client = ClientBuilder.newClient();
  WebTarget target = client.target(
      config.getProperty("base.url") + "/metadata/additionalRelationshipType/"
          + type + "/" + terminology + "/" + version);
  Response response = target.request(MediaType.APPLICATION_XML)
      .header("Authorization", authToken).get();

  String resultString = response.readEntity(String.class);
  if (response.getStatusInfo().getFamily() == Family.SUCCESSFUL) {
    // n/a
  } else {
    throw new Exception(response.toString());
  }
  AdditionalRelationshipType result = ConfigUtility
      .getGraphForString(resultString, AdditionalRelationshipTypeJpa.class);
  return result;
}
项目:UMLS-Terminology-Server    文件:ContentClientRest.java   
@Override
public MapSet getMapSet(String terminologyId, String terminology,
  String version, String authToken) throws Exception {
  Logger.getLogger(getClass()).debug("Content Client - get mapSet "
      + terminologyId + ", " + terminology + ", " + version);
  validateNotEmpty(terminologyId, "terminologyId");
  validateNotEmpty(terminology, "terminology");
  validateNotEmpty(version, "version");
  final Client client = ClientBuilder.newClient();
  final WebTarget target =
      client.target(config.getProperty("base.url") + "/content/mapset/"
          + terminology + "/" + version + "/" + terminologyId);
  final Response response = target.request(MediaType.APPLICATION_XML)
      .header("Authorization", authToken).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 ConfigUtility.getGraphForString(resultString, MapSetJpa.class);
}
项目:UMLS-Terminology-Server    文件:WorkflowClientRest.java   
@Override
public void recomputeConceptStatus(Long projectId, String activityId,
  Boolean updaterFlag, String authToken) throws Exception {
  Logger.getLogger(getClass()).debug(
      "Workflow Client - recompute concept status " + ", " + authToken);

  validateNotEmpty(projectId, "projectId");

  final Client client = ClientBuilder.newClient();
  final WebTarget target = client.target(config.getProperty("base.url")
      + "/workflow/status/compute?projectId=" + projectId
      + (activityId == null ? "" : "&activityId=" + activityId)
      + (updaterFlag == null ? "" : "&update=" + updaterFlag));

  final Response response = target.request(MediaType.APPLICATION_XML)
      .header("Authorization", authToken).post(Entity.json(null));

  if (response.getStatusInfo().getFamily() == Family.SUCCESSFUL) {
    // n/a
  } else {
    throw new Exception(response.toString());
  }
}
项目:UMLS-Terminology-Server    文件:MetadataClientRest.java   
@Override
public void removePrecedenceList(Long id, String authToken) throws Exception {
  Logger.getLogger(getClass())
      .debug("Metadata Client - remove precedence list ");

  Client client = ClientBuilder.newClient();
  WebTarget target = client
      .target(config.getProperty("base.url") + "/metadata/precedence/" + id);
  Response response = target.request(MediaType.APPLICATION_XML)
      .header("Authorization", authToken).delete();

  if (response.getStatusInfo().getFamily() == Family.SUCCESSFUL) {
    // n/a
  } else {
    throw new Exception(response.toString());
  }

}
项目:UMLS-Terminology-Server    文件:ProjectClientRest.java   
@Override
public Project getProject(Long id, String authToken) throws Exception {
  Logger.getLogger(getClass()).debug("Project Client - get project " + id);
  validateNotEmpty(id, "id");

  Client client = ClientBuilder.newClient();
  WebTarget target =
      client.target(config.getProperty("base.url") + "/project/" + id);
  Response response = target.request(MediaType.APPLICATION_XML)
      .header("Authorization", authToken).get();

  String resultString = response.readEntity(String.class);
  if (response.getStatusInfo().getFamily() == Family.SUCCESSFUL) {
    // n/a
  } else {
    throw new Exception(response.toString());
  }

  // converting to object
  ProjectJpa project =
      ConfigUtility.getGraphForString(resultString, ProjectJpa.class);
  return project;
}
项目:UMLS-Terminology-Server    文件:ContentClientRest.java   
@Override
public TreeList findAtomTreeChildren(Long atomId, PfsParameterJpa pfs,
  String authToken) throws Exception {
  final Client client = ClientBuilder.newClient();
  final WebTarget target = client.target(config.getProperty("base.url")
      + "/content/" + "/atom" + "/" + atomId + "/trees/children");

  final String pfsString = ConfigUtility
      .getStringForGraph(pfs == null ? new PfsParameterJpa() : pfs);
  final Response response = target.request(MediaType.APPLICATION_XML)
      .header("Authorization", authToken).post(Entity.xml(pfsString));

  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 ConfigUtility.getGraphForString(resultString, TreeListJpa.class);

}
项目:UMLS-Terminology-Server    文件:MetadataClientRest.java   
@Override
public RootTerminology getRootTerminology(String terminology,
  String authToken) throws Exception {
  Logger.getLogger(getClass())
      .debug("Metadata Client - get root terminology " + terminology);
  validateNotEmpty(terminology, "terminology");

  Client client = ClientBuilder.newClient();
  WebTarget target = client.target(config.getProperty("base.url")
      + "/metadata/rootTerminology/" + terminology);
  Response response = target.request(MediaType.APPLICATION_XML)
      .header("Authorization", authToken).get();

  String resultString = response.readEntity(String.class);
  if (response.getStatusInfo().getFamily() == Family.SUCCESSFUL) {
    // n/a
  } else {
    throw new Exception(response.toString());
  }
  // converting to object
  RootTerminology result =
      ConfigUtility.getGraphForString(resultString, RootTerminologyJpa.class);
  return result;
}
项目:UMLS-Terminology-Server    文件:MetadataClientRest.java   
@Override
public PrecedenceList getPrecedenceList(Long precedenceListId,
  String authToken) throws Exception {
  Logger.getLogger(getClass())
      .debug("Metadata Client - get precedence list " + precedenceListId);

  Client client = ClientBuilder.newClient();
  WebTarget target = client.target(config.getProperty("base.url")
      + "/metadata/precedence/" + precedenceListId);
  Response response = target.request(MediaType.APPLICATION_XML)
      .header("Authorization", authToken).get();

  String resultString = response.readEntity(String.class);
  if (response.getStatusInfo().getFamily() == Family.SUCCESSFUL) {
    // n/a
  } else {
    throw new Exception(response.toString());
  }
  // converting to object
  PrecedenceList result =
      ConfigUtility.getGraphForString(resultString, PrecedenceListJpa.class);
  return result;
}
项目:UMLS-Terminology-Server    文件:ProjectClientRest.java   
@Override
public StringList getQueryTypes(String authToken) throws Exception {
  Logger.getLogger(getClass()).debug("Project Client - getQueryTypes");

  Client client = ClientBuilder.newClient();
  WebTarget target =
      client.target(config.getProperty("base.url") + "/project/queryTypes");
  Response response = target.request(MediaType.APPLICATION_XML)
      .header("Authorization", authToken).get();

  String resultString = response.readEntity(String.class);
  if (response.getStatusInfo().getFamily() == Family.SUCCESSFUL) {
    // n/a
  } else {
    throw new Exception(response.toString());
  }

  // converting to object
  StringList list =
      ConfigUtility.getGraphForString(resultString, StringList.class);
  return list;
}
项目:robots    文件:CharSourceSupplierHttpClientImplTest.java   
@Before
public void setupClient() throws IOException, ExecutionException, InterruptedException, TimeoutException {
    when(client.target(any(URI.class))
                    .request()
                    .accept(Matchers.<MediaType>anyVararg())
                    .header(anyString(), anyObject())
                    .buildGet()
                    .submit()
                    .get(anyLong(), any(TimeUnit.class))
    ).thenReturn(response);

    when(response.getStatusInfo()).thenReturn(statusInfo);
    when(response.getEntity()).thenReturn(ByteSource.empty().openStream());

    when(statusInfo.getStatusCode()).thenReturn(200);
    when(statusInfo.getFamily()).thenReturn(Family.SUCCESSFUL);
    when(statusInfo.getReasonPhrase()).thenReturn("Okay");
}
项目:UMLS-Terminology-Server    文件:ProjectClientRest.java   
@Override
public Boolean userHasSomeProjectRole(String authToken) throws Exception {

  Client client = ClientBuilder.newClient();
  WebTarget target =
      client.target(config.getProperty("base.url") + "/project/user/anyrole");
  Response response = target.request(MediaType.TEXT_PLAIN)
      .header("Authorization", authToken).get();

  String resultString = response.readEntity(String.class);
  if (response.getStatusInfo().getFamily() == Family.SUCCESSFUL) {
    // n/a
  } else {
    throw new Exception(response.toString());
  }

  return resultString.equals("true");

}
项目:UMLS-Terminology-Server    文件:ContentClientRest.java   
@Override
public SearchResultList getComponentsWithNotes(String query,
  PfsParameterJpa pfs, String authToken) throws Exception {
  Logger.getLogger(getClass())
      .debug("Content Client - get components with notes for query");

  final Client client = ClientBuilder.newClient();
  final WebTarget target = client.target(config.getProperty("base.url")
      + "/content/component/notes?query=" + query);
  final String pfsString = ConfigUtility
      .getStringForGraph(pfs == null ? new PfsParameterJpa() : pfs);
  final Response response = target.request(MediaType.APPLICATION_XML)
      .header("Authorization", authToken).post(Entity.xml(pfsString));

  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 ConfigUtility.getGraphForString(resultString,
      SearchResultListJpa.class);
}
项目:UMLS-Terminology-Server    文件:SecurityClientRest.java   
@Override
public UserList getUsers(String authToken) throws Exception {
  Logger.getLogger(getClass()).debug("Security Client - get users");
  Client client = ClientBuilder.newClient();
  WebTarget target =
      client.target(config.getProperty("base.url") + "/security/user/users");
  Response response =
      target.request(MediaType.APPLICATION_XML)
          .header("Authorization", authToken).get();

  String resultString = response.readEntity(String.class);
  if (response.getStatusInfo().getFamily() == Family.SUCCESSFUL) {
    // n/a
  } else {
    throw new Exception(response.toString());
  }

  // converting to object
  UserListJpa list =
      ConfigUtility.getGraphForString(resultString, UserListJpa.class);
  return list;
}
项目:UMLS-Terminology-Server    文件:IntegrationTestClientRest.java   
@Override
public void updateAtom(AtomJpa atom, String authToken) throws Exception {
  Logger.getLogger(getClass())
      .debug("Integration Test Client - update atom" + atom);

  final Client client = ClientBuilder.newClient();
  final WebTarget target =
      client.target(config.getProperty("base.url") + "/test/atom/update");

  final String atomString =
      ConfigUtility.getStringForGraph(atom == null ? new AtomJpa() : atom);
  final Response response = target.request(MediaType.APPLICATION_XML)
      .header("Authorization", authToken).put(Entity.xml(atomString));

  final String resultString = response.readEntity(String.class);
  if (response.getStatusInfo().getFamily() == Family.SUCCESSFUL) {
    // n/a
  } else {
    throw new Exception(resultString);
  }

}
项目:UMLS-Terminology-Server    文件:WorkflowClientRest.java   
@Override
public void stampChecklist(Long projectId, Long id, String activityId,
  boolean approve, String authToken) throws Exception {
  Logger.getLogger(getClass()).debug("Workflow Client - stamp list " + id
      + ", " + approve + ", " + authToken);

  validateNotEmpty(projectId, "projectId");
  validateNotEmpty(id, "id");

  final Client client = ClientBuilder.newClient();
  final WebTarget target = client.target(config.getProperty("base.url")
      + "/workflow/checklist/" + id + "/stamp?projectId=" + projectId
      + (activityId == null ? "" : "&activityId=" + activityId)
      + (approve ? "&approve=true" : ""));

  final Response response = target.request(MediaType.APPLICATION_XML)
      .header("Authorization", authToken).post(Entity.json(null));

  if (response.getStatusInfo().getFamily() == Family.SUCCESSFUL) {
    // n/a
  } else {
    throw new Exception(response.toString());
  }
}
项目:UMLS-Terminology-Server    文件:IntegrationTestClientRest.java   
@Override
public void updateRelationship(ConceptRelationshipJpa relationship,
  String authToken) throws Exception {
  Logger.getLogger(getClass())
      .debug("Integration Test Client - update relationship" + relationship);

  final Client client = ClientBuilder.newClient();
  final WebTarget target = client.target(
      config.getProperty("base.url") + "/test/concept/relationship/update");

  final String relString = ConfigUtility.getStringForGraph(
      relationship == null ? new ConceptRelationshipJpa() : relationship);
  final Response response = target.request(MediaType.APPLICATION_XML)
      .header("Authorization", authToken).put(Entity.xml(relString));

  final String resultString = response.readEntity(String.class);
  if (response.getStatusInfo().getFamily() == Family.SUCCESSFUL) {
    // n/a
  } else {
    throw new Exception(resultString);
  }

}