Example usage for org.apache.http.client.methods CloseableHttpResponse getProtocolVersion

List of usage examples for org.apache.http.client.methods CloseableHttpResponse getProtocolVersion

Introduction

In this page you can find the example usage for org.apache.http.client.methods CloseableHttpResponse getProtocolVersion.

Prototype

ProtocolVersion getProtocolVersion();

Source Link

Usage

From source file:org.jboss.additional.testsuite.jdkall.present.web.servlet.headers.CookieHeaderServletTestCase.java

@ATTest({ "modules/testcases/jdkAll/Wildfly/web/src/main/java#13.0.0",
        "modules/testcases/jdkAll/Eap71x-Proposed/web/src/main/java#7.1.4",
        "modules/testcases/jdkAll/Eap71x/web/src/main/java#7.1.4" })
@OperateOnDeployment(DEPLOYMENT)/*from   w  ww.jav a2  s. c  om*/
public void headerProtocolTest(@ArquillianResource URL url) throws Exception {
    URL testURL = new URL(url.toString() + "cookieHeaderServlet");

    final HttpGet request = new HttpGet(testURL.toString());
    request.setProtocolVersion(HttpVersion.HTTP_1_0);
    CloseableHttpClient httpClient = HttpClientBuilder.create().build();
    CloseableHttpResponse response = null;

    response = httpClient.execute(request);
    System.out.println("Protocol Version : " + response.getProtocolVersion());
    Assert.assertTrue("Protocol Version should be HTTP/1.1.",
            response.getProtocolVersion().toString().contains("HTTP/1.1"));
    IOUtils.closeQuietly(response);
    httpClient.close();

}

From source file:com.lehman.ic9.net.httpClient.java

/**
 * Updates the Javascript response object.
 * @param info is the Javascript response object to update.
 * @param resp is a ClosableHttpResponse object with the actual response.
 * @throws NoSuchMethodException Exception
 * @throws ScriptException Exception/* www .j av  a2  s .  c o  m*/
 */
private void getResponseInfo(Map<String, Object> info, CloseableHttpResponse resp)
        throws NoSuchMethodException, ScriptException {
    // Locale
    Locale jloc = resp.getLocale();
    info.put("locale", jloc.toLanguageTag());

    info.put("protocol", resp.getProtocolVersion().toString());
    info.put("protocolMajor", resp.getProtocolVersion().getMajor());
    info.put("protocolMinor", resp.getProtocolVersion().getMinor());
    info.put("statusLine", resp.getStatusLine().toString());
    info.put("statusCode", resp.getStatusLine().getStatusCode());
    info.put("statusReasonPhrase", resp.getStatusLine().getReasonPhrase());

    // Headers.
    Map<String, Object> hmap = this.eng.newObj(null);
    Header hdrs[] = resp.getAllHeaders();
    for (Header hdr : hdrs) {
        hmap.put(hdr.getName(), hdr.getValue());
    }
    info.put("headers", hmap);

    // Cookies
    Object clist = this.eng.newList();
    this.jsobj.put("cookies", clist);
    for (Cookie C : this.cs.getCookies()) {
        Object nc = this.getApacheCookie(C);
        this.eng.invokeMethod(clist, "push", nc);
    }
}

From source file:Utilities.WebUtilities.java

public String createVM(Hashtable parameters) throws IOException {

    //http://nitlab3.inf.uth.gr:4100/vm-create/server-john/precise/small/192.168.100.10/255.255.254.0/192.168.100.1/node

    String uri = "http://" + _config.getNitosServer() + ".inf.uth.gr:4100/vm-create/";
    String methodResponse = "";

    String vmName = String.valueOf(parameters.get("vmName"));
    String OS = String.valueOf(parameters.get("OS"));
    String vmType = String.valueOf(parameters.get("vmType"));
    String interIP = String.valueOf(parameters.get("interIP"));
    String interMask = String.valueOf(parameters.get("interMask"));
    String interDefaultGateway = String.valueOf(parameters.get("interDefaultGateway"));
    String hostName = String.valueOf(parameters.get("hostName"));

    uri += vmName + "/";
    uri += OS + "/";
    uri += vmType + "/";
    uri += interIP + "/";
    uri += interMask + "/";
    uri += interDefaultGateway + "/";
    uri += hostName;/*from  w  ww .  j ava  2 s .  c  o m*/

    CloseableHttpClient httpclient = HttpClients.createDefault();
    HttpGet httpget = new HttpGet(uri);
    CloseableHttpResponse response = httpclient.execute(httpget);

    try {

        System.out.println(response.getProtocolVersion());
        System.out.println(response.getStatusLine().getStatusCode());
        System.out.println(response.getStatusLine().getReasonPhrase());
        System.out.println(response.getStatusLine().toString());

    } finally {
        response.close();
    }

    return methodResponse;
}

From source file:Utilities.WebUtilities.java

public String startVM(String vmName, String hostName) throws IOException {

    //http://nitlab3.inf.uth.gr:4100/vm-start/server-john

    String uri = "http://" + _config.getNitosServer() + ".inf.uth.gr:4100/vm-start/";
    String methodResponse = "";

    uri += vmName;/*from  w w w. j a  v a  2  s  .c o m*/
    uri += "/" + hostName;

    CloseableHttpClient httpclient = HttpClients.createDefault();
    HttpGet httpget = new HttpGet(uri);
    CloseableHttpResponse response = httpclient.execute(httpget);

    try {

        System.out.println(response.getProtocolVersion());
        System.out.println(response.getStatusLine().getStatusCode());
        System.out.println(response.getStatusLine().getReasonPhrase());
        System.out.println(response.getStatusLine().toString());

    } finally {
        response.close();
    }

    return methodResponse;
}

From source file:Utilities.WebUtilities.java

public String deleteVM(String name) throws IOException {

    String uri = "http://" + _config.getNitosServer() + ".inf.uth.gr:4100/vm-destroy/";
    String methodResponse = "";

    uri += name;//from  w  w  w.j av a 2 s  .  co m

    CloseableHttpClient httpclient = HttpClients.createDefault();
    HttpGet httpget = new HttpGet(uri);

    CloseableHttpResponse response = httpclient.execute(httpget);

    try {

        System.out.println(response.getProtocolVersion());
        System.out.println(response.getStatusLine().getStatusCode());
        System.out.println(response.getStatusLine().getReasonPhrase());
        System.out.println(response.getStatusLine().toString());

    } finally {
        response.close();
    }

    return methodResponse;
}

From source file:Utilities.WebUtilities.java

public void updateHostStats(String hostName, int instance, int slot) throws IOException {

    String uri = "http://" + _config.getNitosServer() + ".inf.uth.gr:4100/host/";
    uri += hostName;// w ww .  j a  v  a 2 s .  co m

    CloseableHttpClient httpclient = HttpClients.createDefault();
    HttpGet httpget = new HttpGet(uri);
    CloseableHttpResponse response = httpclient.execute(httpget);

    try {

        String json = "";
        String output;
        BufferedReader br = new BufferedReader(new InputStreamReader((response.getEntity().getContent())));

        while ((output = br.readLine()) != null) {
            json += output;
        }

        JSONObject body = new JSONObject(json);

        System.out.println(response.getProtocolVersion());
        System.out.println(response.getStatusLine().getStatusCode());
        System.out.println(response.getStatusLine().getReasonPhrase());
        System.out.println(response.getStatusLine().toString());

    } catch (Exception ex) {
        System.out.println(ex.getMessage());
    } finally {
        response.close();
    }

}