Uploaded image for project: 'Spring Integration'
  1. Spring Integration
  2. INT-4299

Folder Closed Exception in After receiving the message - AbstractMessageHandler

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Major
    • Resolution: Complete
    • Affects Version/s: 5.0 M5
    • Fix Version/s: 5.2 M1
    • Component/s: Mail Support
    • Labels:

      Description

      I'm trying to get basic Imapmailreceiver using spring integration and i stumbled up a sticky folder closed exception. I constantly get the Folder closed exception when reading the content of the email, But the I am able to get the subject correctly.
      CONFIG

      <int:channel id="emails"/>
      
      <util:properties id="javaMailProperties">
          <prop key="mail.imap.socketFactory.class">javax.net.ssl.SSLSocketFactory</prop>
          <prop key="mail.imap.socketFactory.fallback">false</prop>
          <prop key="mail.store.protocol">imaps</prop>
          <prop key="mail.debug">false</prop>
      </util:properties>
      <int-mail:imap-idle-channel-adapter id="mailAdapter"
                                   store-uri="ACTUALCREDENTIALHERE"
                                    java-mail-properties="javaMailProperties"
                                    channel="emails"
                                    should-delete-messages="true"
                                    auto-startup="false"
                                    should-mark-messages-as-read="true" />
      <int:service-activator id="receiveEmail" input-channel="emails" ref="MessageReceiver"/>
      <bean id="MessageReceiver" class="org.mail.integration.EmailReader.MessageReceiver" />
      </beans>
      
      • The Mail APP Class
      ApplicationContext ac = new ClassPathXmlApplicationContext("/META-INF/spring/integration/gmail.xml");
      
      
       ImapIdleChannelAdapter ic=(ImapIdleChannelAdapter)ac
          .getBean("mailAdapter");
      
          ic.start();
      
      
      • The service activator is as follows:
        public class MessageReceiver {
            public void handle(javax.mail.Message message){
                MailToStringTransformer m2s = new MailToStringTransformer();
                    m2s.setCharset("utf-8");
        
        
        //payload instanceof MimeMultipart
                    if (message instanceof MimeMessage) {
                        try {
                         System.out.println("inside mimemessagehandler");
                           // javax.mail.Message mailMessage = (javax.mail.Message) payload;
                            System.out.println(message.getSubject());
                            System.out.println(getTextFromMessage(message));
        
                            Address[] receipts = message.getAllRecipients();
                            System.out.println("RECEIPIENTS MAIL ID");
                            if (receipts != null && receipts.length > 0) {
                                for (int i = 0; i < receipts.length; i++) {
                                    System.out.println(((InternetAddress) receipts[i]).getAddress());
                                }
                            }
        
                            System.out.println("FROM MAIL ID");
                            Address[] froms = message.getFrom();
                            String email = froms == null ? null
                                    : ((InternetAddress) froms[0]).getAddress();
                            System.out.println(email);
        
                        } catch (Exception e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
        
                    }
        
                }
        
        
        
            private static  String getTextFromMessage(javax.mail.Message message) throws Exception {
            String result = "";
            if (message.isMimeType("text/plain")) {
                result = message.getContent().toString();
            } else if (message.isMimeType("multipart/*")) {
                MimeMultipart mimeMultipart = (MimeMultipart) message.getContent();
                result = getTextFromMimeMultipart(mimeMultipart);
            }
            return result;
        }
        
        private static String getTextFromMimeMultipart(MimeMultipart mimeMultipart) throws Exception {
            String result = "";
        
            int count = mimeMultipart.getCount();
            System.out.println("CCC "+count);
            for (int i = 0; i < count; i++) {
               // mimeMultipart.toString()
                BodyPart bodyPart = mimeMultipart.getBodyPart(i);
                if (bodyPart.isMimeType("text/plain")) {
                   result = mimeMultipart.toString();//(String) bodyPart.getContent();
        
                } else if (bodyPart.isMimeType("text/html")) {
                    String html = (String) bodyPart.getContent();
                    // result = result + "\n" + org.jsoup.Jsoup.parse(html).text();
                } else if (bodyPart.getContent() instanceof MimeMultipart) {
                    result = result + getTextFromMimeMultipart((MimeMultipart) bodyPart.getContent());
                }
            }
            return result;
        }
        
        }
        

      *Exception :*

      javax.mail.FolderClosedException
      	at javax.mail.internet.MimeBodyPart.getContent(MimeBodyPart.java:659)
      	at org.mail.integration.EmailReader.MessageReceiver.getTextFromMimeMultipart(MessageReceiver.java:101)
      	at org.mail.integration.EmailReader.MessageReceiver.getTextFromMessage(MessageReceiver.java:83)
      	at org.mail.integration.EmailReader.MessageReceiver.handle(MessageReceiver.java:41)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      	at java.lang.reflect.Method.invoke(Method.java:498)
      	at org.springframework.messaging.handler.invocation.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:181)
      	at org.springframework.messaging.handler.invocation.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:114)
      	at org.springframework.integration.util.MessagingMethodInvokerHelper$HandlerMethod.invoke(MessagingMethodInvokerHelper.java:942)
      	at org.springframework.integration.util.MessagingMethodInvokerHelper.invokeHandlerMethod(MessagingMethodInvokerHelper.java:511)
      	at org.springframework.integration.util.MessagingMethodInvokerHelper.processInternal(MessagingMethodInvokerHelper.java:440)
      	at org.springframework.integration.util.MessagingMethodInvokerHelper.process(MessagingMethodInvokerHelper.java:258)
      	at org.springframework.integration.handler.MethodInvokingMessageProcessor.processMessage(MethodInvokingMessageProcessor.java:104)
      	at org.springframework.integration.handler.ServiceActivatingHandler.handleRequestMessage(ServiceActivatingHandler.java:93)
      	at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(AbstractReplyProducingMessageHandler.java:109)
      	at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:131)
      	at org.springframework.integration.dispatcher.AbstractDispatcher.tryOptimizedDispatch(AbstractDispatcher.java:116)
      	at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:132)
      	at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:105)
      	at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:73)
      	at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:423)
      	at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:373)
      	at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:183)
      	at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:162)
      	at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:47)
      	at org.springframework.messaging.core.AbstractMessageSendingTemplate.send(AbstractMessageSendingTemplate.java:107)
      	at org.springframework.integration.endpoint.MessageProducerSupport.sendMessage(MessageProducerSupport.java:188)
      	at org.springframework.integration.mail.ImapIdleChannelAdapter.lambda$createMessageSendingTask$0(ImapIdleChannelAdapter.java:216)
      	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
      	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
      	at java.lang.Thread.run(Thread.java:745
      

        Attachments

          Activity

            People

            Assignee:
            abilan Artem Bilan
            Reporter:
            badri Badri
            Votes:
            4 Vote for this issue
            Watchers:
            14 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: