Search in sources :

Example 41 with HTTPResponse

use of org.wso2.mdm.qsg.dto.HTTPResponse in project product-iots by wso2.

the class WindowsEnrollment method testBST.

@Test(groups = Constants.WindowsEnrollment.WINDOWS_ENROLLMENT_GROUP, description = "Test Windows BST.")
public void testBST() throws Exception {
    JSONObject bsdObject = new JSONObject(Constants.WindowsEnrollment.BSD_PAYLOAD);
    JSONObject childObject = bsdObject.getJSONObject("credentials");
    JSONObject modifiedObject = new JSONObject();
    modifiedObject.put("token", OAuthUtil.getOAuthToken(backendHTTPURL, backendHTTPSURL));
    childObject.put("token", modifiedObject);
    HttpResponse response = client.post(Constants.WindowsEnrollment.BSD_URL, Constants.WindowsEnrollment.BSD_PAYLOAD);
    bsd = response.getData();
    Assert.assertEquals(response.getResponseCode(), HttpStatus.SC_OK);
}
Also used : JSONObject(org.json.JSONObject) HttpResponse(org.wso2.carbon.automation.test.utils.http.client.HttpResponse) Test(org.testng.annotations.Test)

Example 42 with HTTPResponse

use of org.wso2.mdm.qsg.dto.HTTPResponse in project product-iots by wso2.

the class WindowsEnrollment method testMSXCEP.

@Test(groups = Constants.WindowsEnrollment.WINDOWS_ENROLLMENT_GROUP, description = "Test Windows MS XCEP post.", dependsOnMethods = "testBST")
public void testMSXCEP() throws Exception {
    String xml = readXML(Constants.WindowsEnrollment.MS_XCEP_FILE, Constants.UTF8);
    String payload = xml.replace(BSD_PLACEHOLDER, bsd);
    client.setHttpHeader(Constants.CONTENT_TYPE, Constants.APPLICATION_SOAP_XML);
    HttpResponse response = client.post(Constants.WindowsEnrollment.MS_EXCEP, payload);
    Assert.assertEquals(response.getResponseCode(), HttpStatus.SC_ACCEPTED);
}
Also used : HttpResponse(org.wso2.carbon.automation.test.utils.http.client.HttpResponse) Test(org.testng.annotations.Test)

Example 43 with HTTPResponse

use of org.wso2.mdm.qsg.dto.HTTPResponse in project product-iots by wso2.

the class WindowsEnrollment method testDiscoveryPost.

@Test(groups = Constants.WindowsEnrollment.WINDOWS_ENROLLMENT_GROUP, description = "Test Windows Discovery post.")
public void testDiscoveryPost() throws Exception {
    String xml = readXML(Constants.WindowsEnrollment.DISCOVERY_POST_FILE, Constants.UTF8);
    client.setHttpHeader(Constants.CONTENT_TYPE, Constants.APPLICATION_SOAP_XML);
    HttpResponse response = client.post(Constants.WindowsEnrollment.DISCOVERY_POST_URL, xml);
    Assert.assertEquals(response.getResponseCode(), HttpStatus.SC_OK);
}
Also used : HttpResponse(org.wso2.carbon.automation.test.utils.http.client.HttpResponse) Test(org.testng.annotations.Test)

Example 44 with HTTPResponse

use of org.wso2.mdm.qsg.dto.HTTPResponse in project product-iots by wso2.

the class HTTPInvoker method sendHTTPPostWithOAuthSecurity.

public static HTTPResponse sendHTTPPostWithOAuthSecurity(String url, HttpEntity entity, HashMap<String, String> headers) {
    HttpPost post = null;
    HttpResponse response = null;
    HTTPResponse httpResponse = new HTTPResponse();
    CloseableHttpClient httpclient = null;
    try {
        httpclient = (CloseableHttpClient) createHttpClient();
        post = new HttpPost(url);
        post.setEntity(entity);
        for (String key : headers.keySet()) {
            post.setHeader(key, headers.get(key));
        }
        post.setHeader(Constants.Header.AUTH, OAUTH_BEARER + oAuthToken);
        response = httpclient.execute(post);
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    } catch (KeyStoreException e) {
        e.printStackTrace();
    } catch (KeyManagementException e) {
        e.printStackTrace();
    }
    BufferedReader rd = null;
    try {
        rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
    } catch (IOException e) {
        e.printStackTrace();
    }
    StringBuffer result = new StringBuffer();
    String line = "";
    try {
        while ((line = rd.readLine()) != null) {
            result.append(line);
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    httpResponse.setResponseCode(response.getStatusLine().getStatusCode());
    httpResponse.setResponse(result.toString());
    try {
        httpclient.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return httpResponse;
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HTTPResponse(org.wso2.mdm.qsg.dto.HTTPResponse) HttpResponse(org.apache.http.HttpResponse) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) KeyStoreException(java.security.KeyStoreException) KeyManagementException(java.security.KeyManagementException) ClientProtocolException(org.apache.http.client.ClientProtocolException)

Example 45 with HTTPResponse

use of org.wso2.mdm.qsg.dto.HTTPResponse in project product-iots by wso2.

the class HTTPInvoker method sendHTTPPostWithOAuthSecurity.

public static HTTPResponse sendHTTPPostWithOAuthSecurity(String url, String payload, HashMap<String, String> headers) {
    HttpPost post = null;
    HttpResponse response = null;
    HTTPResponse httpResponse = new HTTPResponse();
    CloseableHttpClient httpclient = null;
    try {
        httpclient = (CloseableHttpClient) createHttpClient();
        StringEntity requestEntity = new StringEntity(payload, Constants.UTF_8);
        post = new HttpPost(url);
        post.setEntity(requestEntity);
        for (String key : headers.keySet()) {
            post.setHeader(key, headers.get(key));
        }
        post.setHeader(Constants.Header.AUTH, OAUTH_BEARER + oAuthToken);
        response = httpclient.execute(post);
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    } catch (KeyStoreException e) {
        e.printStackTrace();
    } catch (KeyManagementException e) {
        e.printStackTrace();
    }
    BufferedReader rd = null;
    try {
        rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
    } catch (IOException e) {
        e.printStackTrace();
    }
    StringBuffer result = new StringBuffer();
    String line = "";
    try {
        while ((line = rd.readLine()) != null) {
            result.append(line);
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    httpResponse.setResponseCode(response.getStatusLine().getStatusCode());
    httpResponse.setResponse(result.toString());
    try {
        httpclient.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return httpResponse;
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HTTPResponse(org.wso2.mdm.qsg.dto.HTTPResponse) HttpResponse(org.apache.http.HttpResponse) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) KeyStoreException(java.security.KeyStoreException) KeyManagementException(java.security.KeyManagementException) ClientProtocolException(org.apache.http.client.ClientProtocolException) StringEntity(org.apache.http.entity.StringEntity)

Aggregations

HttpResponse (org.wso2.carbon.automation.test.utils.http.client.HttpResponse)75 Test (org.testng.annotations.Test)72 JsonObject (com.google.gson.JsonObject)15 HTTPResponse (org.wso2.mdm.qsg.dto.HTTPResponse)15 JsonParser (com.google.gson.JsonParser)14 JSONObject (org.json.simple.JSONObject)11 HashMap (java.util.HashMap)9 JsonArray (com.google.gson.JsonArray)8 IOException (java.io.IOException)8 HttpURLConnection (java.net.HttpURLConnection)8 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)7 KeyManagementException (java.security.KeyManagementException)6 KeyStoreException (java.security.KeyStoreException)6 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)6 HttpResponse (org.apache.http.HttpResponse)6 ClientProtocolException (org.apache.http.client.ClientProtocolException)6 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)6 HttpPost (org.apache.http.client.methods.HttpPost)5 JSONArray (org.json.simple.JSONArray)5 JsonElement (com.google.gson.JsonElement)4