com.sun.jersey.client.urlconnection.URLConnectionClientHandler Java Examples

The following examples show how to use com.sun.jersey.client.urlconnection.URLConnectionClientHandler. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EagleServiceBaseClient.java    From Eagle with Apache License 2.0 6 votes vote down vote up
public EagleServiceBaseClient(String host, int port, String basePath, String username, String password) {
    this.host = host;
    this.port = port;
    this.basePath = basePath;
    this.baseEndpoint = buildBathPath().toString();
    this.username = username;
    this.password = password;

    ClientConfig cc = new DefaultClientConfig();
    cc.getProperties().put(DefaultClientConfig.PROPERTY_CONNECT_TIMEOUT, 60 * 1000);
    cc.getProperties().put(DefaultClientConfig.PROPERTY_READ_TIMEOUT, 60 * 1000);
    cc.getClasses().add(JacksonJsonProvider.class);
    cc.getProperties().put(URLConnectionClientHandler.PROPERTY_HTTP_URL_CONNECTION_SET_METHOD_WORKAROUND, true);
    this.client = Client.create(cc);
    client.addFilter(new com.sun.jersey.api.client.filter.GZIPContentEncodingFilter());
    //        Runtime.getRuntime().addShutdownHook(new EagleServiceClientShutdownHook(this));
}
 
Example #2
Source File: EagleServiceBaseClient.java    From eagle with Apache License 2.0 6 votes vote down vote up
public EagleServiceBaseClient(String host, int port, String basePath, String username, String password) {
    this.host = host;
    this.port = port;
    this.basePath = basePath;
    this.baseEndpoint = buildBathPath().toString();
    this.username = username;
    this.password = password;

    ClientConfig cc = new DefaultClientConfig();
    cc.getProperties().put(DefaultClientConfig.PROPERTY_CONNECT_TIMEOUT, 60 * 1000);
    cc.getProperties().put(DefaultClientConfig.PROPERTY_READ_TIMEOUT, 60 * 1000);
    cc.getClasses().add(JacksonJsonProvider.class);
    cc.getProperties().put(URLConnectionClientHandler.PROPERTY_HTTP_URL_CONNECTION_SET_METHOD_WORKAROUND, true);
    this.client = Client.create(cc);
    client.addFilter(new com.sun.jersey.api.client.filter.GZIPContentEncodingFilter());
}
 
Example #3
Source File: SecureClientUtils.java    From atlas with Apache License 2.0 5 votes vote down vote up
public  URLConnectionClientHandler getUrlConnectionClientHandler() {
    return new URLConnectionClientHandler(new HttpURLConnectionFactory() {
        @Override
        public HttpURLConnection getHttpURLConnection(URL url)
                throws IOException {
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();

            if (connection instanceof HttpsURLConnection) {
                LOG.debug("Attempting to configure HTTPS connection using client "
                        + "configuration");
                final SSLFactory factory;
                final SSLSocketFactory sf;
                final HostnameVerifier hv;

                try {
                    Configuration conf = new Configuration();
                    conf.addResource(conf.get(SSLFactory.SSL_CLIENT_CONF_KEY, SecurityProperties.SSL_CLIENT_PROPERTIES));
                    UserGroupInformation.setConfiguration(conf);

                    HttpsURLConnection c = (HttpsURLConnection) connection;
                    factory = getSSLFactory(conf);
                    sf = factory.createSSLSocketFactory();
                    hv = factory.getHostnameVerifier();
                    c.setSSLSocketFactory(sf);
                    c.setHostnameVerifier(hv);
                } catch (Exception e) {
                    LOG.info("Unable to configure HTTPS connection from "
                            + "configuration.  Leveraging JDK properties.");
                }
            }
            return connection;
        }
    });
}
 
Example #4
Source File: SecurityDataEnrichServiceClientImpl.java    From eagle with Apache License 2.0 5 votes vote down vote up
public SecurityDataEnrichServiceClientImpl(String host, int port, String context) {
    this.host = host;
    this.port = port;
    this.context = context;
    this.basePath = buildBasePath();
    ClientConfig cc = new DefaultClientConfig();
    cc.getProperties().put(DefaultClientConfig.PROPERTY_CONNECT_TIMEOUT, 60 * 1000);
    cc.getProperties().put(DefaultClientConfig.PROPERTY_READ_TIMEOUT, 60 * 1000);
    cc.getClasses().add(JacksonJsonProvider.class);
    cc.getProperties().put(URLConnectionClientHandler.PROPERTY_HTTP_URL_CONNECTION_SET_METHOD_WORKAROUND, true);
    this.client = Client.create(cc);
    client.addFilter(new com.sun.jersey.api.client.filter.GZIPContentEncodingFilter());
}
 
