com.sun.jersey.api.client.UniformInterfaceException Java Examples

The following examples show how to use com.sun.jersey.api.client.UniformInterfaceException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestRMWebServices.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Test
public void testInvalidAccept() throws JSONException, Exception {
  WebResource r = resource();
  String responseStr = "";
  try {
    responseStr = r.path("ws").path("v1").path("cluster")
        .accept(MediaType.TEXT_PLAIN).get(String.class);
    fail("should have thrown exception on invalid uri");
  } catch (UniformInterfaceException ue) {
    ClientResponse response = ue.getResponse();
    assertEquals(Status.INTERNAL_SERVER_ERROR,
        response.getClientResponseStatus());
    WebServicesTestUtils.checkStringMatch(
        "error string exists and shouldn't", "", responseStr);
  }
}
 
Example #2
Source File: ClientUtils.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
/**
 * Performs a POST using the specified url and form data.
 *
 * @param uri the uri to post to
 * @param formData the data to post
 * @return the client response of the post
 */
public ClientResponse post(URI uri, Map<String, String> formData) throws ClientHandlerException, UniformInterfaceException {
    // convert the form data
    MultivaluedMapImpl entity = new MultivaluedMapImpl();
    for (String key : formData.keySet()) {
        entity.add(key, formData.get(key));
    }

    // get the resource
    WebResource.Builder resourceBuilder = client.resource(uri).accept(MediaType.APPLICATION_JSON).type(MediaType.APPLICATION_FORM_URLENCODED);

    // add the form data if necessary
    if (!entity.isEmpty()) {
        resourceBuilder = resourceBuilder.entity(entity);
    }

    // perform the request
    return resourceBuilder.post(ClientResponse.class);
}
 
Example #3
Source File: TestAMWebServicesJobs.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Test
public void testJobIdInvalid() throws JSONException, Exception {
  WebResource r = resource();

  try {
    r.path("ws").path("v1").path("mapreduce").path("jobs").path("job_foo")
        .accept(MediaType.APPLICATION_JSON).get(JSONObject.class);
    fail("should have thrown exception on invalid uri");
  } catch (UniformInterfaceException ue) {
    ClientResponse response = ue.getResponse();
    assertEquals(Status.NOT_FOUND, response.getClientResponseStatus());
    assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
    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");
    verifyJobIdInvalid(message, type, classname);
  }
}
 
Example #4
Source File: TestAMWebServicesJobs.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Test
public void testJobIdInvalid() throws JSONException, Exception {
  WebResource r = resource();

  try {
    r.path("ws").path("v1").path("mapreduce").path("jobs").path("job_foo")
        .accept(MediaType.APPLICATION_JSON).get(JSONObject.class);
    fail("should have thrown exception on invalid uri");
  } catch (UniformInterfaceException ue) {
    ClientResponse response = ue.getResponse();
    assertEquals(Status.NOT_FOUND, response.getClientResponseStatus());
    assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
    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");
    verifyJobIdInvalid(message, type, classname);
  }
}
 
Example #5
Source File: CompactionControlClient.java    From emodb with Apache License 2.0 6 votes vote down vote up
@Override
public void deleteStashTime(String id, String dataCenter) {
    checkNotNull(id, "id");
    checkNotNull(dataCenter, "dataCenter");

    try {
        URI uri = _compactionControlSource.clone()
                .segment("_compcontrol", "stash-time", id)
                .queryParam("dataCenter", dataCenter)
                .build();
        _client.resource(uri)
                .type(MediaType.APPLICATION_JSON_TYPE)
                .header(ApiKeyRequest.AUTHENTICATION_HEADER, _apiKey)
                .delete();
    } catch (UniformInterfaceException e) {
        throw convertException(e);
    }
}
 
Example #6
Source File: TestAMWebServicesJobs.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Test
public void testJobIdNonExist() throws JSONException, Exception {
  WebResource r = resource();

  try {
    r.path("ws").path("v1").path("mapreduce").path("jobs")
        .path("job_0_1234").get(JSONObject.class);
    fail("should have thrown exception on invalid uri");
  } catch (UniformInterfaceException ue) {
    ClientResponse response = ue.getResponse();
    assertEquals(Status.NOT_FOUND, response.getClientResponseStatus());
    assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
    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.checkStringMatch("exception message",
        "java.lang.Exception: job, job_0_1234, is not found", message);
    WebServicesTestUtils.checkStringMatch("exception type",
        "NotFoundException", type);
    WebServicesTestUtils.checkStringMatch("exception classname",
        "org.apache.hadoop.yarn.webapp.NotFoundException", classname);
  }
}
 
