-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #38 from project-sunbird/release-1.12
Release 1.12
- Loading branch information
Showing
4 changed files
with
138 additions
and
117 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
47 changes: 47 additions & 0 deletions
47
keycloak/sms-provider/src/main/java/org/sunbird/keycloak/utils/HttpClient.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package org.sunbird.keycloak.utils; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import java.util.Map; | ||
import javax.ws.rs.core.HttpHeaders; | ||
import javax.ws.rs.core.MediaType; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.apache.http.HttpResponse; | ||
import org.apache.http.client.methods.CloseableHttpResponse; | ||
import org.apache.http.client.methods.HttpPost; | ||
import org.apache.http.entity.StringEntity; | ||
import org.apache.http.impl.client.CloseableHttpClient; | ||
import org.apache.http.impl.client.HttpClients; | ||
import org.jboss.logging.Logger; | ||
|
||
public class HttpClient { | ||
|
||
private static Logger logger = Logger.getLogger(HttpClient.class); | ||
|
||
private HttpClient() {} | ||
|
||
public static HttpResponse post(Map<String, Object> requestBody, String uri, | ||
String authorizationKey) { | ||
logger.debug("HttpClient: post called"); | ||
try (CloseableHttpClient client = HttpClients.createDefault()) { | ||
ObjectMapper mapper = new ObjectMapper(); | ||
HttpPost httpPost = new HttpPost(uri); | ||
logger.debug("HttpClient:post: uri = " + uri); | ||
String authKey = Constants.BEARER + " " + authorizationKey; | ||
StringEntity entity = new StringEntity(mapper.writeValueAsString(requestBody)); | ||
logger.debug("HttpClient:post: request entity = " + entity); | ||
httpPost.setEntity(entity); | ||
httpPost.setHeader(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON); | ||
httpPost.setHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON); | ||
if (StringUtils.isNotBlank(authKey)) { | ||
httpPost.setHeader(HttpHeaders.AUTHORIZATION, authKey); | ||
} | ||
CloseableHttpResponse response = client.execute(httpPost); | ||
logger.debug("HttpClient:post: statusCode = " + response.getStatusLine().getStatusCode()); | ||
return response; | ||
} catch (Exception e) { | ||
logger.error("HttpClient:post: Exception occurred = " + e); | ||
} | ||
return null; | ||
} | ||
|
||
} |
This file contains 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