Last active
July 6, 2017 05:20
-
-
Save pjmuley/13c322f8e96913e8cde6f7c99d5c280a to your computer and use it in GitHub Desktop.
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
String client_id="85b56xxxxxxxxxxxxxxxxxxxxxxxxxb968fd"; | |
String client_secret="2B792xxxxxxxxxxxxxxxxxxxxxx3B3b1"; | |
String authURI="https://mq-us-west-2.anypoint.mulesoft.com/api/v1/authorize"; | |
// Get access token required for publish/subscribe API's | |
Client client = Client.create(); | |
WebResource webResource = client.resource(authURI); | |
String input = "client_id="+client_id+"&client_secret="+client_secret+"&grant_type=client_credentials"; | |
ClientResponse response = webResource.header("Content-Type", "application/x-www-form-urlencoded") | |
.accept("application/json") | |
.post(ClientResponse.class, input); | |
String authResponse = response.getEntity(String.class); | |
// Retireve and store access-token,org-id and env-id values from JSON response | |
JSONParser jsonParser=new JSONParser(); | |
JSONObject jsonObject= (JSONObject) jsonParser.parse(authResponse); | |
String access_token=(String)jsonObject.get("access_token"); | |
JSONObject structure = (JSONObject) jsonObject.get("simple_client"); | |
String orgId=(String)structure.get("orgId"); | |
String envId=(String)structure.get("envId"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment