Created
August 26, 2012 03:31
-
-
Save rtekie/3473588 to your computer and use it in GitHub Desktop.
Java example of using API to notify CronSentry upon a job completion
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Java example of using API to notify CronSentry upon a job completion | |
// For API documentation please go to http://www.cronsentry.com/help#api | |
// The example uses Apache HttpComponents http://hc.apache.org/ | |
import java.util.ArrayList; | |
import java.util.List; | |
import org.apache.http.HttpEntity; | |
import org.apache.http.HttpResponse; | |
import org.apache.http.NameValuePair; | |
import org.apache.http.client.entity.UrlEncodedFormEntity; | |
import org.apache.http.client.methods.HttpPost; | |
import org.apache.http.impl.client.DefaultHttpClient; | |
import org.apache.http.message.BasicNameValuePair; | |
import org.apache.http.protocol.HTTP; | |
import org.apache.http.util.EntityUtils; | |
public class CronsentryNotifyApp { | |
public static void main(String args[]) { | |
try { | |
// set POST variables | |
HttpPost httpost = new HttpPost("http://api.cronsentry.com/api/v1/notifications"); | |
List <NameValuePair> nvps = new ArrayList <NameValuePair>(); | |
nvps.add(new BasicNameValuePair("api_key", "YOUR_API_KEY")); | |
nvps.add(new BasicNameValuePair("job_name", "Your job name")); | |
nvps.add(new BasicNameValuePair("status", "1")); | |
nvps.add(new BasicNameValuePair("message", "Please change me")); | |
httpost.setEntity(new UrlEncodedFormEntity(nvps)); | |
// do POST | |
DefaultHttpClient httpclient = new DefaultHttpClient(); | |
HttpResponse response = httpclient.execute(httpost); | |
// check response | |
System.out.println(response.getStatusLine()); | |
System.out.println(EntityUtils.toString(response.getEntity())); | |
} catch (java.io.IOException ex) { | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment