本文整理了Java中javax.ws.rs.core.Response.getStatus
方法的一些代码示例,展示了Response.getStatus
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Response.getStatus
方法的具体详情如下:
包路径:javax.ws.rs.core.Response
类名称:Response
方法名:getStatus
[英]Get the status code associated with the response.
[中]获取与响应关联的状态代码。
代码示例来源:origin: confluentinc/ksql
private <T> RestResponse<T> getRequest(final String path, final Class<T> type) {
try (Response response = client.target(serverAddress)
.path(path)
.request(MediaType.APPLICATION_JSON_TYPE)
.get()) {
return response.getStatus() == Response.Status.OK.getStatusCode()
? RestResponse.successful(response.readEntity(type))
: createErrorResponse(path, response);
} catch (final Exception e) {
throw new KsqlRestClientException("Error issuing GET to KSQL server. path:" + path, e);
}
}
代码示例来源:origin: apache/incubator-druid
@Override
public void run()
{
Response response = queryResource.cancelQuery("id_1", testServletRequest);
Assert.assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatus());
waitForCancellationLatch.countDown();
waitFinishLatch.countDown();
}
}
代码示例来源:origin: confluentinc/ksql
private static <T> RestResponse<T> createErrorResponse(
final String path,
final Response response) {
final KsqlErrorMessage errorMessage = response.readEntity(KsqlErrorMessage.class);
if (errorMessage != null) {
return RestResponse.erroneous(errorMessage);
}
if (response.getStatus() == Status.NOT_FOUND.getStatusCode()) {
return RestResponse.erroneous(404, "Path not found. Path='" + path + "'. "
+ "Check your ksql http url to make sure you are connecting to a ksql server.");
}
if (response.getStatus() == Status.UNAUTHORIZED.getStatusCode()) {
return RestResponse.erroneous(UNAUTHORIZED_ERROR_MESSAGE);
}
if (response.getStatus() == Status.FORBIDDEN.getStatusCode()) {
return RestResponse.erroneous(FORBIDDEN_ERROR_MESSAGE);
}
return RestResponse.erroneous(
Errors.toErrorCode(response.getStatus()), "The server returned an unexpected error.");
}
代码示例来源:origin: OryxProject/oryx
@Test
public void testGet() {
Response response = target("/ready").request().get();
Assert.assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
}
代码示例来源:origin: apache/incubator-druid
@Test
public void testHandleSimpleDELETE()
{
final Response response = abstractListenerHandler.handleDELETE(valid_id);
Assert.assertEquals(202, response.getStatus());
Assert.assertEquals(obj, response.getEntity());
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldGet404IfRemovingNonExistentNodeIndexing()
{
Response response = service.deleteFromNodeIndex( "nodes", "bogus", "bogus", 999999 );
assertEquals( Status.NOT_FOUND.getStatusCode(), response.getStatus() );
}
代码示例来源:origin: aol/micro-server
@Test
public void runAppAndBasicTest() throws InterruptedException, ExecutionException{
Response response = rest.get("http://localhost:8080/simple-app/status/ping");
assertThat(response.getStatus(),is(400));
assertThat(response.readEntity(String.class), containsString("{\"errorCode\":\"EMPTY_REQUEST\",\"message\":\"Error id:"));
}
}
代码示例来源:origin: Netflix/eureka
@Test
public void testStatusOverrideDeleteReturnsNotFoundErrorCodeIfInstanceNotRegistered() throws Exception {
Response response = instanceResource.deleteStatusUpdate(InstanceStatus.OUT_OF_SERVICE.name(), "false", "0");
assertThat(response.getStatus(), is(equalTo(Status.NOT_FOUND.getStatusCode())));
}
代码示例来源:origin: oracle/helidon
private Optional<SignedJwt> getAndCacheAppTokenFromServer() {
MultivaluedMap<String, String> formData = new MultivaluedHashMap<>();
formData.putSingle("grant_type", "client_credentials");
formData.putSingle("scope", "urn:opc:idm:__myscopes__");
Response tokenResponse = tokenEndpoint
.request()
.accept(MediaType.APPLICATION_JSON_TYPE)
.post(Entity.form(formData));
if (tokenResponse.getStatusInfo().getFamily() == Response.Status.Family.SUCCESSFUL) {
JsonObject response = tokenResponse.readEntity(JsonObject.class);
String accessToken = response.getString(ACCESS_TOKEN_KEY);
LOGGER.finest(() -> "Access token: " + accessToken);
SignedJwt signedJwt = SignedJwt.parseToken(accessToken);
this.appToken = signedJwt;
this.appJwt = signedJwt.getJwt();
return Optional.of(signedJwt);
} else {
LOGGER.severe("Failed to obtain access token for application to read groups"
+ " from IDCS. Response code: " + tokenResponse.getStatus() + ", entity: "
+ tokenResponse.readEntity(String.class));
return Optional.empty();
}
}
代码示例来源:origin: liferay/liferay-portal
private ApioResult _invokeBuilder(
String httpMethod, Invocation.Builder builder,
Entity<String> entity)
throws ApioException {
Response response = _handleResponse(httpMethod, builder, entity);
String messageEntity = response.readEntity(String.class);
int statusCode = response.getStatus();
Response.StatusType statusType = response.getStatusInfo();
if (statusType.getFamily() == Response.Status.Family.SUCCESSFUL) {
return new ApioResult(statusCode, messageEntity);
}
if (_log.isDebugEnabled()) {
_log.debug(
"{} request failed: {}. \n{}", httpMethod, statusCode,
messageEntity);
}
throw new ApioException(
statusCode, "Request failed: \n" + messageEntity);
}
代码示例来源:origin: apache/incubator-pinot
@Test
public void testTableSizeNotFound() {
Response response = _webTarget.path("table/unknownTable/size").request().get(Response.class);
Assert.assertEquals(response.getStatus(), Response.Status.NOT_FOUND.getStatusCode());
}
代码示例来源:origin: OryxProject/oryx
@Test
public void testGet() {
Response response = target("/ready").request().get();
Assert.assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
}
代码示例来源:origin: apache/incubator-druid
@Test
public void testHandle()
{
final Response response = abstractListenerHandler.handleGET(good_id);
Assert.assertEquals(200, response.getStatus());
Assert.assertEquals(good_object, response.getEntity());
}
代码示例来源:origin: neo4j/neo4j
@Test
public void shouldGet404IfRemovingNonExistentRelationshipIndexing()
{
Response response = service.deleteFromRelationshipIndex( "relationships", "bogus", "bogus", 999999 );
assertEquals( Status.NOT_FOUND.getStatusCode(), response.getStatus() );
}
代码示例来源:origin: aol/micro-server
@Test
public void runAppAndBasicTest(){
Response response = rest.get("http://localhost:8080/simple-app/status/ping");
assertThat(response.getStatus(),is(400));
assertThat(response.readEntity(String.class), containsString("{\"errorCode\":\"INTERNAL_SERVER_ERROR\",\"message\":"));
}
}
代码示例来源:origin: Netflix/eureka
@Test
public void testStatusOverrideReturnsNotFoundErrorCodeIfInstanceNotRegistered() throws Exception {
Response response = instanceResource.statusUpdate(InstanceStatus.OUT_OF_SERVICE.name(), "false", "0");
assertThat(response.getStatus(), is(equalTo(Status.NOT_FOUND.getStatusCode())));
}
代码示例来源:origin: jersey/jersey
public String start() {
final Response response = addProperties(client.target(requestTokenUri).request())
.post(null);
if (response.getStatus() != 200) {
throw new RuntimeException(LocalizationMessages.ERROR_REQUEST_REQUEST_TOKEN(response.getStatus()));
}
final MultivaluedMap<String, String> formParams = response.readEntity(Form.class).asMap();
parameters.token(formParams.getFirst(OAuth1Parameters.TOKEN));
secrets.tokenSecret(formParams.getFirst(OAuth1Parameters.TOKEN_SECRET));
return UriBuilder.fromUri(authorizationUri).queryParam(OAuth1Parameters.TOKEN, parameters.getToken())
.build().toString();
}
代码示例来源:origin: traccar/traccar
@Override
public void sendMessageSync(String destAddress, String message, boolean command) throws MessageException {
Response response = getRequestBuilder().post(Entity.entity(preparePayload(destAddress, message), mediaType));
if (response.getStatus() / 100 != 2) {
throw new MessageException(response.readEntity(String.class));
}
}
代码示例来源:origin: OryxProject/oryx
@Test
public void testGet() {
Response response = target("/ready").request().get();
Assert.assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
}
代码示例来源:origin: apache/incubator-druid
@Test
public void testExceptionalHandle()
{
final Response response = abstractListenerHandler.handleGET(error_id);
Assert.assertEquals(500, response.getStatus());
Assert.assertEquals(ImmutableMap.of("error", error_message), response.getEntity());
}
内容来源于网络,如有侵权,请联系作者删除!