Skip to content

Instantly share code, notes, and snippets.

@anuragkapur
Last active August 29, 2015 14:05
Show Gist options
  • Save anuragkapur/654958ed5e527e7b101e to your computer and use it in GitHub Desktop.
Save anuragkapur/654958ed5e527e7b101e to your computer and use it in GitHub Desktop.
public class PlaygroundHttpClient {
private static final String X_FORWARDED_FOR = "X-Forwarded-For";
private void executeHttpGetOnDropwizardPlaygroundGreeting(String xForwardedFor, String name, String userAgent) {
URI uri = null;
try {
uri = new URIBuilder()
.setScheme("http")
.setHost("192.168.0.1")
.setPort(8080)
.setPath("/")
.build();
} catch (URISyntaxException e) {
e.printStackTrace();
}
HttpGet httpGet = new HttpGet(uri);
httpGet.setHeader(X_FORWARDED_FOR, xForwardedFor);
httpGet.setHeader(HttpHeaders.USER_AGENT, userAgent);
CloseableHttpClient httpclient = HttpClients.createDefault();
CloseableHttpResponse response = null;
try {
response = httpclient.execute(httpGet);
System.out.println(response);
} catch (IOException e) {
e.printStackTrace();
} finally {
if (response != null) {
try {
response.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
public static void main(String[] args) {
final PlaygroundHttpClient playgroundHttpClient = new PlaygroundHttpClient();
Runnable runnable1 = new Runnable() {
@Override
public void run() {
for(int i=0; i<100000; i++) {
playgroundHttpClient.executeHttpGetOnDropwizardPlaygroundGreeting("66.66.66.66", "svc1", "svc1");
}
}
};
new Thread(runnable1).start();
Runnable runnable2 = new Runnable() {
@Override
public void run() {
for(int i=0; i<100000; i++) {
playgroundHttpClient.executeHttpGetOnDropwizardPlaygroundGreeting("77.77.77.77", "svc2", "svc2");
}
}
};
new Thread(runnable2).start();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment