1

I have test env.: [REST API]-->[RabbitMQ] and trying to send the file (with multipart) to REST API and read from RabbitMQ directly:

* bytes expectedPayload = read('flask.png')
And multipart file file = { read: 'flask.png', contentType: 'application/json' }
And multipart field message = { messageFlowName: 'TestMSGFlow', moduleInstanceId: 5 }
When method POST
Then status 200
 ...
* bytes receivedPayload = amqpConnection.getMessagePayload('test.rabbitmq.queue', 'testChannel')
And match receivedPayload == read('flask.png')

amqpConnection.getMessagePayload method:

public byte[] getMessagePayload(String queueName, Channel channel)  {
    byte[] message = null;

    try {
        GetResponse response = channel.basicGet(queueName, true);
        if (response == null) {
            System.out.println("DEBUG: No message found.");
        } else {
            AMQP.BasicProperties props = response.getProps();
            return response.getBody();
        }

    } catch (IOException e) {
        e.printStackTrace();
    }

    return message;
}

I'm getting the result:

actual: [B@64b70919, expected: [B@4e31c3ec, reason: actual and expected byte-arrays are not equal

I've tried to use *.json instead of *.png (as test file) and it works well. How to make it works with *.png too?

Roman L.
  • 79
  • 7

1 Answers1

1

It should work, so looks like you have a mistake in your routine to extract a byte array out of the channel / message.

Maybe some encoding / decoding is involved ? https://stackoverflow.com/a/47469363/143475

You can do a simple test:

* bytes temp = read('flask.png')
* match temp == read('flask.png')
Peter Thomas
  • 54,465
  • 21
  • 84
  • 248