Announcement Announcement Module
Collapse
No announcement yet.
Mail outbound adapter error Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Mail outbound adapter error

    Hello all
    i am trying out mail outbound channel adapter in spring integration and i am receiving few errors..
    Situation is this: i am sending messages to a mailChannel and i have configured an outbound-channel-adapter tor ead from that channel and create email messages.
    here's my configuration
    Code:
    <?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:integration="http://www.springframework.org/schema/integration"
        xmlns:mail="http://www.springframework.org/schema/integration/mail"
        xsi:schemaLocation="http://www.springframework.org/schema/beans
                http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
                http://www.springframework.org/schema/integration
                http://www.springframework.org/schema/integration/spring-integration-1.0.xsd
                http://www.springframework.org/schema/integration/mail
                http://www.springframework.org/schema/integration/mail/spring-integration-mail-1.0.xsd">
    
    	<integration:channel id="mailChannel" />
    
    	<mail:outbound-channel-adapter channel="mailChannel" mail-sender="mailSender"/>
    
        <bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
      		<property name="host">
      			<value>mailhost.bzwint.com</value>
      		</property>
    	</bean>
    	
    	<mail:header-enricher
    					 input-channel="mailChannel" 
    					 subject="Example Mail"
                         to="[email protected]"
                         from="[email protected]"/>
    	
    </beans>
    and here's the exception i am receiving
    Code:
    2009-12-17 10:20:47,035[listener.DefaultMessageListenerContainer] WARN - Execution of JMS message listener failed [org.springframework.jms.listener.DefaultMessageListenerContainer#0-1]
    org.springframework.integration.message.MessageHandlingException: Unable to create MailMessage from payload type [com.sample.domain.TestMessage], expected byte array or String.
    	at org.springframework.integration.mail.MailSendingMessageHandler.convertMessageToMailMessage(MailSendingMessageHandler.java:96)
    	at org.springframework.integration.mail.MailSendingMessageHandler.handleMessage(MailSendingMessageHandler.java:69)
    	at org.springframework.integration.dispatcher.AbstractDispatcher.sendMessageToHandler(AbstractDispatcher.java:85)
    	at org.springframework.integration.dispatcher.AbstractUnicastDispatcher.dispatch(AbstractUnicastDispatcher.java:54)
    	at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:56)
    	at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:116)
    	at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:94)
    	at org.springframework.integration.channel.MessageChannelTemplate.doSend(MessageChannelTemplate.java:223)
    	at org.springframework.integration.channel.MessageChannelTemplate.send(MessageChannelTemplate.java:180)
    	at org.springframework.integration.router.AbstractMessageRouter.handleMessageInternal(AbstractMessageRouter.java:76)
    	at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:48)
    	at org.springframework.integration.dispatcher.AbstractDispatcher.sendMessageToHandler(AbstractDispatcher.java:85)
    	at org.springframework.integration.dispatcher.AbstractUnicastDispatcher.dispatch(AbstractUnicastDispatcher.java:54)
    	at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:56)
    	at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:116)
    	at org.springframework.integration.channel.MessageChannelTemplate.doSend(MessageChannelTemplate.java:222)
    	at org.springframework.integration.channel.MessageChannelTemplate.send(MessageChannelTemplate.java:180)
    i am sending messages of class TestMessage, code is below
    Code:
    package com.sample.domain;
    
    import java.io.Serializable;
    
    public class TestMessage  implements Serializable
    {
    	
    	/**
    	 * 
    	 */
    	private static final long serialVersionUID = 1L;
    	private String content;
    	private MessageType messageType;
    	
    	public TestMessage(String content, MessageType messageType)
    	{
    		this.content = content;
    		this.messageType = messageType;
    	}
    	
    	public String getContent() {
    		return content;
    	}
    	public MessageType getMessageType() {
    		return messageType;
    	}
    	
    	@Override
    	public String toString()
    	{
    		return getContent() + "," + getMessageType().name(); 
    	}
    
    }
    according to docs, adapter willt ry to send a string representation of the message....but somehow i am getting the exception above

    anyone could help?

    regards
    marco

  • #2
    Ok, i fixed it.
    Somehow i came across JIRA INT-535 which made me think to use a Transformer .. so i created a Tranformer that creates a MailMessage out of my TestMessage.
    Then i created a Message with payload = MailMessage

    could anyone confirm that in order to send out a mail message, a tranformer is always required?

    i quote the reference manual below
    If the received Message's payload is already a MailMessage instance, it will be sent directly. Therefore, it is generally recommended to precede this consumer with a Transformer for non-trivial MailMessage construction requirements. However, a few simple Message mapping strategies are supported out-of-the-box. For example, if the message payload is a byte array, then that will be mapped to an attachment. If the payload is neither a MailMessage or byte array, then a MailMessage will be created with text content corresponding to the value returned from the Spring Integration Message payload's toString() method. For simple text-based emails, simply provide a String-based Message payload
    Perhaps i understood it incorrectly...

    regards
    marco

    Comment


    • #3
      What you are doing now is correct. The documentation needs to be updated. Basically, we realized that toString() was too broad, and that you could end up with email text content that is not at all what you would expect.

      We do provide a generic toString Transformer out-of-the-box (including namespace support in the core Spring Integration namespace), so you might just want to use that instead of a custom Transformer implementation.

      Could you please open a JIRA issue for the documentation to be updated?

      Thank you,
      Mark

      Comment


      • #4
        Mark
        could you kindly post me the JIRA URL?

        rgds
        marco

        Comment


        • #5
          Ignore my prev post mark,
          i have created INT-934


          http://jira.springframework.org/browse/INT-934

          Comment


          • #6
            Thank you. We'll address it for 2.0 M2!

            What version are you using?

            Comment


            • #7
              Hello
              1.0.2SR1

              i do apologize, i think i have deleted the origiinal sprign distribution i downloaded
              all my jars are ending with 1.0.2.SR1

              Regards
              marco

              Comment

              Working...
              X