Search in sources :

Example 31 with Client

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

the class TestTimelineReaderWebServices method testGetEntityCustomFields.

@Test
public void testGetEntityCustomFields() throws Exception {
    Client client = createClient();
    try {
        // Fields are case insensitive.
        URI uri = URI.create("http://localhost:" + serverPort + "/ws/v2/" + "timeline/clusters/cluster1/apps/app1/entities/app/id_1?" + "fields=CONFIGS,Metrics,info");
        ClientResponse resp = getResponse(client, uri);
        TimelineEntity entity = resp.getEntity(TimelineEntity.class);
        assertEquals(MediaType.APPLICATION_JSON + "; " + JettyUtils.UTF_8, resp.getType().toString());
        assertNotNull(entity);
        assertEquals("id_1", entity.getId());
        assertEquals("app", entity.getType());
        assertEquals(3, entity.getConfigs().size());
        assertEquals(3, entity.getMetrics().size());
        assertTrue("UID should be present", entity.getInfo().containsKey(TimelineReaderManager.UID_KEY));
        // Includes UID.
        assertEquals(3, entity.getInfo().size());
        // No events will be returned as events are not part of fields.
        assertEquals(0, entity.getEvents().size());
    } finally {
        client.destroy();
    }
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) Client(com.sun.jersey.api.client.Client) TimelineEntity(org.apache.hadoop.yarn.api.records.timelineservice.TimelineEntity) URI(java.net.URI) Test(org.junit.Test)

Example 32 with Client

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

the class TestRMHA method checkActiveRMWebServices.

// Do some sanity testing of the web-services after fail-over.
private void checkActiveRMWebServices() throws JSONException {
    // Validate web-service
    Client webServiceClient = Client.create(new DefaultClientConfig());
    InetSocketAddress rmWebappAddr = NetUtils.getConnectAddress(rm.getWebapp().getListenerAddress());
    String webappURL = "http://" + rmWebappAddr.getHostName() + ":" + rmWebappAddr.getPort();
    WebResource webResource = webServiceClient.resource(webappURL);
    String path = app.getApplicationId().toString();
    ClientResponse response = webResource.path("ws").path("v1").path("cluster").path("apps").path(path).accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
    assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, response.getType().toString());
    JSONObject json = response.getEntity(JSONObject.class);
    assertEquals("incorrect number of elements", 1, json.length());
    JSONObject appJson = json.getJSONObject("app");
    assertEquals("ACCEPTED", appJson.getString("state"));
// Other stuff is verified in the regular web-services related tests
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) DefaultClientConfig(com.sun.jersey.api.client.config.DefaultClientConfig) JSONObject(org.codehaus.jettison.json.JSONObject) InetSocketAddress(java.net.InetSocketAddress) WebResource(com.sun.jersey.api.client.WebResource) Client(com.sun.jersey.api.client.Client)

Example 33 with Client

use of com.sun.jersey.api.client.Client in project neo4j by neo4j.

the class EnterpriseServerIT method shouldBeAbleToStartInHAMode.

@Test
public void shouldBeAbleToStartInHAMode() throws Throwable {
    // Given
    NeoServer server = EnterpriseServerBuilder.server().usingDataDir(folder.getRoot().getAbsolutePath()).withProperty(mode.name(), "HA").withProperty(server_id.name(), "1").withProperty(initial_hosts.name(), ":5001").persistent().build();
    try {
        server.start();
        server.getDatabase();
        assertThat(server.getDatabase().getGraph(), is(instanceOf(HighlyAvailableGraphDatabase.class)));
        Client client = Client.create();
        ClientResponse r = client.resource("http://localhost:7474/db/manage/server/ha").accept(APPLICATION_JSON).get(ClientResponse.class);
        assertEquals(200, r.getStatus());
        assertThat(r.getEntity(String.class), containsString("master"));
    } finally {
        server.stop();
    }
}
Also used : NeoServer(org.neo4j.server.NeoServer) ClientResponse(com.sun.jersey.api.client.ClientResponse) Matchers.containsString(org.hamcrest.Matchers.containsString) Client(com.sun.jersey.api.client.Client) Test(org.junit.Test)

Example 34 with Client

use of com.sun.jersey.api.client.Client in project neo4j by neo4j.

the class NeoServerStartupLoggingIT method shouldLogStartup.

@Test
public void shouldLogStartup() throws Exception {
    // Check the logs
    assertThat(out.toString().length(), is(greaterThan(0)));
    // Check the server is alive
    Client nonRedirectingClient = Client.create();
    nonRedirectingClient.setFollowRedirects(false);
    final JaxRsResponse response = new RestRequest(server.baseUri(), nonRedirectingClient).get();
    assertThat(response.getStatus(), is(greaterThan(199)));
}
Also used : RestRequest(org.neo4j.server.rest.RestRequest) JaxRsResponse(org.neo4j.server.rest.JaxRsResponse) Client(com.sun.jersey.api.client.Client) Test(org.junit.Test)

Example 35 with Client

use of com.sun.jersey.api.client.Client in project neo4j by neo4j.

the class RedirectToBrowserTest method shouldRedirectToBrowserUsingXForwardedHeaders.

@Test
public void shouldRedirectToBrowserUsingXForwardedHeaders() throws Exception {
    Client nonRedirectingClient = Client.create();
    nonRedirectingClient.setFollowRedirects(false);
    final JaxRsResponse response = new RestRequest(server.baseUri(), nonRedirectingClient).accept(MediaType.TEXT_HTML_TYPE).header("X-Forwarded-Host", "foo.bar:8734").header("X-Forwarded-Proto", "https").get(server.baseUri().toString());
    assertEquals(303, response.getStatus());
    assertEquals(new URI("https://foo.bar:8734/browser/"), response.getLocation());
    response.close();
}
Also used : RestRequest(org.neo4j.server.rest.RestRequest) JaxRsResponse(org.neo4j.server.rest.JaxRsResponse) Client(com.sun.jersey.api.client.Client) URI(java.net.URI) Test(org.junit.Test)

Aggregations

Client (com.sun.jersey.api.client.Client)87 ClientResponse (com.sun.jersey.api.client.ClientResponse)61 Test (org.junit.Test)59 URI (java.net.URI)51 TimelineEntity (org.apache.hadoop.yarn.api.records.timelineservice.TimelineEntity)36 Set (java.util.Set)30 WebResource (com.sun.jersey.api.client.WebResource)19 HashSet (java.util.HashSet)19 GenericType (com.sun.jersey.api.client.GenericType)17 DefaultClientConfig (com.sun.jersey.api.client.config.DefaultClientConfig)9 TimelineMetric (org.apache.hadoop.yarn.api.records.timelineservice.TimelineMetric)9 JSONObject (org.codehaus.jettison.json.JSONObject)7 ClientConfig (com.sun.jersey.api.client.config.ClientConfig)6 URLConnectionClientHandler (com.sun.jersey.client.urlconnection.URLConnectionClientHandler)4 ArrayList (java.util.ArrayList)4 FlowRunEntity (org.apache.hadoop.yarn.api.records.timelineservice.FlowRunEntity)4 YarnClient (org.apache.hadoop.yarn.client.api.YarnClient)4 ClientHandlerException (com.sun.jersey.api.client.ClientHandlerException)3 HTTPBasicAuthFilter (com.sun.jersey.api.client.filter.HTTPBasicAuthFilter)3 JSONException (org.codehaus.jettison.json.JSONException)3