[rabbitmq-discuss] Http API: new user
jandres
jandres at omie.es
Thu Aug 22 11:34:31 BST 2013
Hi,
i'm trying to create a new user using the HTTP API.
I can list the users that already exists, but when I try to create a new
one, I get this error:
org.springframework.web.client.ResourceAccessException: I/O error on PUT
request for "http://localhost:15672/api/users/newUser":Software caused
connection abort: recv failed; nested exception is java.net.SocketException:
Software caused connection abort: recv failed
I'm using Spring, and this is my code:
---------------
ConfigurableApplicationContext context = new
ClassPathXmlApplicationContext("config/client-rest-config.xml");
DefaultHttpClient httpClient = context.getBean(DefaultHttpClient.class);
RestTemplate restTemplate = context.getBean(RestTemplate.class);
String uri = "http://localhost:15672/api/users/newUser";
HttpHeaders headers = new HttpHeaders();
headers.setContentType( MediaType.APPLICATION_JSON );
String pass = "{\"name\":\"newUser\", \"password\":\"secret\",
\"tags\":\"administrator\"}";
HttpEntity<String> request= new HttpEntity<String>( pass, headers );
UsernamePasswordCredentials creds =
new UsernamePasswordCredentials("guest", "guest");
AuthScope authScope = new AuthScope(AuthScope.ANY_HOST,
AuthScope.ANY_PORT, AuthScope.ANY_REALM);
httpClient.getCredentialsProvider().setCredentials(authScope,
creds);
try
{
restTemplate.put( uri, request);
}catch(Exception e){
System.err.println(e);
}
try
{
restTemplate.exchange(uri, HttpMethod.PUT, request, Object.class);
}catch(Exception e){
System.err.println(e);
}
Object usuarios =
restTemplate.getForObject("http://localhost:15672/api/users", Object.class);
System.out.println("OK");
----------
I get the error in the lines:
restTemplate.put( uri, request);
...
restTemplate.exchange(uri, HttpMethod.PUT, request, Object.class);
But i can list the users in the line:
Object usuarios =
restTemplate.getForObject("http://localhost:15672/api/users", Object.class);
Thank you!
--
View this message in context: http://rabbitmq.1065348.n5.nabble.com/Http-API-new-user-tp29013.html
Sent from the RabbitMQ mailing list archive at Nabble.com.
More information about the rabbitmq-discuss
mailing list