Example #7
Source File: TestHsWebServicesJobs.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Test
public void testJobIdInvalid() throws JSONException, Exception {
  WebResource r = resource();

  try {
    r.path("ws").path("v1").path("history").path("mapreduce").path("jobs")
        .path("job_foo").accept(MediaType.APPLICATION_JSON)
        .get(JSONObject.class);
    fail("should have thrown exception on invalid uri");
  } catch (UniformInterfaceException ue) {
    ClientResponse response = ue.getResponse();
    assertEquals(Status.NOT_FOUND, response.getClientResponseStatus());
    assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
    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");
    verifyJobIdInvalid(message, type, classname);

  }
}
 
Example #8
Source File: TestRMWebServices.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Test
public void testInvalidUri() throws JSONException, Exception {
  WebResource r = resource();
  String responseStr = "";
  try {
    responseStr = r.path("ws").path("v1").path("cluster").path("bogus")
        .accept(MediaType.APPLICATION_JSON).get(String.class);
    fail("should have thrown exception on invalid uri");
  } catch (UniformInterfaceException ue) {
    ClientResponse response = ue.getResponse();
    assertEquals(Status.NOT_FOUND, response.getClientResponseStatus());

    WebServicesTestUtils.checkStringMatch(
        "error string exists and shouldn't", "", responseStr);
  }
}
 
Example #9
Source File: TestAHSWebServices.java    From hadoop with Apache License 2.0 6 votes vote down vote up
@Test
public void testInvalidAccept() throws JSONException, Exception {
  WebResource r = resource();
  String responseStr = "";
  try {
    responseStr =
        r.path("ws").path("v1").path("applicationhistory")
          .queryParam("user.name", USERS[round])
          .accept(MediaType.TEXT_PLAIN).get(String.class);
    fail("should have thrown exception on invalid uri");
  } catch (UniformInterfaceException ue) {
    ClientResponse response = ue.getResponse();
    assertEquals(Status.INTERNAL_SERVER_ERROR,
      response.getClientResponseStatus());
    WebServicesTestUtils.checkStringMatch(
      "error string exists and shouldn't", "", responseStr);
  }
}
 
Example #10
Source File: XKeyREST.java    From ranger with Apache License 2.0 6 votes vote down vote up
private void handleError(Exception e) {
	String message = e.getMessage();
	if (e instanceof UniformInterfaceException){
		 UniformInterfaceException uie=(UniformInterfaceException)e;
		 message = uie.getResponse().getEntity(String.class);
		 logger.error(message);
		 try {
			JSONObject objRE = new JSONObject(message);
			message = objRE.getString("RemoteException");
			JSONObject obj = new JSONObject(message);
			message = obj.getString("message");
		} catch (JSONException e1) {
			message = e1.getMessage();
		}			
	}			
	if (!(message==null) && !(message.isEmpty()) && message.contains("Connection refused")){
		message = "Connection refused : Please check the KMS provider URL and whether the Ranger KMS is running";			
	} else if (!(message==null) && !(message.isEmpty()) && (message.contains("response status of 403") || message.contains("HTTP Status 403"))){
		message = UNAUTHENTICATED_MSG;
	} else if (!(message==null) && !(message.isEmpty()) && (message.contains("response status of 401") || message.contains("HTTP Status 401 - Authentication required"))){
		message = UNAUTHENTICATED_MSG;
	} else if (message == null) {
	    message = UNAUTHENTICATED_MSG;
	}
	throw restErrorUtil.createRESTException(message, MessageEnums.ERROR_SYSTEM);
}
 
Example #11
Source File: TestAMWebServicesJobs.java    From big-c with Apache License 2.0 6 votes vote down vote up
@Test
public void testJobIdNonExist() throws JSONException, Exception {
  WebResource r = resource();

  try {
    r.path("ws").path("v1").path("mapreduce").path("jobs")
        .path("job_0_1234").get(JSONObject.class);
    fail("should have thrown exception on invalid uri");
  } catch (UniformInterfaceException ue) {
    ClientResponse response = ue.getResponse();
    assertEquals(Status.NOT_FOUND, response.getClientResponseStatus());
    assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
    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.checkStringMatch("exception message",
        "java.lang.Exception: job, job_0_1234, is not found", message);
    WebServicesTestUtils.checkStringMatch("exception type",
        "NotFoundException", type);
    WebServicesTestUtils.checkStringMatch("exception classname",
        "org.apache.hadoop.yarn.webapp.NotFoundException", classname);
  }
}
 
Example #12
Source File: TeamctiyRest.java    From TeamcityTriggerHook with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Trigger a build on the Teamcity instance using vcs root
 *
 * @param repository - {@link Repository}
 * @param url - url to TeamCity server
 * @param username - TeamCity user name
 * @param password - TeamCity user password
 * @return "OK" if it worked. Otherwise, an error message.
 */
@GET
@Path(value = "testconnection")
@Produces("text/plain; charset=UTF-8")
public Response testconnection(
        @Context final Repository repository,
        @QueryParam("url") final String url,
        @QueryParam("username") final String username,
        @QueryParam("password") final String password,
        @QueryParam("debugon") final String isDebugOn) {

  String realPasswordValue = password;
  if (Constant.TEAMCITY_PASSWORD_SAVED_VALUE.equals(realPasswordValue)) {
    realPasswordValue = this.connectionSettings.getPassword(repository);
  }

  final Client restClient = Client.create(Constant.REST_CLIENT_CONFIG);
  restClient.addFilter(new HTTPBasicAuthFilter(username, realPasswordValue));

  try {
    final ClientResponse response = restClient.resource(url + "/app/rest/builds?locator=lookupLimit:0").accept(MediaType.APPLICATION_XML).get(ClientResponse.class);
    if (ClientResponse.Status.OK == response.getClientResponseStatus()) {
      this.connectionSettings.savePassword(realPasswordValue, repository);
      return Response.ok(Constant.TEAMCITY_PASSWORD_SAVED_VALUE).build();
    } else {
      return Response.status(response.getClientResponseStatus()).entity(response.getEntity(String.class)).build();
    }
  } catch (final UniformInterfaceException | ClientHandlerException e) {
    return Response.status(Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build();
  } finally {
    restClient.destroy();
  }
}
 
Example #13
Source File: TestRMWebServicesApps.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Test
public void testInvalidApp() throws JSONException, Exception {
  rm.start();
  MockNM amNodeManager = rm.registerNode("127.0.0.1:1234", 2048);
  rm.submitApp(CONTAINER_MB);
  amNodeManager.nodeHeartbeat(true);
  WebResource r = resource();

  try {
    r.path("ws").path("v1").path("cluster").path("apps")
        .path("application_invalid_12").accept(MediaType.APPLICATION_JSON)
        .get(JSONObject.class);
    fail("should have thrown exception on invalid appid");
  } catch (UniformInterfaceException ue) {
    ClientResponse response = ue.getResponse();

    assertEquals(Status.BAD_REQUEST, response.getClientResponseStatus());
    assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
    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.checkStringMatch("exception message",
        "For input string: \"invalid\"", message);
    WebServicesTestUtils.checkStringMatch("exception type",
        "NumberFormatException", type);
    WebServicesTestUtils.checkStringMatch("exception classname",
        "java.lang.NumberFormatException", classname);

  } finally {
    rm.stop();
  }
}
 
Example #14
Source File: DockerClientAuthTest.java    From docker-java with Apache License 2.0 5 votes vote down vote up
@Test
public void testAuthInvalid() throws Exception {
       System.setProperty("docker.io.password", "garbage");
	try {
		dockerClient.auth();
           fail();
	} catch (DockerException e) {
		assertThat(e.getCause(), Matchers.instanceOf(UniformInterfaceException.class));
		assertEquals(((UniformInterfaceException) e.getCause()).getResponse().getStatus(), 401);
	}
}
 
Example #15
Source File: DatabusClientFactory.java    From emodb with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isRetriableException(Exception e) {
    return super.isRetriableException(e) ||
            (e instanceof UniformInterfaceException &&
                    ((UniformInterfaceException) e).getResponse().getStatus() >= 500) ||
            Iterables.any(Throwables.getCausalChain(e), Predicates.instanceOf(ClientHandlerException.class));
}
 
Example #16
Source File: TestRMWebServicesNodes.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Test
public void testNonexistNodeXML() throws JSONException, Exception {
  rm.registerNode("h1:1234", 5120);
  rm.registerNode("h2:1235", 5121);
  WebResource r = resource();
  try {
    r.path("ws").path("v1").path("cluster").path("nodes")
        .path("node_invalid:99").accept(MediaType.APPLICATION_XML)
        .get(JSONObject.class);

    fail("should have thrown exception on non-existent nodeid");
  } catch (UniformInterfaceException ue) {
    ClientResponse response = ue.getResponse();
    assertEquals(Status.NOT_FOUND, response.getClientResponseStatus());
    assertEquals(MediaType.APPLICATION_XML_TYPE, response.getType());
    String msg = response.getEntity(String.class);
    System.out.println(msg);
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder db = dbf.newDocumentBuilder();
    InputSource is = new InputSource();
    is.setCharacterStream(new StringReader(msg));
    Document dom = db.parse(is);
    NodeList nodes = dom.getElementsByTagName("RemoteException");
    Element element = (Element) nodes.item(0);
    String message = WebServicesTestUtils.getXmlString(element, "message");
    String type = WebServicesTestUtils.getXmlString(element, "exception");
    String classname = WebServicesTestUtils.getXmlString(element,
        "javaClassName");
    verifyNonexistNodeException(message, type, classname);
  } finally {
    rm.stop();
  }
}
 
Example #17
Source File: TestAMWebServicesTasks.java    From big-c with Apache License 2.0 5 votes vote down vote up
@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();
      assertEquals(Status.NOT_FOUND, response.getClientResponseStatus());
      assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
      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.checkStringMatch("exception message",
          "java.lang.Exception: TaskId string : "
              + "bogustaskid is not properly formed", message);
      WebServicesTestUtils.checkStringMatch("exception type",
          "NotFoundException", type);
      WebServicesTestUtils.checkStringMatch("exception classname",
          "org.apache.hadoop.yarn.webapp.NotFoundException", classname);
    }
  }
}
 
