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;
}
Aggregations