Exception during mail connection requires folder to be reset
------------------------------------------------------------
Key: CAMEL-2231
URL: https://issues.apache.org/activemq/browse/CAMEL-2231
Project: Apache Camel
Issue Type: Bug
Components: camel-mail
Affects Versions: 2.0.0, 1.6.2
Environment: 2.1-SNAPSHOT
Reporter: Christopher Hunt
I think that this problem may still be around with 2.1-SNAPSHOT:
http://fusesource.com/forums/thread.jspa?threadID=746&tstart=0
I noticed that I had a pop3 server outage and then subsequently had a similar
problem i.e. IllegalStateException, folder not open.
Here's when the outage started.
{code}
2009-11-26 11:57:55,316 [: MailComponent] WARN ultPollingConsumerPollStrategy
- Consumer Consumer[pop3://...] could not poll endpoint: pop3://... caused by:
Connect failed
javax.mail.MessagingException: Connect failed;
nested exception is:
java.net.NoRouteToHostException: No route to host
at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:161)
at javax.mail.Service.connect(Service.java:288)
at
org.apache.camel.component.mail.MailConsumer.ensureIsConnected(MailConsumer.java:241)
at
org.apache.camel.component.mail.MailConsumer.poll(MailConsumer.java:79)
at
org.apache.camel.impl.ScheduledPollConsumer.run(ScheduledPollConsumer.java:108)
at
java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
at
java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:317)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:150)
at
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(ScheduledThreadPoolExecutor.java:98)
at
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(ScheduledThreadPoolExecutor.java:181)
at
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:205)
at
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.net.NoRouteToHostException: No route to host
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:519)
at java.net.Socket.connect(Socket.java:469)
at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:233)
at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:189)
at com.sun.mail.pop3.Protocol.<init>(Protocol.java:94)
at com.sun.mail.pop3.POP3Store.getPort(POP3Store.java:214)
at com.sun.mail.pop3.POP3Store.protocolConnect(POP3Store.java:157)
... 13 more
{code}
This went on for about a minute or so and there was no more in the log file
until several hours later - in fact when an email appeared in the INBOX. I know
this because my personal email account was copied on the email and so I have
the timestamp.
I then get the following message every time I poll the server and have to
re-start my application to get over it:
{code}
2009-11-26 19:19:57,293 [: MailComponent] ERROR MailConsumer
- Folder not open
java.lang.IllegalStateException: Folder not open
at javax.mail.Folder.getMessages(Folder.java:938)
at javax.mail.Folder.search(Folder.java:1226)
at
org.apache.camel.component.mail.MailConsumer.poll(MailConsumer.java:107)
at
org.apache.camel.impl.ScheduledPollConsumer.run(ScheduledPollConsumer.java:108)
at
java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
at
java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:317)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:150)
at
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(ScheduledThreadPoolExecutor.java:98)
at
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(ScheduledThreadPoolExecutor.java:181)
at
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:205)
at
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
{code}
I took a look at MailConsumer.java and note the following code:
{code}
236 if (!connected) {
237 if (LOG.isDebugEnabled()) {
238 LOG.debug("Connecting to MailStore: " +
endpoint.getConfiguration().getMailStoreLogInformation());
239 }
240 store = sender.getSession().getStore(config.getProtocol());
241 store.connect(config.getHost(), config.getPort(),
config.getUsername(), config.getPassword());
242 }
{code}
If you're not connected then how is it possible to have a folder? Following
this logic my recommendation is to insert the following at line 242:
{code}
241 store.connect(config.getHost(), config.getPort(),
config.getUsername(), config.getPassword());
folder = null;
242 }
{code}
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.