Example #18
Source File: TestAMWebServicesJobs.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Test
public void testJobIdInvalidBogus() throws JSONException, Exception {
  WebResource r = resource();

  try {
    r.path("ws").path("v1").path("mapreduce").path("jobs").path("bogusfoo")
        .get(JSONObject.class);
    fail("should have thrown exception on invalid uri");
  } catch (UniformInterfaceException ue) {
    ClientResponse response = ue.getResponse();
    assertEquals(Status.NOT_FOUND, response.getClientResponseStatus());
    assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
    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
        .checkStringMatch(
            "exception message",
            "java.lang.Exception: JobId string : bogusfoo is not properly formed",
            message);
    WebServicesTestUtils.checkStringMatch("exception type",
        "NotFoundException", type);
    WebServicesTestUtils.checkStringMatch("exception classname",
        "org.apache.hadoop.yarn.webapp.NotFoundException", classname);
  }
}
 
Example #19
Source File: DataStoreClientFactory.java    From emodb with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isRetriableException(Exception e) {
    return super.isRetriableException(e) ||
            (e instanceof UniformInterfaceException &&
            ((UniformInterfaceException) e).getResponse().getStatus() >= 500) ||
            Iterables.any(Throwables.getCausalChain(e), Predicates.instanceOf(ClientHandlerException.class));
}
 
Example #20
Source File: TestNMWebServicesApps.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Test
public void testNodeSingleAppsMissing() throws JSONException, Exception {
  WebResource r = resource();
  Application app = new MockApp(1);
  nmContext.getApplications().put(app.getAppId(), app);
  addAppContainers(app);
  Application app2 = new MockApp(2);
  nmContext.getApplications().put(app2.getAppId(), app2);
  addAppContainers(app2);

  try {
    r.path("ws").path("v1").path("node").path("apps")
        .path("application_1234_0009").accept(MediaType.APPLICATION_JSON)
        .get(JSONObject.class);
    fail("should have thrown exception on invalid user query");
  } catch (UniformInterfaceException ue) {
    ClientResponse response = ue.getResponse();
    assertEquals(Status.NOT_FOUND, response.getClientResponseStatus());
    assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
    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.checkStringMatch("exception message",
        "java.lang.Exception: app with id application_1234_0009 not found",
        message);
    WebServicesTestUtils.checkStringMatch("exception type",
        "NotFoundException", type);
    WebServicesTestUtils.checkStringMatch("exception classname",
        "org.apache.hadoop.yarn.webapp.NotFoundException", classname);
  }
}
 
