Apache Camel如何使用邮件组件(如何编写xml)

时间:2018-08-27 06:13:45

标签: xml apache-camel blueprint-osgi

我正在尝试使用apache Camel和xml来获取邮件。 请教我如何编写xml。

※我只想用xml检查新邮件。邮件移到新邮件后。

  1. 我通过telnet发送到邮件
  2. 我检查了邮箱(新目录(Maildir))中的邮件
  3. 我写了xml。(您可以在下面查看)
  4. 我部署了jar文件,并且发生了错误。(您可以在下面查看)

・ XML

<?xml version="1.0" encoding="UTF-8"?>
<blueprint
  xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="
    http://www.osgi.org/xmlns/blueprint/v1.0.0
    https://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
  <camelContext xmlns="http://camel.apache.org/schema/blueprint">
  <route trace="true">
          <to uri="pop3://ipaddress?to=user@domain&amp;username=user@domain&amp;password=user&amp;unseen=true" />
  </route>
  </camelContext>
</blueprint>

・错误

2018-08-27 04:57:57,360 | INFO  | mix-7.0.0/deploy | fileinstall                      | 4 - org.apache.felix.fileinstall - 3.5.6 | Installing bundle mail-blueprint / 0.1.0.SNAPSHOT
2018-08-27 04:57:57,478 | WARN  | mix-7.0.0/deploy | NamespaceHandlerRegistryImpl     | 28 - org.apache.aries.blueprint.core - 1.7.1 | NamespaceHandler org.apache.camel.blueprint.handler.CamelNamespaceHandler is behaving badly and should be fixed
2018-08-27 04:57:57,661 | WARN  | mix-7.0.0/deploy | DefaultTypeConverter             | 43 - org.apache.camel.camel-core - 2.16.4 | Overriding type converter from: StaticMethodTypeConverter: public static org.apache.activemq.command.ActiveMQDestination org.apache.activemq.camel.converter.ActiveMQConverter.toDestination(java.lang.String) to: StaticMethodTypeConverter: public static org.apache.activemq.command.ActiveMQDestination org.apache.activemq.camel.converter.ActiveMQConverter.toDestination(java.lang.String)
2018-08-27 04:57:57,661 | WARN  | mix-7.0.0/deploy | DefaultTypeConverter             | 43 - org.apache.camel.camel-core - 2.16.4 | Overriding type converter from: InstanceMethodTypeConverter: public org.apache.activemq.command.ActiveMQMessage org.apache.activemq.camel.converter.ActiveMQMessageConverter.toMessage(org.apache.camel.Exchange) throws javax.jms.JMSException to: InstanceMethodTypeConverter: public org.apache.activemq.command.ActiveMQMessage org.apache.activemq.camel.converter.ActiveMQMessageConverter.toMessage(org.apache.camel.Exchange) throws javax.jms.JMSException
2018-08-27 04:57:57,661 | WARN  | mix-7.0.0/deploy | DefaultTypeConverter             | 43 - org.apache.camel.camel-core - 2.16.4 | Overriding type converter from: InstanceMethodTypeConverter: public org.apache.camel.Processor org.apache.activemq.camel.converter.ActiveMQMessageConverter.toProcessor(javax.jms.MessageListener) to: InstanceMethodTypeConverter: public org.apache.camel.Processor org.apache.activemq.camel.converter.ActiveMQMessageConverter.toProcessor(javax.jms.MessageListener)
2018-08-27 04:57:57,667 | WARN  | mix-7.0.0/deploy | BeanRecipe                       | 28 - org.apache.aries.blueprint.core - 1.7.1 | Object to be destroyed is not an instance of UnwrapperedBeanHolder, type: null
2018-08-27 04:57:57,667 | ERROR | mix-7.0.0/deploy | BlueprintContainerImpl           | 28 - org.apache.aries.blueprint.core - 1.7.1 | Unable to start blueprint container for bundle mail-blueprint/0.1.0.SNAPSHOT
org.osgi.service.blueprint.container.ComponentDefinitionException: Unable to initialize bean .camelBlueprint.factory.camel-2
        at org.apache.aries.blueprint.container.BeanRecipe.runBeanProcInit(BeanRecipe.java:738)[28:org.apache.aries.blueprint.core:1.7.1]
        at org.apache.aries.blueprint.container.BeanRecipe.internalCreate2(BeanRecipe.java:848)[28:org.apache.aries.blueprint.core:1.7.1]
        at org.apache.aries.blueprint.container.BeanRecipe.internalCreate(BeanRecipe.java:811)[28:org.apache.aries.blueprint.core:1.7.1]
        at org.apache.aries.blueprint.di.AbstractRecipe$1.call(AbstractRecipe.java:79)[28:org.apache.aries.blueprint.core:1.7.1]
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)[:1.8.0_181]
        at org.apache.aries.blueprint.di.AbstractRecipe.create(AbstractRecipe.java:88)[28:org.apache.aries.blueprint.core:1.7.1]
        at org.apache.aries.blueprint.container.BlueprintRepository.createInstances(BlueprintRepository.java:255)[28:org.apache.aries.blueprint.core:1.7.1]
        at org.apache.aries.blueprint.container.BlueprintRepository.createInstance(BlueprintRepository.java:233)[28:org.apache.aries.blueprint.core:1.7.1]
        at org.apache.aries.blueprint.container.BlueprintRepository.create(BlueprintRepository.java:148)[28:org.apache.aries.blueprint.core:1.7.1]
        at org.apache.aries.blueprint.container.BlueprintContainerImpl.getComponentInstance(BlueprintContainerImpl.java:796)[28:org.apache.aries.blueprint.core:1.7.1]
        at org.apache.camel.blueprint.handler.CamelNamespaceHandler$CamelDependenciesFinder.process(CamelNamespaceHandler.java:980)[40:org.apache.camel.camel-blueprint:2.16.4]
        at org.apache.aries.blueprint.container.BlueprintContainerImpl.processProcessors(BlueprintContainerImpl.java:569)[28:org.apache.aries.blueprint.core:1.7.1]
        at org.apache.aries.blueprint.container.BlueprintContainerImpl.doRun(BlueprintContainerImpl.java:395)[28:org.apache.aries.blueprint.core:1.7.1]
        at org.apache.aries.blueprint.container.BlueprintContainerImpl.run(BlueprintContainerImpl.java:276)[28:org.apache.aries.blueprint.core:1.7.1]
        at org.apache.aries.blueprint.container.BlueprintExtender.createContainer(BlueprintExtender.java:300)[28:org.apache.aries.blueprint.core:1.7.1]
        at org.apache.aries.blueprint.container.BlueprintExtender.createContainer(BlueprintExtender.java:269)[28:org.apache.aries.blueprint.core:1.7.1]
        at org.apache.aries.blueprint.container.BlueprintExtender.createContainer(BlueprintExtender.java:265)[28:org.apache.aries.blueprint.core:1.7.1]
        at org.apache.aries.blueprint.container.BlueprintExtender.modifiedBundle(BlueprintExtender.java:255)[28:org.apache.aries.blueprint.core:1.7.1]
        at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$Tracked.customizerModified(BundleHookBundleTracker.java:500)[39:org.apache.aries.util:1.1.1]
        at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$Tracked.customizerModified(BundleHookBundleTracker.java:433)[39:org.apache.aries.util:1.1.1]
        at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$AbstractTracked.track(BundleHookBundleTracker.java:725)[39:org.apache.aries.util:1.1.1]
        at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$Tracked.bundleChanged(BundleHookBundleTracker.java:463)[39:org.apache.aries.util:1.1.1]
        at org.apache.aries.util.tracker.hook.BundleHookBundleTracker$BundleEventHook.event(BundleHookBundleTracker.java:422)[39:org.apache.aries.util:1.1.1]
        at org.apache.felix.framework.util.SecureAction.invokeBundleEventHook(SecureAction.java:1179)[org.apache.felix.framework-5.6.1.jar:]
        at org.apache.felix.framework.EventDispatcher.createWhitelistFromHooks(EventDispatcher.java:730)[org.apache.felix.framework-5.6.1.jar:]
        at org.apache.felix.framework.EventDispatcher.fireBundleEvent(EventDispatcher.java:485)[org.apache.felix.framework-5.6.1.jar:]
        at org.apache.felix.framework.Felix.fireBundleEvent(Felix.java:4541)[org.apache.felix.framework-5.6.1.jar:]
        at org.apache.felix.framework.Felix.startBundle(Felix.java:2172)[org.apache.felix.framework-5.6.1.jar:]
        at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:998)[org.apache.felix.framework-5.6.1.jar:]
        at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundle(DirectoryWatcher.java:1253)[4:org.apache.felix.fileinstall:3.5.6]
        at org.apache.felix.fileinstall.internal.DirectoryWatcher.startBundles(DirectoryWatcher.java:1225)[4:org.apache.felix.fileinstall:3.5.6]
        at org.apache.felix.fileinstall.internal.DirectoryWatcher.doProcess(DirectoryWatcher.java:512)[4:org.apache.felix.fileinstall:3.5.6]
        at org.apache.felix.fileinstall.internal.DirectoryWatcher.process(DirectoryWatcher.java:361)[4:org.apache.felix.fileinstall:3.5.6]
        at org.apache.felix.fileinstall.internal.DirectoryWatcher.run(DirectoryWatcher.java:312)[4:org.apache.felix.fileinstall:3.5.6]
