[rabbitmq-discuss] Http API: new user

Simon MacMullen simon at rabbitmq.com
Thu Aug 22 11:48:15 BST 2013


That looks superficially like it should work. Does anything show up in 
the logs when it fails?

Cheers, Simon

On 22/08/2013 11:34AM, jandres wrote:
> 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.
> _______________________________________________
> rabbitmq-discuss mailing list
> rabbitmq-discuss at lists.rabbitmq.com
> https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss
>

-- 
Simon MacMullen
RabbitMQ, Pivotal


More information about the rabbitmq-discuss mailing list