Hafiz,

There is no code sample for it now. To create one , you need to go through the 
code base for Ranger Public Api.

Check it in git hub for ranger source public api 
https://github.com/apache/incubator-ranger/blob/master/security-admin/src/main/java/org/apache/ranger/rest/PublicAPIs.java

Idea is what ever the responses you got in your GET operation, you need to map 
it to the POST operation's object with new values for repo and do the post 
call. ( you will be doing a of bunch of set operation on the object and do POST 
in your java )

Hope this gives you the idea.

Thanks,
Ramesh



From: Hafiz Mujadid <[email protected]<mailto:[email protected]>>
Reply-To: 
"[email protected]<mailto:[email protected]>" 
<[email protected]<mailto:[email protected]>>
Date: Saturday, August 8, 2015 at 1:27 PM
To: "[email protected]<mailto:[email protected]>" 
<[email protected]<mailto:[email protected]>>
Subject: Re: issue with rest api

Hi Ramesh

thanks for your response. I got the solution. here is my working code


val httpclient = new DefaultHttpClient()
    val httpget = new HttpGet(repo_url + "/" + id)
    httpget.addHeader(BasicScheme.authenticate(
      new UsernamePasswordCredentials(username, password),
      "UTF-8", false))
    httpget.setHeader("Accept", "application/json")
    val response = httpclient.execute(httpget)
    EntityUtils.toString(response.getEntity())


But I am failing in how to create a repository using rest api. is there any 
java code example?

thanks

On Sun, Aug 9, 2015 at 12:40 AM, Ramesh Mani 
<[email protected]<mailto:[email protected]>> wrote:
Hafiz

Please try using the following if it fetches.

"http://localhost:6080/service/public/api/repository<http://localhost:6080/service/public/api/repository/1>?type=hdfs"

For a quicker check you can use curl calls.

curl -i -X GET --header "Accept:application/json" -H "Content-Type: 
application/json" -u admin:admin 
http://localhost:6080/service/public/api/repository?type=hdfs

Also let me know the name of  service/ repository which you created and which 
you are querying to download.

Try this and let me know.

Regards,
Ramesh

From: Hafiz Mujadid <[email protected]<mailto:[email protected]>>
Reply-To: 
"[email protected]<mailto:[email protected]>" 
<[email protected]<mailto:[email protected]>>
Date: Saturday, August 8, 2015 at 10:18 AM
To: "[email protected]<mailto:[email protected]>" 
<[email protected]<mailto:[email protected]>>
Subject: issue with rest api

Hi

I am trying to use rest api's in my java/scala code

here is my code
 val httpclient = new DefaultHttpClient()
    val auth = new AuthScope(host, AuthScope.ANY_PORT)
    val credentials = new UsernamePasswordCredentials("admin", "admin")
    httpclient.getCredentialsProvider()
      .setCredentials(auth, credentials)
    val httpget = new 
HttpGet("http://localhost:6080/service/public/api/repository/1";)
    httpget.setHeader("Accept", "application/xml")
    val response = httpclient.execute(httpget)
    val entity = response.getEntity
    if (entity != null) {
      val in = new BufferedReader(new InputStreamReader(entity.getContent()))
      var line = in.readLine()
      var response = new StringBuffer()
      while (line != null) {
        response.append(line + "/n")
        line = in.readLine()
      }
      in.close()
      println(response.toString())
    }


But it is not returning repository details



any suggestion how can i use rest services in my java application?

Thanks



--
Regards: HAFIZ MUJADID

Reply via email to