Search in sources :

Example 31 with DefaultClientConfig

use of com.sun.jersey.api.client.config.DefaultClientConfig in project coprhd-controller by CoprHD.

the class GlanceApiFactory method getApi.

/**
 * Return Glance API client, create if not present
 *
 * @param provider Storage Provider URI
 * @return
 */
public GlanceApi getApi(URI provider, GlanceEndPointInfo endPoint) {
    boolean isNew = false;
    GlanceApi glanceApi = _clientMap.get(provider.toString());
    if (glanceApi == null) {
        isNew = true;
        ClientConfig config = new DefaultClientConfig();
        Client jerseyClient = Client.create(config);
        glanceApi = new GlanceApi(endPoint, jerseyClient);
        _clientMap.putIfAbsent(provider.toString(), glanceApi);
    }
    if (!isNew) {
        // Token gets expired, if the instance is not new refresh it.
        glanceApi.getClient().setAuthTokenHeader(endPoint.getGlanceToken());
    }
    return glanceApi;
}
Also used : DefaultClientConfig(com.sun.jersey.api.client.config.DefaultClientConfig) DefaultClientConfig(com.sun.jersey.api.client.config.DefaultClientConfig) ClientConfig(com.sun.jersey.api.client.config.ClientConfig) Client(com.sun.jersey.api.client.Client)

Example 32 with DefaultClientConfig

use of com.sun.jersey.api.client.config.DefaultClientConfig in project opennms by OpenNMS.

the class RestClientTest method setUp.

@Before
public void setUp() {
    ClientConfig config = new DefaultClientConfig();
    m_client = Client.create(config);
    m_client.addFilter(new HTTPBasicAuthFilter("demo", "demo"));
    m_resource = m_client.resource("http://demo.opennms.org/opennms/rest/alarms");
}
Also used : DefaultClientConfig(com.sun.jersey.api.client.config.DefaultClientConfig) DefaultClientConfig(com.sun.jersey.api.client.config.DefaultClientConfig) ClientConfig(com.sun.jersey.api.client.config.ClientConfig) HTTPBasicAuthFilter(com.sun.jersey.api.client.filter.HTTPBasicAuthFilter) Before(org.junit.Before)

Example 33 with DefaultClientConfig

use of com.sun.jersey.api.client.config.DefaultClientConfig in project ORCID-Source by ORCID.

the class OrcidJerseyClientHandler method create.

public static Client create(boolean isDevelopmentMode, Map<String, Object> properties) {
    ClientConfig config = null;
    if (isDevelopmentMode) {
        // DANGER!!! Trust all certs
        LOGGER.info("TRUSTING ALL SSL CERTS IN DEV MODE!!!");
        config = new DevJerseyClientConfig();
    } else {
        config = new DefaultClientConfig();
    }
    Set<String> keyset = properties.keySet();
    for (String key : keyset) {
        config.getProperties().put(key, properties.get(key));
    }
    config.getClasses().add(JacksonJaxbJsonProvider.class);
    return Client.create(config);
}
Also used : DefaultClientConfig(com.sun.jersey.api.client.config.DefaultClientConfig) DevJerseyClientConfig(org.orcid.util.DevJerseyClientConfig) DevJerseyClientConfig(org.orcid.util.DevJerseyClientConfig) DefaultClientConfig(com.sun.jersey.api.client.config.DefaultClientConfig) ClientConfig(com.sun.jersey.api.client.config.ClientConfig)

Example 34 with DefaultClientConfig

use of com.sun.jersey.api.client.config.DefaultClientConfig in project nhin-d by DirectProject.

the class BaseTestPlan method getResource.

public static WebResource getResource(String serviceURL) {
    final ClientConfig config = new DefaultClientConfig();
    config.getSingletons().add(new ConfigJSONProvider());
    // need to set timeouts so we don't block forever in the event of a bad URL or hung web server
    config.getProperties().put(ClientConfig.PROPERTY_CONNECT_TIMEOUT, CONNECTION_TIMEOUT);
    config.getProperties().put(ClientConfig.PROPERTY_READ_TIMEOUT, READ_TIMEOUT);
    final Client client = Client.create(config);
    WebResource resource = client.resource(serviceURL);
    return resource;
}
Also used : DefaultClientConfig(com.sun.jersey.api.client.config.DefaultClientConfig) WebResource(com.sun.jersey.api.client.WebResource) ConfigJSONProvider(org.nhindirect.config.providers.ConfigJSONProvider) DefaultClientConfig(com.sun.jersey.api.client.config.DefaultClientConfig) ClientConfig(com.sun.jersey.api.client.config.ClientConfig) Client(com.sun.jersey.api.client.Client)

Example 35 with DefaultClientConfig

use of com.sun.jersey.api.client.config.DefaultClientConfig in project hadoop by apache.

the class TimelineConnector method serviceInit.

@Override
protected void serviceInit(Configuration conf) throws Exception {
    super.serviceInit(conf);
    ClientConfig cc = new DefaultClientConfig();
    cc.getClasses().add(YarnJacksonJaxbJsonProvider.class);
    sslFactory = getSSLFactory(conf);
    connConfigurator = getConnConfigurator(sslFactory);
    if (UserGroupInformation.isSecurityEnabled()) {
        authenticator = new KerberosDelegationTokenAuthenticator();
    } else {
        authenticator = new PseudoDelegationTokenAuthenticator();
    }
    authenticator.setConnectionConfigurator(connConfigurator);
    connectionRetry = new TimelineClientConnectionRetry(conf);
    client = new Client(new URLConnectionClientHandler(new TimelineURLConnectionFactory(authUgi, authenticator, connConfigurator, token, doAsUser)), cc);
    if (requireConnectionRetry) {
        TimelineJerseyRetryFilter retryFilter = new TimelineJerseyRetryFilter(connectionRetry);
        client.addFilter(retryFilter);
    }
}
Also used : DefaultClientConfig(com.sun.jersey.api.client.config.DefaultClientConfig) PseudoDelegationTokenAuthenticator(org.apache.hadoop.security.token.delegation.web.PseudoDelegationTokenAuthenticator) URLConnectionClientHandler(com.sun.jersey.client.urlconnection.URLConnectionClientHandler) ClientConfig(com.sun.jersey.api.client.config.ClientConfig) DefaultClientConfig(com.sun.jersey.api.client.config.DefaultClientConfig) Client(com.sun.jersey.api.client.Client) KerberosDelegationTokenAuthenticator(org.apache.hadoop.security.token.delegation.web.KerberosDelegationTokenAuthenticator)

Aggregations

DefaultClientConfig (com.sun.jersey.api.client.config.DefaultClientConfig)65 ClientConfig (com.sun.jersey.api.client.config.ClientConfig)55 Client (com.sun.jersey.api.client.Client)42 WebResource (com.sun.jersey.api.client.WebResource)21 HTTPBasicAuthFilter (com.sun.jersey.api.client.filter.HTTPBasicAuthFilter)15 ClientResponse (com.sun.jersey.api.client.ClientResponse)14 HTTPSProperties (com.sun.jersey.client.urlconnection.HTTPSProperties)9 HostnameVerifier (javax.net.ssl.HostnameVerifier)7 SSLSession (javax.net.ssl.SSLSession)7 TrustManager (javax.net.ssl.TrustManager)7 ClientHandlerException (com.sun.jersey.api.client.ClientHandlerException)6 URLConnectionClientHandler (com.sun.jersey.client.urlconnection.URLConnectionClientHandler)6 IOException (java.io.IOException)6 VisibleForTesting (com.google.common.annotations.VisibleForTesting)5 ClientFilter (com.sun.jersey.api.client.filter.ClientFilter)5 LoggingFilter (com.sun.jersey.api.client.filter.LoggingFilter)5 SecureRandom (java.security.SecureRandom)5 SSLContext (javax.net.ssl.SSLContext)5 URISyntaxException (java.net.URISyntaxException)4 ArrayList (java.util.ArrayList)4