[rabbitmq-discuss] Http API: new user

Frank Shearar frank.shearar at gmail.com
Thu Aug 22 14:08:51 BST 2013


On 22 August 2013 13:37, SAG - Jonathan Andrés <jandres at omie.es> wrote:
> No, I can't see anything in the logs, just the exception in the client.
>
> I have tried with CURL (curl -i -u guest:guest -H "content-type:applicacion/json" -XPUT -d '{"password":"secret", "tags":"administrator"}' http://localhost:15672/api/users/newUser )
>
> But I get the error: 415 Unsupported Media Type.

That's because you need "content-type:application/json". Note the "t".

frank

>
> -----Mensaje original-----
> De: Simon MacMullen [mailto:simon at rabbitmq.com]
> Enviado el: jueves, 22 de agosto de 2013 12:48
> Para: Discussions about RabbitMQ
> CC: SAG - Jonathan Andrés
> Asunto: Re: [rabbitmq-discuss] Http API: new user
>
> 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
> _______________________________________________
> rabbitmq-discuss mailing list
> rabbitmq-discuss at lists.rabbitmq.com
> https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss


More information about the rabbitmq-discuss mailing list