Example #5
Source File: CoordinatorClient.java    From eagle with Apache License 2.0 5 votes vote down vote up
public CoordinatorClient(String host, int port, String context) {
    this.host = host;
    this.port = port;
    this.context = context;
    this.basePath = buildBasePath();
    ClientConfig cc = new DefaultClientConfig();
    cc.getProperties().put(DefaultClientConfig.PROPERTY_CONNECT_TIMEOUT, 60 * 1000);
    cc.getProperties().put(DefaultClientConfig.PROPERTY_READ_TIMEOUT, 60 * 1000);
    cc.getClasses().add(JacksonJsonProvider.class);
    cc.getProperties().put(URLConnectionClientHandler.PROPERTY_HTTP_URL_CONNECTION_SET_METHOD_WORKAROUND, true);
    this.client = Client.create(cc);
    client.addFilter(new com.sun.jersey.api.client.filter.GZIPContentEncodingFilter());
}
 
Example #6
Source File: MetadataServiceClientImpl.java    From eagle with Apache License 2.0 5 votes vote down vote up
public MetadataServiceClientImpl(String host, int port, String context) {
    this.host = host;
    this.port = port;
    this.context = context;
    this.basePath = buildBasePath();
    ClientConfig cc = new DefaultClientConfig();
    cc.getProperties().put(DefaultClientConfig.PROPERTY_CONNECT_TIMEOUT, 60 * 1000);
    cc.getProperties().put(DefaultClientConfig.PROPERTY_READ_TIMEOUT, 60 * 1000);
    cc.getClasses().add(JacksonJsonProvider.class);
    cc.getProperties().put(URLConnectionClientHandler.PROPERTY_HTTP_URL_CONNECTION_SET_METHOD_WORKAROUND, true);
    this.client = Client.create(cc);
    client.addFilter(new com.sun.jersey.api.client.filter.GZIPContentEncodingFilter());
}
 
Example #7
Source File: OracleStorageService.java    From front50 with Apache License 2.0 5 votes vote down vote up
public OracleStorageService(OracleProperties oracleProperties) throws IOException {
  this.region = oracleProperties.getRegion();
  this.bucketName = oracleProperties.getBucketName();
  this.namespace = oracleProperties.getNamespace();
  this.compartmentId = oracleProperties.getCompartmentId();

  Supplier<InputStream> privateKeySupplier =
      new SimplePrivateKeySupplier(oracleProperties.getSshPrivateKeyFilePath());
  AuthenticationDetailsProvider provider =
      SimpleAuthenticationDetailsProvider.builder()
          .userId(oracleProperties.getUserId())
          .fingerprint(oracleProperties.getFingerprint())
          .privateKeySupplier(privateKeySupplier)
          .passPhrase(oracleProperties.getPrivateKeyPassphrase())
          .tenantId(oracleProperties.getTenancyId())
          .build();

  RequestSigner requestSigner = DefaultRequestSigner.createRequestSigner(provider);

  ClientConfig clientConfig = new DefaultClientConfig();
  client = new Client(new URLConnectionClientHandler(), clientConfig);
  client.addFilter(new OracleStorageService.RequestSigningFilter(requestSigner));

  FilterProvider filters =
      new SimpleFilterProvider()
          .addFilter(ExplicitlySetFilter.NAME, ExplicitlySetFilter.INSTANCE);
  objectMapper.setFilterProvider(filters);
}
 
Example #8
Source File: TimelineReaderFactory.java    From tez with Apache License 2.0 5 votes vote down vote up
@Override
public Client getHttpClient() {
  ClientConfig config = new DefaultClientConfig(JSONRootElementProvider.App.class);
  HttpURLConnectionFactory urlFactory = new PseudoAuthenticatedURLConnectionFactory(connectionConf);
  Client httpClient = new Client(new URLConnectionClientHandler(urlFactory), config);
  return httpClient;
}
 
Example #9
Source File: ATSImportTool.java    From tez with Apache License 2.0 5 votes vote down vote up
private Client getHttpClient() {
  if (httpClient == null) {
    ClientConfig config = new DefaultClientConfig(JSONRootElementProvider.App.class);
    HttpURLConnectionFactory urlFactory = new PseudoAuthenticatedURLConnectionFactory();
    return new Client(new URLConnectionClientHandler(urlFactory), config);
  }
  return httpClient;
}
 
