use of com.sun.jersey.api.client.UniformInterfaceException in project OpenAM by OpenRock.
the class PrivilegeRestTest method validateUniformInterfaceException.
private void validateUniformInterfaceException(UniformInterfaceException e, int expectedStatusCode, String methodName) throws Exception {
int errorCode = e.getResponse().getStatus();
if (errorCode != 400) {
throw new Exception("PrivilegeRestTest." + methodName + ": incorrect error code");
}
String json = e.getResponse().getEntity(String.class);
JSONObject jo = new JSONObject(json);
if (jo.optInt("statusCode") != expectedStatusCode) {
throw new Exception("PrivilegeRestTest." + methodName + ", status code not " + expectedStatusCode);
}
}
use of com.sun.jersey.api.client.UniformInterfaceException in project apex-core by apache.
the class StramWebServicesTest method testInvalidAccept.
@Test
@SuppressWarnings("UnusedAssignment")
public void testInvalidAccept() throws JSONException, Exception {
// suppress logging in jersey to get rid of expected stack traces from test log
java.util.logging.Logger.getLogger("org.glassfish.grizzly.servlet.ServletHandler").setLevel(Level.OFF);
java.util.logging.Logger.getLogger("com.sun.jersey.spi.container.ContainerResponse").setLevel(Level.OFF);
WebResource r = resource();
String responseStr = "";
try {
responseStr = r.path(StramWebServices.PATH).accept(MediaType.TEXT_PLAIN).get(String.class);
fail("should have thrown exception on invalid accept");
} catch (UniformInterfaceException ue) {
ClientResponse response = ue.getResponse();
assertEquals(Status.INTERNAL_SERVER_ERROR, response.getClientResponseStatus());
StramTestSupport.checkStringMatch("error string exists and shouldn't", "", responseStr);
}
}
use of com.sun.jersey.api.client.UniformInterfaceException in project ORCID-Source by ORCID.
the class SalesForceDaoImpl method getFreshAccessToken.
private String getFreshAccessToken() {
LOGGER.info("About get SalesForce access token");
WebResource resource = client.resource(tokenEndPointUrl);
Form form = new Form();
form.add("grant_type", "password");
form.add("client_id", clientId);
form.add("client_secret", clientSecret);
form.add("username", username);
form.add("password", password);
ClientResponse response = resource.accept(MediaType.APPLICATION_JSON_TYPE).type(MediaType.APPLICATION_FORM_URLENCODED_TYPE).post(ClientResponse.class, form);
if (response.getStatus() == 200) {
try {
return response.getEntity(JSONObject.class).getString("access_token");
} catch (ClientHandlerException | UniformInterfaceException | JSONException e) {
throw new RuntimeException("Unable to extract access token from response", e);
}
} else {
throw new RuntimeException("Error getting access token from SalesForce, status code = " + response.getStatus() + ", reason = " + response.getStatusInfo().getReasonPhrase() + ", body = " + response.getEntity(String.class));
}
}
use of com.sun.jersey.api.client.UniformInterfaceException in project hadoop by apache.
the class TestRMWebServicesNodes method testNodesQueryStateInvalid.
@Test
public void testNodesQueryStateInvalid() throws JSONException, Exception {
WebResource r = resource();
getNewRMNode("h1", 1234, 5120);
getNewRMNode("h2", 1235, 5121);
try {
r.path("ws").path("v1").path("cluster").path("nodes").queryParam("states", "BOGUSSTATE").accept(MediaType.APPLICATION_JSON).get(JSONObject.class);
fail("should have thrown exception querying invalid state");
} catch (UniformInterfaceException ue) {
ClientResponse response = ue.getResponse();
assertResponseStatusCode(Status.BAD_REQUEST, response.getStatusInfo());
assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, response.getType().toString());
JSONObject msg = response.getEntity(JSONObject.class);
JSONObject exception = msg.getJSONObject("RemoteException");
assertEquals("incorrect number of elements", 3, exception.length());
String message = exception.getString("message");
String type = exception.getString("exception");
String classname = exception.getString("javaClassName");
WebServicesTestUtils.checkStringContains("exception message", "org.apache.hadoop.yarn.api.records.NodeState.BOGUSSTATE", message);
WebServicesTestUtils.checkStringMatch("exception type", "IllegalArgumentException", type);
WebServicesTestUtils.checkStringMatch("exception classname", "java.lang.IllegalArgumentException", classname);
}
}
use of com.sun.jersey.api.client.UniformInterfaceException in project hadoop by apache.
the class TestRMWebServicesNodes method testNonexistNodeDefault.
// test that the exception output defaults to JSON
@Test
public void testNonexistNodeDefault() throws JSONException, Exception {
getNewRMNode("h1", 1234, 5120);
getNewRMNode("h2", 1235, 5121);
WebResource r = resource();
try {
r.path("ws").path("v1").path("cluster").path("nodes").path("node_invalid:99").get(JSONObject.class);
fail("should have thrown exception on non-existent nodeid");
} catch (UniformInterfaceException ue) {
ClientResponse response = ue.getResponse();
assertResponseStatusCode(Status.NOT_FOUND, response.getStatusInfo());
assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, response.getType().toString());
JSONObject msg = response.getEntity(JSONObject.class);
JSONObject exception = msg.getJSONObject("RemoteException");
assertEquals("incorrect number of elements", 3, exception.length());
String message = exception.getString("message");
String type = exception.getString("exception");
String classname = exception.getString("javaClassName");
verifyNonexistNodeException(message, type, classname);
}
}
Aggregations