本文整理匯總了Java中javax.ws.rs.core.Response.StatusType.getStatusCode方法的典型用法代碼示例。如果您正苦於以下問題:Java StatusType.getStatusCode方法的具體用法?Java StatusType.getStatusCode怎麽用?Java StatusType.getStatusCode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.ws.rs.core.Response.StatusType
的用法示例。
在下文中一共展示了StatusType.getStatusCode方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: 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()
);
}
}
示例3: insertAppointment
import javax.ws.rs.core.Response.StatusType; //導入方法依賴的package包/類
public URI insertAppointment(AppointmentType resource) {
Response response = client.target(connection)
.path("/rest/api/appointments")
.request()
// overrides previous headers: Content-Type, Content-Language, Content-Encoding
.post(xml(resource));
response.close();
if (response.getStatus() >= HTTP_BAD_REQUEST) {
StatusType stat = response.getStatusInfo();
throw new IllegalStateException(stat.getStatusCode() + "/" + stat.getFamily().name()
+ " " + stat.getReasonPhrase());
}
return response.getLocation();
}
示例4: updateIssueWithoutCharset
import javax.ws.rs.core.Response.StatusType; //導入方法依賴的package包/類
public void updateIssueWithoutCharset(int issueId, ResourcesType resource) {
Response response = client.target(connection)
.path("/rest/api/2.0-alpha1/issues/{id}")
.resolveTemplate("id", issueId)
.request()
// overrides previous headers: Content-Type, Content-Language, Content-Encoding
.put(xml(resource));
response.close();
if (response.getStatus() >= HTTP_BAD_REQUEST) {
StatusType stat = response.getStatusInfo();
throw new IllegalStateException(stat.getStatusCode() + "/" + stat.getFamily().name()
+ " " + stat.getReasonPhrase());
}
}
示例5: updateIssue
import javax.ws.rs.core.Response.StatusType; //導入方法依賴的package包/類
public void updateIssue(int issueId, ResourcesType resource) {
Response response = client.target(connection)
.path("/rest/api/2.0-alpha1/issues/{id}")
.resolveTemplate("id", issueId)
.request()
// overrides previous headers: Content-Type, Content-Language, Content-Encoding
.put(entity(resource, MediaType.valueOf(APPLICATION_XML + "; charset=UTF-8")));
response.close();
if (response.getStatus() >= HTTP_BAD_REQUEST) {
StatusType stat = response.getStatusInfo();
throw new IllegalStateException(stat.getStatusCode() + "/" + stat.getFamily().name()
+ " " + stat.getReasonPhrase());
}
}
示例6: updateIssueAsJson
import javax.ws.rs.core.Response.StatusType; //導入方法依賴的package包/類
public void updateIssueAsJson(int issueId, ResourcesType resource) {
Response response = client.target(connection)
.path("/rest/api/2.0-alpha1/issues/{id}")
.resolveTemplate("id", issueId)
.request()
// overrides previous headers: Content-Type, Content-Language, Content-Encoding
.put(entity(resource, MediaType.valueOf(APPLICATION_JSON)));
response.close();
if (response.getStatus() >= HTTP_BAD_REQUEST) {
StatusType stat = response.getStatusInfo();
throw new IllegalStateException(stat.getStatusCode() + "/" + stat.getFamily().name()
+ " " + stat.getReasonPhrase());
}
}
示例7: updateIssueIfLast
import javax.ws.rs.core.Response.StatusType; //導入方法依賴的package包/類
public boolean updateIssueIfLast(int issueId, ResourcesType resource, String md5) {
MultivaluedMap<String, Object> headers = new MultivaluedHashMap<>();
headers.putSingle("If-Match", md5);
Response response = client.target(connection)
.path("/rest/api/2.0-alpha1/issues/{id}")
.resolveTemplate("id", issueId)
.request()
.headers(headers)
// overrides previous headers: Content-Type, Content-Language, Content-Encoding
.put(entity(resource, MediaType.valueOf(APPLICATION_XML + "; charset=UTF-8")));
response.close();
if (response.getStatus() != HTTP_OK && response.getStatus() != HTTP_NOT_MODIFIED) {
StatusType stat = response.getStatusInfo();
throw new IllegalStateException(stat.getStatusCode() + "/" + stat.getFamily().name()
+ " " + stat.getReasonPhrase());
}
return response.getStatus() == HTTP_OK;
}
示例8: addStatusType
import javax.ws.rs.core.Response.StatusType; //導入方法依賴的package包/類
public void addStatusType(StatusType status) {
if (statusMap.containsKey(status.getStatusCode())) {
throw new IllegalStateException("repeated status code: " + status.getStatusCode());
}
statusMap.put(status.getStatusCode(), status);
}
示例9: 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);
}
}
示例10: 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;
}
示例11: getSuccessfulResponse
import javax.ws.rs.core.Response.StatusType; //導入方法依賴的package包/類
/**
* Get the return value for a successful response.
* @param response
* @param returnType
* @param status
* @return
*/
@SuppressWarnings("unchecked")
protected <T> T getSuccessfulResponse(Response response, Class<T> returnType, StatusType status) {
if ( returnType == null || status.getStatusCode() == Status.NO_CONTENT.getStatusCode() ) {
return null;
} else if ( returnType.isAssignableFrom(response.getClass()) ) {
return (T)response;
} else {
return response.readEntity(returnType);
}
}
示例12: writeResponse
import javax.ws.rs.core.Response.StatusType; //導入方法依賴的package包/類
@Override
public void writeResponse(StatusType statusType, Map<String, List<String>> headers,
OutputStream entityOutputStream) throws IOException {
String body = ((ByteArrayOutputStream) entityOutputStream).toString(StandardCharsets.UTF_8.name());
response = new DefaultServiceResponse(body, headers, statusType.getStatusCode(),
statusType.getReasonPhrase());
}
示例13: GatewayResponse
import javax.ws.rs.core.Response.StatusType; //導入方法依賴的package包/類
public GatewayResponse(@Nullable String body, @Nonnull Map<String, String> headers,
@Nonnull StatusType statusType, boolean base64Encoded) {
requireNonNull(headers);
requireNonNull(statusType);
this.statusCode = statusType.getStatusCode();
this.body = body;
this.headers = Collections.unmodifiableMap(new HashMap<>(headers));
this.base64Encoded = base64Encoded;
}
示例14: createApiException
import javax.ws.rs.core.Response.StatusType; //導入方法依賴的package包/類
/**
* Create an {@link AuthleteApiException} instance.
*/
private AuthleteApiException createApiException(Throwable cause, Response response)
{
// Error message.
String message = cause.getMessage();
if (response == null)
{
// Create an exception without HTTP response information.
return new AuthleteApiException(message, cause);
}
// Status code and status message.
int statusCode = 0;
String statusMessage = null;
// Get the status information.
StatusType type = response.getStatusInfo();
if (type != null)
{
statusCode = type.getStatusCode();
statusMessage = type.getReasonPhrase();
}
// Response body.
String responseBody = null;
// If the response has response body.
if (hasEntity(response))
{
// Get the response body.
responseBody = extractResponseBody(response);
}
// Response headers.
Map<String, List<String>> headers = response.getStringHeaders();
// Create an exception with HTTP response information.
return new AuthleteApiException(message, cause, statusCode, statusMessage, responseBody, headers);
}
示例15: checkAndHandleResponse
import javax.ws.rs.core.Response.StatusType; //導入方法依賴的package包/類
private void checkAndHandleResponse(String content, StatusType status) {
if (status.getStatusCode() == Status.OK.getStatusCode()) {
return;
}
final String errorMessage = extractErrorMessage(content, status);
if (status.getStatusCode() == Status.BAD_REQUEST.getStatusCode()) {
throw new ConnectionInitializationException(errorMessage);
} else if (status.getStatusCode() == Status.UNAUTHORIZED.getStatusCode()) {
throw new UnauthorizedException(errorMessage);
} else {
throw new ConnectionInitializationException(errorMessage);
}
}