paolosalvatori / ServiceBusExplorer

The Service Bus Explorer allows users to connect to a Service Bus namespace and administer messaging entities in an easy manner. The tool provides advanced features like import/export functionality or the ability to test topic, queues, subscriptions, relay services, notification hubs and events hubs.
MIT License
2.01k stars 584 forks source link

"Cannot decode String in UTF-8" error while repairing message #451

Closed abhikt48 closed 3 years ago

abhikt48 commented 4 years ago

Hi Team,

We are facing "Cannot decode String in UTF-8" issue while repair message. We faced this issue in two cases

  1. Resubmit selected messages in batch mode
  2. Repair and Resubmit message with String, WCF, ByteArray body type

Steps to reproduce issue for first case

  1. Publish 4-5 message with qpid JMS client as String
  2. Receive message with qpid JMS client but do not acknowledge the messages. So messages will go in dead letter queue.
  3. From ServiceBus explorer - receive dead letter messages in peek mode a. Select 2-3 DL message and click on Resubmit messages in Batch Mode b. Click on Submit button c. Select intermediate Queue/topic to send messages
  4. Start to receive message from intermediate Queue/topic with Qpid JMS Client. Then you will start getting "Cannot decode String in UTF-8" error

Steps to reproduce issue for second case

  1. Publish 4-5 messages with qpid JMS client as String
  2. Receive message with qpid JMS client but do not acknowledge the messages. So messages will go in dead letter queue.
  3. From ServiceBus explorer - receive dead letter messages in peek mode a. Select 1 DL message and click on Repair and Resubmit selected message b. Select body type as String, WCF, ByteArray b. Click on Submit button c. Select intermediate Queue/topic to send messages
  4. Start to receive message from intermediate Queue/topic with Qpid JMS Client. Then you will start getting "Cannot decode String in UTF-8" error

If we send message as ByteArray[] from Qpid JMS client then "Resubmit messages in Batch Mode" is working fine.

Could you please take a look on this issue and let me know for any concern.

Error Stack Trace

