Package javax.ws.rs.client

Examples of javax.ws.rs.client.Client


        response.close();
    }

    @Test
    public void testLoggingFilterClientClass() {
        Client client = client();
        client.register(CustomLoggingFilter.class).property("foo", "bar");
        CustomLoggingFilter.preFilterCalled = CustomLoggingFilter.postFilterCalled = 0;
        String s = target().path(ROOT_PATH).request().get(String.class);
        assertEquals(HelloWorldResource.CLICHED_MESSAGE, s);
        assertEquals(1, CustomLoggingFilter.preFilterCalled);
        assertEquals(1, CustomLoggingFilter.postFilterCalled);
        client.close();
    }
View Full Code Here


        client.close();
    }

    @Test
    public void testLoggingFilterClientInstance() {
        Client client = client();
        client.register(new CustomLoggingFilter()).property("foo", "bar");
        CustomLoggingFilter.preFilterCalled = CustomLoggingFilter.postFilterCalled = 0;
        String s = target().path(ROOT_PATH).request().get(String.class);
        assertEquals(HelloWorldResource.CLICHED_MESSAGE, s);
        assertEquals(1, CustomLoggingFilter.preFilterCalled);
        assertEquals(1, CustomLoggingFilter.postFilterCalled);
        client.close();
    }
View Full Code Here

        assertEquals(1, CustomLoggingFilter.postFilterCalled);
    }

    @Test
    public void testConfigurationUpdate() {
        Client client1 = client();
        client1.register(CustomLoggingFilter.class).property("foo", "bar");

        Client client = ClientBuilder.newClient(client1.getConfiguration());
        CustomLoggingFilter.preFilterCalled = CustomLoggingFilter.postFilterCalled = 0;
        String s = target().path(ROOT_PATH).request().get(String.class);
        assertEquals(HelloWorldResource.CLICHED_MESSAGE, s);
        assertEquals(1, CustomLoggingFilter.preFilterCalled);
        assertEquals(1, CustomLoggingFilter.postFilterCalled);
        client.close();
    }
View Full Code Here

        ClientConfig config = new ClientConfig();
        config.property(ClientProperties.CHUNKED_ENCODING_SIZE, 1024);
        config.connectorProvider(new JettyConnectorProvider());
        config.register(new LoggingFilter(LOGGER, true));

        Client client = ClientBuilder.newClient(config);
        WebTarget r = client.target(getBaseUri());

        byte[] content = new byte[1024 * 1024];
        assertTrue(Arrays.equals(content, r.request().post(Entity.entity(content, MediaType.APPLICATION_OCTET_STREAM_TYPE)).readEntity(byte[].class)));

        Response cr = r.request().post(Entity.text("POST"));
        assertTrue(cr.hasEntity());
        cr.close();

        client.close();
    }
View Full Code Here

    }

    @Test
    public void testFooBarOptions() {
        startServer(HelloWorldResource.class);
        Client client = ClientBuilder.newClient();
        Response response = client.target(getUri()).path("helloworld").request().header("Accept", "foo/bar").options();
        assertEquals(200, response.getStatus());
        final String allowHeader = response.getHeaderString("Allow");
        _checkAllowContent(allowHeader);
        assertEquals(0, response.getLength());
        assertEquals("foo/bar", response.getMediaType().toString());
View Full Code Here

        ClientConfig cc = new ClientConfig();
        cc.property(JettyClientProperties.SSL_CONFIG, sslConfig);
        cc.connectorProvider(new JettyConnectorProvider());

        Client client = ClientBuilder.newClient(cc);

        System.out.println("Client: GET " + Server.BASE_URI);

        WebTarget target = client.target(Server.BASE_URI);
        target.register(new LoggingFilter());

        Response response;

        response = target.path("/").request().get(Response.class);

        assertEquals(401, response.getStatus());

        client.close();
    }
View Full Code Here

        ClientConfig cc = new ClientConfig();
        cc.property(JettyClientProperties.SSL_CONFIG, sslConfig);
        cc.connectorProvider(new JettyConnectorProvider());

        Client client = ClientBuilder.newClient(cc);

        System.out.println("Client: GET " + Server.BASE_URI);

        WebTarget target = client.target(Server.BASE_URI);
        target.register(new LoggingFilter());

        boolean caught = false;

        try {
            target.path("/").request().get(String.class);
        } catch (Exception e) {
            caught = true;
        }

        assertTrue(caught);
        // solaris throws java.net.SocketException instead of SSLHandshakeException
        // assertTrue(msg.contains("SSLHandshakeException"));

        client.close();
    }
View Full Code Here

    /**
     * Verifier of JERSEY-2424 fix.
     */
    @Test
    public void testHttpClientInstanceAccess() {
        final Client client = ClientBuilder.newClient(new ClientConfig().connectorProvider(new ApacheConnectorProvider()));
        final HttpClient hcOnClient = ApacheConnectorProvider.getHttpClient(client);
        // important: the web target instance in this test must be only created AFTER the client has been pre-initialized
        // (see org.glassfish.jersey.client.Initializable.preInitialize method). This is here achieved by calling the
        // connector provider's static getHttpClient method above.
        final WebTarget target = client.target("http://localhost/");
        final HttpClient hcOnTarget = ApacheConnectorProvider.getHttpClient(target);

        assertNotNull("HTTP client instance set on JerseyClient should not be null.", hcOnClient);
        assertNotNull("HTTP client instance set on JerseyWebTarget should not be null.", hcOnTarget);
        assertSame("HTTP client instance set on JerseyClient should be the same instance as the one set on JerseyWebTarget" +
View Full Code Here

    @Test
    public void testCookieResource() {
        ClientConfig cc = new ClientConfig();
        cc.connectorProvider(new ApacheConnectorProvider());
        Client client = ClientBuilder.newClient(cc);
        WebTarget r = client.target(getBaseUri());


        assertEquals("NO-COOKIE", r.request().get(String.class));
        assertEquals("value", r.request().get(String.class));
    }
View Full Code Here

        testTarget(target, true);
    }

    @Test
    public void testFromClient() throws Exception {
        final Client client = ClientBuilder.newClient();
        final RxWebTarget<RxFutureInvoker> target = Rx.from(client, RxFutureInvoker.class)
                .target("http://jersey.java.net");

        testTarget(target, false);
    }
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.