Example #10
Source File: TimelineClientImpl.java    From hadoop with Apache License 2.0 4 votes vote down vote up
protected void serviceInit(Configuration conf) throws Exception {
  UserGroupInformation ugi = UserGroupInformation.getCurrentUser();
  UserGroupInformation realUgi = ugi.getRealUser();
  if (realUgi != null) {
    authUgi = realUgi;
    doAsUser = ugi.getShortUserName();
  } else {
    authUgi = ugi;
    doAsUser = null;
  }
  ClientConfig cc = new DefaultClientConfig();
  cc.getClasses().add(YarnJacksonJaxbJsonProvider.class);
  connConfigurator = newConnConfigurator(conf);
  if (UserGroupInformation.isSecurityEnabled()) {
    authenticator = new KerberosDelegationTokenAuthenticator();
  } else {
    authenticator = new PseudoDelegationTokenAuthenticator();
  }
  authenticator.setConnectionConfigurator(connConfigurator);
  token = new DelegationTokenAuthenticatedURL.Token();

  connectionRetry = new TimelineClientConnectionRetry(conf);
  client = new Client(new URLConnectionClientHandler(
      new TimelineURLConnectionFactory()), cc);
  TimelineJerseyRetryFilter retryFilter = new TimelineJerseyRetryFilter();
  client.addFilter(retryFilter);

  if (YarnConfiguration.useHttps(conf)) {
    resURI = URI
        .create(JOINER.join("https://", conf.get(
            YarnConfiguration.TIMELINE_SERVICE_WEBAPP_HTTPS_ADDRESS,
            YarnConfiguration.DEFAULT_TIMELINE_SERVICE_WEBAPP_HTTPS_ADDRESS),
            RESOURCE_URI_STR));
  } else {
    resURI = URI.create(JOINER.join("http://", conf.get(
        YarnConfiguration.TIMELINE_SERVICE_WEBAPP_ADDRESS,
        YarnConfiguration.DEFAULT_TIMELINE_SERVICE_WEBAPP_ADDRESS),
        RESOURCE_URI_STR));
  }
  LOG.info("Timeline service address: " + resURI);
  super.serviceInit(conf);
}
 
Example #11
Source File: TimelineClientImpl.java    From big-c with Apache License 2.0 4 votes vote down vote up
protected void serviceInit(Configuration conf) throws Exception {
  UserGroupInformation ugi = UserGroupInformation.getCurrentUser();
  UserGroupInformation realUgi = ugi.getRealUser();
  if (realUgi != null) {
    authUgi = realUgi;
    doAsUser = ugi.getShortUserName();
  } else {
    authUgi = ugi;
    doAsUser = null;
  }
  ClientConfig cc = new DefaultClientConfig();
  cc.getClasses().add(YarnJacksonJaxbJsonProvider.class);
  connConfigurator = newConnConfigurator(conf);
  if (UserGroupInformation.isSecurityEnabled()) {
    authenticator = new KerberosDelegationTokenAuthenticator();
  } else {
    authenticator = new PseudoDelegationTokenAuthenticator();
  }
  authenticator.setConnectionConfigurator(connConfigurator);
  token = new DelegationTokenAuthenticatedURL.Token();

  connectionRetry = new TimelineClientConnectionRetry(conf);
  client = new Client(new URLConnectionClientHandler(
      new TimelineURLConnectionFactory()), cc);
  TimelineJerseyRetryFilter retryFilter = new TimelineJerseyRetryFilter();
  client.addFilter(retryFilter);

  if (YarnConfiguration.useHttps(conf)) {
    resURI = URI
        .create(JOINER.join("https://", conf.get(
            YarnConfiguration.TIMELINE_SERVICE_WEBAPP_HTTPS_ADDRESS,
            YarnConfiguration.DEFAULT_TIMELINE_SERVICE_WEBAPP_HTTPS_ADDRESS),
            RESOURCE_URI_STR));
  } else {
    resURI = URI.create(JOINER.join("http://", conf.get(
        YarnConfiguration.TIMELINE_SERVICE_WEBAPP_ADDRESS,
        YarnConfiguration.DEFAULT_TIMELINE_SERVICE_WEBAPP_ADDRESS),
        RESOURCE_URI_STR));
  }
  LOG.info("Timeline service address: " + resURI);
  super.serviceInit(conf);
}
 
Example #12
Source File: ServiceInstanceRepository.java    From ecs-cf-service-broker with Apache License 2.0 4 votes vote down vote up
@PostConstruct
public void initialize() throws URISyntaxException {
    logger.info(format("Creating S3 config with repository endpoint %s", broker.getRepositoryEndpoint()));

    S3Config s3Config = new S3Config(new URI(broker.getRepositoryEndpoint()));

    logger.debug(format("Created S3 config %s", s3Config));

    s3Config.withIdentity(broker.getPrefixedUserName()).withSecretKey(broker.getRepositorySecret());

    this.s3 = new S3JerseyClient(s3Config, new URLConnectionClientHandler());

    logger.debug(format("JerseyClient S3 config %s", this.s3.getS3Config()));

    this.bucket = broker.getPrefixedBucketName();

    logger.info("Service repository bucket name: {}", this.bucket);
}