Search in sources :

Example 1 with WebResource

use of com.sun.jersey.api.client.WebResource in project hadoop by apache.

the class TestRMWithCSRFFilter method testAllowNonBrowserInteractionWithoutHeader.

@Test
public void testAllowNonBrowserInteractionWithoutHeader() throws Exception {
    WebResource r = resource();
    ClientResponse response = r.path("ws").path("v1").path("cluster").path("info").accept("application/xml").get(ClientResponse.class);
    assertTrue("Should have been accepted", response.getStatus() == Status.OK.getStatusCode());
    assertEquals(MediaType.APPLICATION_XML_TYPE + "; " + JettyUtils.UTF_8, response.getType().toString());
    String xml = response.getEntity(String.class);
    verifyClusterInfoXML(xml);
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) WebResource(com.sun.jersey.api.client.WebResource) Test(org.junit.Test)

Example 2 with WebResource

use of com.sun.jersey.api.client.WebResource in project hadoop by apache.

the class TestRMWithXFSFilter method testSameOrigin.

@Test
public void testSameOrigin() throws Exception {
    createInjector("SAMEORIGIN");
    WebResource r = resource();
    ClientResponse response = r.path("ws").path("v1").path("cluster").path("info").accept("application/xml").get(ClientResponse.class);
    assertTrue("Should have received SAMEORIGIN x-frame options header", response.getHeaders().get(XFrameOptionsFilter.X_FRAME_OPTIONS).get(0).equals("SAMEORIGIN"));
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) WebResource(com.sun.jersey.api.client.WebResource) Test(org.junit.Test)

Example 3 with WebResource

use of com.sun.jersey.api.client.WebResource in project hadoop by apache.

the class TestRMWithXFSFilter method testExplicitlyDisabled.

@Test
public void testExplicitlyDisabled() throws Exception {
    createInjector(null, true);
    WebResource r = resource();
    ClientResponse response = r.path("ws").path("v1").path("cluster").path("info").accept("application/xml").get(ClientResponse.class);
    assertFalse("Should have not received x-frame options header", response.getHeaders().get(XFrameOptionsFilter.X_FRAME_OPTIONS) == null);
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) WebResource(com.sun.jersey.api.client.WebResource) Test(org.junit.Test)

Example 4 with WebResource

use of com.sun.jersey.api.client.WebResource in project hadoop by apache.

the class TestRMWebServicesReservation method testNonExistentQueueRequestListReservation.

@Test
public void testNonExistentQueueRequestListReservation() throws Exception {
    rm.start();
    setupCluster(100);
    ReservationId id1 = getReservationIdTestHelper(1);
    ReservationId id2 = getReservationIdTestHelper(2);
    reservationSubmissionTestHelper("reservation/submit", MediaType.APPLICATION_JSON, clock.getTime(), "res_1", id1);
    reservationSubmissionTestHelper("reservation/submit", MediaType.APPLICATION_JSON, clock.getTime(), "res_2", id2);
    WebResource resource = constructWebResource(LIST_RESERVATION_PATH).queryParam("queue", DEFAULT_QUEUE + "_invalid");
    testListReservationHelper(resource, Status.BAD_REQUEST);
    rm.stop();
}
Also used : ReservationId(org.apache.hadoop.yarn.api.records.ReservationId) WebResource(com.sun.jersey.api.client.WebResource) Test(org.junit.Test)

Example 5 with WebResource

use of com.sun.jersey.api.client.WebResource in project hadoop by apache.

the class TestRMWebServicesReservation method testInvalidEndTimeRequestListReservation.

@Test
public void testInvalidEndTimeRequestListReservation() throws Exception {
    rm.start();
    setupCluster(100);
    long time = clock.getTime() + MINIMUM_RESOURCE_DURATION;
    ReservationId id1 = getReservationIdTestHelper(1);
    ReservationId id2 = getReservationIdTestHelper(2);
    reservationSubmissionTestHelper("reservation/submit", MediaType.APPLICATION_JSON, time, "res_1", id1);
    reservationSubmissionTestHelper("reservation/submit", MediaType.APPLICATION_JSON, time + MINIMUM_RESOURCE_DURATION, "res_2", id2);
    WebResource resource = constructWebResource(LIST_RESERVATION_PATH).queryParam("start-time", Long.toString((long) (time + MINIMUM_RESOURCE_DURATION * 1.3))).queryParam("end-time", "-1").queryParam("include-resource-allocations", "true").queryParam("queue", DEFAULT_QUEUE);
    JSONObject json = testListReservationHelper(resource);
    if (!this.isAuthenticationEnabled() && json == null) {
        return;
    }
    JSONObject reservations = json.getJSONObject("reservations");
    testRDLHelper(reservations);
    String reservationName = reservations.getJSONObject("reservation-definition").getString("reservation-name");
    assertEquals(reservationName, "res_2");
    rm.stop();
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) ReservationId(org.apache.hadoop.yarn.api.records.ReservationId) WebResource(com.sun.jersey.api.client.WebResource) Test(org.junit.Test)

Aggregations

WebResource (com.sun.jersey.api.client.WebResource)911 ClientResponse (com.sun.jersey.api.client.ClientResponse)673 Test (org.junit.Test)506 JSONObject (org.codehaus.jettison.json.JSONObject)310 UniformInterfaceException (com.sun.jersey.api.client.UniformInterfaceException)136 Job (org.apache.hadoop.mapreduce.v2.app.job.Job)110 Client (com.sun.jersey.api.client.Client)106 JobId (org.apache.hadoop.mapreduce.v2.api.records.JobId)103 JSONArray (org.codehaus.jettison.json.JSONArray)69 JerseyTest (com.sun.jersey.test.framework.JerseyTest)53 ClientHandlerException (com.sun.jersey.api.client.ClientHandlerException)49 NodeList (org.w3c.dom.NodeList)47 Document (org.w3c.dom.Document)45 StringReader (java.io.StringReader)44 DocumentBuilder (javax.xml.parsers.DocumentBuilder)43 InputSource (org.xml.sax.InputSource)43 List (java.util.List)42 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)42 Task (org.apache.hadoop.mapreduce.v2.app.job.Task)42 MultivaluedMapImpl (com.sun.jersey.core.util.MultivaluedMapImpl)39