Example #21
Source File: TestHsWebServicesTasks.java    From big-c with Apache License 2.0 5 votes vote down vote up
@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("history").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();
      assertEquals(Status.NOT_FOUND, response.getClientResponseStatus());
      assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
      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.checkStringMatch("exception message",
          "java.lang.Exception: TaskId string : "
              + "bogustaskid is not properly formed", message);
      WebServicesTestUtils.checkStringMatch("exception type",
          "NotFoundException", type);
      WebServicesTestUtils.checkStringMatch("exception classname",
          "org.apache.hadoop.yarn.webapp.NotFoundException", classname);
    }
  }
}
 
Example #22
Source File: TestAHSWebServices.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Test
public void testInvalidUri2() throws JSONException, Exception {
  WebResource r = resource();
  String responseStr = "";
  try {
    responseStr = r.queryParam("user.name", USERS[round])
        .accept(MediaType.APPLICATION_JSON).get(String.class);
    fail("should have thrown exception on invalid uri");
  } catch (UniformInterfaceException ue) {
    ClientResponse response = ue.getResponse();
    assertEquals(Status.NOT_FOUND, response.getClientResponseStatus());
    WebServicesTestUtils.checkStringMatch(
      "error string exists and shouldn't", "", responseStr);
  }
}
 
Example #23
Source File: TestRMWebServicesApps.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Test
public void testAppsQueryStateInvalid() throws JSONException, Exception {
  rm.start();
  MockNM amNodeManager = rm.registerNode("127.0.0.1:1234", 2048);
  rm.submitApp(CONTAINER_MB);
  amNodeManager.nodeHeartbeat(true);
  WebResource r = resource();

  try {
    r.path("ws").path("v1").path("cluster").path("apps")
        .queryParam("state", "INVALID_test")
        .accept(MediaType.APPLICATION_JSON).get(JSONObject.class);
    fail("should have thrown exception on invalid state query");
  } catch (UniformInterfaceException ue) {
    ClientResponse response = ue.getResponse();
    assertEquals(Status.BAD_REQUEST, response.getClientResponseStatus());
    assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
    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",
        "Invalid application-state INVALID_test",
        message);
    WebServicesTestUtils.checkStringMatch("exception type",
        "BadRequestException", type);
    WebServicesTestUtils.checkStringMatch("exception classname",
        "org.apache.hadoop.yarn.webapp.BadRequestException", classname);

  } finally {
    rm.stop();
  }
}
 
Example #24
Source File: ApplicationWsDelegateTest.java    From roboconf-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testRemoveInstance_nonExistingInstance() {
	try {
		this.client.getApplicationDelegate().removeInstance( this.app.getName(), "/I-do-not-exist" );
		Assert.fail( "Expecting exception" );
	} catch ( UniformInterfaceException e ) {
		// Not found!
		Assert.assertEquals( 404, e.getResponse().getStatus() );
	}
}
 
Example #25
Source File: TestRMWebServicesApps.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Test
public void testAppsQueryStatesInvalid() throws JSONException, Exception {
  rm.start();
  MockNM amNodeManager = rm.registerNode("127.0.0.1:1234", 2048);
  rm.submitApp(CONTAINER_MB);
  amNodeManager.nodeHeartbeat(true);
  WebResource r = resource();

  try {
    r.path("ws").path("v1").path("cluster").path("apps")
        .queryParam("states", "INVALID_test")
        .accept(MediaType.APPLICATION_JSON).get(JSONObject.class);
    fail("should have thrown exception on invalid state query");
  } catch (UniformInterfaceException ue) {
    ClientResponse response = ue.getResponse();
    assertEquals(Status.BAD_REQUEST, response.getClientResponseStatus());
    assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
    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",
        "Invalid application-state INVALID_test",
        message);
    WebServicesTestUtils.checkStringMatch("exception type",
        "BadRequestException", type);
    WebServicesTestUtils.checkStringMatch("exception classname",
        "org.apache.hadoop.yarn.webapp.BadRequestException", classname);

  } finally {
    rm.stop();
  }
}
 
Example #26
Source File: TestAHSWebServices.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Test
public void testInvalidUri2() throws JSONException, Exception {
  WebResource r = resource();
  String responseStr = "";
  try {
    responseStr = r.queryParam("user.name", USERS[round])
        .accept(MediaType.APPLICATION_JSON).get(String.class);
    fail("should have thrown exception on invalid uri");
  } catch (UniformInterfaceException ue) {
    ClientResponse response = ue.getResponse();
    assertEquals(Status.NOT_FOUND, response.getClientResponseStatus());
    WebServicesTestUtils.checkStringMatch(
      "error string exists and shouldn't", "", responseStr);
  }
}
 
