[ https://issues.apache.org/jira/browse/STREAMS-496?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15967074#comment-15967074 ]
ASF GitHub Bot commented on STREAMS-496: ---------------------------------------- Github user jfrazee commented on a diff in the pull request: https://github.com/apache/incubator-streams/pull/360#discussion_r111306867 --- Diff: streams-contrib/streams-provider-twitter/src/main/java/org/apache/streams/twitter/api/Twitter.java --- @@ -0,0 +1,521 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.streams.twitter.api; + +import org.apache.streams.jackson.StreamsJacksonMapper; +import org.apache.streams.twitter.TwitterConfiguration; +import org.apache.streams.twitter.pojo.Tweet; +import org.apache.streams.twitter.pojo.User; +import org.apache.streams.twitter.provider.TwitterProviderUtil; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ArrayNode; +import org.apache.commons.lang3.StringUtils; +import org.apache.http.HttpRequestInterceptor; +import org.apache.http.client.HttpRequestRetryHandler; +import org.apache.http.client.config.RequestConfig; +import org.apache.http.client.params.ClientPNames; +import org.apache.http.client.params.CookiePolicy; +import org.apache.http.client.utils.URIBuilder; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClientBuilder; +import org.apache.juneau.json.JsonParser; +import org.apache.juneau.parser.ParseException; +import org.apache.juneau.plaintext.PlainTextSerializer; +import org.apache.juneau.rest.client.RestCall; +import org.apache.juneau.rest.client.RestCallException; +import org.apache.juneau.rest.client.RestClient; +//import org.apache.juneau.rest.client.RestClientBuilder; +import org.apache.juneau.rest.client.RetryOn; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.net.URISyntaxException; +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.concurrent.ConcurrentHashMap; + +/** + * Implementation of all twitter interfaces using juneau. + */ +public class Twitter implements Followers, Friends, Statuses, Users { + + private static final Logger LOGGER = LoggerFactory.getLogger(Twitter.class); + + private static Map<TwitterConfiguration, Twitter> INSTANCE_MAP = new ConcurrentHashMap<>(); + + private TwitterConfiguration configuration; + + private ObjectMapper mapper; + + private String rootUrl; + + private CloseableHttpClient httpclient; + + private HttpRequestInterceptor oauthInterceptor; + + RestClient restClient; + + private Twitter(TwitterConfiguration configuration) throws InstantiationException { + this.configuration = configuration; + this.rootUrl = TwitterProviderUtil.baseUrl(configuration); + this.oauthInterceptor = new TwitterOAuthRequestInterceptor(configuration.getOauth()); + this.httpclient = HttpClientBuilder.create() + .addInterceptorFirst(oauthInterceptor) + .setDefaultRequestConfig(RequestConfig.custom() + .setConnectionRequestTimeout(5000) + .setConnectTimeout(5000) + .setSocketTimeout(5000) + .setCookieSpec("easy") + .build() + ) + .setMaxConnPerRoute(20) + .setMaxConnTotal(100) + .build(); + +// TODO: juneau-6.2.0-incubating +// this.restClient = new RestClientBuilder() +// .httpClient(httpclient, true) +// .parser(JsonParser.class) +// .rootUrl(rootUrl) +// .retryable( +// configuration.getRetryMax().intValue(), +// configuration.getRetrySleepMs(), +// new TwitterRetryHandler()) +// .build(); + this.restClient = new RestClient() + .setHttpClient(httpclient) + .setParser(JsonParser.class) + .setRootUrl(rootUrl); + + this.mapper = StreamsJacksonMapper.getInstance(); + } + + public static Twitter getInstance(TwitterConfiguration configuration) throws InstantiationException { + if (INSTANCE_MAP.containsKey(configuration) && INSTANCE_MAP.get(configuration) != null) { + return INSTANCE_MAP.get(configuration); + } else { + Twitter twitter = new Twitter(configuration); + INSTANCE_MAP.put(configuration, twitter); + return INSTANCE_MAP.get(configuration); + } + } + + @Override + public List<Tweet> userTimeline(StatusesUserTimelineRequest parameters) { + try { +// TODO: juneau-6.2.0-incubating +// Statuses restStatuses = restClient.getRemoteableProxy("/statuses/user_timeline.json", Statuses.class); +// List<Tweet> result = restStatuses.userTimeline(parameters); +// return result; + URIBuilder uriBuilder = new URIBuilder() + .setPath("/statuses/user_timeline.json"); + if( Objects.nonNull(parameters.getUserId()) && StringUtils.isNotBlank(parameters.getUserId().toString())) { --- End diff -- I think the nonNull() checks are redundant because isNotBlank() "Checks if a String is not empty (""), not null and not whitespace only." > Remove twitter4j dependency from streams-provider-twitter > --------------------------------------------------------- > > Key: STREAMS-496 > URL: https://issues.apache.org/jira/browse/STREAMS-496 > Project: Streams > Issue Type: Task > Reporter: Steve Blackmon > Assignee: Steve Blackmon > Fix For: 0.5.1 > > Original Estimate: 4h > Remaining Estimate: 4h > > Per discussion on legal@ releases that include modules with the json license > are not permitted after April 30, 2017. > twitter4j has such a dependency and has shown little willingness to address > it. > Switch off twitter4j to HTTP API interaction. -- This message was sent by Atlassian JIRA (v6.3.15#6346)