本文整理汇总了Java中javax.ws.rs.core.Response.Status.Family类的典型用法代码示例。如果您正苦于以下问题:Java Family类的具体用法?Java Family怎么用?Java Family使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Family类属于javax.ws.rs.core.Response.Status包,在下文中一共展示了Family类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleMessage
import javax.ws.rs.core.Response.Status.Family; //导入依赖的package包/类
/**
* 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);
}
}
}
示例2: toResponse
import javax.ws.rs.core.Response.Status.Family; //导入依赖的package包/类
@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();
}
示例3: httpErrorContent
import javax.ws.rs.core.Response.Status.Family; //导入依赖的package包/类
/**
* 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);
}
示例4: findByDescriptionId
import javax.ws.rs.core.Response.Status.Family; //导入依赖的package包/类
/**
* 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);
}
示例5: findByConceptId
import javax.ws.rs.core.Response.Status.Family; //导入依赖的package包/类
/**
* 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);
}
示例6: assertStatus
import javax.ws.rs.core.Response.Status.Family; //导入依赖的package包/类
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;
}
示例7: status
import javax.ws.rs.core.Response.Status.Family; //导入依赖的package包/类
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()
);
}
}
示例8: processResponse
import javax.ws.rs.core.Response.Status.Family; //导入依赖的package包/类
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;
}
示例9: removeUserPreferences
import javax.ws.rs.core.Response.Status.Family; //导入依赖的package包/类
@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());
}
}
示例10: removeConceptNote
import javax.ws.rs.core.Response.Status.Family; //导入依赖的package包/类
@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());
}
}
示例11: findConceptTreeChildren
import javax.ws.rs.core.Response.Status.Family; //导入依赖的package包/类
@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);
}
示例12: getEclExpressionResultCount
import javax.ws.rs.core.Response.Status.Family; //导入依赖的package包/类
@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());
}
}
示例13: getTerminology
import javax.ws.rs.core.Response.Status.Family; //导入依赖的package包/类
@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;
}
示例14: removeAlgorithmConfig
import javax.ws.rs.core.Response.Status.Family; //导入依赖的package包/类
@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());
}
}
示例15: addReleaseInfo
import javax.ws.rs.core.Response.Status.Family; //导入依赖的package包/类
@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;
}