Aha. 'twas a schoolboy error in fact. Replacing (String) to blah.toString() did the trick. Thanks Noel!
----- Original Message ----- From: "Martin Woolley" <[EMAIL PROTECTED]> To: "'James Users List'" <[EMAIL PROTECTED]> Sent: Friday, January 17, 2003 7:18 AM Subject: RE: ClassCastException / getAttribute > Hi > > I set the attribute in another matcher that executed prior to this one. It's > in a different processor. Does this matter? Yes, I did mean to do things > this way but that doesn't mean it makes sense! What I want to be able to do > is pass some indication of the result of processing one matcher to a matcher > later in the chain. I figured that I could do this by setting attributes in > the context. Is there an alternative? The "per recipient" bit is because > there can be a variety of reasons why a recipient be matched in the first > matcher, and I want to pass that information forward. Advise on best > practice most certainly invited. > > And I'll look at your coding suggestion as well of course. > > Thanks Noel > > Martin > > -----Original Message----- > From: Noel J. Bergman [mailto:[EMAIL PROTECTED]] > Sent: 16 January 2003 21:38 > To: James-User Mailing List > Subject: RE: ClassCastException / getAttribute > > > 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]> > > > > > -- > To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> > For additional commands, e-mail: <mailto:[EMAIL PROTECTED]> > ---------------------------------------------------------------------------T his email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. Copying this email or in any way disseminating its content to any other person is strictly prohibited. If you have received this email in error please notify [EMAIL PROTECTED] -------------------------------------------------------------------------- This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. Copying this email or in any way disseminating its content to any other person is strictly prohibited. If you have received this email in error please notify [EMAIL PROTECTED] -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
