use of com.sun.jersey.api.client.UniformInterfaceException in project hadoop by apache.
the class TestAMWebServicesTasks method testTaskIdBogus.
@Test
public void testTaskIdBogus() throws JSONException, Exception {
WebResource r = resource();
Map<JobId, Job> jobsMap = appContext.getAllJobs();
for (JobId id : jobsMap.keySet()) {
String jobId = MRApps.toString(id);
String tid = "bogustaskid";
try {
r.path("ws").path("v1").path("mapreduce").path("jobs").path(jobId).path("tasks").path(tid).get(JSONObject.class);
fail("should have thrown exception on invalid uri");
} 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");
WebServicesTestUtils.checkStringEqual("exception message", "java.lang.Exception: TaskId string : " + "bogustaskid is not properly formed" + "\nReason: java.util.regex.Matcher[pattern=" + TaskID.TASK_ID_REGEX + " region=0,11 lastmatch=]", message);
WebServicesTestUtils.checkStringMatch("exception type", "NotFoundException", type);
WebServicesTestUtils.checkStringMatch("exception classname", "org.apache.hadoop.yarn.webapp.NotFoundException", classname);
}
}
}
use of com.sun.jersey.api.client.UniformInterfaceException in project OpenAM by OpenRock.
the class ListenerRestTest method validateUniformInterfaceException.
private void validateUniformInterfaceException(UniformInterfaceException e, int expectedStatusCode, String methodName) throws Exception {
int errorCode = e.getResponse().getStatus();
if (errorCode != 400) {
throw new Exception("ListenerRestTest." + methodName + ": incorrect error code");
}
String json = e.getResponse().getEntity(String.class);
JSONObject jo = new JSONObject(json);
if (jo.optInt("statusCode") != expectedStatusCode) {
throw new Exception("ListenerRestTest." + methodName + ", status code not " + expectedStatusCode);
}
}
use of com.sun.jersey.api.client.UniformInterfaceException in project OpenAM by OpenRock.
the class ListenerRestTest method noURLInPost.
private void noURLInPost() throws Exception {
Form form = new Form();
form.add("resources", RESOURCE_NAME + "/*");
form.add("subject", hashedTokenId);
try {
listenerClient.header(RestServiceManager.SUBJECT_HEADER_NAME, tokenIdHeader).cookie(cookie).post(String.class, form);
} catch (UniformInterfaceException e) {
validateUniformInterfaceException(e, 426, "noURLInPost");
}
}
use of com.sun.jersey.api.client.UniformInterfaceException in project OpenAM by OpenRock.
the class PrivilegeRestTest method noJSONStringInPost.
private void noJSONStringInPost() throws Exception {
Form form = new Form();
form.add("subject", hashedTokenId);
try {
webClient.header(RestServiceManager.SUBJECT_HEADER_NAME, tokenIdHeader).cookie(cookie).post(String.class, form);
} catch (UniformInterfaceException e) {
validateUniformInterfaceException(e, 9, "noJSONStringInPost");
}
}
use of com.sun.jersey.api.client.UniformInterfaceException in project OpenAM by OpenRock.
the class OAuthServiceUtils method getUUIDByTokenId.
public static String getUUIDByTokenId(String tokenId) throws OAuthServiceException {
String uuid;
MultivaluedMapImpl params = new MultivaluedMapImpl();
params.add(SUBJECT_ID, tokenId);
params.add("attributenames", UUID_SESSION_PROPERTY_NAME);
String response;
try {
response = attributesResource.queryParams(params).get(String.class);
} catch (UniformInterfaceException uie) {
throw new OAuthServiceException("Get uuid failed", uie);
}
if (response == null) {
return null;
}
int index = response.indexOf(USERDETAILS_NAME_KEY + "=" + UUID_SESSION_PROPERTY_NAME);
index = response.indexOf(USERDETAILS_VALUE_KEY + "=", index);
int startIdx = index + USERDETAILS_VALUE_KEY.length() + 1;
int idx = response.indexOf(USERDETAILS_NAME_KEY + "=", startIdx);
int endIdx;
if (idx > 0) {
endIdx = idx;
} else {
endIdx = response.length() - 1;
}
uuid = response.substring(startIdx, endIdx).trim();
return uuid;
}
Aggregations