http plugin updated. log plugin added.
This commit is contained in:
parent
a1a5e391b8
commit
f5f0455f3c
|
@ -1,4 +1,4 @@
|
||||||
package org.bench4q.agent.plugin.timer;
|
package org.bench4q.agent.plugin.basic;
|
||||||
|
|
||||||
import org.bench4q.agent.plugin.Behavior;
|
import org.bench4q.agent.plugin.Behavior;
|
||||||
import org.bench4q.agent.plugin.Plugin;
|
import org.bench4q.agent.plugin.Plugin;
|
|
@ -0,0 +1,132 @@
|
||||||
|
package org.bench4q.agent.plugin.basic;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.io.OutputStreamWriter;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URL;
|
||||||
|
import org.bench4q.agent.plugin.Behavior;
|
||||||
|
import org.bench4q.agent.plugin.Plugin;
|
||||||
|
|
||||||
|
@Plugin("Http")
|
||||||
|
public class HttpPlugin {
|
||||||
|
|
||||||
|
public HttpPlugin() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Behavior("Get")
|
||||||
|
public boolean get(String url) {
|
||||||
|
try {
|
||||||
|
URL target = new URL(url);
|
||||||
|
HttpURLConnection httpURLConnection = (HttpURLConnection) target
|
||||||
|
.openConnection();
|
||||||
|
httpURLConnection.setDoOutput(false);
|
||||||
|
httpURLConnection.setDoInput(true);
|
||||||
|
httpURLConnection.setUseCaches(false);
|
||||||
|
httpURLConnection.setRequestMethod("GET");
|
||||||
|
BufferedReader bufferedReader = new BufferedReader(
|
||||||
|
new InputStreamReader(httpURLConnection.getInputStream()));
|
||||||
|
int temp = -1;
|
||||||
|
StringBuffer stringBuffer = new StringBuffer();
|
||||||
|
while ((temp = bufferedReader.read()) != -1) {
|
||||||
|
stringBuffer.append((char) temp);
|
||||||
|
}
|
||||||
|
bufferedReader.close();
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Behavior("Post")
|
||||||
|
public boolean post(String url, String content) {
|
||||||
|
try {
|
||||||
|
URL target = new URL(url);
|
||||||
|
HttpURLConnection httpURLConnection = (HttpURLConnection) target
|
||||||
|
.openConnection();
|
||||||
|
httpURLConnection.setDoOutput(true);
|
||||||
|
httpURLConnection.setDoInput(true);
|
||||||
|
httpURLConnection.setUseCaches(false);
|
||||||
|
httpURLConnection.setRequestMethod("POST");
|
||||||
|
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(
|
||||||
|
httpURLConnection.getOutputStream());
|
||||||
|
outputStreamWriter.write(content);
|
||||||
|
outputStreamWriter.flush();
|
||||||
|
outputStreamWriter.close();
|
||||||
|
BufferedReader bufferedReader = new BufferedReader(
|
||||||
|
new InputStreamReader(httpURLConnection.getInputStream()));
|
||||||
|
int temp = -1;
|
||||||
|
StringBuffer stringBuffer = new StringBuffer();
|
||||||
|
while ((temp = bufferedReader.read()) != -1) {
|
||||||
|
stringBuffer.append((char) temp);
|
||||||
|
}
|
||||||
|
bufferedReader.close();
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Behavior("Put")
|
||||||
|
public boolean put(String url, String content) {
|
||||||
|
try {
|
||||||
|
URL target = new URL(url);
|
||||||
|
HttpURLConnection httpURLConnection = (HttpURLConnection) target
|
||||||
|
.openConnection();
|
||||||
|
httpURLConnection.setDoOutput(true);
|
||||||
|
httpURLConnection.setDoInput(true);
|
||||||
|
httpURLConnection.setUseCaches(false);
|
||||||
|
httpURLConnection.setRequestMethod("PUT");
|
||||||
|
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(
|
||||||
|
httpURLConnection.getOutputStream());
|
||||||
|
outputStreamWriter.write(content);
|
||||||
|
outputStreamWriter.flush();
|
||||||
|
outputStreamWriter.close();
|
||||||
|
BufferedReader bufferedReader = new BufferedReader(
|
||||||
|
new InputStreamReader(httpURLConnection.getInputStream()));
|
||||||
|
int temp = -1;
|
||||||
|
StringBuffer stringBuffer = new StringBuffer();
|
||||||
|
while ((temp = bufferedReader.read()) != -1) {
|
||||||
|
stringBuffer.append((char) temp);
|
||||||
|
}
|
||||||
|
bufferedReader.close();
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Behavior("Delete")
|
||||||
|
public boolean delete(String url, String content) {
|
||||||
|
try {
|
||||||
|
URL target = new URL(url);
|
||||||
|
HttpURLConnection httpURLConnection = (HttpURLConnection) target
|
||||||
|
.openConnection();
|
||||||
|
httpURLConnection.setDoOutput(true);
|
||||||
|
httpURLConnection.setDoInput(true);
|
||||||
|
httpURLConnection.setUseCaches(false);
|
||||||
|
httpURLConnection.setRequestMethod("DELETE");
|
||||||
|
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(
|
||||||
|
httpURLConnection.getOutputStream());
|
||||||
|
outputStreamWriter.write(content);
|
||||||
|
outputStreamWriter.flush();
|
||||||
|
outputStreamWriter.close();
|
||||||
|
BufferedReader bufferedReader = new BufferedReader(
|
||||||
|
new InputStreamReader(httpURLConnection.getInputStream()));
|
||||||
|
int temp = -1;
|
||||||
|
StringBuffer stringBuffer = new StringBuffer();
|
||||||
|
while ((temp = bufferedReader.read()) != -1) {
|
||||||
|
stringBuffer.append((char) temp);
|
||||||
|
}
|
||||||
|
bufferedReader.close();
|
||||||
|
return true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
package org.bench4q.agent.plugin.basic;
|
||||||
|
|
||||||
|
import org.bench4q.agent.plugin.Behavior;
|
||||||
|
import org.bench4q.agent.plugin.Plugin;
|
||||||
|
|
||||||
|
@Plugin("Log")
|
||||||
|
public class LogPlugin {
|
||||||
|
public LogPlugin() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Behavior("Log")
|
||||||
|
public boolean log(String message) {
|
||||||
|
System.out.println(message);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,72 +0,0 @@
|
||||||
package org.bench4q.agent.plugin.http;
|
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.io.OutputStreamWriter;
|
|
||||||
import java.net.HttpURLConnection;
|
|
||||||
import java.net.URL;
|
|
||||||
import org.bench4q.agent.plugin.Behavior;
|
|
||||||
import org.bench4q.agent.plugin.Plugin;
|
|
||||||
|
|
||||||
@Plugin("Http")
|
|
||||||
public class HttpPlugin {
|
|
||||||
|
|
||||||
public HttpPlugin() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Behavior("Get")
|
|
||||||
public boolean get(String url) {
|
|
||||||
try {
|
|
||||||
URL target = new URL(url);
|
|
||||||
HttpURLConnection httpURLConnection = (HttpURLConnection) target
|
|
||||||
.openConnection();
|
|
||||||
httpURLConnection.setDoOutput(false);
|
|
||||||
httpURLConnection.setDoInput(true);
|
|
||||||
httpURLConnection.setUseCaches(false);
|
|
||||||
httpURLConnection.setRequestMethod("GET");
|
|
||||||
BufferedReader bufferedReader = new BufferedReader(
|
|
||||||
new InputStreamReader(httpURLConnection.getInputStream()));
|
|
||||||
int temp = -1;
|
|
||||||
StringBuffer stringBuffer = new StringBuffer();
|
|
||||||
while ((temp = bufferedReader.read()) != -1) {
|
|
||||||
stringBuffer.append((char) temp);
|
|
||||||
}
|
|
||||||
bufferedReader.close();
|
|
||||||
return true;
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Behavior("Post")
|
|
||||||
public boolean post(String url, String content) {
|
|
||||||
try {
|
|
||||||
URL target = new URL(url);
|
|
||||||
HttpURLConnection httpURLConnection = (HttpURLConnection) target
|
|
||||||
.openConnection();
|
|
||||||
httpURLConnection.setDoOutput(true);
|
|
||||||
httpURLConnection.setDoInput(true);
|
|
||||||
httpURLConnection.setUseCaches(false);
|
|
||||||
httpURLConnection.setRequestMethod("POST");
|
|
||||||
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(
|
|
||||||
httpURLConnection.getOutputStream());
|
|
||||||
outputStreamWriter.write(content);
|
|
||||||
outputStreamWriter.flush();
|
|
||||||
outputStreamWriter.close();
|
|
||||||
BufferedReader bufferedReader = new BufferedReader(
|
|
||||||
new InputStreamReader(httpURLConnection.getInputStream()));
|
|
||||||
int temp = -1;
|
|
||||||
StringBuffer stringBuffer = new StringBuffer();
|
|
||||||
while ((temp = bufferedReader.read()) != -1) {
|
|
||||||
stringBuffer.append((char) temp);
|
|
||||||
}
|
|
||||||
bufferedReader.close();
|
|
||||||
return true;
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue