Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring integration:imap - error: Target object of type [class myEmailReciever] has no eligible methods for handling Messages

I'm trying to use spring integration email mechanism. I used this link for reference: http://blog.solidcraft.eu/2011/04/read-emails-from-imap-with-spring.html

unfortunately i get an error message on server start-up:

Caused by: java.lang.IllegalArgumentException: Target object of type [class src.com.project.myEmailReciever] has no eligible methods for handling Messages.
at org.springframework.util.Assert.notEmpty(Assert.java:294)
at org.springframework.integration.util.MessagingMethodInvokerHelper.findHandlerMethodsForTarget(MessagingMethodInvokerHelper.java:348)
at org.springframework.integration.util.MessagingMethodInvokerHelper.<init>(MessagingMethodInvokerHelper.java:165)
at org.springframework.integration.util.MessagingMethodInvokerHelper.<init>(MessagingMethodInvokerHelper.java:103)
at org.springframework.integration.util.MessagingMethodInvokerHelper.<init>(MessagingMethodInvokerHelper.java:107)
at org.springframework.integration.handler.MethodInvokingMessageProcessor.<init>(MethodInvokingMessageProcessor.java:48)
at org.springframework.integration.handler.ServiceActivatingHandler.<init>(ServiceActivatingHandler.java:42)
at org.springframework.integration.config.ServiceActivatorFactoryBean.createMethodInvokingHandler(ServiceActivatorFactoryBean.java:48)
at org.springframework.integration.config.AbstractStandardMessageHandlerFactoryBean.createHandler(AbstractStandardMessageHandlerFactoryBean.java:72)
at org.springframework.integration.config.AbstractSimpleMessageHandlerFactoryBean.createHandlerInternal(AbstractSimpleMessageHandlerFactoryBean.java:89)
at org.springframework.integration.config.AbstractSimpleMessageHandlerFactoryBean.getObject(AbstractSimpleMessageHandlerFactoryBean.java:68)
at org.springframework.integration.config.AbstractSimpleMessageHandlerFactoryBean.getObject(AbstractSimpleMessageHandlerFactoryBean.java:31)
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:142)
... 30 more

apparently the function in my receiving class :

public void receive(MimeMessage mimeMessage) {

//doSomthing
   }

is not eligible for handling emails.. anyone know how do i solve this?

edit here are my classes\ xml's:

@Component
@Scope("prototype")
public class MessageFactory {

@Autowired
private ApplicationContext ctx;

private static final Logger logger = LoggerFactory.getLogger(MessageFactory.class);

ObjectMapper mapper = new ObjectMapper();


public boolean receive(MimeMessage mimeMessage) {

    System.out.println("try");
    return true;
   }
}

xml:

  <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:mail="http://www.springframework.org/schema/integration/mail"
   xmlns:int="http://www.springframework.org/schema/integration"
   xmlns:util="http://www.springframework.org/schema/util"
   xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/integration/mail
        http://www.springframework.org/schema/integration/mail/spring-integration-mail-2.0.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd">

<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">true</prop>
</util:properties>

<mail:inbound-channel-adapter id="imapAdapter"
                                  store-uri="imaps://username:[email protected]:993/INBOX"                                    
                                  channel="recieveEmailChannel"                                         
                                  should-delete-messages="false"
                                  should-mark-messages-as-read="true"                                     
                                  auto-startup="true"

                                  java-mail-properties="javaMailProperties">

    <int:poller fixed-delay="5" time-unit="SECONDS" />
</mail:inbound-channel-adapter>

<int:channel id="recieveEmailChannel">       
    <int:interceptors>
        <int:wire-tap channel="logger"/>
    </int:interceptors>
</int:channel>

<int:logging-channel-adapter id="logger" level="DEBUG"/>

<int:service-activator input-channel="recieveEmailChannel" ref="messageFactory" method="receive"/>

<bean id="messageFactory" class="src.com.project.service.factories.MessageFactory">
</bean>

like image 318
Urbanleg Avatar asked Jan 13 '23 21:01

Urbanleg


1 Answers

This error generally is a configuration problem.

Conditions that might cause it include...

  • Misspelled method attribute in the <service-activator/> configuration
  • The method's not public
  • requires-reply="true" and the method returns void (like yours)
like image 155
Gary Russell Avatar answered Jan 21 '23 11:01

Gary Russell