Caused by: java.lang.IllegalArgumentException: Route has no outputs: Route[[From[pop3://ipaddress?to=user@domain&username=user@domain&password=user&unseen=true]] -> []]
        at org.apache.camel.model.RouteDefinitionHelper.sanityCheckRoute(RouteDefinitionHelper.java:353)
        at org.apache.camel.core.xml.AbstractCamelContextFactoryBean.prepareRoutes(AbstractCamelContextFactoryBean.java:400)
        at org.apache.camel.core.xml.AbstractCamelContextFactoryBean.setupRoutes(AbstractCamelContextFactoryBean.java:377)
        at org.apache.camel.blueprint.CamelContextFactoryBean.afterPropertiesSet(CamelContextFactoryBean.java:322)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)[:1.8.0_181]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)[:1.8.0_181]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)[:1.8.0_181]
        at java.lang.reflect.Method.invoke(Method.java:498)[:1.8.0_181]
        at org.apache.aries.blueprint.utils.ReflectionUtils.invoke(ReflectionUtils.java:299)[28:org.apache.aries.blueprint.core:1.7.1]
        at org.apache.aries.blueprint.container.BeanRecipe.invoke(BeanRecipe.java:980)[28:org.apache.aries.blueprint.core:1.7.1]
        at org.apache.aries.blueprint.container.BeanRecipe.runBeanProcInit(BeanRecipe.java:736)[28:org.apache.aries.blueprint.core:1.7.1]
        ... 33 more
