當前位置: 首頁>>代碼示例>>Java>>正文


Java ClientResponse類代碼示例

本文整理匯總了Java中com.sun.jersey.api.client.ClientResponse的典型用法代碼示例。如果您正苦於以下問題:Java ClientResponse類的具體用法?Java ClientResponse怎麽用?Java ClientResponse使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ClientResponse類屬於com.sun.jersey.api.client包,在下文中一共展示了ClientResponse類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testTaskAttemptsSlash

import com.sun.jersey.api.client.ClientResponse; //導入依賴的package包/類
@Test
public void testTaskAttemptsSlash() 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());
      ClientResponse response = r.path("ws").path("v1").path("mapreduce")
          .path("jobs").path(jobId).path("tasks").path(tid).path("attempts/")
          .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
      assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
      JSONObject json = response.getEntity(JSONObject.class);
      verifyAMTaskAttempts(json, task);
    }
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:19,代碼來源:TestAMWebServicesAttempts.java

示例2: testSendHeartbeat

import com.sun.jersey.api.client.ClientResponse; //導入依賴的package包/類
@Test
public void testSendHeartbeat() throws InterruptedException {
    ZSession session = createSession("2");
    
    Thread.sleep(1000);
    WebResource wr = sessionsr.path(session.id);
    Builder b = wr.accept(MediaType.APPLICATION_JSON);
    
    ClientResponse cr = b.put(ClientResponse.class, null);
    assertEquals(ClientResponse.Status.OK, cr.getClientResponseStatus());
    
    Thread.sleep(1500);
    assertTrue(ZooKeeperService.isConnected(CONTEXT_PATH, session.id));
    
    Thread.sleep(1000);
    assertFalse(ZooKeeperService.isConnected(CONTEXT_PATH, session.id));
}
 
開發者ID:maoling,項目名稱:fuck_zookeeper,代碼行數:18,代碼來源:SessionTest.java

示例3: testGet

import com.sun.jersey.api.client.ClientResponse; //導入依賴的package包/類
@Test
public void testGet() throws Exception {
    LOG.info("STARTING " + getName());

    if (expectedStat != null) {
        if (expectedStat.data64 != null || expectedStat.dataUtf8 == null) {
            zk.setData(expectedStat.path, expectedStat.data64, -1);
        } else {
            zk.setData(expectedStat.path,
                    expectedStat.dataUtf8.getBytes(), -1);
        }
    }

    ClientResponse cr = znodesr.path(path).queryParam("dataformat", encoding)
        .accept(accept).get(ClientResponse.class);
    assertEquals(expectedStatus, cr.getClientResponseStatus());

    if (expectedStat == null) {
        return;
    }

    ZStat zstat = cr.getEntity(ZStat.class);
    assertEquals(expectedStat, zstat);
    assertEquals(znodesr.path(path).toString(), zstat.uri);
}
 
開發者ID:maoling,項目名稱:fuck_zookeeper,代碼行數:26,代碼來源:GetTest.java

示例4: postRest

import com.sun.jersey.api.client.ClientResponse; //導入依賴的package包/類
/**
 * Performs a REST POST operation of a json string on the base
 * XOS REST URI with an optional additional URI suffix.
 *
 * @param uri URI suffix to append to base URI
 * @param json JSON string to post
 */
public void postRest(String uri, String json) {
    WebResource.Builder builder = getClientBuilder(uri);
    ClientResponse response;

    try {
        response = builder.post(ClientResponse.class, json);
    } catch (ClientHandlerException e) {
        log.warn("Unable to contact REST server: {}", e.getMessage());
        return;
    }

    if (response.getStatus() != HTTP_CREATED) {
        log.info("REST POST request returned error code {}",
                 response.getStatus());
    }
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:24,代碼來源:XosManagerRestUtils.java

示例5: testTasksXML

import com.sun.jersey.api.client.ClientResponse; //導入依賴的package包/類
@Test
public void testTasksXML() throws JSONException, Exception {

  WebResource r = resource();
  Map<JobId, Job> jobsMap = appContext.getAllJobs();
  for (JobId id : jobsMap.keySet()) {
    String jobId = MRApps.toString(id);
    ClientResponse response = r.path("ws").path("v1").path("mapreduce")
        .path("jobs").path(jobId).path("tasks")
        .accept(MediaType.APPLICATION_XML).get(ClientResponse.class);
    assertEquals(MediaType.APPLICATION_XML_TYPE, response.getType());
    String xml = response.getEntity(String.class);
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder db = dbf.newDocumentBuilder();
    InputSource is = new InputSource();
    is.setCharacterStream(new StringReader(xml));
    Document dom = db.parse(is);
    NodeList tasks = dom.getElementsByTagName("tasks");
    assertEquals("incorrect number of elements", 1, tasks.getLength());
    NodeList task = dom.getElementsByTagName("task");
    verifyAMTaskXML(task, jobsMap.get(id));
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:24,代碼來源:TestAMWebServicesTasks.java

示例6: testTasksQueryReduce

import com.sun.jersey.api.client.ClientResponse; //導入依賴的package包/類
@Test
public void testTasksQueryReduce() throws JSONException, Exception {
  WebResource r = resource();
  Map<JobId, Job> jobsMap = appContext.getAllJobs();
  for (JobId id : jobsMap.keySet()) {
    String jobId = MRApps.toString(id);
    String type = "r";
    ClientResponse response = r.path("ws").path("v1").path("history")
        .path("mapreduce").path("jobs").path(jobId).path("tasks")
        .queryParam("type", type).accept(MediaType.APPLICATION_JSON)
        .get(ClientResponse.class);
    assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
    JSONObject json = response.getEntity(JSONObject.class);
    assertEquals("incorrect number of elements", 1, json.length());
    JSONObject tasks = json.getJSONObject("tasks");
    JSONArray arr = tasks.getJSONArray("task");
    assertEquals("incorrect number of elements", 1, arr.length());
    verifyHsTask(arr, jobsMap.get(id), type);
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:21,代碼來源:TestHsWebServicesTasks.java

示例7: testJobIdSlash

import com.sun.jersey.api.client.ClientResponse; //導入依賴的package包/類
@Test
public void testJobIdSlash() throws JSONException, Exception {
  WebResource r = resource();
  Map<JobId, Job> jobsMap = appContext.getAllJobs();
  for (JobId id : jobsMap.keySet()) {
    String jobId = MRApps.toString(id);

    ClientResponse response = r.path("ws").path("v1").path("history")
        .path("mapreduce").path("jobs").path(jobId + "/")
        .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
    assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
    JSONObject json = response.getEntity(JSONObject.class);
    assertEquals("incorrect number of elements", 1, json.length());
    JSONObject info = json.getJSONObject("job");

    VerifyJobsUtils.verifyHsJob(info, appContext.getJob(id));
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:19,代碼來源:TestHsWebServicesJobs.java

示例8: testTaskAttemptsDefault

import com.sun.jersey.api.client.ClientResponse; //導入依賴的package包/類
@Test
public void testTaskAttemptsDefault() 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());
      ClientResponse response = r.path("ws").path("v1").path("mapreduce")
          .path("jobs").path(jobId).path("tasks").path(tid).path("attempts")
          .get(ClientResponse.class);
      assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
      JSONObject json = response.getEntity(JSONObject.class);
      verifyAMTaskAttempts(json, task);
    }
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:19,代碼來源:TestAMWebServicesAttempts.java

示例9: testJobsQueryFinishTimeBegin

import com.sun.jersey.api.client.ClientResponse; //導入依賴的package包/類
@Test
public void testJobsQueryFinishTimeBegin() throws JSONException, Exception {
  WebResource r = resource();
  // the mockJobs finish time is the current time + some random amount
  Long now = System.currentTimeMillis();
  ClientResponse response = r.path("ws").path("v1").path("history")
      .path("mapreduce").path("jobs")
      .queryParam("finishedTimeBegin", String.valueOf(now))
      .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
  assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
  JSONObject json = response.getEntity(JSONObject.class);
  assertEquals("incorrect number of elements", 1, json.length());
  JSONObject jobs = json.getJSONObject("jobs");
  JSONArray arr = jobs.getJSONArray("job");
  assertEquals("incorrect number of elements", 3, arr.length());
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:17,代碼來源:TestHsWebServicesJobsQuery.java

示例10: testJobsQueryFinishTimeBeginNegative

import com.sun.jersey.api.client.ClientResponse; //導入依賴的package包/類
@Test
public void testJobsQueryFinishTimeBeginNegative() throws JSONException,
    Exception {
  WebResource r = resource();
  ClientResponse response = r.path("ws").path("v1").path("history")
      .path("mapreduce").path("jobs")
      .queryParam("finishedTimeBegin", String.valueOf(-1000))
      .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
  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",
      "java.lang.Exception: finishedTimeBegin must be greater than 0",
      message);
  WebServicesTestUtils.checkStringMatch("exception type",
      "BadRequestException", type);
  WebServicesTestUtils.checkStringMatch("exception classname",
      "org.apache.hadoop.yarn.webapp.BadRequestException", classname);
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:25,代碼來源:TestHsWebServicesJobsQuery.java

示例11: testJobAttempts

import com.sun.jersey.api.client.ClientResponse; //導入依賴的package包/類
@Test
public void testJobAttempts() throws JSONException, Exception {
  WebResource r = resource();
  Map<JobId, Job> jobsMap = appContext.getAllJobs();
  for (JobId id : jobsMap.keySet()) {
    String jobId = MRApps.toString(id);

    ClientResponse response = r.path("ws").path("v1")
        .path("mapreduce").path("jobs").path(jobId).path("jobattempts")
        .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
    assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
    JSONObject json = response.getEntity(JSONObject.class);
    assertEquals("incorrect number of elements", 1, json.length());
    JSONObject info = json.getJSONObject("jobAttempts");
    verifyJobAttempts(info, jobsMap.get(id));
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:18,代碼來源:TestAMWebServicesJobs.java

示例12: testJobsDefault

import com.sun.jersey.api.client.ClientResponse; //導入依賴的package包/類
@Test
public void testJobsDefault() throws JSONException, Exception {
  WebResource r = resource();
  ClientResponse response = r.path("ws").path("v1").path("history")
      .path("mapreduce").path("jobs").get(ClientResponse.class);
  assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
  JSONObject json = response.getEntity(JSONObject.class);
  assertEquals("incorrect number of elements", 1, json.length());
  JSONObject jobs = json.getJSONObject("jobs");
  JSONArray arr = jobs.getJSONArray("job");
  assertEquals("incorrect number of elements", 1, arr.length());
  JSONObject info = arr.getJSONObject(0);
  Job job = appContext.getPartialJob(MRApps.toJobID(info.getString("id")));
  VerifyJobsUtils.verifyHsJobPartial(info, job);

}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:17,代碼來源:TestHsWebServicesJobs.java

示例13: testTaskIdSlash

import com.sun.jersey.api.client.ClientResponse; //導入依賴的package包/類
@Test
public void testTaskIdSlash() 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());
      ClientResponse response = r.path("ws").path("v1").path("mapreduce")
          .path("jobs").path(jobId).path("tasks").path(tid + "/")
          .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
      assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
      JSONObject json = response.getEntity(JSONObject.class);
      assertEquals("incorrect number of elements", 1, json.length());
      JSONObject info = json.getJSONObject("task");
      verifyAMSingleTask(info, task);
    }
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:21,代碼來源:TestAMWebServicesTasks.java

示例14: testAppsQueryQueue

import com.sun.jersey.api.client.ClientResponse; //導入依賴的package包/類
@Test
public void testAppsQueryQueue() throws JSONException, Exception {
  rm.start();
  MockNM amNodeManager = rm.registerNode("127.0.0.1:1234", 2048);
  rm.submitApp(CONTAINER_MB);
  rm.submitApp(CONTAINER_MB);

  amNodeManager.nodeHeartbeat(true);
  WebResource r = resource();

  ClientResponse response = r.path("ws").path("v1").path("cluster")
      .path("apps").queryParam("queue", "default")
      .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
  assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
  JSONObject json = response.getEntity(JSONObject.class);
  assertEquals("incorrect number of elements", 1, json.length());
  JSONObject apps = json.getJSONObject("apps");
  assertEquals("incorrect number of elements", 1, apps.length());
  JSONArray array = apps.getJSONArray("app");
  assertEquals("incorrect number of elements", 2, array.length());
  rm.stop();
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:23,代碼來源:TestRMWebServicesApps.java

示例15: testJobConfXML

import com.sun.jersey.api.client.ClientResponse; //導入依賴的package包/類
@Test
public void testJobConfXML() throws JSONException, Exception {
  WebResource r = resource();
  Map<JobId, Job> jobsMap = appContext.getAllJobs();
  for (JobId id : jobsMap.keySet()) {
    String jobId = MRApps.toString(id);

    ClientResponse response = r.path("ws").path("v1").path("mapreduce")
        .path("jobs").path(jobId).path("conf")
        .accept(MediaType.APPLICATION_XML).get(ClientResponse.class);
    assertEquals(MediaType.APPLICATION_XML_TYPE, response.getType());
    String xml = response.getEntity(String.class);
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder db = dbf.newDocumentBuilder();
    InputSource is = new InputSource();
    is.setCharacterStream(new StringReader(xml));
    Document dom = db.parse(is);
    NodeList info = dom.getElementsByTagName("conf");
    verifyAMJobConfXML(info, jobsMap.get(id));
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:22,代碼來源:TestAMWebServicesJobConf.java


注:本文中的com.sun.jersey.api.client.ClientResponse類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。