Search in sources :

Example 41 with KeyManagementException

use of org.wso2.carbon.apimgt.core.exception.KeyManagementException in project product-iots by wso2.

the class HTTPInvoker method sendHTTPPutWithOAuthSecurity.

public static HTTPResponse sendHTTPPutWithOAuthSecurity(String url, String payload, HashMap<String, String> headers) {
    HttpPut put = null;
    HttpResponse response = null;
    HTTPResponse httpResponse = new HTTPResponse();
    CloseableHttpClient httpclient = null;
    try {
        httpclient = (CloseableHttpClient) createHttpClient();
        StringEntity requestEntity = new StringEntity(payload, Constants.UTF_8);
        put = new HttpPut(url);
        put.setEntity(requestEntity);
        for (String key : headers.keySet()) {
            put.setHeader(key, headers.get(key));
        }
        put.setHeader(Constants.Header.AUTH, OAUTH_BEARER + oAuthToken);
        response = httpclient.execute(put);
    } 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 : 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) HttpPut(org.apache.http.client.methods.HttpPut) KeyManagementException(java.security.KeyManagementException) ClientProtocolException(org.apache.http.client.ClientProtocolException) StringEntity(org.apache.http.entity.StringEntity)

Aggregations

KeyManagementException (org.wso2.carbon.apimgt.core.exception.KeyManagementException)25 Response (feign.Response)17 Test (org.testng.annotations.Test)13 KeyManagementException (java.security.KeyManagementException)11 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)11 HashMap (java.util.HashMap)11 OAuth2IntrospectionResponse (org.wso2.carbon.apimgt.core.auth.dto.OAuth2IntrospectionResponse)11 Gson (com.google.gson.Gson)10 KeyStoreException (java.security.KeyStoreException)9 ScopeInfo (org.wso2.carbon.apimgt.core.auth.dto.ScopeInfo)9 IOException (java.io.IOException)8 OAuth2ServiceStubs (org.wso2.carbon.apimgt.core.auth.OAuth2ServiceStubs)8 DCRMServiceStub (org.wso2.carbon.apimgt.core.auth.DCRMServiceStub)7 ScopeRegistration (org.wso2.carbon.apimgt.core.auth.ScopeRegistration)7 HttpResponse (org.apache.http.HttpResponse)6 ClientProtocolException (org.apache.http.client.ClientProtocolException)6 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)6 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)6 OAuthApplicationInfo (org.wso2.carbon.apimgt.core.models.OAuthApplicationInfo)6 Scope (org.wso2.carbon.apimgt.core.models.Scope)6