当前位置: 首页>>代码示例>>Java>>正文


Java Authentication类代码示例

本文整理汇总了Java中com.twitter.hbc.httpclient.auth.Authentication的典型用法代码示例。如果您正苦于以下问题:Java Authentication类的具体用法?Java Authentication怎么用?Java Authentication使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Authentication类属于com.twitter.hbc.httpclient.auth包,在下文中一共展示了Authentication类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: configureStreamClient

import com.twitter.hbc.httpclient.auth.Authentication; //导入依赖的package包/类
private static BasicClient configureStreamClient(BlockingQueue<String> msgQueue, String twitterKeys, List<Long> userIds, List<String> terms) {
    Hosts hosts = new HttpHosts(Constants.STREAM_HOST);
    StatusesFilterEndpoint endpoint = new StatusesFilterEndpoint()
            .followings(userIds)
            .trackTerms(terms);
    endpoint.stallWarnings(false);

    String[] keys = twitterKeys.split(":");
    Authentication auth = new OAuth1(keys[0], keys[1], keys[2], keys[3]);

    ClientBuilder builder = new ClientBuilder()
            .name("Neo4j-Twitter-Stream")
            .hosts(hosts)
            .authentication(auth)
            .endpoint(endpoint)
            .processor(new StringDelimitedProcessor(msgQueue));

    return builder.build();
}
 
开发者ID:neo4j-examples,项目名称:neo4j-twitter-stream,代码行数:20,代码来源:TwitterStreamProcessor.java

示例2: getTwitterClient

import com.twitter.hbc.httpclient.auth.Authentication; //导入依赖的package包/类
private  Client getTwitterClient(Properties props, BlockingQueue<String> messageQueue) {

        String clientName = props.getProperty("clientName");
        String consumerKey = props.getProperty("consumerKey");
        String consumerSecret = props.getProperty("consumerSecret");
        String token = props.getProperty("token");
        String tokenSecret = props.getProperty("tokenSecret");
        List<String> searchTerms = Arrays.asList(props.getProperty("searchTerms").split(","));

        Authentication authentication = new OAuth1(consumerKey,consumerSecret,token,tokenSecret);
        Hosts hosebirdHosts = new HttpHosts(Constants.STREAM_HOST);
        StatusesFilterEndpoint hosebirdEndpoint = new StatusesFilterEndpoint();

        hosebirdEndpoint.trackTerms(searchTerms);

        ClientBuilder clientBuilder = new ClientBuilder();
        clientBuilder.name(clientName)
                .hosts(hosebirdHosts)
                .authentication(authentication)
                .endpoint(hosebirdEndpoint)
                .processor(new StringDelimitedProcessor(messageQueue));

          return clientBuilder.build();

    }
 
开发者ID:bbejeck,项目名称:kafka-streams,代码行数:26,代码来源:TwitterDataSource.java

示例3: ClientBase

import com.twitter.hbc.httpclient.auth.Authentication; //导入依赖的package包/类
ClientBase(String name, HttpClient client, Hosts hosts, StreamingEndpoint endpoint, Authentication auth,
           HosebirdMessageProcessor processor, ReconnectionManager manager, RateTracker rateTracker,
           @Nullable BlockingQueue<Event> eventsQueue) {
    this.client = Preconditions.checkNotNull(client);
    this.name = Preconditions.checkNotNull(name);

    this.endpoint = Preconditions.checkNotNull(endpoint);
    this.hosts = Preconditions.checkNotNull(hosts);
    this.auth = Preconditions.checkNotNull(auth);

    this.processor = Preconditions.checkNotNull(processor);
    this.reconnectionManager = Preconditions.checkNotNull(manager);
    this.rateTracker = Preconditions.checkNotNull(rateTracker);

    this.eventsQueue = eventsQueue;

    this.exitEvent = new AtomicReference<Event>();

    this.isRunning = new CountDownLatch(1);
    this.statsReporter = new StatsReporter();

    this.connectionEstablished = new AtomicBoolean(false);
    this.reconnect = new AtomicBoolean(false);
}
 
开发者ID:LaurentTardif,项目名称:AgileGrenoble2015,代码行数:25,代码来源:ClientBase.java

示例4: constructRequest

