【问题标题】:Camel Beans - dynamic email subjectCamel Beans - 动态电子邮件主题
【发布时间】:2015-03-23 18:55:53
【问题描述】:

您好,我已经在 activemq 中配置了 camel.xml 文件来发送邮件。这是xml配置代码

<beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="
 http://camel.apache.org/schema/spring                                                   http://camel.apache.org/schema/spring/camel-spring.xsd
 http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
<propertyPlaceholder id="properties" location="classpath:properties"/>

<route>
  <description>Event Detected</description>
  <from uri="activemq:topic:Events?selector=JMSType='Event'"/>
  <to uri="xslt:file:{{activemq.conf}}/XLSs/Event.xsl"/>
  <to uri="smtp://mail.net:25?from=abc@abc.com&amp;to=abc@abc.com&amp;subject= Hello World!&amp;contentType=text/html"/>
</route>
</camelContext>
</bean>
</beans>

这是我用来将 xml 转换为 html 以在邮件正文中发送的 Event.xslt。

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet   version="1.0"                  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/Event">
  <html>
    <head>
      <title>Event Detected!</title>
    </head>
    <body>
    <h2>
      Event Detected!
    </h2>       
    <xsl:value-of select="Title"/>       
  </body>
</html>

有没有办法可以动态地将邮件主题设置为邮件正文中的 Title 属性?

这也是我的xml

 <?xml version="1.0" encoding="utf-8" ?> 
 <Event xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    xmlns:xsd="http://www.w3.org/2001/XMLSchema">
 <Title>Test</Title>  
 </Event>

【问题讨论】:

    标签: xslt jms apache-camel activemq


    【解决方案1】:

    您可以使用 xpath 从消息正文中提取标题,并将其设置为名称为主题的标题。然后邮件组件将使用标头中的值作为电子邮件主题。

    一些很长的东西

    <setHeader headerName="Subject">
      <xpath>/Event/Title/text()</xpath>
    </setHeader>
    

    请注意,xpath 可能很棘手,尤其是当您的 xml 使用命名空间时。如果是这种情况,那么 xpath 表达式也必须使用命名空间映射。

    查看更多详情

    【讨论】:

    • 嗨@clausibsen 当我在setHeader标签中将字符串声明为常量时,它工作正常 Test 但是当我指定我的 xpath 邮件组件本身不工作。
    • 我还在我的问题中添加了 xml 部分。
    • 它工作正常。我必须在指向我的 xslt 的 to uri 标记之前声明 标记。非常感谢!!!
    猜你喜欢
    • 1970-01-01
    • 2023-03-25
    • 2013-05-20
    • 2015-08-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多