Example #27
Source File: TestAMWebServicesAttempts.java    From big-c with Apache License 2.0 5 votes vote down vote up
private void testTaskAttemptIdErrorGeneric(String attid, String error)
    throws JSONException, Exception {
  WebResource r = resource();
  Map<JobId, Job> jobsMap = appContext.getAllJobs();

  for (JobId id : jobsMap.keySet()) {
    String jobId = MRApps.toString(id);

    for (Task task : jobsMap.get(id).getTasks().values()) {
      String tid = MRApps.toString(task.getID());

      try {
        r.path("ws").path("v1").path("mapreduce").path("jobs").path(jobId)
            .path("tasks").path(tid).path("attempts").path(attid)
            .accept(MediaType.APPLICATION_JSON).get(JSONObject.class);
        fail("should have thrown exception on invalid uri");
      } catch (UniformInterfaceException ue) {
        ClientResponse response = ue.getResponse();
        assertEquals(Status.NOT_FOUND, response.getClientResponseStatus());
        assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
        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.checkStringMatch("exception message", error,
            message);
        WebServicesTestUtils.checkStringMatch("exception type",
            "NotFoundException", type);
        WebServicesTestUtils.checkStringMatch("exception classname",
            "org.apache.hadoop.yarn.webapp.NotFoundException", classname);
      }
    }
  }
}
 
Example #28
Source File: TestAMWebServicesJobs.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Test
public void testJobIdInvalidXML() throws JSONException, Exception {
  WebResource r = resource();

  try {
    r.path("ws").path("v1").path("mapreduce").path("jobs").path("job_foo")
        .accept(MediaType.APPLICATION_XML).get(JSONObject.class);
    fail("should have thrown exception on invalid uri");
  } catch (UniformInterfaceException ue) {
    ClientResponse response = ue.getResponse();
    assertEquals(Status.NOT_FOUND, response.getClientResponseStatus());
    assertEquals(MediaType.APPLICATION_XML_TYPE, response.getType());
    String msg = response.getEntity(String.class);
    System.out.println(msg);
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder db = dbf.newDocumentBuilder();
    InputSource is = new InputSource();
    is.setCharacterStream(new StringReader(msg));
    Document dom = db.parse(is);
    NodeList nodes = dom.getElementsByTagName("RemoteException");
    Element element = (Element) nodes.item(0);
    String message = WebServicesTestUtils.getXmlString(element, "message");
    String type = WebServicesTestUtils.getXmlString(element, "exception");
    String classname = WebServicesTestUtils.getXmlString(element,
        "javaClassName");
    verifyJobIdInvalid(message, type, classname);
  }
}
 
Example #29
Source File: TestAMWebServicesJobs.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Test
public void testJobIdInvalidBogus() throws JSONException, Exception {
  WebResource r = resource();

  try {
    r.path("ws").path("v1").path("mapreduce").path("jobs").path("bogusfoo")
        .get(JSONObject.class);
    fail("should have thrown exception on invalid uri");
  } catch (UniformInterfaceException ue) {
    ClientResponse response = ue.getResponse();
    assertEquals(Status.NOT_FOUND, response.getClientResponseStatus());
    assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
    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
        .checkStringMatch(
            "exception message",
            "java.lang.Exception: JobId string : bogusfoo is not properly formed",
            message);
    WebServicesTestUtils.checkStringMatch("exception type",
        "NotFoundException", type);
    WebServicesTestUtils.checkStringMatch("exception classname",
        "org.apache.hadoop.yarn.webapp.NotFoundException", classname);
  }
}
 
Example #30
Source File: TestRMWebServicesNodes.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Test
public void testNonexistNode() throws JSONException, Exception {
  rm.registerNode("h1:1234", 5120);
  rm.registerNode("h2:1235", 5121);
  WebResource r = resource();
  try {
    r.path("ws").path("v1").path("cluster").path("nodes")
        .path("node_invalid:99").accept(MediaType.APPLICATION_JSON)
        .get(JSONObject.class);

    fail("should have thrown exception on non-existent nodeid");
  } catch (UniformInterfaceException ue) {
    ClientResponse response = ue.getResponse();
    assertEquals(Status.NOT_FOUND, response.getClientResponseStatus());
    assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
    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);

  } finally {
    rm.stop();
  }
}