Ask Your Question
0

Asynchronous Rest call issue...

asked 2014-09-24 01:03:15 -0700

anonymous user

Anonymous

updated 2014-09-25 23:31:06 -0700

When asynchronous Rest calls are made, then some of them return 401 authrozation error. The workaround that i tried was to make authenticate(String username, String credentials) method in ControllerCustomRealm.java synchronized, which resolved to problem.

But this doesnt seem like a good way to resolve it. I want a solution that is asynchronous. Please help me with this.

edit retag flag offensive close merge delete

Comments

Can you provide some more details as to what REST calls you were trying to make? Are they to URLs under /restconf or somewhere else? What version of the controller are you using? If can provide sample client code that would be helpful as well.

Devin Avery ( 2014-09-26 04:27:23 -0700 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2014-09-26 05:56:36 -0700

harshawasthi90 gravatar image

odl version : Hydrogen
here is the sample code..


import com.sun.jersey.api.client.Client; import com.sun.jersey.api.client.ClientResponse; import com.sun.jersey.api.client.WebResource; import com.sun.jersey.api.client.filter.HTTPBasicAuthFilter;

public class TestRestCall {

public static void main(String[] args) {
    new TestRestCall().run(args);
}

private void run(String[] args) {

    final HTTPBasicAuthFilter authFilter = new HTTPBasicAuthFilter("abc",
            "abc");
    final Client client = Client.create();
    client.addFilter(authFilter);
    final WebResource resource = client
            .resource("http://10.200.8.14:9191/controller/nb/v2/topology/default");

    for (int i = 1; i <= 10; i++) {
        final int j = i;
        new Thread() {
            public void run() {
                ClientResponse response = resource
                        .accept("application/xml")
                        .get(ClientResponse.class);
                if (response.getStatus() != 200) {
                    System.out.println(j + " Failed "
                            + response.getStatus());
                } else {
                    System.out.println(j + " Success");
                }
            }
        }.start();
    }
}

}


Output (It differs each time i run it..)
6 Failed 401
5 Success
8 Failed 401
7 Failed 401
10 Failed 401
4 Success
2 Success
9 Success
3 Success
1 Success

edit flag offensive delete publish link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

[hide preview]

Stats

Asked: 2014-09-24 01:03:15 -0700

Seen: 210 times

Last updated: Sep 26 '14