Search in sources :

Example 31 with ClientConfig

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

Example 32 with ClientConfig

use of org.glassfish.jersey.client.ClientConfig in project jersey by jersey.

the class CookieTest method testCookies.

@Test
public void testCookies() {
    ClientConfig cc = new ClientConfig();
    cc.connectorProvider(new JettyConnectorProvider());
    JerseyClient client = JerseyClientBuilder.createClient(cc);
    WebTarget r = client.target(getBaseUri());
    assertEquals("NO-COOKIE", r.request().get(String.class));
    assertEquals("value", r.request().get(String.class));
    final JettyConnector connector = (JettyConnector) client.getConfiguration().getConnector();
    assertNotNull(connector.getCookieStore().getCookies());
    assertEquals(1, connector.getCookieStore().getCookies().size());
    assertEquals("value", connector.getCookieStore().getCookies().get(0).getValue());
    client.close();
}
Also used : WebTarget(javax.ws.rs.client.WebTarget) ClientConfig(org.glassfish.jersey.client.ClientConfig) JerseyClient(org.glassfish.jersey.client.JerseyClient) Test(org.junit.Test) JerseyTest(org.glassfish.jersey.test.JerseyTest)

Example 33 with ClientConfig

use of org.glassfish.jersey.client.ClientConfig in project jersey by jersey.

the class WebTargetValueSupplierProvider method resolveConfig.

private ClientConfig resolveConfig(final String configClassProperty, final BindingModel binding) {
    Class<? extends Configuration> configClass = binding.getConfigClass();
    final Object _cc = serverConfig.get().getProperty(configClassProperty);
    if (_cc != null) {
        Class<?> cc;
        if (_cc instanceof String) {
            cc = AccessController.doPrivileged(ReflectionHelper.classForNamePA((String) _cc));
        } else if (_cc instanceof Class) {
            cc = (Class<?>) _cc;
        } else {
            // will cause a warning
            cc = null;
        }
        if (cc != null && Configuration.class.isAssignableFrom(cc)) {
            configClass = cc.asSubclass(Configuration.class);
        } else {
            Errors.warning(this, LocalizationMessages.ILLEGAL_CLIENT_CONFIG_CLASS_PROPERTY_VALUE(configClassProperty, _cc, configClass.getName()));
        }
    }
    final Configuration cfg = clientConfigProvider.apply(configClass);
    return (cfg instanceof ClientConfig) ? (ClientConfig) cfg : new ClientConfig().loadFrom(cfg);
}
Also used : Configuration(javax.ws.rs.core.Configuration) ClientConfig(org.glassfish.jersey.client.ClientConfig)

Example 34 with ClientConfig

use of org.glassfish.jersey.client.ClientConfig in project jersey by jersey.

the class EntityFilteringClientTest method testEntityAnnotationsOverConfiguration.

@Test
public void testEntityAnnotationsOverConfiguration() throws Exception {
    final ClientConfig config = new ClientConfig().property(EntityFilteringFeature.ENTITY_FILTERING_SCOPE, SecondaryDetailedView.Factory.get());
    configureClient(config);
    final String fields = ClientBuilder.newClient(config).target(getBaseUri()).request().post(Entity.entity(new ManyFilteringsOnClassEntity(), ENTITY_FILTERING, new Annotation[] { PrimaryDetailedView.Factory.get() }), String.class);
    assertSameFields(fields, "field,accessor,property,manyEntities.property1,manyEntities.field1,oneEntities.field2," + "oneEntities.property2,oneEntities.property1,oneEntities.field1,defaultEntities.field,defaultEntities" + ".property");
}
Also used : ManyFilteringsOnClassEntity(org.glassfish.jersey.tests.e2e.entity.filtering.domain.ManyFilteringsOnClassEntity) ClientConfig(org.glassfish.jersey.client.ClientConfig) Annotation(java.lang.annotation.Annotation) Test(org.junit.Test)

Example 35 with ClientConfig

use of org.glassfish.jersey.client.ClientConfig in project dropwizard by dropwizard.

the class ResourceTestRule method apply.

@Override
public Statement apply(Statement base, Description description) {
    return new Statement() {

        @Override
        public void evaluate() throws Throwable {
            DropwizardTestResourceConfig.CONFIGURATION_REGISTRY.put(configuration.getId(), configuration);
            try {
                test = new JerseyTest() {

                    @Override
                    protected TestContainerFactory getTestContainerFactory() {
                        return configuration.testContainerFactory;
                    }

                    @Override
                    protected DeploymentContext configureDeployment() {
                        return ServletDeploymentContext.builder(new DropwizardTestResourceConfig(configuration)).initParam(ServletProperties.JAXRS_APPLICATION_CLASS, DropwizardTestResourceConfig.class.getName()).initParam(DropwizardTestResourceConfig.CONFIGURATION_ID, configuration.getId()).build();
                    }

                    @Override
                    protected void configureClient(ClientConfig clientConfig) {
                        final JacksonJsonProvider jsonProvider = new JacksonJsonProvider();
                        jsonProvider.setMapper(configuration.mapper);
                        configuration.clientConfigurator.accept(clientConfig);
                        clientConfig.register(jsonProvider);
                    }
                };
                test.setUp();
                base.evaluate();
            } finally {
                DropwizardTestResourceConfig.CONFIGURATION_REGISTRY.remove(configuration.getId());
                test.tearDown();
            }
        }
    };
}
Also used : DeploymentContext(org.glassfish.jersey.test.DeploymentContext) ServletDeploymentContext(org.glassfish.jersey.test.ServletDeploymentContext) JerseyTest(org.glassfish.jersey.test.JerseyTest) Statement(org.junit.runners.model.Statement) JacksonJsonProvider(com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider) ClientConfig(org.glassfish.jersey.client.ClientConfig) TestContainerFactory(org.glassfish.jersey.test.spi.TestContainerFactory) InMemoryTestContainerFactory(org.glassfish.jersey.test.inmemory.InMemoryTestContainerFactory)

Aggregations

ClientConfig (org.glassfish.jersey.client.ClientConfig)94 Test (org.junit.Test)77 Client (javax.ws.rs.client.Client)74 JerseyTest (org.glassfish.jersey.test.JerseyTest)51 WebTarget (javax.ws.rs.client.WebTarget)46 Response (javax.ws.rs.core.Response)33 ClientResponse (org.glassfish.jersey.client.ClientResponse)12 Invocation (javax.ws.rs.client.Invocation)8 CountDownLatch (java.util.concurrent.CountDownLatch)7 UsernamePasswordCredentials (org.apache.http.auth.UsernamePasswordCredentials)7 CredentialsProvider (org.apache.http.client.CredentialsProvider)7 JerseyClient (org.glassfish.jersey.client.JerseyClient)6 SSLContext (javax.net.ssl.SSLContext)5 ProcessingException (javax.ws.rs.ProcessingException)5 ClientBuilder (javax.ws.rs.client.ClientBuilder)5 ApacheConnectorProvider (org.glassfish.jersey.apache.connector.ApacheConnectorProvider)5 IOException (java.io.IOException)4 HttpUrlConnectorProvider (org.glassfish.jersey.client.HttpUrlConnectorProvider)4 ResourceConfig (org.glassfish.jersey.server.ResourceConfig)4 Ignore (org.junit.Ignore)4