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); } }
@Override public void run() { Response response = queryResource.cancelQuery("id_1", testServletRequest); Assert.assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatus()); waitForCancellationLatch.countDown(); waitFinishLatch.countDown(); } }
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."); }
@Test public void testGet() { Response response = target("/ready").request().get(); Assert.assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); }
@Test public void testHandleSimpleDELETE() { final Response response = abstractListenerHandler.handleDELETE(valid_id); Assert.assertEquals(202, response.getStatus()); Assert.assertEquals(obj, response.getEntity()); }
@Test public void shouldGet404IfRemovingNonExistentNodeIndexing() { Response response = service.deleteFromNodeIndex( "nodes", "bogus", "bogus", 999999 ); assertEquals( Status.NOT_FOUND.getStatusCode(), response.getStatus() ); }
@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:")); } }
@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()))); }
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(); } }
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); }
@Test public void testTableSizeNotFound() { Response response = _webTarget.path("table/unknownTable/size").request().get(Response.class); Assert.assertEquals(response.getStatus(), Response.Status.NOT_FOUND.getStatusCode()); }
@Test public void testGet() { Response response = target("/ready").request().get(); Assert.assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); }
@Test public void testHandle() { final Response response = abstractListenerHandler.handleGET(good_id); Assert.assertEquals(200, response.getStatus()); Assert.assertEquals(good_object, response.getEntity()); }
@Test public void shouldGet404IfRemovingNonExistentRelationshipIndexing() { Response response = service.deleteFromRelationshipIndex( "relationships", "bogus", "bogus", 999999 ); assertEquals( Status.NOT_FOUND.getStatusCode(), response.getStatus() ); }
@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\":")); } }
@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()))); }
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(); }
@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)); } }
@Test public void testGet() { Response response = target("/ready").request().get(); Assert.assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); }
@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()); }