Domanda

I am trying to create a new exchange using the http api request. The URL I have used to create Exchange is , http://guest:guest@localhost:55672/api/exchanges/%2F/myexq1 but it gives me error of 401 Unauthorized. I am using chrome rest client to do this request. What could be the reason? Any help will appreciated.

È stato utile?

Soluzione

Have solve the problem in other way. The error is there while using the URL http://guest:guest@localhost:55672/api/exchanges/%2F/myexq1 . But to acheive my goal I have written a small class. Here is the code:

        DefaultHttpClient httpClient = new DefaultHttpClient();         
        HttpHost targetHost = new HttpHost("xx.xx.xx.xx", 55672, "http");

        HttpPut request = new HttpPut(
                "/api/queues/%2F/q1");

        httpClient.getCredentialsProvider().setCredentials(
                new AuthScope(targetHost.getHostName(), targetHost.getPort()), 
                new UsernamePasswordCredentials("guest", "guest"));

        AuthCache authCache = new BasicAuthCache();
        BasicScheme basicAuth = new BasicScheme();
        authCache.put(targetHost, basicAuth);
        BasicHttpContext localcontext = new BasicHttpContext();
        localcontext.setAttribute(ClientContext.AUTH_CACHE, authCache);

        request.addHeader("Content-Type", "application/json");

        StringEntity input = new StringEntity(
                 "{\"vhost\":\"/\",\"durable\":\"false\",\"auto_delete\":\"false\",\"arguments\":{}}");

        request.setEntity(input);

        HttpResponse response = httpClient.execute(targetHost, request, localcontext);

Jar I have included is:

commons-codec-1.4
commons-logging-1.1.1
httpclient-4.1.3
httpclient-cache-4.1.3
httpcore-4.1.4
httpmime-4.1.3
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top