Exception stack is: Cannot decode String in UTF-8 (javax.jms.JMSException) (org.mule.transport.ConnectException)
  java.nio.charset.CoderResult.throwException(CoderResult.java:281)
  java.nio.charset.CharsetDecoder.decode(CharsetDecoder.java:816)
  org.apache.qpid.jms.provider.amqp.message.AmqpJmsTextMessageFacade.getText(AmqpJmsTextMessageFacade.java:84)
  org.apache.qpid.jms.provider.amqp.message.AmqpJmsTextMessageFacade.copy(AmqpJmsTextMessageFacade.java:65)
  org.apache.qpid.jms.provider.amqp.message.AmqpJmsTextMessageFacade.copy(AmqpJmsTextMessageFacade.java:41)
  org.apache.qpid.jms.message.JmsTextMessage.copy(JmsTextMessage.java:37)
  org.apache.qpid.jms.message.JmsTextMessage.copy(JmsTextMessage.java:25)
  org.apache.qpid.jms.JmsMessageConsumer.copy(JmsMessageConsumer.java:419)
  org.apache.qpid.jms.JmsMessageConsumer.deliverNextPending(JmsMessageConsumer.java:769)
  org.apache.qpid.jms.JmsMessageConsumer.access$100(JmsMessageConsumer.java:61)
  org.apache.qpid.jms.JmsMessageConsumer$MessageDeliverTask.run(JmsMessageConsumer.java:840)
  java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
  java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
  org.apache.qpid.jms.util.QpidJMSThreadFactory$1.run(QpidJMSThreadFactory.java:86)
  java.lang.Thread.run(Thread.java:745)
  (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
  ********************************************************************************\n"
paolosalvatori commented 4 years ago

Thanks @abhikt48 for the detailed description of the issue. To make a quick recap, when resubmitting messages from the deadletter queue of a queue or subscription, no matter if you resubmit messages one at the time or in batch mode, and no matter the message type (string, WCF, bytearray) you select, you get the "Cannot decode String in UTF-8", right? I assume that if you just receive the message from the queue or subscription, you don't get this error, right? This means that there is some problem when cloning the payload of the original message for the resubmission and this problem happens only when receiving the message via JMS.

abhikt48 commented 4 years ago

@paolosalvatori - Thanks for quick update. Please find below details.

Thanks @abhikt48 for the detailed description of the issue. To make a quick recap, when resubmitting messages from the deadletter queue of a queue or subscription, no matter if you resubmit messages one at the time or in batch mode, and no matter the message type (string, WCF, bytearray) you select, you get the "Cannot decode String in UTF-8", right?

prerequisite - message should be sent by Qpid JMS client as String/Text message(javax.jms.TextMessage)

If we submit one message at a time with Stream body type then there is no issue. But,

  1. If we submit one message at a time with string, WCF, ByteArray body type then there is "Cannot decode String in UTF-8" issue.
  2. If we submit 2-3 message in batch mode with Stream body type then there is "Cannot decode String in UTF-8" issue.
  3. I have not tried string, WCF, ByteArray body type in batch mode. I am assuming issue will be there because if issue is there for Stream then it could be there for other body type as well in batch mode.

I assume that if you just receive the message from the queue or subscription, you don't get this error, right? This means that there is some problem when cloning the payload of the original message for the resubmission and this problem happens only when receiving the message via JMS.

Yes you are right. If we receive message normally then there is no issue. But if we receive after cloning then we started getting decode error. Yes you are right - there is a issue in cloning of message payload. But we don't have any issue if original message content is ByteArray. We faced issue for String/TextMessage(javax.jms.TextMessage) only.

Please let me know if you need any other information.

abhikt48 commented 4 years ago

Hey @paolosalvatori,

I hope you are doing great. Did you get chance to look on this issue? Is it possible for you to provide fix on this issue?

abhikt48 commented 4 years ago

Hey @paolosalvatori ,

I was doing testing and found ContentType also plays an important role for reproducing this issue. Please find below details and let me know for any information.

If you want to set content type with Qpid JMS, then please find below code snippet for setting content type.

((AmqpJmsMessageFacade) ((JmsMessage) jmsMessage).getFacade()).setContentType(Symbol.valueOf(contentType));

Use Cases

UTf8-issue
paolosalvatori commented 4 years ago

Thanks a lot @abhikt48 for the very detailed analysis! Now, since ContentType plays a role and you get errors only when using application/json or text/json ContentType, do you think we should try to find a fix, or are you ok to close the issue as you know what are the combinations that work as expected with no issues?

abhikt48 commented 4 years ago

@paolosalvatori Thanks for update. We definitely need fix for this issue. Please apply fix for above 3 cases where we are getting UTF8 error.

Just FYI - We got this issue in PROD environment where we are using ServiceBus explorer for replay messages. Our lot of scenarios matches above conditions, so we definitely need fix.

Please let me know if you need any other information.

abhikt48 commented 4 years ago

@paolosalvatori - Did you get chance to take a look on this issue?

abhikt48 commented 3 years ago

@paolosalvatori - Could you please provide us fix on this issue ?

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

abhikt48 commented 3 years ago

I think this issue is still available. Could you please fix this issue.

ErikMogensen commented 3 years ago

@abhikt48 , one of the most recently merged PRs may have fixed or at least changed this issue. Please build the latest bits from the develop branch and see if the behavior is the same.

paolosalvatori commented 3 years ago

@ErikMogensen @abhikt48 can I close this issue?

ErikMogensen commented 3 years ago

Yes, @abhikt48 let us know if there is a problem. The fix is now part of the v5 release.

abhikt48 commented 3 years ago

@paolosalvatori @ErikMogensen - Sorry for late reply. I tested today with 5.0.1 version, unfortunately, this is not working as expected. , Please find below steps to reproduce this issue -

  1. Publish message fromqpid-jms-client-0.56.0, with text/json ContentType. Please refer below screenshot image

  2. Repair and submit message as String Body Type . Please refer below screenshot image

  3. Receive message from qpid-jms-client-0.56.0, and you can receive below error Reason 'Cannot decode String in UTF-8' - 'class javax.jms.JMSException', cause 'java.nio.charset.MalformedInputException: Input length = 1'

Can I request you to please reopen this issue?

ErikMogensen commented 3 years ago

Ok.

  1. Are you able to reopen this issue yourself? I just want to know if that is possible.

  2. The fix that I referred to caused a new bug in v5.0.1. There is a fix in the current develop branch. Are you able to build from the develop branch and test again?

abhikt48 commented 3 years ago

@ErikMogensen Thanks for quick update. Please find below details.

  1. I don’t have any option to open ticket. I think, I don’t have sufficient rights.
  2. I don’t know how to build from develop branches. It will be great if you can upload SNAPSHOT version, so i can download and share results accordingly.
paolosalvatori commented 3 years ago

@abhikt48 are you a C# developer? If yes, what development environment do you use? Visual Studio? Visual Studio Code? To reopen the issue you just have to press the button below: Reopen and comment.

abhikt48 commented 3 years ago

@paolosalvatori - I am a Java Developer and use eclipse based ID for development.

Unfortunately, I am not getting reopen button. Please find below screenshot.

image

paolosalvatori commented 3 years ago

Thanks @abhikt48 we reopened the issue, but I cannot guarantee we can look at it now. I need a repro to understand the issue. Can you please provide a way to reproduce the problem? Thanks

abhikt48 commented 3 years ago

@paolosalvatori Thanks for reopening the tickets.

Please find below steps to replicate this issue. As we faced this issue in Java application, so created sample JAVA application to replicate this issue.

  1. Create two queues - One for publishing and another for receiving
  2. Refer qpid-jms-client-sample application
  3. Modify below parameters in Constants.java class
    • PUBLISHER_QUEUE_NAME = "**"
    • RECEIVER_QUEUE_NAME = "****"
    • SBUS_NAME = "***"; // Only Service BUS name without extension ".servicebus.windows.net"
    • USERNAME = "***"
    • PASSWORD = "****"
  4. Run Publisher.java as Java application to publish message
  5. Open ServiceBus explorer, Repair and submit message as String Body Type . While submitting please select same queue which you defined on above RECEIVER_QUEUE_NAME . Please refer below screenshot image
  6. Run Receiver.java as Java application to receive single message You can expect below Cannot decode String in UTF-8 error -
Exception in thread "main" javax.jms.JMSException: Cannot decode String in UTF-8
    at org.apache.qpid.jms.exceptions.JmsExceptionSupport.create(JmsExceptionSupport.java:90)
    at org.apache.qpid.jms.provider.amqp.message.AmqpJmsTextMessageFacade.getText(AmqpJmsTextMessageFacade.java:87)
    at org.apache.qpid.jms.provider.amqp.message.AmqpJmsTextMessageFacade.copy(AmqpJmsTextMessageFacade.java:65)
    at org.apache.qpid.jms.provider.amqp.message.AmqpJmsTextMessageFacade.copy(AmqpJmsTextMessageFacade.java:41)
    at org.apache.qpid.jms.message.JmsTextMessage.copy(JmsTextMessage.java:37)
    at org.apache.qpid.jms.message.JmsTextMessage.copy(JmsTextMessage.java:25)
    at org.apache.qpid.jms.JmsMessageConsumer.copy(JmsMessageConsumer.java:421)
    at org.apache.qpid.jms.JmsMessageConsumer.receive(JmsMessageConsumer.java:213)
    at com.qpid.samples.Receiver.receiveMessage(Receiver.java:19)
    at com.qpid.samples.Receiver.main(Receiver.java:32)
Caused by: java.nio.charset.MalformedInputException: Input length = 1
    at java.nio.charset.CoderResult.throwException(CoderResult.java:281)
    at java.nio.charset.CharsetDecoder.decode(CharsetDecoder.java:816)
    at org.apache.qpid.jms.provider.amqp.message.AmqpJmsTextMessageFacade.getText(AmqpJmsTextMessageFacade.java:84)
    ... 8 more

Please let me know if you need any other input.

paolosalvatori commented 3 years ago

Hi @abhikt48 I need to find some time to spend to investigate the issue. I'm moving on to a new team so I'll be a little busy. Expect a delayed answer. Should I forget about this issue, please ping or just reply to this message.

abhikt48 commented 3 years ago

HI @paolosalvatori , No Problem, I can understand. Please do needful whenever you got time.

kashish52 commented 3 years ago

Hi, I am also facing the similar issue while resubmitting the message using byte array. I did some debugging and got the byte array content of the body and decoded it online the message is adding some extra characters in front and end of the message Starting of the message @ base64Binary3http://schemas.microsoft.com/2003/10/Serialization/ End of the message 

But the strange thing is it looks just fine in Service Bus Explorer itself

paolosalvatori commented 3 years ago

Can you please debug the code and submit a PR? I can't reproduce the issue and in addition, I'm quite busy in this period. Thanks

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.