Announcement Announcement Module
Collapse
No announcement yet.
"Attribute is not allowed to appear in element" error in mail:header-enricher Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • "Attribute is not allowed to appear in element" error in mail:header-enricher

    Here's a simple problem I'm having with the mail:header-enricher. I'm using the definitions directly from the reference manual and have included the mail namespaces and spring-integration-mail dependency in the pom. I'm using the following chain:

    Code:
    	<chain id="mailHandler" input-channel="sendMailNotificationChannel"
    							output-channel="stdout">
    		<mail:header-enricher 
    		     subject="You Have Mail"
                         to="[email protected]"
                         cc="[email protected]"
                         bcc="[email protected]"
                         from="[email protected]"
                         reply-to="[email protected]"
                        overwrite="false"/>
    		<mail:outbound-channel-adapter 
    	             host="smtp-server.com" username="user" password="userpass"/>  
    	</chain>
    The error I'm seeing when I execute this is:
    Code:
    Exception in thread "main" org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 77 in XML document from class path resource [META-INF/spring/integration/mycontex.xml] is invalid; nested exception is org.xml.sax.SAXParseException: cvc-complex-type.3.2.2: Attribute 'subject' is not allowed to appear in element 'mail:header-enricher'.
    Is this header-enricher obsolete or has it been changed? Here's the namespaces I'm using:

    Code:
    <beans:beans xmlns="http://www.springframework.org/schema/integration" 
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xmlns:beans="http://www.springframework.org/schema/beans"
    	xmlns:stream="http://www.springframework.org/schema/integration/stream"
        xmlns:mail="http://www.springframework.org/schema/integration/mail"
    	xmlns:si-xml="http://www.springframework.org/schema/integration/xml"
    	xmlns:int-feed="http://www.springframework.org/schema/integration/feed"
    	xmlns:ws="http://www.springframework.org/schema/integration/ws"
    	xsi:schemaLocation="http://www.springframework.org/schema/integration/ws http://www.springframework.org/schema/integration/ws/spring-integration-ws.xsd
    		http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
    		http://www.springframework.org/schema/integration/stream http://www.springframework.org/schema/integration/stream/spring-integration-stream.xsd
    		http://www.springframework.org/schema/integration/feed http://www.springframework.org/schema/integration/feed/spring-integration-feed-2.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/integration/xml http://www.springframework.org/schema/integration/xml/spring-integration-xml-2.0.xsd 
    		http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
    Seems pretty straightforward but the compiler doesn't like it for some reason. What am I missing?

  • #2
    Hi -

    A quick question - which version of Spring Integration are you using? 2.0.4?

    Comment


    • #3
      I'm using 2.0.3.RELEASE for all my spring-integration dependencies. I updated my dependencies to use the 2.0.4RELEASE but I'm still seeing the error.
      Last edited by dwrightsd; Jun 17th, 2011, 09:37 AM.

      Comment


      • #4
        Hi,

        It looks like the reference documentation is incorrect. Instead of attributes the mail:header-enricher is configured through sub-elements. The following example will work:

        <int:channel id="mailchannel"/>

        <int-mail:header-enricher input-channel="mailchannel" output-channel="mail" >
        <int-mail:subject value="You Have Mail"/>
        <int-mail:to value="[email protected]"/>
        <int-mail:cc value="[email protected]"/>
        <int-mail:bcc value="[email protected]"/>
        <int-mail:from value="[email protected]"/>
        <int-mail:reply-to value="[email protected]" />
        </int-mail:header-enricher>
        <int-mail:outbound-channel-adapter id="mail" host="localhost" username="test" password="test" />

        I have created a Jira issue for this: https://jira.springsource.org/browse/INT-1946

        Thanks a lot for bringing this to our attention!

        Cheers,

        Gunnar

        Comment


        • #5
          Gunnar,

          Thanks, that fixed the initial problem. I still seem to have a dependency issue because the classloader isn't finding org.springframework.mail.javamail.JavaMailSenderIm pl. Here's the error:
          Code:
          Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.mail.javamail.JavaMailSenderImpl#0': Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: javax/mail/MessagingException
          I've got the spring-integration-mail dependency in my pom. Is there another needed?

          Comment


          • #6
            I added a dependency for javax.mail to the pom. This resolved the classloader problem but opened up another can of exceptions:
            Code:
            Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.integration.handler.MessageHandlerChain#1': Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'java.util.ArrayList' to required type 'java.util.List' for property 'handlers'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [org.springframework.integration.endpoint.EventDrivenConsumer] to required type [org.springframework.integration.core.MessageHandler] for property 'handlers[1]': no matching editors or conversion strategy found
            Not sure I'm headed in the right direction with the added javax.mail dependency.

            Comment


            • #7
              Could you please post your configuration that triggers this error?

              Comment


              • #8
                Also, have you looked at our mail samples? http://git.springsource.org/spring-i...ter/basic/mail
                Hopefully it will lead you to what the issue is.

                Comment


                • #9
                  Here's my generic pom listing:
                  Code:
                  	<properties>
                  		<spring.integration.version>2.0.4.RELEASE</spring.integration.version>
                  		<log4j.version>1.2.16</log4j.version>
                  		<junit.version>4.7</junit.version>
                  	</properties>
                  	<dependencies>
                  		<dependency>
                  		  <groupId>javax.mail</groupId>
                  		  <artifactId>mail</artifactId>
                  		  <version>1.4.1</version>
                  		</dependency>		
                                  <dependency>
                  		    <groupId>org.springframework</groupId>
                  		    <artifactId>spring-jdbc</artifactId>
                  		    <version>3.0.5.RELEASE</version>
                  		</dependency>
                  		<dependency>
                  		    <groupId>org.springframework.integration</groupId>
                  		    <artifactId>spring-integration-jdbc</artifactId>
                  		    <version>${spring.integration.version}</version>
                  		</dependency>
                  		<dependency>
                  			<groupId>org.springframework.integration</groupId>
                  			<artifactId>spring-integration-feed</artifactId>
                  			<version>${spring.integration.version}</version>
                  		</dependency>
                  		<dependency>
                  			<groupId>org.springframework.integration</groupId>
                  			<artifactId>spring-integration-mail</artifactId>
                  			<version>${spring.integration.version}</version>
                  		</dependency>
                  		<dependency>
                  			<groupId>org.springframework.integration</groupId>
                  			<artifactId>spring-integration-stream</artifactId>
                  			<version>${spring.integration.version}</version>
                  		</dependency>
                  		<dependency>
                  			<groupId>log4j</groupId>
                  			<artifactId>log4j</artifactId>
                  			<version>${log4j.version}</version>
                  		</dependency>
                  		<!-- test-scoped dependencies -->
                  		<dependency>
                  			<groupId>junit</groupId>
                  			<artifactId>junit</artifactId>
                  			<version>${junit.version}</version>
                  		</dependency>
                  	</dependencies>
                  Here's the bean definition that is causing the error:
                  Code:
                  	<chain id="mailHandler" input-channel="sendMailNotificationChannel"
                  							output-channel="stdout">
                  		<mail:header-enricher>
                                   <mail:subject value="You Have Mail"/>
                                   <mail:to value="[email protected]"/>
                                   <mail:from value="[email protected]"/>
                          </mail:header-enricher>
                   		<mail:outbound-channel-adapter id="outboundMail"
                  	             host="smtp-server.example.com" username="user" password="password"/>  
                  	</chain>

                  Comment


                  • #10
                    OK, that is why I asked to look at the sample as it shows the simples way of doing what you are trying to do.
                    Part of the issue is with the fact that you have outbound-adapter as the last component in the chain that defines an output channel. Adapters (inbound and outbound) are uni-directional (fire and forget). This means that there is nothing going to be produced by the outbound adapter to send to 'stdout' channel.

                    Let's try to simplify a little.
                    Remove chain all together and simply define input and output channels on the header enricher and then connect outbound adapter to the output channe of the header enricher.
                    Once we got this to work we'll put it in the chain if you wish.
                    Cheers

                    Comment


                    • #11
                      Oleg,
                      I took a look at the mail example and added the javax-activation dependency in addition to javax-mail. I also added namespaces for util following the examples. I'm still seeing the exception.

                      Comment


                      • #12
                        Oleg,

                        I broke up the chain and connected it as you indicated and it appears to be correctly working.

                        Code:
                        	<mail:header-enricher input-channel="sendMailNotificationChannel"
                        						  output-channel="outboundMailChannel">
                                        <mail:subject value="You Have Mail"/>
                                        <mail:to value="[email protected]"/>
                                        <mail:from value="[email protected]"/>
                               </mail:header-enricher>
                        
                        	<channel id="outboundMailChannel"/>
                        	       
                        	<mail:outbound-channel-adapter id="outboundMail" channel="outboundMailChannel"
                                    host="smtp-server.example.com" username="user" password="password"/>
                        I'm now getting a "Could not connect to SMTP host:..." error which shows it is attempting the connection. Assuming that our company firewall is not blocking this should I be able to specify the smtp server as the host as shown or is there some other syntax for the outbound connection? I'm using the same syntax as is used to set up an email account with the provider.

                        Comment


                        • #13
                          Actually i just realized that mail samples are only dealing with receiving mail and not sending, so I apologize for that and we'll make sure we have sending samples as well.

                          Yea, it should work. Another simpler option would be to configure mail-sender and then inject it into outbound adapter.
                          Here is the sample I use with GMail
                          Code:
                          <bean id="mailSender" class="org.springframework.mail.javamail.JavaMailSenderImpl">
                          		<property name="host" value="smtp.gmail.com" />
                          		<property name="port" value="587" />
                          		<property name="username" value="${email.username}" />
                          		<property name="password" value="${email.password}" />
                          		<property name="javaMailProperties">
                          		   <props>
                          		   		  <prop key="mail.debug">true</prop>
                          	       	      <prop key="mail.smtp.auth">true</prop>
                          	       	      <prop key="mail.smtp.starttls.enable">true</prop>
                          	       	   </props>
                          		</property>
                          	</bean>

                          Comment


                          • #14
                            I'll have to talk with our company IT or the mail provider. Its using port 25 by default and may be getting blocked on our end. We use Microsoft Exchange internally and they prevent us from using outside email accounts so that may be where it is failing. Thanks again.

                            Comment

                            Working...
                            X