Search in sources :

Example 1 with WebTarget

use of javax.ws.rs.client.WebTarget 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));
}
Also used : WebTarget(javax.ws.rs.client.WebTarget) ClientConfig(org.glassfish.jersey.client.ClientConfig) Client(javax.ws.rs.client.Client) JerseyTest(org.glassfish.jersey.test.JerseyTest) Test(org.junit.Test)

Example 2 with WebTarget

use of javax.ws.rs.client.WebTarget in project jersey by jersey.

the class FollowRedirectsTest method testDontFollow.

@Test
public void testDontFollow() {
    WebTarget t = target("test/redirect");
    t.property(ClientProperties.FOLLOW_REDIRECTS, false);
    assertEquals(303, t.request().get().getStatus());
}
Also used : WebTarget(javax.ws.rs.client.WebTarget) Test(org.junit.Test) JerseyTest(org.glassfish.jersey.test.JerseyTest)

Example 3 with WebTarget

use of javax.ws.rs.client.WebTarget 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();
    }
}
Also used : WebTarget(javax.ws.rs.client.WebTarget) PoolingHttpClientConnectionManager(org.apache.http.impl.conn.PoolingHttpClientConnectionManager) HttpClientConnectionManager(org.apache.http.conn.HttpClientConnectionManager) ClientConfig(org.glassfish.jersey.client.ClientConfig) Client(javax.ws.rs.client.Client) ConnectionPoolTimeoutException(org.apache.http.conn.ConnectionPoolTimeoutException) IOException(java.io.IOException) InternalServerErrorException(javax.ws.rs.InternalServerErrorException) HttpException(org.apache.http.HttpException) PoolingHttpClientConnectionManager(org.apache.http.impl.conn.PoolingHttpClientConnectionManager)

Example 4 with WebTarget

use of javax.ws.rs.client.WebTarget in project jersey by jersey.

the class AuthTest method testPreemptiveAuth.

@Test
public void testPreemptiveAuth() {
    CredentialsProvider credentialsProvider = new org.apache.http.impl.client.BasicCredentialsProvider();
    credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("name", "password"));
    ClientConfig cc = new ClientConfig();
    cc.property(ApacheClientProperties.CREDENTIALS_PROVIDER, credentialsProvider).property(ApacheClientProperties.PREEMPTIVE_BASIC_AUTHENTICATION, true);
    cc.connectorProvider(new ApacheConnectorProvider());
    Client client = ClientBuilder.newClient(cc);
    WebTarget r = client.target(getBaseUri());
    assertEquals("GET", r.request().get(String.class));
}
Also used : CredentialsProvider(org.apache.http.client.CredentialsProvider) WebTarget(javax.ws.rs.client.WebTarget) ClientConfig(org.glassfish.jersey.client.ClientConfig) Client(javax.ws.rs.client.Client) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) JerseyTest(org.glassfish.jersey.test.JerseyTest) Test(org.junit.Test)

Example 5 with WebTarget

use of javax.ws.rs.client.WebTarget in project jersey by jersey.

the class AuthTest method testAuthInteractiveGet.

@Test
public void testAuthInteractiveGet() {
    CredentialsProvider credentialsProvider = new org.apache.http.impl.client.BasicCredentialsProvider();
    credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("name", "password"));
    ClientConfig cc = new ClientConfig();
    cc.property(ApacheClientProperties.CREDENTIALS_PROVIDER, credentialsProvider);
    cc.connectorProvider(new ApacheConnectorProvider());
    Client client = ClientBuilder.newClient(cc);
    WebTarget r = client.target(getBaseUri()).path("test");
    assertEquals("GET", r.request().get(String.class));
}
Also used : CredentialsProvider(org.apache.http.client.CredentialsProvider) WebTarget(javax.ws.rs.client.WebTarget) ClientConfig(org.glassfish.jersey.client.ClientConfig) Client(javax.ws.rs.client.Client) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) JerseyTest(org.glassfish.jersey.test.JerseyTest) Test(org.junit.Test)

Aggregations

WebTarget (javax.ws.rs.client.WebTarget)1393 Response (javax.ws.rs.core.Response)712 Test (org.junit.Test)702 Client (javax.ws.rs.client.Client)318 JerseyTest (org.glassfish.jersey.test.JerseyTest)297 Invocation (javax.ws.rs.client.Invocation)106 List (java.util.List)76 ProcessingException (javax.ws.rs.ProcessingException)71 Builder (javax.ws.rs.client.Invocation.Builder)71 ClientBuilder (javax.ws.rs.client.ClientBuilder)69 GenericType (javax.ws.rs.core.GenericType)64 ArrayList (java.util.ArrayList)61 IOException (java.io.IOException)59 Message (com.remswork.project.alice.model.support.Message)58 PulsarAdminException (org.apache.pulsar.client.admin.PulsarAdminException)58 InputStream (java.io.InputStream)52 NamespaceName (org.apache.pulsar.common.naming.NamespaceName)52 ClientConfig (org.glassfish.jersey.client.ClientConfig)52 Form (javax.ws.rs.core.Form)42 MultiPart (org.glassfish.jersey.media.multipart.MultiPart)42