import com.twitter.hbc.httpclient.auth.Authentication; //导入依赖的package包/类
public static HttpUriRequest constructRequest(String host, Endpoint endpoint, Authentication auth) {
    String url = host + endpoint.getURI();
    if (endpoint.getHttpMethod().equalsIgnoreCase(HttpGet.METHOD_NAME)) {
        HttpGet get = new HttpGet(url);
        logger.info("Build Request -url : " + url) ;
        logger.info("Build Request -get" + get) ;
        logger.info("Build Request -auth" + auth) ;

        if (auth != null)
            auth.signRequest(get, null);
        return get;
    } else if (endpoint.getHttpMethod().equalsIgnoreCase(HttpPost.METHOD_NAME) ) {
        HttpPost post = new HttpPost(url);

        post.setEntity(new StringEntity(endpoint.getPostParamString(), Constants.DEFAULT_CHARSET));
        post.setHeader(HttpHeaders.CONTENT_TYPE, "application/x-www-form-urlencoded");
        if (auth != null)
            auth.signRequest(post, endpoint.getPostParamString());

        return post;
    } else {
        throw new IllegalArgumentException("Bad http method: " + endpoint.getHttpMethod());
    }
}
 
开发者ID:LaurentTardif,项目名称:AgileGrenoble2015,代码行数:25,代码来源:HttpConstants.java

示例5: setConfig

import com.twitter.hbc.httpclient.auth.Authentication; //导入依赖的package包/类
/**
 * Sets the configuration for this TwitterStreaming instance, is required to be called in order to run a TwitterStreamer.
 *
 * @param auth          OAuth authentication data
 * @param terms         List of filter terms
 * @param downloadMedia true, if media downloader enabled, false to disable media downloads
 * @param properties    CouchDB properties for the Crawcial Twitter Database
 * @param imgSize       requested imgSize (thumb, small, medium, large)
 * @param mediaHttps    true if https should be used for media downloads
 * @param location      A geo location filter (optional)
 * @throws IllegalArgumentException If your configuration is invalid
 */
public void setConfig(Authentication auth, List<String> terms, boolean downloadMedia,
                      CouchDbProperties properties, String imgSize, boolean mediaHttps, Location location) throws IllegalArgumentException {
    if (!downloadMedia ^ Arrays.asList(imgSizes).contains(imgSize)) {
        // Receive OAuth params
        this.auth = auth;

        if (location != null) {
            locations = Arrays.asList(location);
        } else {
            locations = null;
        }

        // Reset DatabaseService & set download mode
        ds.init(downloadMedia, properties, imgSize, mediaHttps);

        // Terms for filtering
        this.terms = terms;
        logger.info("Filtering tweets with terms {}", terms.toString());
        lowMemory = false;
        configSet = true;
    } else {
        configSet = false;
        throw new IllegalArgumentException("Invalid imgSize");
    }
}
 
开发者ID:slauber,项目名称:Crawcial,代码行数:38,代码来源:TwitterStreamer.java

示例6: oAuth

import com.twitter.hbc.httpclient.auth.Authentication; //导入依赖的package包/类
private static Authentication oAuth() {
	final Properties properties = new Properties();
	final String fileName = "config.properties";
	final InputStream is = TwitterStream.class.getClassLoader().getResourceAsStream(fileName);
	if (is != null) {
		try {
			properties.load(is);
		} catch (IOException e) {
			System.err.println(e.getMessage());
		}
	} else {
		System.err.println("property file '" + fileName + "' not found in the classpath");
	}
	final String consumerKey = properties.getProperty("consumerKey");
	final String consumerSecret = properties.getProperty("consumerSecret");
	final String accessToken = properties.getProperty("accessToken");
	final String accessTokenSecret = properties.getProperty("accessTokenSecret");

	Authentication hosebirdAuth = new OAuth1(consumerKey, consumerSecret, accessToken, accessTokenSecret);
	return hosebirdAuth;
}
 
开发者ID:cyriux,项目名称:hexagonal-sentimental,代码行数:22,代码来源:TwitterStream.java

示例7: setupHosebirdClient

import com.twitter.hbc.httpclient.auth.Authentication; //导入依赖的package包/类
public static void setupHosebirdClient() {
       /** Declare the host you want to connect to, the endpoint, and authentication (basic auth or oauth) */
	Hosts hosebirdHosts = new HttpHosts(Constants.STREAM_HOST);
	StatusesFilterEndpoint endpoint = new StatusesFilterEndpoint();

       // Optional: set up some followings and track terms
	List<Long> followings = Lists.newArrayList(1234L, 566788L);
	List<String> terms = Lists.newArrayList("twitter", "api");
	endpoint.followings(followings);
	endpoint.trackTerms(terms);

	Authentication hosebirdAuth = new OAuth1(
       		Helper.properties().getProperty("consumerKey"),
       		Helper.properties().getProperty("consumerSecret"),
       		Helper.properties().getProperty("token"),
       		Helper.properties().getProperty("secret"));

       ClientBuilder builder = new ClientBuilder()
        .name("Hosebird-Client-01")		// optional: mainly for the logs
        .hosts(hosebirdHosts)
        .authentication(hosebirdAuth)
        .endpoint(endpoint)
        .processor(new StringDelimitedProcessor(msgQueue));

	hosebirdClient = builder.build();
}
 
开发者ID:twitterdev,项目名称:twttr-kinesis,代码行数:27,代码来源:TweetCollector.java

示例8: initializeConnection

import com.twitter.hbc.httpclient.auth.Authentication; //导入依赖的package包/类
/**
 * Initialize Hosebird Client to be able to consume Twitter's Streaming API
 */
private void initializeConnection() {

	if (LOG.isInfoEnabled()) {
		LOG.info("Initializing Twitter Streaming API connection");
	}

	queue = new LinkedBlockingQueue<String>(queueSize);

	StatusesSampleEndpoint endpoint = new StatusesSampleEndpoint();
	endpoint.stallWarnings(false);

	Authentication auth = authenticate();

	initializeClient(endpoint, auth);

	if (LOG.isInfoEnabled()) {
		LOG.info("Twitter Streaming API connection established successfully");
	}
}
 
开发者ID:citlab,项目名称:vs.msc.ws14,代码行数:23,代码来源:TwitterSource.java

示例9: BasicClient

import com.twitter.hbc.httpclient.auth.Authentication; //导入依赖的package包/类
public BasicClient(String name, Hosts hosts, StreamingEndpoint endpoint, Authentication auth, boolean enableGZip, HosebirdMessageProcessor processor,
                   ReconnectionManager reconnectionManager, RateTracker rateTracker, ExecutorService executorService,
                   @Nullable BlockingQueue<Event> eventsQueue, HttpParams params, SchemeRegistry schemeRegistry) {
  Preconditions.checkNotNull(auth);
  HttpClient client;
  if (enableGZip) {
    client = new RestartableHttpClient(auth, enableGZip, params, schemeRegistry);
  } else {
    DefaultHttpClient defaultClient = new DefaultHttpClient(new PoolingClientConnectionManager(schemeRegistry), params);

    /** Set auth **/
    auth.setupConnection(defaultClient);
    client = defaultClient;
  }

  this.canRun = new AtomicBoolean(true);
  this.executorService = executorService;
  this.clientBase = new ClientBase(name, client, hosts, endpoint, auth, processor, reconnectionManager, rateTracker, eventsQueue);
}
 
开发者ID:twitter,项目名称:hbc,代码行数:20,代码来源:BasicClient.java

示例10: ClientBase

import com.twitter.hbc.httpclient.auth.Authentication; //导入依赖的package包/类
ClientBase(String name, HttpClient client, Hosts hosts, StreamingEndpoint endpoint, Authentication auth,
           HosebirdMessageProcessor processor, ReconnectionManager manager, RateTracker rateTracker,
           @Nullable BlockingQueue<Event> eventsQueue) {
  this.client = Preconditions.checkNotNull(client);
  this.name = Preconditions.checkNotNull(name);

  this.endpoint = Preconditions.checkNotNull(endpoint);
  this.hosts = Preconditions.checkNotNull(hosts);
  this.auth = Preconditions.checkNotNull(auth);

  this.processor = Preconditions.checkNotNull(processor);
  this.reconnectionManager = Preconditions.checkNotNull(manager);
  this.rateTracker = Preconditions.checkNotNull(rateTracker);

  this.eventsQueue = eventsQueue;

  this.exitEvent = new AtomicReference<Event>();

  this.isRunning = new CountDownLatch(1);
  this.statsReporter = new StatsReporter();

  this.connectionEstablished = new AtomicBoolean(false);
  this.reconnect = new AtomicBoolean(false);
}
 
