本文整理匯總了Java中javax.ws.rs.core.Response.StatusType.getFamily方法的典型用法代碼示例。如果您正苦於以下問題:Java StatusType.getFamily方法的具體用法?Java StatusType.getFamily怎麽用?Java StatusType.getFamily使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.ws.rs.core.Response.StatusType
的用法示例。
在下文中一共展示了StatusType.getFamily方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: toResponse
import javax.ws.rs.core.Response.StatusType; //導入方法依賴的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();
}
示例2: httpErrorContent
import javax.ws.rs.core.Response.StatusType; //導入方法依賴的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);
}
示例3: status
import javax.ws.rs.core.Response.StatusType; //導入方法依賴的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()
);
}
}
示例4: setStatusInfo
import javax.ws.rs.core.Response.StatusType; //導入方法依賴的package包/類
public void setStatusInfo(final StatusType statusInfo) {
if (statusInfo != null) {
statusCode = statusInfo.getStatusCode();
family = statusInfo.getFamily();
reasonPhrase = statusInfo.getReasonPhrase();
} else {
setStatusInfo(Status.OK);
}
}
示例5: assertSuccesfulAuthentication
import javax.ws.rs.core.Response.StatusType; //導入方法依賴的package包/類
@Override
protected int assertSuccesfulAuthentication(final Response response) {
final StatusType statusInfo = response.getStatusInfo();
final Family family = statusInfo.getFamily();
final int statusCode = statusInfo.getStatusCode();
final String reasonPhrase = statusInfo.getReasonPhrase();
assertEquals(family, SUCCESSFUL,
"status: " + statusCode + " " + reasonPhrase);
return statusCode;
}
示例6: assertSuccessful
import javax.ws.rs.core.Response.StatusType; //導入方法依賴的package包/類
public static void assertSuccessful(Response response) {
final StatusType responseStatus = response.getStatusInfo();
if (responseStatus.getFamily() != Status.Family.SUCCESSFUL) {
final StringBuilder sb = new StringBuilder();
sb.append("Response ").append(responseStatus.getStatusCode()).append(" ").append(responseStatus.getReasonPhrase());
if (response.hasEntity()) {
sb.append(", Response: ").append(response.readEntity(String.class));
}
throw new AssertionError(sb);
}
}
示例7: checkResponseAndGetOutput
import javax.ws.rs.core.Response.StatusType; //導入方法依賴的package包/類
/**
* Check the response code. If successful, return the entity with the given return type,
* otherwise throw an exception.
* @param response
* @param returnType
* @return The entity from the given {@link ClientResponse} if available
*/
protected <T> T checkResponseAndGetOutput(String httpMethod, Builder builder, Response response, Class<T> returnType) {
StatusType status = response.getStatusInfo();
if ( status != null && status.getFamily() == Family.SUCCESSFUL ) {
return getSuccessfulResponse(response, returnType, status);
} else {
throw getUnsuccesfulResponseException(response);
}
}