Package javax.ws.rs.client

Examples of javax.ws.rs.client.Client


    @Test
    public void addBidirectionalGzipSupportIfEnabled() throws Exception {
        final JerseyClientConfiguration configuration = new JerseyClientConfiguration();
        configuration.setGzipEnabled(true);

        final Client client = builder.using(configuration)
                .using(executorService, objectMapper).build("test");
        assertThat(Iterables.filter(client.getConfiguration().getInstances(), GZipDecoder.class)
                .iterator().hasNext()).isTrue();
        assertThat(Iterables.filter(client.getConfiguration().getInstances(), ConfiguredGZipEncoder.class)
                .iterator().hasNext()).isTrue();
    }
View Full Code Here


    @Test
    public void disablesGzipSupportIfDisabled() throws Exception {
        final JerseyClientConfiguration configuration = new JerseyClientConfiguration();
        configuration.setGzipEnabled(false);

        final Client client = builder.using(configuration)
                .using(executorService, objectMapper).build("test");

        assertThat(Iterables.filter(client.getConfiguration().getInstances(), GZipDecoder.class)
                .iterator().hasNext()).isFalse();
        assertThat(Iterables.filter(client.getConfiguration().getInstances(), ConfiguredGZipEncoder.class)
                .iterator().hasNext()).isFalse();
    }
View Full Code Here

    }

    @Test
    public void test400StatusCode() {
        startServer(ExceptionResource.class);
        Client client = ClientBuilder.newClient();
        WebTarget r = client.target(getUri().path("400").build());
        assertEquals(400, r.request().get(Response.class).getStatus());
    }
View Full Code Here

    public void testAuthGet() {
        ClientConfig config = new ClientConfig();
        config.property(JettyClientProperties.PREEMPTIVE_BASIC_AUTHENTICATION,
                new BasicAuthentication(getBaseUri(), "WallyWorld", "name", "password"));
        config.connectorProvider(new JettyConnectorProvider());
        Client client = ClientBuilder.newClient(config);

        Response response = client.target(getBaseUri()).path(PATH).request().get();
        assertEquals("GET", response.readEntity(String.class));
        client.close();
    }
View Full Code Here

    }

    @Test
    public void test500StatusCode() {
        startServer(ExceptionResource.class);
        Client client = ClientBuilder.newClient();
        WebTarget r = client.target(getUri().path("500").build());

        assertEquals(500, r.request().get(Response.class).getStatus());
    }
View Full Code Here

    public void testAuthPost() {
        ClientConfig config = new ClientConfig();
        config.property(JettyClientProperties.PREEMPTIVE_BASIC_AUTHENTICATION,
                new BasicAuthentication(getBaseUri(), "WallyWorld", "name", "password"));
        config.connectorProvider(new JettyConnectorProvider());
        Client client = ClientBuilder.newClient(config);

        Response response = client.target(getBaseUri()).path(PATH).request().post(Entity.text("POST"));
        assertEquals("POST", response.readEntity(String.class));
        client.close();
    }
View Full Code Here

    public void testAuthDelete() {
        ClientConfig config = new ClientConfig();
        config.property(JettyClientProperties.PREEMPTIVE_BASIC_AUTHENTICATION,
                new BasicAuthentication(getBaseUri(), "WallyWorld", "name", "password"));
        config.connectorProvider(new JettyConnectorProvider());
        Client client = ClientBuilder.newClient(config);

        Response response = client.target(getBaseUri()).path(PATH).request().delete();
        assertEquals(response.getStatus(), 204);
        client.close();
    }
View Full Code Here

    @Test
    public void testSlow() {
        final URI u = target().getUri();
        ClientConfig config = new ClientConfig().property(ClientProperties.READ_TIMEOUT, 1000);
        config.connectorProvider(new JettyConnectorProvider());
        Client c = ClientBuilder.newClient(config);
        WebTarget t = c.target(u);
        try {
            t.path("test/timeout").request().get();
        } catch (ProcessingException e) {
            assertThat("Unexpected processing exception cause",
                    e.getCause(), instanceOf(TimeoutException.class));
        } finally {
            c.close();
        }
    }
View Full Code Here

    @Test
    public void testUnknownHost() throws URISyntaxException {
        ClientConfig config = new ClientConfig().property(ClientProperties.CONNECT_TIMEOUT, 1000);
        config.connectorProvider(new JettyConnectorProvider());
        Client c = ClientBuilder.newClient(config);
        final URI u = new URI("http://google.com:81");
        WebTarget target = c.target(u);
        try {
            target.request().get();
        } catch (ProcessingException e) {
            assertThat("Unexpected processing exception cause",
                    e.getCause().getCause(),
                    anyOf(instanceOf(SocketTimeoutException.class), instanceOf(NoRouteToHostException.class)));
        } finally {
            c.close();
        }
    }
View Full Code Here

        Reloader reloader = new Reloader();
        rc.registerInstances(reloader);

        startServer(rc);

        Client client = ClientBuilder.newClient();
        WebTarget r = client.target(getUri().path("/").build());

        assertEquals("one", r.path("one").request().get(String.class));
        assertEquals(404, r.path("two").request().get(Response.class).getStatus());

        // add Two resource
View Full Code Here

TOP

Related Classes of javax.ws.rs.client.Client

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.