开发者ID:twitter,项目名称:hbc,代码行数:25,代码来源:ClientBase.java

示例11: constructRequest

import com.twitter.hbc.httpclient.auth.Authentication; //导入依赖的package包/类
public static HttpUriRequest constructRequest(String host, Endpoint endpoint, Authentication auth) {
  String url = host + endpoint.getURI();
  if (endpoint.getHttpMethod().equalsIgnoreCase(HttpGet.METHOD_NAME)) {
    HttpGet get = new HttpGet(url);
    if (auth != null)
      auth.signRequest(get, null);
    return get;
  } else if (endpoint.getHttpMethod().equalsIgnoreCase(HttpPost.METHOD_NAME) ) {
    HttpPost post = new HttpPost(url);

    post.setEntity(new StringEntity(endpoint.getPostParamString(), Constants.DEFAULT_CHARSET));
    post.setHeader(HttpHeaders.CONTENT_TYPE, "application/x-www-form-urlencoded");
    if (auth != null)
      auth.signRequest(post, endpoint.getPostParamString());

    return post;
  } else {
    throw new IllegalArgumentException("Bad http method: " + endpoint.getHttpMethod());
  }
}
 
开发者ID:twitter,项目名称:hbc,代码行数:21,代码来源:HttpConstants.java

示例12: streamTwitter

import com.twitter.hbc.httpclient.auth.Authentication; //导入依赖的package包/类
public static void streamTwitter(String consumerKey, String consumerSecret, String accessToken, String accessSecret) throws InterruptedException {

		BlockingQueue<String> statusQueue = new LinkedBlockingQueue<String>(10000);

		StatusesSampleEndpoint ending = new StatusesSampleEndpoint();
		ending.stallWarnings(false);

		Authentication twitterAuth = new OAuth1(consumerKey, consumerSecret, accessToken, accessSecret);

		BasicClient twitterClient = new ClientBuilder()
				.name("Twitter client")
				.hosts(Constants.STREAM_HOST)
				.endpoint(ending)
				.authentication(twitterAuth)
				.processor(new StringDelimitedProcessor(statusQueue))
				.build();


		twitterClient.connect();


		for (int msgRead = 0; msgRead < 1000; msgRead++) {
			if (twitterClient.isDone()) {
				System.out.println(twitterClient.getExitEvent().getMessage());
				break;
			}

			String msg = statusQueue.poll(10, TimeUnit.SECONDS);
			if (msg == null) {
				System.out.println("Waited 10 seconds - no message received");
			} else {
				System.out.println(msg);
			}
		}

		twitterClient.stop();

		System.out.printf("%d messages processed!\n", twitterClient.getStatsTracker().getNumMessages());
	}
 
开发者ID:PacktPublishing,项目名称:Machine-Learning-End-to-Endguide-for-Java-developers,代码行数:40,代码来源:SampleStreamExample.java

示例13: setup

import com.twitter.hbc.httpclient.auth.Authentication; //导入依赖的package包/类
@Before
public void setup() {
    this.client = mock(BasicClient.class);
    this.cb = mock(ClientBuilder.class);
    when(cb.name("Twitter Api Reader")).thenReturn(cb);
    when(cb.hosts(Constants.STREAM_HOST)).thenReturn(cb);
    when(cb.endpoint(any(StreamingEndpoint.class))).thenReturn(cb);
    when(cb.authentication(any(Authentication.class))).thenReturn(cb);
    when(cb.processor(any(HosebirdMessageProcessor.class))).thenReturn(cb);
    when(cb.retries(10)).thenReturn(cb);
    when(cb.build()).thenReturn(client);
    this.logger = mock(Logger.class);
    this.clientReadAndSendPredicate = new ReadAndSendPredicate() {
            @Override
            public boolean process() {
                return !client.isDone();
            }
        };

    this.config = new TwitterApiReaderConfig();
    this.config.hosebird = new HosebirdConfig();
    this.config.twitterapi = new TwitterApiConfig();
    this.config.twitterapi.consumerKey = "aaaaa";
    this.config.twitterapi.consumerSecret = "bbbbb";
    this.config.twitterapi.accessToken = "ccccc";
    this.config.twitterapi.accessSecret = "ddddd";
    this.config.hosebird.retries = 10;
    this.config.hosebird.bufferSize = 10000;
    this.config.kafka = new KafkaConfig();
    this.config.kafka.topic = "Data";
    this.config.metrics = new MetricsConfig();
    this.config.metrics.host = "G_HOST";
    this.config.metrics.port = 1111;
    this.config.metrics.prefix = "G_PREFIX";
    this.config.metrics.reportingTime = 2;
}
 
