Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@pjmuley
Last active July 6, 2017 05:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pjmuley/13c322f8e96913e8cde6f7c99d5c280a to your computer and use it in GitHub Desktop.
Save pjmuley/13c322f8e96913e8cde6f7c99d5c280a to your computer and use it in GitHub Desktop.
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