Permalink
Browse files

Added SSL for HTTP streams, enabled by default. Bumped version to 1.3.4.

  • Loading branch information...
1 parent 50c1294 commit 049ab249ac0a61ff2286df08fc48596b49440ad0 Stuart Dallas committed May 15, 2012
View
10 README.md
@@ -22,6 +22,10 @@ The following libraries are included in the lib folder.
* Junit (4.9b2 included)
http://www.junit.org/
+The library will use SSL connections by default. While we recommend using SSL
+you may disable it if required by passing false as the third parameter when
+creating a user, or by calling user.enableSSL(false) on the user object.
+
License
-------
@@ -33,6 +37,12 @@ more details.
Changelog
---------
+* v.1.3.4 Added SSL support for HTTP streams (2012-05-15)
+
+ This is enabled by default and can be disabled by passing false as the third
+ parameter to the User constructor, or calling enableSSL(false) on the User
+ object.
+
* v.1.3.3 Subscriptions are no longer lost on reconnection (2012-05-15)
* v.1.3.2 Added User-Agent header to the StreamConsumers (2012-03-13)
View
27 src/org/datasift/User.java
@@ -65,6 +65,13 @@
* @access protected
*/
protected String _api_key = "";
+
+ /**
+ * Whether we should use SSL where supported.
+ *
+ * @access protected
+ */
+ protected boolean _use_ssl = true;
/**
* The rate limit returned by the last API call.
@@ -164,8 +171,28 @@ public int getRateLimitRemaining() {
public String getStreamBaseURL() {
return _stream_base_url;
}
+
+ /**
+ * Enable or disable the use of SSL where supported.
+ *
+ * @access public
+ * @param use_ssl
+ */
+ public void enableSSL(boolean use_ssl) {
+ _use_ssl = use_ssl;
+ }
/**
+ * Returns whether SSL should be used where supported.
+ *
+ * @access public
+ * @return boolean True if SSL should be used.
+ */
+ public boolean useSSL() {
+ return _use_ssl;
+ }
+
+ /**
* Set the ApiClient object to use when accessing the API.
*
* @param api_client
View
2 src/org/datasift/streamconsumer/HttpMultiThread.java
@@ -110,7 +110,7 @@ public void run() {
if (getConsumerState() == StreamConsumer.STATE_RUNNING) {
// Attempt to connect and start processing incoming interactions
DefaultHttpClient client = new DefaultHttpClient();
- String url = "http://"
+ String url = "http" + (_user.useSSL() ? "s" : "") + "://"
+ _user.getStreamBaseURL() + "multi?hashes=" + _hashes.toString().replace(", ", ",").replace("[", "").replace("]", "");
HttpGet get = new HttpGet(url);
try {
View
2 src/org/datasift/streamconsumer/HttpThread.java
@@ -97,7 +97,7 @@ public void run() {
// Attempt to connect and start processing incoming interactions
DefaultHttpClient client = new DefaultHttpClient();
try {
- HttpGet get = new HttpGet("http://"
+ HttpGet get = new HttpGet("http" + (_user.useSSL() ? "s" : "") + "://"
+ _user.getStreamBaseURL() + _definition.getHash());
try {
get.addHeader("Authorization", _user.getUsername() + ":" + _user.getAPIKey());

0 comments on commit 049ab24

Please sign in to comment.