response.reasonPhrase = cr.getStatusInfo().getReasonPhrase(); response.headers = cr.getHeaders(); return response; response.reasonPhrase = cr.getStatusInfo().getReasonPhrase(); return response; }else {
statusCode = response.getStatusInfo().getStatusCode(); responseHeaders = response.getHeaders(); if(response.getStatusInfo().getStatusCode() == ClientResponse.Status.NO_CONTENT.getStatusCode()) { return null; } else if (response.getStatusInfo().getFamily() == Family.SUCCESSFUL) { if (returnType == null) return null; response.getStatusInfo().getStatusCode(), message, response.getHeaders(),
public Response.StatusType getStatusInfo() { return response.getStatusInfo(); } }
public ClientException(ClientResponse cr) { super(cr.getStatusInfo().getReasonPhrase()); this.cr = cr; }
private JSONObject checkResponse(ClientResponse response, int requiredStatus, String errorMessage) { if (response.getStatus() != requiredStatus) { throw new RuntimeException(errorMessage + ", status code = " + response.getStatus() + ", reason = " + response.getStatusInfo().getReasonPhrase() + ", body = " + response.getEntity(String.class)); } if (requiredStatus == 204) { return null; } return response.getEntity(JSONObject.class); }
private void checkAuthorization(ClientResponse response) { if (response.getStatus() == 401) { throw new SalesForceUnauthorizedException("Unauthorized reponse from SalesForce, status code = " + response.getStatus() + ", reason = " + response.getStatusInfo().getReasonPhrase() + ", body= " + response.getEntity(String.class)); } }
/** * Makes the given {@link ClientResponse} {@link AutoCloseable} by wrapping it in a {@link CloseableClientResponse}. */ public static CloseableClientResponse of(ClientResponse response) { return new CloseableClientResponse(response.getStatusInfo(), getResponseHeaders(response), response.getEntityInputStream(), response.getClient().getMessageBodyWorkers()); }
private JSONObject testListReservationHelper(WebResource resource, Status status) throws Exception { Thread.sleep(1000); ClientResponse response = resource.get(ClientResponse.class); if (!this.isAuthenticationEnabled()) { assertResponseStatusCode(Status.UNAUTHORIZED, response.getStatusInfo()); return null; } assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, response.getType().toString()); assertResponseStatusCode(status, response.getStatusInfo()); return response.getEntity(JSONObject.class); }
private static void verifyHttpResponse(Client client, URI uri, Status expectedStatus) { ClientResponse resp = client.resource(uri).accept(MediaType.APPLICATION_JSON) .type(MediaType.APPLICATION_JSON).get(ClientResponse.class); assertNotNull(resp); assertEquals(resp.getStatusInfo().getStatusCode(), expectedStatus.getStatusCode()); }
@Test public void testInvalidUri2() throws JSONException, Exception { WebResource r = resource(); String responseStr = ""; try { responseStr = r.accept(MediaType.APPLICATION_JSON).get(String.class); fail("should have thrown exception on invalid uri"); } catch (UniformInterfaceException ue) { ClientResponse response = ue.getResponse(); assertResponseStatusCode(Status.NOT_FOUND, response.getStatusInfo()); WebServicesTestUtils.checkStringMatch( "error string exists and shouldn't", "", responseStr); } }
@Override public Void call() throws Exception { ClientResponse response = resource().path("ws").path("v1").path("cluster") .path("delegation-token").accept(contentType) .delete(ClientResponse.class); assertResponseStatusCode(Status.BAD_REQUEST, response.getStatusInfo()); return null; } });
@Override public DelegationToken call() throws Exception { ClientResponse response = resource().path("ws").path("v1").path("cluster") .path("delegation-token").accept(contentType) .entity(dtoken, mediaType).post(ClientResponse.class); assertResponseStatusCode(Status.OK, response.getStatusInfo()); DelegationToken tok = getDelegationTokenFromResponse(response); return tok; } });
private void verifySimpleAuthCancel() { // contents of header don't matter; request should never get that far ClientResponse response = resource().path("ws").path("v1").path("cluster") .path("delegation-token").queryParam("user.name", "testuser") .header(RMWebServices.DELEGATION_TOKEN_HEADER, "random") .delete(ClientResponse.class); assertResponseStatusCode(Status.FORBIDDEN, response.getStatusInfo()); }
@Override public DelegationToken call() throws Exception { ClientResponse response = resource().path("ws").path("v1").path("cluster") .path("delegation-token").accept(contentType) .entity(dtoken, mediaType).post(ClientResponse.class); assertResponseStatusCode(Status.OK, response.getStatusInfo()); DelegationToken tok = getDelegationTokenFromResponse(response); return tok; } });
@Override public Void call() throws Exception { ClientResponse response = resource().path("ws").path("v1").path("cluster") .path("delegation-token") .header(yarnTokenHeader, "random-string").accept(contentType) .delete(ClientResponse.class); assertResponseStatusCode(Status.BAD_REQUEST, response.getStatusInfo()); return null; } });
@Override public DelegationToken call() throws Exception { ClientResponse response = resource().path("ws").path("v1").path("cluster") .path("delegation-token").accept(contentType) .entity(dtoken, mediaType).post(ClientResponse.class); assertResponseStatusCode(Status.OK, response.getStatusInfo()); DelegationToken tok = getDelegationTokenFromResponse(response); return tok; } });
private void verifySimpleAuthCreate(String mediaType, String contentType, String body) { ClientResponse response = resource().path("ws").path("v1").path("cluster") .path("delegation-token").queryParam("user.name", "testuser") .accept(contentType).entity(body, mediaType) .post(ClientResponse.class); assertResponseStatusCode(Status.FORBIDDEN, response.getStatusInfo()); }
@Override public Void call() throws Exception { ClientResponse response = resource().path("ws").path("v1").path("cluster") .path("delegation-token") .header(yarnTokenHeader, tmpToken.getToken()) .accept(contentType).delete(ClientResponse.class); assertResponseStatusCode(Status.OK, response.getStatusInfo()); assertTokenCancelled(tmpToken.getToken()); return null; } });
@Override public Void call() throws Exception { ClientResponse response = resource().path("ws").path("v1").path("cluster") .path("delegation-token") .header(yarnTokenHeader, tmpToken2.getToken()) .accept(contentType).delete(ClientResponse.class); assertResponseStatusCode(Status.FORBIDDEN, response.getStatusInfo()); assertValidRMToken(tmpToken2.getToken()); return null; } });
@Test public void testInvalidApp() { ApplicationId appId = ApplicationId.newInstance(0, MAX_APPS + 1); WebResource r = resource(); ClientResponse response = r.path("ws").path("v1").path("applicationhistory").path("apps") .path(appId.toString()) .queryParam("user.name", USERS[round]) .accept(MediaType.APPLICATION_JSON) .get(ClientResponse.class); assertResponseStatusCode("404 not found expected", Status.NOT_FOUND, response.getStatusInfo()); }