diff --git a/.gitignore b/.gitignore
index 4874fbf..2b30b21 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,3 +2,7 @@
.classpath
.project
.settings
+
+# IntelliJ files
+.idea/
+*.iml
diff --git a/LICENSE.txt b/LICENSE.txt
new file mode 100644
index 0000000..538dd93
--- /dev/null
+++ b/LICENSE.txt
@@ -0,0 +1,26 @@
+Copyright (c) 2015, Indicative
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+The views and conclusions contained in the software and documentation are those
+of the authors and should not be interpreted as representing official policies,
+either expressed or implied, of the FreeBSD Project.
diff --git a/README.md b/README.md
index 5aea83f..4f72a74 100644
--- a/README.md
+++ b/README.md
@@ -10,7 +10,14 @@ Features:
Sample usage:
- // First, call the Indicative class's apiKey() method and pass in your API key,
+ // If you're integrating with a Maven project, just add the following dependency to your pom.xml file:
+
+ com.indicative.client.java
+ indicative-java
+ 1.0.3
+
+
+ // Call the Indicative class's apiKey() method and pass in your API key,
// which you can find on the Project Settings page. You'll only have to do this once.
Indicative.apiKey("Your-API-Key-Goes-Here");
@@ -21,4 +28,4 @@ You should modify and extend this class to your heart's content. If you make an
As a best practice, consider adding a method that takes as a parameter the object representing your user, and adds certain default properties based on that user's characteristics (e.g., gender, age, etc.).
-For more details, see our documentation at: http://www.indicative.com/docs/integration.html
+For more details, see our documentation at: http://app.indicative.com/docs/integration.html
diff --git a/pom.xml b/pom.xml
index e51493a..b1efadc 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,22 +1,44 @@
-
+4.0.0com.indicative.client.javaIndicative-Java
- 1.0.1
+ 1.0.4-SNAPSHOTjarIndicative-Java
+ Java Client for Indicative's REST APIhttps://github.com/Indicative/Indicative-Java
+
+
+ Simplified BSD License
+ repo
+ https://github.com/Indicative/Indicative-Java/blob/master/LICENSE.txt
+ 2-clause BSD License, aka the FreeBSD License. See LICENSE.txt
+
+
+
+ scm:git:git://github.com/Indicative/Indicative-Java.git
+ scm:git:https://bealeindicative@github.com/Indicative/Indicative-Java.githttps://github.com/Indicative/Indicative-Java
- scm:git:git@github.com:Indicative/Indicative-Java.git
- scm:git:git@github.com:Indicative/Indicative-Java.git
- HEAD
+
+
+ andrewbeale
+ Andrew Beale
+ andrew.beale@indicative.com
+
+
+
+
+ org.sonatype.oss
+ oss-parent
+ 7
+
+
@@ -24,8 +46,8 @@
maven-compiler-plugin3.0
- 1.6
- 1.6
+ 1.7
+ 1.7
diff --git a/src/main/java/com/indicative/client/java/Indicative.java b/src/main/java/com/indicative/client/java/Indicative.java
index 93ae73c..7abc681 100644
--- a/src/main/java/com/indicative/client/java/Indicative.java
+++ b/src/main/java/com/indicative/client/java/Indicative.java
@@ -36,6 +36,11 @@ public class Indicative {
* Enable this to see some basic details printed to the default logger
*/
private static final boolean DEBUG = false;
+
+ /**
+ * The number of times to retry a failed POST to Indicative before giving up.
+ */
+ private static final int NUM_RETRY_ATTEMPTS = 2;
/**
* A class used to asynchronously post Events to the Indicative API
@@ -60,17 +65,31 @@ private PostThread(Event event) {
*/
@Override
public void run() {
- sendPost(event.toJson());
+ int retryAttempt = 0;
+ boolean callSuccessful = false;
+ String eventJson = event.toJson();
+
+ while (!callSuccessful && retryAttempt <= NUM_RETRY_ATTEMPTS) {
+ callSuccessful = sendPost(eventJson);
+ retryAttempt++;
+ }
+
+ if (!callSuccessful) {
+ LOG.log(Level.SEVERE, "Unable to POST event to Indicative after {0} failed attempts : {1}", new Object[] { retryAttempt, this.event.toJson() });
+ }
}
/**
* Sends the Event's JSON representation to the Indicative API endpoint via an HTTP POST.
*
* @param body
+ * @return a boolean that's true if the POST was successful
*/
- private void sendPost(String body) {
+ private boolean sendPost(String body) {
HttpURLConnection con = null;
DataOutputStream wr = null;
+ boolean successful = false;
+
try {
URL url = new URL(REST_ENDPOINT_URL);
con = (HttpURLConnection) url.openConnection();
@@ -82,6 +101,7 @@ private void sendPost(String body) {
con.setRequestProperty("Accept-Charset", "UTF-8");
con.addRequestProperty("Content-Type", "application/json; charset=UTF-8");
con.setRequestProperty("Content-Length", "" + Integer.toString(bodyBytes.length));
+ con.addRequestProperty("Indicative-Client", "Java");
// Send post request
con.setDoOutput(true);
@@ -110,9 +130,12 @@ private void sendPost(String body) {
}
in.close();
- LOG.log(Level.SEVERE, response.toString());
+ LOG.log(Level.SEVERE, response.toString());
+ } else {
+ successful = true;
}
+
} catch (MalformedURLException ex) {
LOG.log(Level.SEVERE, null, ex);
} catch (IOException ex) {
@@ -131,6 +154,8 @@ private void sendPost(String body) {
}
}
}
+
+ return successful;
}
}
@@ -139,7 +164,6 @@ private void sendPost(String body) {
*
* @param apiKey The API key for your project. You can find this on your Project Settings page.
*/
-
public static void apiKey(String apiKey) {
Indicative.API_KEY = apiKey;
}