title: Get access token from Oauth2 rest api using java
body: <p>I need to call Oauth2 ResT API service to fetch the access token and expire_in values from the JSON file by it.</p>
  
  <p>Below is a sample CURL which i need to call using JAVA i am beginner in JAVA so not able to figure out how to do it however i can do it using shell script.</p>
  
  <pre><code>curl -u 'ClientId:Clientaccesskey' https://oauth2.url/oauth/token -X POST -d 'response_type=token&amp;client_id=ClientId&amp;username=user&amp;password=userpassword&amp;scope=process&amp;grant_type=password'
  </code></pre>
  
  <p>Sample JSON retured by above curl command --</p>
  
  <pre><code>{"access_token":"accessTokentobefetched","token_type":"bearer","refresh_token":"refreshToken","expires_in":7199,"scope":"process","jti":"somehexadecimalvaliu"}
  </code></pre>
  
  <p>In shell script we can fetch the value of access token and other fields using AWK command and other commands.</p>
  
  <p>So i need to call this CURL command in JAVA and fetch the value of access token and other keys from the JSON file.</p>
  
  <p>Any help which can help me start with this is welcome as i am new to JAVA and learning.</p>