Skip to content

Instantly share code, notes, and snippets.

@vishnu667
Created May 8, 2014 01:47
Show Gist options
  • Save vishnu667/f933e42cfe809f79e819 to your computer and use it in GitHub Desktop.
Save vishnu667/f933e42cfe809f79e819 to your computer and use it in GitHub Desktop.
package org.helloworld;
import org.json.simple.JSONObject;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.atomic.AtomicInteger;
/**
* Hello world!
*
*/
public class App
{
private static AtomicInteger counter = new AtomicInteger();
public static void main( String[] args )
{
for(int i =0;i<10000;i++)
fireUrl();
System.out.println("ended "+counter.get());
}
public static void fireUrl(){
try {
String url = "http://localhost:1341/incrementCount";
URL obj = new URL(url);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("POST");
con.setRequestProperty("Host","vuukle.com");
con.setRequestProperty("Connection","keep-alive");
con.setRequestProperty("Content-Length","98");
con.setRequestProperty("Accept","application/json, text/javascript, */*; q=0.01");
con.setRequestProperty("X-NewRelic-ID","VgYBVlFWGwIEVVlXBQA=");
con.setRequestProperty("Origin","http://vuukle.com");
con.setRequestProperty("X-Requested-With","XMLHttpRequest");
con.setRequestProperty("User-Agent","Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/33.0.1750.152 Chrome/33.0.1750.152 Safari/537.36");
con.setRequestProperty("Content-Type","application/json; charset=UTF-8");
con.setRequestProperty("Referer","http://vuukle.com/rating.aspx?uri=http%3A//www.thehindu.com/opinion/lead/a-new-economic-agenda/article5944375.ece%3Futm_source%3Dvuukle%26utm_medium%3Dnotification_email%26utm_campaign%3Dvuukle_referral&id=432081eb-6e8e-4abc-a88f-ca5357aa7244&bizUniqueId=5944375&d=0&t=opinion,lead&h=A%20new%20economic%20agenda&l=&l_d=&cl=1000&vv=1.45");
con.setRequestProperty("Accept-Encoding","gzip,deflate,sdch");
con.setRequestProperty("Accept-Language","en-US,en;q=0.8,fr;q=0.6,id;q=0.4,ms;q=0.2,zh-CN;q=0.2");
con.setRequestProperty("Cookie","__cfduid=dd2133a0e8b013a5cbe820af7bb4999801396437896235; X-Mapping-fjhppofk=A1BD2DB578E64382C2D611B70152F039; ASP.NET_SessionId=u4wzoj4yjm5lhl1bo4rqmcos; __utma=48753441.661127688.1396437913.1396437913.1398459429.2; __utmb=48753441.35.9.1398461317141; __utmc=48753441; __utmz=48753441.1398459429.2.2.utmcsr=thehindu.com|utmccn=(referral)|utmcmd=referral|utmcct=/opinion/lead/a-new-economic-agenda/article5944375.ece");
con.setDoOutput(true);
JSONObject parent=new JSONObject();
parent.put("key","R175870");
parent.put("rId","213508");
parent.put("like_dislike","1");
parent.put("bizId","432081eb-6e8e-4abc-a88f-ca5357aa7244");
OutputStreamWriter wr= new OutputStreamWriter(con.getOutputStream());
wr.write(parent.toString());
OutputStream os = con.getOutputStream();
os.write(parent.toString().getBytes("UTF-8"));
os.close();
int responseCode = con.getResponseCode();
BufferedReader in = new BufferedReader(
new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
//print result
/*
System.out.println(response.toString()+" "+counter.get());
if(response.toString().contains("response.toString()")){
counter.incrementAndGet();
}
*/
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment