Created
August 9, 2012 09:11
-
-
Save krmahadevan/3302548 to your computer and use it in GitHub Desktop.
This class shows you how to post against a grid servlet and get information.
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
package raw.selenium; | |
import java.io.BufferedReader; | |
import java.io.IOException; | |
import java.io.InputStreamReader; | |
import java.net.URL; | |
import org.apache.http.HttpHost; | |
import org.apache.http.HttpResponse; | |
import org.apache.http.client.ClientProtocolException; | |
import org.apache.http.client.HttpClient; | |
import org.apache.http.impl.client.DefaultHttpClient; | |
import org.apache.http.message.BasicHttpRequest; | |
import org.json.JSONException; | |
import org.json.JSONObject; | |
import org.testng.Assert; | |
public class NodeInfoFromGrid { | |
static String hubHost = "localhost"; | |
static int hubPort = 4444; | |
public static void main(String[] args) throws ClientProtocolException, IOException, JSONException { | |
URL proxyApi = new URL("http://" + hubHost + ":" + hubPort + "/grid/admin/MyConsoleServlet"); | |
HttpClient client = new DefaultHttpClient(); | |
BasicHttpRequest r = new BasicHttpRequest("GET", proxyApi.toExternalForm()); | |
HttpHost host = new HttpHost(hubHost, hubPort); | |
HttpResponse response = client.execute(host, r); | |
Assert.assertEquals(200, response.getStatusLine().getStatusCode()); | |
JSONObject o = extractObject(response); | |
System.out.println(o); | |
} | |
private static JSONObject extractObject(HttpResponse resp) throws IOException, JSONException { | |
BufferedReader rd = new BufferedReader(new InputStreamReader(resp.getEntity().getContent())); | |
StringBuilder s = new StringBuilder(); | |
String line; | |
while ((line = rd.readLine()) != null) { | |
s.append(line); | |
} | |
rd.close(); | |
return new JSONObject(s.toString()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This class can be used to post against a Servlet as shown in the gist : https://gist.github.com/3302497