use of javax.ws.rs.client.Client in project jersey by jersey.
the class UnderlyingCookieStoreAccessTest method testCookieStoreInstanceAccess.
@Test
public void testCookieStoreInstanceAccess() {
final Client client = ClientBuilder.newClient(new ClientConfig().connectorProvider(new ApacheConnectorProvider()));
final CookieStore csOnClient = ApacheConnectorProvider.getCookieStore(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 getCookieStore method above.
final WebTarget target = client.target("http://localhost/");
final CookieStore csOnTarget = ApacheConnectorProvider.getCookieStore(target);
assertNotNull("CookieStore instance set on JerseyClient should not be null.", csOnClient);
assertNotNull("CookieStore instance set on JerseyWebTarget should not be null.", csOnTarget);
assertSame("CookieStore instance set on JerseyClient should be the same instance as the one set on JerseyWebTarget" + "(provided the target instance has not been further configured).", csOnClient, csOnTarget);
}
use of javax.ws.rs.client.Client in project jersey by jersey.
the class RetryHandlerTest method testRetryGet.
@Test
public void testRetryGet() throws IOException {
ClientConfig cc = new ClientConfig();
cc.connectorProvider(new ApacheConnectorProvider());
cc.property(ApacheClientProperties.RETRY_HANDLER, (HttpRequestRetryHandler) (exception, executionCount, context) -> true);
cc.property(ClientProperties.READ_TIMEOUT, READ_TIMEOUT_MS);
Client client = ClientBuilder.newClient(cc);
WebTarget r = client.target(getBaseUri());
assertEquals("GET", r.request().get(String.class));
}
use of javax.ws.rs.client.Client in project jersey by jersey.
the class AuthTest method testAuthDelete.
@Test
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();
}
use of javax.ws.rs.client.Client in project jersey by jersey.
the class HelloWorldTest method testLoggingFilterClientClass.
@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();
}
use of javax.ws.rs.client.Client in project jersey by jersey.
the class HelloWorldTest method testLoggingFilterClientInstance.
@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();
}
Aggregations