2018-08-27 04:57:57,678 | INFO  | mix-7.0.0/deploy | fileinstall                      | 4 - org.apache.felix.fileinstall - 3.5.6 | Started bundle: file:/opt/apache-servicemix-7.0.0/deploy/mail-blueprint-0.1.0-SNAPSHOT.jar

谢谢 ====================================== >

我固定了代码。我在下面每隔1分钟收到一次servicemix.log。 我检查邮件(新目录)移动到当前目录。 但是我无法在servicemix.log上检查telnet DATA的内容 我期望以下行为

【问题】 当我添加以下代码时,为什么没有错误?

<log message="received the message with xml" />

・代码

<?xml version="1.0" encoding="UTF-8"?> 
<blueprint
  xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="
    http://www.osgi.org/xmlns/blueprint/v1.0.0
    https://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">

  <camelContext xmlns="http://camel.apache.org/schema/blueprint">

  <route id="email-consumer-entrypoint-route" trace="true">
          <from uri="pop3://ipadress?to=user@domain&amp;username=user@domain&amp;password=user&amp;unseen=true&amp;consumer.delay=60000&amp;mapMailMessage=false&amp;fetchSize=1" />
          <log message="received the message with xml" />
  </route>
  </camelContext>

</blueprint>

・ servicemix.log

2018-08-27 07:19:42,960 | INFO  |  pop3://ipaddress | email-consumer-entrypoint-route  | 43 - org.apache.camel.camel-core - 2.16.4 | received the message with xml
2018-08-27 07:20:44,444 | INFO  |  pop3://ipaddress | email-consumer-entrypoint-route  | 43 - org.apache.camel.camel-core - 2.16.4 | received the message with xml

・期待行为

  1. 部署jar文件并移动时没有错误 / opt / serviecmix / deploy目录。
  2. 检查servicemix.log并仅查找新目录的新内容 文件(邮件)
  3. 检查cur目录并查找从新目录移出的邮件。

谢谢

================================================ -

我已修复并检查是否在servicemix.log上收到邮件 我有一个新问题。

【问题】 ・我想用“ to”标记下面的代码。   但是它无法读取“新目录(文件)”,也无法在servicemix.log上写入日志消息。   我可以像下面那样将端点写到“ to”标签吗?

<route id="email-consumer-entrypoint-route" trace="true">
 <from uri="direct:start" />
 <log message="received the message with xml" />
 <to uri="imap://ipaddress?to=user@domain&amp;username=user@domain&amp;password=user&amp;unseen=true&amp;consumer.delay=60000&amp;mapMailMessage=false&amp;fetchSize=1" />
</route>

・固定代码

<?xml version="1.0" encoding="UTF-8"?>
<blueprint
  xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="
    http://www.osgi.org/xmlns/blueprint/v1.0.0
    https://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">

  <camelContext xmlns="http://camel.apache.org/schema/blueprint">

  <route id="email-consumer-entrypoint-route" trace="true">
    <from uri="imap://ipaddress?to=user@domain&amp;username=user@domain&amp;password=user&amp;unseen=true&amp;consumer.delay=60000&amp;mapMailMessage=false&amp;fetchSize=1" />
    <log message="received the message with xml" />
  </route>

  </camelContext>

</blueprint>

谢谢 ====================================== >

非常感谢您。 我有新问题。

【问题】

  1. 我想只使用一次mailapi来使用sheduler(例如 quartz2组件)。(想要指定时间)我正在尝试使用 crystal2组件,但由于无效代码而没有移动。您可以 请参阅下面的代码。我应该怎么写?
  2. 我不使用“ consumer.delay”参数,如何停止该功能?

・错误

 - 2.16.4 | Error occurred during starting Camel: CamelContext(camel-2) due CronExpression '0 0/5 * * * ?@domain' is invalid.
java.lang.RuntimeException: CronExpression '0 0/5 * * * ?@domain' is invalid.

谢谢

1 个答案:

答案 0 :(得分:0)

当您说“带有XML的Apache Camel”时,我想您的意思是说是Spring DSL。

另一件事是,要使用骆驼接收电子邮件,您将需要使用骆驼邮件组件。就像收到一封电子邮件-

<route id="email-consumer-entrypoint-route">
            <from uri="imaps://imap.gmail.com?username=username@gmail.com&password=p@ssword&delete=false&unseen=true&consumer.delay=60000&mapMailMessage=false&fetchSize=1" />

有关更多详细信息,请查看http://camel.apache.org/mail.html