400 Bad Request when trying to read messages from a queue

1,135 views
Skip to first unread message

Anisha Kamble

unread,
Apr 7, 2016, 5:38:54 PM4/7/16
to rabbitmq-users
API URL I am using: http://xyz:55672/api/queues/%2F/abcDeadLetterQueue.DEV/get

Following is the POST request (Java/Apache HTTP):

String encoding = Base64.encodeBase64String("user:password"
.getBytes());

HttpClient httpClient = HttpClients.createDefault();
HttpPost httpPostRequest = new HttpPost("http://xyz:55672/api/queues/%2F/abcDeadLetterQueue.DEV/get"));
httpPostRequest.setHeader("Authorization", "Basic " + encoding);

List<NameValuePair> params = new ArrayList<NameValuePair>(3);
params.add(new BasicNameValuePair("count", "1"));
params.add(new BasicNameValuePair("requeue", "true"));
params.add(new BasicNameValuePair("encoding", "auto"));

httpPostRequest.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
HttpResponse httpPostResponse = httpClient.execute(httpPostRequest);

Response:
HttpResponseProxy{HTTP/1.1 400 Bad Request [Server: MochiWeb/1.1 WebMachine/1.9.0 (someone had painted it blue), Date: Thu, 07 Apr 2016 21:23:33 GMT, Content-Type: text/html, Content-Length: 43] ResponseEntityProxy{[Content-Type: text/html,Content-Length: 43,Chunked: false]}}

Hitting the same URL with the same credentials through the browser is giving me a correct response. However, I I am not getting it through the code.

Any ideas as to what I could be doing wrong? The RabbitMQ server is up and running (2/3 nodes).

Thank you.

Michael Klishin

unread,
Apr 7, 2016, 5:51:26 PM4/7/16
to rabbitm...@googlegroups.com, Anisha Kamble
On 8 April 2016 at 00:38:57, Anisha Kamble (tyw...@gmail.com) wrote:
> Hitting the same URL with the same credentials through the browser
> is giving me a correct response. However, I I am not getting it
> through the code.

You can use Wireshark to inspect HTTP request bodies. We've had some of these issues with our Java HTTP API client
and it comes down to what headers the client sends by default, for example, what content type it requests and accepts.

There client is here, feel free to draw some inspiration from it or use/extend it instead of rolling your own :
https://github.com/rabbitmq/hop
--
MK

Staff Software Engineer, Pivotal/RabbitMQ


Anisha Kamble

unread,
Apr 8, 2016, 11:54:11 AM4/8/16
to rabbitmq-users, tyw...@gmail.com
Thank you Michael. I am trying to use Hop but there seems to be no Client class as far as I can tell. Is it no longer being used? If so, what should I use in its place? I don't see anything in the usage guide that can tell me how to get started.

Michael Klishin

unread,
Apr 8, 2016, 12:26:25 PM4/8/16
to rabbitm...@googlegroups.com
It's certainly there:

The API hasn't changed in any significant way since the very first version. Please check that
Hop dependency resolves in your project/build system.

--
You received this message because you are subscribed to the Google Groups "rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-user...@googlegroups.com.
To post to this group, send email to rabbitm...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Anisha Kamble

unread,
Apr 8, 2016, 12:36:03 PM4/8/16
to rabbitmq-users
I've added the following to my parent project's pom:
<repository>
          <id>spring-releases</id>
               <url>https://repo.spring.io/release</url>
   </repository>

And the following to the child project (where my actual class is):
<dependency>
<groupId>com.rabbitmq</groupId>
<artifactId>http-client</artifactId>
<version>1.0.0.RELEASE</version>
</dependency>

It got the following jars:
amqp-client-3.0.3
spring-rabbit-1.3.3.RELEASE

However, the amqp-client-3.0.3 jar only has the following packages:
com.rabbitmq.client
com.rabbitmq.client.impl
com.rabbitmq.tools
com.rabbitmq.tools.json
com.rabbitmq.tools.jsonrpc
com.rabbitmq.utility

Did I do something wrong? I've cleaned and updated the Maven dependencies multiple times.
Message has been deleted

Anisha Kamble

unread,
Apr 8, 2016, 12:39:39 PM4/8/16
to rabbitmq-users
I tried also with version 1.0.0.M1. Same result.

Anisha Kamble

unread,
Apr 8, 2016, 12:45:56 PM4/8/16
to rabbitmq-users
Are you updating the doc as I post here? :)

Right now this is what I have:
<repository>
 
<id>spring-milestones</id>
 
<url>http://repo.spring.io/milestone</url>
</repository>


<dependency>
   
<groupId>com.rabbitmq</groupId>
   
<artifactId>http-client</artifactId>
   <version>1.0.0.M1</version>
</dependency>

The packages are still the same.

Anisha Kamble

unread,
Apr 8, 2016, 12:54:36 PM4/8/16
to rabbitmq-users
Ah I finally see it now. Thank you :)

Michael Klishin

unread,
Apr 8, 2016, 2:52:45 PM4/8/16
to rabbitm...@googlegroups.com
Hop is an HTTP API client. It is a completely different library from the RabbitMQ Java client.

Sorry but general Java and Maven dependency management questions are outside of the scope of this list.

Anisha Kamble

unread,
Apr 10, 2016, 6:28:10 PM4/10/16
to rabbitm...@googlegroups.com
So I put in the URL and credentials for the server and put in a log statement to get the current RabbitMQ version from the client. But nothing happens. Again, I've validated the IP address and credentials. The server is up and running. It's just two simple statements, yet I can't seem to get a response from the server. What could be the issue? With my first attempt, sans Hop, I was at least getting a 400, but now nothing.
You received this message because you are subscribed to a topic in the Google Groups "rabbitmq-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/rabbitmq-users/DN28n_DHmBU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to rabbitmq-user...@googlegroups.com.

To post to this group, send email to rabbitm...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Row, row, row your boat
Gently down the stream.
Merrily, merrily, merrily, merrily
Life is but a dream.

Michael Klishin

unread,
Apr 10, 2016, 6:32:44 PM4/10/16
to rabbitm...@googlegroups.com
We cannot suggest a whole lot with this much information.

What's in RabbitMQ logs? (HTTP request logging is enabled separately, see http://www.rabbitmq.com/management.html)
What does your code look like? 
Have you tried using a Java debugger to learn what's going on?

"nothing happens" is not terribly specific .

On 8 April 2016 at 21:52:39, Michael Klishin (mkli...@pivotal.io) wrote:
> Hop is an HTTP API client. It is a completely different library from the
> RabbitMQ Java client.
>
> Sorry but general Java and Maven dependency management questions are
> outside of the scope of this list.
>
> On Fri, Apr 8, 2016 at 7:54 PM, Anisha Kamble wrote:
>
> > Ah I finally see it now. Thank you :)
> >
> >
> > On Friday, 8 April 2016 12:45:56 UTC-4, Anisha Kamble wrote:
> >>
> >> Are you updating the doc as I post here? :)
> >>
> >> Right now this is what I have:
> >>
> >>
> >> spring-milestones
> >> http://repo.spring.io/milestone
> >>
> >>
> >>
> >> com.rabbitmq
> >> http-client
> >> 1.0.0.M1
> >>
> >>
> >>
> >> The packages are still the same.
> >>
> >>
> >> On Friday, 8 April 2016 12:39:39 UTC-4, Anisha Kamble wrote:
> >>>
> >>> I tried also with version 1.0.0.M1. Same result.
> >>>
> >>> On Friday, 8 April 2016 12:36:03 UTC-4, Anisha Kamble wrote:
> >>>>
> >>>> I've added the following to my parent project's pom:
> >>>>
> >>>> spring-releases
> >>>> https://repo.spring.io/release
> >>>>
> >>>>
> >>>> And the following to the child project (where my actual class is):
> >>>>
> >>>> com.rabbitmq
> >>>> http-client
> >>>> 1.0.0.RELEASE
> >>>>
> >>>>
> >>>> It got the following jars:
> >>>> amqp-client-3.0.3
> >>>> spring-rabbit-1.3.3.RELEASE
> >>>>
> >>>> However, the amqp-client-3.0.3 jar only has the following packages:
> >>>> com.rabbitmq.client
> >>>> com.rabbitmq.client.impl
> >>>> com.rabbitmq.tools
> >>>> com.rabbitmq.tools.json
> >>>> com.rabbitmq.tools.jsonrpc
> >>>> com.rabbitmq.utility
> >>>>
> >>>> Did I do something wrong? I've cleaned and updated the Maven
> >>>> dependencies multiple times.
> >>>>
> >>>> On Friday, 8 April 2016 12:26:25 UTC-4, Michael Klishin wrote:
> >>>>>
> >>>>> It's certainly there:
> >>>>>
> >>>>> https://github.com/rabbitmq/hop/tree/master/src/main/java/com/rabbitmq/http/client
> >>>>>
> >>>>> The API hasn't changed in any significant way since the very first
> >>>>> version. Please check that
> >>>>> Hop dependency resolves in your project/build system.
> >>>>>
> >>>>> On Fri, Apr 8, 2016 at 6:54 PM, Anisha Kamble

Michael Klishin

unread,
Apr 10, 2016, 6:49:44 PM4/10/16
to rabbitm...@googlegroups.com, Anisha Kamble
On 11 April 2016 at 01:28:09, Anisha Kamble (tyw...@gmail.com) wrote:
> Have you tried using a Java debugger to learn what's going on?

…o r take a thread dump with Visual VM/jstack.
Reply all
Reply to author
Forward
0 new messages