Hi,
Hafiz is right, you need to set the username/password in the request
header. Also make sure that the user you are setting has either of the
following roles: Admin, Keyadmin or Delegate Admin.
Since only users with these roles have permission to view the policy.

Hi,



Regard,
Bhavik Patel
+91-7208744109

On Tue, Jun 21, 2016 at 10:56 AM, Hafiz Mujadid <[email protected]>
wrote:

> Hi,
> You need to set username and password in your http request. You can modify
> following code to do so
>
> DefaultHttpClient httpclient = new DefaultHttpClient()HttpGet httpget
> = new HttpGet(url)
> httpget.setHeader("Content-Type",
> "application/json")httpget.setHeader("Accept",
> "application/json")httpget.addHeader(BasicScheme.authenticate(  new
> UsernamePasswordCredentials(RANGER_USERNAME,
> RANGER_PASSWORD),                       "UTF-8", false))val response =
> httpclient.execute(httpget)
>
>
> On Mon, Jun 20, 2016 at 1:30 PM, haihui xu <[email protected]> wrote:
>
> >     Hi, Ranger team!  I  recently study on ranger, and call ranger rest
> api
> >  by httpclient, but it failed!
> >     The following is mycode:
> >
> > public static void testGetRequest(String url) throws
> > IllegalStateException, IOException {
> > HttpClient client = new HttpClient();
> > StringBuilder sb = new StringBuilder();
> > InputStream ins = null;
> > GetMethod method = new GetMethod(url);
> > method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new
> > DefaultHttpMethodRetryHandler(3, false));
> > int statusCode = client.executeMethod(method);
> > System.out.println("statusCode: " + statusCode);
> > if (statusCode == HttpStatus.SC_OK) {
> > ins = method.getResponseBodyAsStream();
> > byte[] b = new byte[1024];
> > int r_len = 0;
> > while ((r_len = ins.read(b)) > 0) {
> > sb.append(new String(b, 0, r_len, method.getResponseCharSet()));
> > }
> > }
> > method.releaseConnection();
> > if (ins != null) {
> > ins.close();
> > }
> > }
> >
> >       public static void main(String[] args) throws Exception {
> > String url = "http://10.133.47.146:6080/service/public/v2/api/policy/1";;
> > testGetRequest(url);
> > }
> >
> > Run the above program, the statusCode is 401!  Unauthorized !
> > Could I add  any parameter when I call the rest api? How to resolve the
> > problem? I hope you can describe how to call ranger rest api  on
> > https://cwiki.apache.org/confluence/display/RANGER/Index .
> >
> > Thank you very much! Good Luck!
> >
> > Haihui Xu.
> >
>
>
>
> --
> Regards: HAFIZ MUJADID
>

Reply via email to