Permalink
Browse files

Merge pull request #20 from 3ft9/SSL

Added SSL support for HTTP streams
  • Loading branch information...
3ft9 Ltd
3ft9 Ltd committed May 15, 2012
2 parents e9924c3 + 9beb08a commit 7ddeb8b974591ceac063e8280f161b68132b351a
View
@@ -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
@@ -4,7 +4,7 @@
<property name="deploy.dir" value="../deploy"/>
<property name="classes.dir" value="../deploy/classes"/>
- <property name="version" value="1.3.2"/>
+ <property name="version" value="1.3.4"/>
<path id="class.path">
<fileset dir="../lib">
View
@@ -7,7 +7,7 @@
<groupId>com.mediasift</groupId>
<artifactId>datasift-java</artifactId>
<packaging>jar</packaging>
- <version>1.3.2</version>
+ <version>1.3.4</version>
<name>DataSift Java Client library</name>
<description>A client library for interacting with the DataSift API on the JVM.</description>
View
@@ -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,7 +171,27 @@ 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.
*
@@ -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 {
@@ -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 7ddeb8b

Please sign in to comment.