开发者ID:datasift,项目名称:datasift-connector,代码行数:37,代码来源:TestTwitterApiReader.java

示例14: setup

import com.twitter.hbc.httpclient.auth.Authentication; //导入依赖的package包/类
@Before
public void setup() {
    this.client = mock(BasicClient.class);
    this.cb = mock(ClientBuilder.class);
    when(cb.name("Gnip Reader")).thenReturn(cb);
    when(cb.hosts(Constants.ENTERPRISE_STREAM_HOST)).thenReturn(cb);
    when(cb.endpoint(any(StreamingEndpoint.class))).thenReturn(cb);
    when(cb.authentication(any(Authentication.class))).thenReturn(cb);
    when(cb.processor(any(HosebirdMessageProcessor.class))).thenReturn(cb);
    when(cb.retries(10)).thenReturn(cb);
    when(cb.build()).thenReturn(client);
    this.logger = mock(Logger.class);
    this.clientReadAndSendPredicate = new ReadAndSendPredicate() {
        @Override
        public boolean process() {
            return !client.isDone();
        }
    };

    this.config = new ConcreteHosebirdConfig();
    this.config.hosebird = new HosebirdConfig();
    this.config.hosebird.retries = 10;
    this.config.hosebird.bufferSize = 10000;
    this.config.kafka = new KafkaConfig();
    this.config.kafka.topic = "Data";
    this.config.metrics = new MetricsConfig();
    this.config.metrics.host = "G_HOST";
    this.config.metrics.port = 1111;
    this.config.metrics.prefix = "G_PREFIX";
    this.config.metrics.reportingTime = 2;
}
 
开发者ID:datasift,项目名称:datasift-connector,代码行数:32,代码来源:TestHosebirdReader.java

示例15: setup

import com.twitter.hbc.httpclient.auth.Authentication; //导入依赖的package包/类
@Before
public void setup() {
    this.client = mock(BasicClient.class);
    this.cb = mock(ClientBuilder.class);
    when(cb.name("Gnip Reader")).thenReturn(cb);
    when(cb.hosts(Constants.ENTERPRISE_STREAM_HOST_v2)).thenReturn(cb);
    when(cb.endpoint(any(StreamingEndpoint.class))).thenReturn(cb);
    when(cb.authentication(any(Authentication.class))).thenReturn(cb);
    when(cb.processor(any(HosebirdMessageProcessor.class))).thenReturn(cb);
    when(cb.retries(10)).thenReturn(cb);
    when(cb.build()).thenReturn(client);
    this.logger = mock(Logger.class);
    this.clientReadAndSendPredicate = new ReadAndSendPredicate() {
            @Override
            public boolean process() {
                return !client.isDone();
            }
        };

    this.config = new GnipReaderConfig();
    this.config.gnip = new GnipConfig();
    this.config.hosebird = new HosebirdConfig();
    this.config.gnip.account = "ACCOUNT";
    this.config.gnip.product = "PRODUCT";
    this.config.gnip.label = "LABEL";
    this.config.gnip.username = "USERNAME";
    this.config.gnip.password = "PASSWORD";
    this.config.hosebird.retries = 10;
    this.config.hosebird.bufferSize = 10000;
    this.config.kafka = new KafkaConfig();
    this.config.kafka.topic = "Data";
    this.config.metrics = new MetricsConfig();
    this.config.metrics.host = "G_HOST";
    this.config.metrics.port = 1111;
    this.config.metrics.prefix = "G_PREFIX";
    this.config.metrics.reportingTime = 2;
}
 
开发者ID:datasift,项目名称:datasift-connector,代码行数:38,代码来源:TestGnipReader.java


注:本文中的com.twitter.hbc.httpclient.auth.Authentication类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。