Martin,
Being pressed for time, I'm looking at the obvious:
java.lang.ClassCastException: java.lang.StringBuffer
I'm wondering if the exception weren't at:
String reason = (String) r;
so you might try r.toString() instead.
When did you setup those attributes, and do you really mean to have a global
attribute in the MailetContext per e-mail address and named by the address?
Same question, but did you mean to be calling getInitParameter?
--- Noel
-----Original Message-----
From: Martin Woolley [mailto:[EMAIL PROTECTED]]
Sent: Thursday, January 16, 2003 16:03
To: James Users List (E-mail)
Subject: ClassCastException / getAttribute
Hi
I'm playing around with James, getting myself familiar with the way mailets
and matchers are written. I ran into a problem today though wherein the code
below generated a ClassCastException. Extracts from the mailet.log file and
spoolmanager.log file (which includes the exception) follow. The problem
appears to emanate from the call to MailContext.getAttribute.
Any obvious schoolboy errors in here?
Thanks
public Collection match(Mail mail) {
MailetContext mc = getMailetContext();
Object o [] = mail.getRecipients().toArray();
ArrayList matchedRecipients = new ArrayList();
int l = o.length;
for (int i=0;i<l;i++) {
MailAddress ma = (MailAddress) o[i];
log("Checking reason attribute for recipient: "+ma.toString());
Object r = mc.getAttribute(ma.toString());
if (r != null) {
String reason = (String) r;
log("Reason = "+reason);
if (reason.indexOf("NaughtyWords") > -1) {
log("This recipient needs vetting for naughty words");
matchedRecipients.add(ma);
}
}
}
return matchedRecipients;
}
mailet.log contains:
16/01/03 20:56:30 INFO James.Mailet: FoundNaughtyWords: Checking reason
attribute for recipient: rebecca@localhost
16/01/03 20:56:30 INFO James.Mailet: ToRepository: Storing mail
Mail1042750587968-1 in file://var/mail/error/
spoolmanager.log contains:
16/01/03 21:02:01 ERROR spoolmanager: Exception in processor <vetting>
java.lang.ClassCastException: java.lang.StringBuffer
at com.woolleynet.james.matchers.FoundNaughtyWords.match(Unknown Source)
at
org.apache.james.transport.LinearProcessor.service(LinearProcessor.java:319)
at
org.apache.james.transport.JamesSpoolManager.process(JamesSpoolManager.java:
385)
at
org.apache.james.transport.JamesSpoolManager.run(JamesSpoolManager.java:315)
at
org.apache.avalon.excalibur.thread.impl.ExecutableRunnable.execute(Executabl
eRunnable.java:47)
at
org.apache.avalon.excalibur.thread.impl.WorkerThread.run(WorkerThread.java:8
0)
16/01/03 21:02:01 ERROR spoolmanager: An error occurred processing
Mail1042750919465-1 through vetting
16/01/03 21:02:01 ERROR spoolmanager: Result was error
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>