0

javax.mail.Message mimeMessage = (javax.mail.Message)array[1]; throws

com.liferay.portal.kernel.messaging.MessageListenerException: java.lang.ClassCastException: javax.mail.internet.MimeMessage cannot be cast to javax.mail.Message.
Caused by: java.lang.ClassCastException: javax.mail.internet.MimeMessage cannot be cast to javax.mail.Message
public void Receive(Message message) throws Exception {

    Object[] array = (Object[])message.getPayload();

    FileVersion sourceFileVersion = (FileVersion)array[0];
    javax.mail.Message mimeMessage = (javax.mail.Message)array[1];
Josua Marcel C
  • 3,122
  • 6
  • 45
  • 87
Simone Sorgon
  • 155
  • 1
  • 14
  • 1
    This suggests a classpath problem with multiple JavaMail libraries being used. – Mark Rotteveel Apr 01 '19 at 15:09
  • so what can i do? i mus change compileInclude with compileOnly ? – Simone Sorgon Apr 01 '19 at 15:19
  • 1
    Find out where the classpath issue is coming from and fix it. Prime candidates are things like JavaMail being included in your application and in your application server. – Mark Rotteveel Apr 01 '19 at 15:21
  • ok i understand, thanks ! – Simone Sorgon Apr 01 '19 at 15:42
  • 2
    Duplicate of [java.lang.ClassCastException: com.sun.mail.handlers.multipart\_mixed cannot be cast to javax.activation.DataContentHandler](https://stackoverflow.com/questions/55403413/java-lang-classcastexception-com-sun-mail-handlers-multipart-mixed-cannot-be-ca). The root cause is *exactly* the same as in the question that you asked a couple of days ago. – Olaf Kock Apr 02 '19 at 07:52

1 Answers1

-2

That's because you are casting MimeMessage to Message, try changing as below,

MimeMessage mimeMessage = (javax.mail.internet.MimeMessage) array[1];
Santosh
  • 874
  • 11
  • 21
  • 1
    A [`javax.mail.internet.MimeMessage`](https://eclipse-ee4j.github.io/javamail/docs/api/javax/mail/internet/MimeMessage.html) extends `javax.mail.Message`, so the cast is appropriate. The fact it doesn't work indicates a classpath problem. – Mark Rotteveel Apr 01 '19 at 15:10
  • If this worked the original code would work too. The error message already states explicity that this doesn't work.. Answer is pointless. – user207421 Apr 02 '19 at 11:01