Author: norman
Date: Fri Feb 19 18:23:29 2010
New Revision: 911891
URL: http://svn.apache.org/viewvc?rev=911891&view=rev
Log:
Start POC for camel as Processor etc (JAMES-971)
Added:
james/server/trunk/spoolmanager/src/main/java/org/apache/james/transport/camel/
james/server/trunk/spoolmanager/src/main/java/org/apache/james/transport/camel/MailMessage.java
james/server/trunk/spoolmanager/src/main/java/org/apache/james/transport/camel/MailProcessorRouteBuilder.java
james/server/trunk/spoolmanager/src/main/java/org/apache/james/transport/camel/MailetProcessor.java
james/server/trunk/spoolmanager/src/main/java/org/apache/james/transport/camel/MatcherSplitter.java
james/server/trunk/spoolmanager/src/main/java/org/apache/james/transport/camel/SpoolComponent.java
james/server/trunk/spoolmanager/src/main/java/org/apache/james/transport/camel/SpoolConsumer.java
james/server/trunk/spoolmanager/src/main/java/org/apache/james/transport/camel/SpoolEndPoint.java
james/server/trunk/spoolmanager/src/main/java/org/apache/james/transport/camel/SpoolProducer.java
james/server/trunk/spoolmanager/src/main/resources/META-INF/
james/server/trunk/spoolmanager/src/main/resources/META-INF/services/
james/server/trunk/spoolmanager/src/main/resources/META-INF/services/org/
james/server/trunk/spoolmanager/src/main/resources/META-INF/services/org/apache/
james/server/trunk/spoolmanager/src/main/resources/META-INF/services/org/apache/james/
james/server/trunk/spoolmanager/src/main/resources/META-INF/services/org/apache/james/transport/
james/server/trunk/spoolmanager/src/main/resources/META-INF/services/org/apache/james/transport/camel/
james/server/trunk/spoolmanager/src/main/resources/META-INF/services/org/apache/james/transport/camel/spool
Modified:
james/server/trunk/pom.xml
james/server/trunk/spoolmanager/pom.xml
james/server/trunk/spring-deployment/pom.xml
Modified: james/server/trunk/pom.xml
URL:
http://svn.apache.org/viewvc/james/server/trunk/pom.xml?rev=911891&r1=911890&r2=911891&view=diff
==============================================================================
--- james/server/trunk/pom.xml (original)
+++ james/server/trunk/pom.xml Fri Feb 19 18:23:29 2010
@@ -1026,8 +1026,19 @@
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-core</artifactId>
+ <version>2.1.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-spring</artifactId>
+ <version>2.1.0</version>
+ <scope>runtime</scope>
+ </dependency>
- </dependencies>
+ </dependencies>
</dependencyManagement>
<profiles>
Modified: james/server/trunk/spoolmanager/pom.xml
URL:
http://svn.apache.org/viewvc/james/server/trunk/spoolmanager/pom.xml?rev=911891&r1=911890&r2=911891&view=diff
==============================================================================
--- james/server/trunk/spoolmanager/pom.xml (original)
+++ james/server/trunk/spoolmanager/pom.xml Fri Feb 19 18:23:29 2010
@@ -82,6 +82,11 @@
<artifactId>commons-configuration</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-core</artifactId>
+ </dependency>
+
<dependency>
<groupId>org.apache.james</groupId>
<artifactId>apache-standard-mailets</artifactId>
Added:
james/server/trunk/spoolmanager/src/main/java/org/apache/james/transport/camel/MailMessage.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/spoolmanager/src/main/java/org/apache/james/transport/camel/MailMessage.java?rev=911891&view=auto
==============================================================================
---
james/server/trunk/spoolmanager/src/main/java/org/apache/james/transport/camel/MailMessage.java
(added)
+++
james/server/trunk/spoolmanager/src/main/java/org/apache/james/transport/camel/MailMessage.java
Fri Feb 19 18:23:29 2010
@@ -0,0 +1,53 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.james.transport.camel;
+
+import org.apache.camel.impl.DefaultMessage;
+import org.apache.mailet.Mail;
+
+/**
+ * Message for Mails
+ *
+ */
+public class MailMessage extends DefaultMessage{
+ public final static String STATE = "mailstate";
+
+ private Mail mail;
+ public MailMessage(Mail mail) {
+ this.mail = mail;
+ }
+
+
+ @Override
+ protected Object createBody() {
+ return mail;
+ }
+
+
+ @Override
+ public Object getHeader(String name) {
+ if (STATE.equals(name)) {
+ return mail.getState();
+ }
+ return super.getHeader(name);
+ }
+
+
+}
Added:
james/server/trunk/spoolmanager/src/main/java/org/apache/james/transport/camel/MailProcessorRouteBuilder.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/spoolmanager/src/main/java/org/apache/james/transport/camel/MailProcessorRouteBuilder.java?rev=911891&view=auto
==============================================================================
---
james/server/trunk/spoolmanager/src/main/java/org/apache/james/transport/camel/MailProcessorRouteBuilder.java
(added)
+++
james/server/trunk/spoolmanager/src/main/java/org/apache/james/transport/camel/MailProcessorRouteBuilder.java
Fri Feb 19 18:23:29 2010
@@ -0,0 +1,209 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.james.transport.camel;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.annotation.PreDestroy;
+import javax.annotation.Resource;
+import javax.mail.MessagingException;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.model.ChoiceDefinition;
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.HierarchicalConfiguration;
+import org.apache.commons.logging.Log;
+import org.apache.james.lifecycle.Configurable;
+import org.apache.james.lifecycle.LogEnabled;
+import org.apache.james.transport.MailetLoader;
+import org.apache.james.transport.MatcherLoader;
+import org.apache.mailet.Mailet;
+import org.apache.mailet.Matcher;
+import org.apache.mailet.base.MatcherInverter;
+
+/**
+ * Build up the Camel Route by parsing the spoolmanager.xml configuration
file.
+ *
+ * @author norman
+ *
+ */
+public class MailProcessorRouteBuilder extends RouteBuilder implements
Configurable, LogEnabled {
+
+ private MatcherLoader matcherLoader;
+ private HierarchicalConfiguration config;
+ private MailetLoader mailetLoader;
+ private Log logger;
+
+ private List<Mailet> mailets = new ArrayList<Mailet>();
+
+ @Resource(name = "matcherpackages")
+ public void setMatcherLoader(MatcherLoader matcherLoader) {
+ this.matcherLoader = matcherLoader;
+ }
+
+ @Resource(name = "mailetpackages")
+ public void setMailetLoader(MailetLoader mailetLoader) {
+ this.mailetLoader = mailetLoader;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.camel.builder.RouteBuilder#configure()
+ */
+ @SuppressWarnings("unchecked")
+ @Override
+ public void configure() throws Exception {
+
+
+ ChoiceDefinition spoolDef = from("spool://spoolRepository").choice();
+
+ List<HierarchicalConfiguration> processorConfs =
config.configurationsAt("processor");
+ for (int i = 0; i < processorConfs.size(); i++) {
+ final HierarchicalConfiguration processorConf =
processorConfs.get(i);
+ String processorName = processorConf.getString("[...@name]");
+
+ // Check which route we need to go
+ ChoiceDefinition processorDef =
spoolDef.when(header(MailMessage.STATE).isEqualTo(processorName));
+
+ final List<HierarchicalConfiguration> mailetConfs =
processorConf.configurationsAt("mailet");
+ // Loop through the mailet configuration, load
+ // all of the matcher and mailets, and add
+ // them to the processor.
+ for (int j = 0; j < mailetConfs.size(); j++) {
+ HierarchicalConfiguration c = mailetConfs.get(j);
+
+ // We need to set this because of correctly parsing comma
+ String mailetClassName = c.getString("[...@class]");
+ String matcherName = c.getString("[...@match]", null);
+ String invertedMatcherName = c.getString("[...@notmatch]",
null);
+
+ Mailet mailet = null;
+ Matcher matcher = null;
+ try {
+
+ if (matcherName != null && invertedMatcherName != null) {
+ // if no matcher is configured throw an Exception
+ throw new ConfigurationException("Please configure
only match or nomatch per mailet");
+ } else if (matcherName != null) {
+ matcher = matcherLoader.getMatcher(matcherName);
+ } else if (invertedMatcherName != null) {
+ matcher = new
MatcherInverter(matcherLoader.getMatcher(invertedMatcherName));
+
+ } else {
+ // default matcher is All
+ matcher = matcherLoader.getMatcher("All");
+ }
+
+ // The matcher itself should log that it's been inited.
+ if (logger.isInfoEnabled()) {
+ StringBuffer infoBuffer = new
StringBuffer(64).append("Matcher ").append(matcherName).append("
instantiated.");
+ logger.info(infoBuffer.toString());
+ }
+ } catch (MessagingException ex) {
+ // **** Do better job printing out exception
+ if (logger.isErrorEnabled()) {
+ StringBuffer errorBuffer = new
StringBuffer(256).append("Unable to init matcher
").append(matcherName).append(": ").append(ex.toString());
+ logger.error(errorBuffer.toString(), ex);
+ if (ex.getNextException() != null) {
+ logger.error("Caused by nested exception: ",
ex.getNextException());
+ }
+ }
+ System.err.println("Unable to init matcher " +
matcherName);
+ System.err.println("Check spool manager logs for more
details.");
+ // System.exit(1);
+ throw new ConfigurationException("Unable to init matcher",
ex);
+ }
+ try {
+ mailet = mailetLoader.getMailet(mailetClassName, c);
+ if (logger.isInfoEnabled()) {
+ StringBuffer infoBuffer = new
StringBuffer(64).append("Mailet ").append(mailetClassName).append("
instantiated.");
+ logger.info(infoBuffer.toString());
+ }
+ } catch (MessagingException ex) {
+ // **** Do better job printing out exception
+ if (logger.isErrorEnabled()) {
+ StringBuffer errorBuffer = new
StringBuffer(256).append("Unable to init mailet
").append(mailetClassName).append(": ").append(ex.toString());
+ logger.error(errorBuffer.toString(), ex);
+ if (ex.getNextException() != null) {
+ logger.error("Caused by nested exception: ",
ex.getNextException());
+ }
+ }
+ System.err.println("Unable to init mailet " +
mailetClassName);
+ System.err.println("Check spool manager logs for more
details.");
+ throw new ConfigurationException("Unable to init mailet",
ex);
+ }
+ if (mailet != null && matcher != null) {
+ // Store the matcher to use for splitter
+ processorDef.setHeader(MatcherSplitter.MATCHER_HEADER,
constant(matcher))
+ // do splitting
+ .split().method(MatcherSplitter.class)
+ // check if we need to execute the mailet and
remove headers
+
.choice().when(header(MatcherSplitter.MATCHER_MATCHED_HEADER).isEqualTo(true)).process(new
MailetProcessor(mailet)).removeHeader(MatcherSplitter.MATCHER_MATCHED_HEADER)
+ .end()
+ .end()
+ // remove matcher from header
+ .removeHeader(MatcherSplitter.MATCHER_HEADER);
+
+ // store mailet for later destroy on shutdown
+ mailets.add(mailet);
+ }
+
+
+ }
+ }
+
+ // just use a mock for now
+ spoolDef.end().to("mock:end");
+
+ }
+
+ @PreDestroy
+ public void dispose() {
+ Iterator<Mailet> it = mailets.iterator();
+ boolean debugEnabled = logger.isDebugEnabled();
+ while (it.hasNext()) {
+ Mailet mailet = it.next();
+ if (debugEnabled) {
+ logger.debug("Shutdown mailet " + mailet.getMailetInfo());
+ }
+ mailet.destroy();
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.apache.james.lifecycle.Configurable#configure(org.apache.commons.configuration.HierarchicalConfiguration)
+ */
+ public void configure(HierarchicalConfiguration config) throws
ConfigurationException {
+ this.config = config;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.apache.james.lifecycle.LogEnabled#setLog(org.apache.commons.logging.Log)
+ */
+ public void setLog(Log log) {
+ this.logger = log;
+
+ }
+
+}
Added:
james/server/trunk/spoolmanager/src/main/java/org/apache/james/transport/camel/MailetProcessor.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/spoolmanager/src/main/java/org/apache/james/transport/camel/MailetProcessor.java?rev=911891&view=auto
==============================================================================
---
james/server/trunk/spoolmanager/src/main/java/org/apache/james/transport/camel/MailetProcessor.java
(added)
+++
james/server/trunk/spoolmanager/src/main/java/org/apache/james/transport/camel/MailetProcessor.java
Fri Feb 19 18:23:29 2010
@@ -0,0 +1,35 @@
+package org.apache.james.transport.camel;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.mailet.Mail;
+import org.apache.mailet.Mailet;
+
+/**
+ * Mailet wrapper which execute a Mailet in a Processor
+ *
+ */
+public class MailetProcessor implements Processor{
+
+ private Mailet mailet;
+
+ public MailetProcessor(Mailet mailet) {
+ this.mailet = mailet;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.camel.Processor#process(org.apache.camel.Exchange)
+ */
+ public void process(Exchange exchange) throws Exception {
+ //System.out.println("Call mailet " + mailet);
+ try {
+ mailet.service((Mail)exchange.getIn().getBody());
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw e;
+ }
+
+ }
+
+}
Added:
james/server/trunk/spoolmanager/src/main/java/org/apache/james/transport/camel/MatcherSplitter.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/spoolmanager/src/main/java/org/apache/james/transport/camel/MatcherSplitter.java?rev=911891&view=auto
==============================================================================
---
james/server/trunk/spoolmanager/src/main/java/org/apache/james/transport/camel/MatcherSplitter.java
(added)
+++
james/server/trunk/spoolmanager/src/main/java/org/apache/james/transport/camel/MatcherSplitter.java
Fri Feb 19 18:23:29 2010
@@ -0,0 +1,100 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.james.transport.camel;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.mail.MessagingException;
+
+import org.apache.camel.Body;
+import org.apache.camel.Header;
+import org.apache.james.core.MailImpl;
+import org.apache.mailet.Mail;
+import org.apache.mailet.MailAddress;
+import org.apache.mailet.Matcher;
+
+/**
+ * A Splitter for use with Camel to split the MailMessage into many pieces if
needed. This is done
+ * by use a Matcher.
+ *
+ *
+ */
+public class MatcherSplitter {
+
+ public final static String MATCHER_MATCHED_HEADER = "matched";
+
+ public final static String MATCHER_HEADER = "matcher";
+
+ /**
+ * Generate a List of MailMessage instances for the give @Body. This is
done by using the given Matcher to see if we need more then one instance of the
+ * MailMessage
+ *
+ * @param matcher Matcher to use for splitting
+ * @param mail Mail which is stored in the @Body of the MailMessage
+ * @return mailMessageList
+ * @throws MessagingException
+ */
+ public List<MailMessage> split(@Header(MATCHER_HEADER) Matcher
matcher,@Body Mail mail) throws MessagingException {
+ //System.out.println("Call matcher " + matcher);
+ List<MailMessage> mails = new ArrayList<MailMessage>();
+ boolean fullMatch = false;
+
+
+ Collection<MailAddress> matchedRcpts = matcher.match(mail);
+
+ // check if the matcher matched
+ if (matchedRcpts != null && matchedRcpts.isEmpty() == false) {
+
+ // check if we need to create another instance of the mail. This
is only needed if not all
+ // recipients matched
+ if (matchedRcpts.equals(mail.getRecipients()) == false) {
+ Mail newMail = new MailImpl(mail);
+ newMail.setRecipients(matchedRcpts);
+
+ MailMessage newmsg = new MailMessage(newMail);
+
+ // Set a header because the matcher matched. This can be used
later when processing the route
+ newmsg.setHeader(MATCHER_MATCHED_HEADER, true);
+ mails.add(newmsg);
+
+ List<MailAddress> rcpts = new
ArrayList<MailAddress>(mail.getRecipients());
+ Iterator<MailAddress> rcptsIterator =
newMail.getRecipients().iterator();
+ while(rcptsIterator.hasNext()) {
+ rcpts.remove(rcptsIterator.next());
+ }
+ mail.setRecipients(rcpts);
+ } else {
+ // all recipients matched
+ fullMatch = true;
+ }
+ }
+ MailMessage mailMsg = new MailMessage(mail);
+ if (fullMatch) {
+ // Set a header because the matcher matched. This can be used
later when processing the route
+ mailMsg.setHeader("match", true);
+ }
+ mails.add(mailMsg);
+
+ return mails;
+ }
+}
Added:
james/server/trunk/spoolmanager/src/main/java/org/apache/james/transport/camel/SpoolComponent.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/spoolmanager/src/main/java/org/apache/james/transport/camel/SpoolComponent.java?rev=911891&view=auto
==============================================================================
---
james/server/trunk/spoolmanager/src/main/java/org/apache/james/transport/camel/SpoolComponent.java
(added)
+++
james/server/trunk/spoolmanager/src/main/java/org/apache/james/transport/camel/SpoolComponent.java
Fri Feb 19 18:23:29 2010
@@ -0,0 +1,63 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.james.transport.camel;
+
+import java.util.List;
+import java.util.Map;
+
+import javax.annotation.Resource;
+
+import org.apache.camel.Endpoint;
+import org.apache.camel.impl.DefaultComponent;
+import org.apache.james.services.SpoolManager;
+import org.apache.james.services.SpoolRepository;
+import org.apache.mailet.MailetConfig;
+import org.apache.mailet.MatcherConfig;
+
+public class SpoolComponent extends DefaultComponent implements SpoolManager {
+
+ private SpoolRepository spool;
+
+ @Resource(name="spoolrepository")
+ public void setSpoolRepository(SpoolRepository spool) {
+ this.spool = spool;
+ }
+
+ @Override
+ protected Endpoint createEndpoint(String uri, String remaining,
Map<String, Object> parameters) throws Exception {
+
+ return new SpoolEndPoint(uri,this, spool);
+ }
+
+ public List<MailetConfig> getMailetConfigs(String processorName) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public List<MatcherConfig> getMatcherConfigs(String processorName) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public String[] getProcessorNames() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+}
Added:
james/server/trunk/spoolmanager/src/main/java/org/apache/james/transport/camel/SpoolConsumer.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/spoolmanager/src/main/java/org/apache/james/transport/camel/SpoolConsumer.java?rev=911891&view=auto
==============================================================================
---
james/server/trunk/spoolmanager/src/main/java/org/apache/james/transport/camel/SpoolConsumer.java
(added)
+++
james/server/trunk/spoolmanager/src/main/java/org/apache/james/transport/camel/SpoolConsumer.java
Fri Feb 19 18:23:29 2010
@@ -0,0 +1,105 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.james.transport.camel;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.impl.DefaultConsumer;
+import org.apache.camel.impl.DefaultEndpoint;
+import org.apache.james.lifecycle.LifecycleUtil;
+import org.apache.james.services.SpoolRepository;
+import org.apache.mailet.Mail;
+
+public class SpoolConsumer extends DefaultConsumer{
+
+
+ private SpoolRepository spool;
+ private Processor processor;
+
+ public SpoolConsumer(DefaultEndpoint endpoint, Processor processor,
SpoolRepository spool) {
+ super(endpoint, processor);
+ this.spool = spool;
+ this.processor = processor;
+ }
+
+
+ public Exchange receive() {
+ Exchange ex = getEndpoint().createExchange();
+
+ Mail mail;
+ try {
+ mail = spool.accept();
+
+ // Only remove an email from the spool is processing is
+ // complete, or if it has no recipients
+ if ((Mail.GHOST.equals(mail.getState())) ||
+ (mail.getRecipients() == null) ||
+ (mail.getRecipients().size() == 0)) {
+ spool.remove(mail.getName());
+ //if (logger.isDebugEnabled()) {
+ StringBuffer debugBuffer =
+ new StringBuffer(64)
+ .append("==== Removed from spool mail ")
+ .append(mail.getName())
+ .append("====");
+ // logger.debug(debugBuffer.toString());
+ // }
+ System.out.println(debugBuffer.toString());
+ LifecycleUtil.dispose(mail);
+
+ }
+
+ ex.setIn(new MailMessage(mail));
+ processor.process(ex);
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ ex.setException(e);
+
+ }
+ return ex;
+
+ }
+
+
+ @Override
+ protected void doStart() throws Exception {
+ super.doStart();
+ Thread t = new Thread(new Runnable() {
+
+ public void run() {
+ while(true) {
+ receive();
+ }
+ }
+
+ });
+ t.setDaemon(true);
+ t.start();
+ }
+
+
+ @Override
+ protected void doStop() throws Exception {
+ super.doStop();
+
+ }
+
+}
Added:
james/server/trunk/spoolmanager/src/main/java/org/apache/james/transport/camel/SpoolEndPoint.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/spoolmanager/src/main/java/org/apache/james/transport/camel/SpoolEndPoint.java?rev=911891&view=auto
==============================================================================
---
james/server/trunk/spoolmanager/src/main/java/org/apache/james/transport/camel/SpoolEndPoint.java
(added)
+++
james/server/trunk/spoolmanager/src/main/java/org/apache/james/transport/camel/SpoolEndPoint.java
Fri Feb 19 18:23:29 2010
@@ -0,0 +1,67 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.james.transport.camel;
+
+import org.apache.camel.Consumer;
+import org.apache.camel.Processor;
+import org.apache.camel.Producer;
+import org.apache.camel.impl.DefaultEndpoint;
+import org.apache.james.services.SpoolRepository;
+
+public class SpoolEndPoint extends DefaultEndpoint{
+
+ private SpoolRepository spool;
+
+
+ public SpoolEndPoint(String endpointUri, SpoolComponent component,
SpoolRepository spool) {
+ super(endpointUri, component);
+ this.spool = spool;
+ }
+
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.camel.Endpoint#createProducer()
+ */
+ public Producer createProducer() throws Exception {
+ return new SpoolProducer(this,spool);
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.camel.IsSingleton#isSingleton()
+ */
+ public boolean isSingleton() {
+ return true;
+ }
+
+
+ /*
+ * (non-Javadoc)
+ * @see
org.apache.camel.Endpoint#createConsumer(org.apache.camel.Processor)
+ */
+ public Consumer createConsumer(Processor processor) throws Exception {
+ SpoolConsumer consumer = new SpoolConsumer(this,processor,spool);
+ //configureConsumer(consumer);
+ return consumer;
+
+ }
+
+}
Added:
james/server/trunk/spoolmanager/src/main/java/org/apache/james/transport/camel/SpoolProducer.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/spoolmanager/src/main/java/org/apache/james/transport/camel/SpoolProducer.java?rev=911891&view=auto
==============================================================================
---
james/server/trunk/spoolmanager/src/main/java/org/apache/james/transport/camel/SpoolProducer.java
(added)
+++
james/server/trunk/spoolmanager/src/main/java/org/apache/james/transport/camel/SpoolProducer.java
Fri Feb 19 18:23:29 2010
@@ -0,0 +1,49 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+package org.apache.james.transport.camel;
+
+import org.apache.camel.Endpoint;
+import org.apache.camel.Exchange;
+import org.apache.camel.impl.DefaultProducer;
+import org.apache.camel.util.ExchangeHelper;
+import org.apache.james.services.SpoolRepository;
+import org.apache.mailet.Mail;
+
+public class SpoolProducer extends DefaultProducer{
+
+ private SpoolRepository spool;
+
+ public SpoolProducer(Endpoint endpoint, SpoolRepository spool) {
+ super(endpoint);
+ this.spool = spool;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.camel.Processor#process(org.apache.camel.Exchange)
+ */
+ public void process(Exchange exchange) throws Exception {
+ Exchange newExchange = getEndpoint().createExchange(exchange);
+ Mail mail = (Mail) newExchange.getIn().getBody();
+ spool.store(mail);
+ ExchangeHelper.copyResults(exchange, newExchange);
+ }
+
+}
Added:
james/server/trunk/spoolmanager/src/main/resources/META-INF/services/org/apache/james/transport/camel/spool
URL:
http://svn.apache.org/viewvc/james/server/trunk/spoolmanager/src/main/resources/META-INF/services/org/apache/james/transport/camel/spool?rev=911891&view=auto
==============================================================================
---
james/server/trunk/spoolmanager/src/main/resources/META-INF/services/org/apache/james/transport/camel/spool
(added)
+++
james/server/trunk/spoolmanager/src/main/resources/META-INF/services/org/apache/james/transport/camel/spool
Fri Feb 19 18:23:29 2010
@@ -0,0 +1,18 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+class=org.apache.james.transport.camel.SpoolComponent
Modified: james/server/trunk/spring-deployment/pom.xml
URL:
http://svn.apache.org/viewvc/james/server/trunk/spring-deployment/pom.xml?rev=911891&r1=911890&r2=911891&view=diff
==============================================================================
--- james/server/trunk/spring-deployment/pom.xml (original)
+++ james/server/trunk/spring-deployment/pom.xml Fri Feb 19 18:23:29 2010
@@ -210,6 +210,17 @@
<artifactId>commons-logging</artifactId>
</dependency>
<dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-core</artifactId>
+ <scope>runtime</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-spring</artifactId>
+ <scope>runtime</scope>
+ </dependency>
+
+ <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<scope>runtime</scope>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]