use of javax.ws.rs.client.Client in project jersey by jersey.
the class MyResourceTest method setUp.
@Before
public void setUp() throws Exception {
// start the server
server = Main.startServer();
// create the client
Client c = ClientBuilder.newClient();
// uncomment the following line if you want to enable
// support for JSON in the client (you also have to uncomment
// dependency on jersey-media-json module in pom.xml and Main.startServer())
// --
// c.configuration().enable(new org.glassfish.jersey.media.json.JsonJaxbFeature());
target = c.target(Main.BASE_URI);
}
use of javax.ws.rs.client.Client in project jersey by jersey.
the class AuthTest method testAuthPostWithClientFilter.
@Test
public void testAuthPostWithClientFilter() {
ClientConfig cc = new ClientConfig();
cc.connectorProvider(new ApacheConnectorProvider());
Client client = ClientBuilder.newClient(cc);
client.register(HttpAuthenticationFeature.basic("name", "password"));
WebTarget r = client.target(getBaseUri()).path("test/filter");
assertEquals("POST", r.request().post(Entity.text("POST"), String.class));
}
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);
}
use of javax.ws.rs.client.Client in project jersey by jersey.
the class HelloWorldTest method testConfigurationUpdate.
@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 = client.target(getBaseUri()).path(ROOT_PATH).request().get(String.class);
assertEquals(HelloWorldResource.CLICHED_MESSAGE, s);
assertEquals(1, CustomLoggingFilter.preFilterCalled);
assertEquals(1, CustomLoggingFilter.postFilterCalled);
}
use of javax.ws.rs.client.Client in project jersey by jersey.
the class HelloWorldTest method _testConnectionPoolSharing.
public void _testConnectionPoolSharing(final boolean sharingEnabled) throws Exception {
final HttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager();
final ClientConfig cc = new ClientConfig();
cc.property(ApacheClientProperties.CONNECTION_MANAGER, connectionManager);
cc.property(ApacheClientProperties.CONNECTION_MANAGER_SHARED, sharingEnabled);
cc.connectorProvider(new ApacheConnectorProvider());
final Client clientOne = ClientBuilder.newClient(cc);
WebTarget target = clientOne.target(getBaseUri()).path(ROOT_PATH);
target.request().get();
clientOne.close();
final boolean exceptionExpected = !sharingEnabled;
final Client clientTwo = ClientBuilder.newClient(cc);
target = clientTwo.target(getBaseUri()).path(ROOT_PATH);
try {
target.request().get();
if (exceptionExpected) {
Assert.fail("Exception expected");
}
} catch (Exception e) {
if (!exceptionExpected) {
Assert.fail("Exception not expected");
}
} finally {
clientTwo.close();
}
if (sharingEnabled) {
connectionManager.shutdown();
}
}
Aggregations