Thanks Noel. Advice gratefully received. Martin
----- Original Message ----- From: "Noel J. Bergman" <[EMAIL PROTECTED]> To: "James Users List" <[EMAIL PROTECTED]> Sent: Friday, January 17, 2003 2:50 PM Subject: RE: ClassCastException / getAttribute > Martin, > > The ability to pass information related to a match from one matcher to > another will be part of the Mailet API v3, by using Mail attributes. What > you've done is globally assocated a string value with an e-mail address as > the key. Ripe for conflict and collision on many fronts. No guarantee that > other code won't use the same key for a different purpose, not association > of the value with a particular message, no contract for when the data gets > cleaned up. > > If you must do this today, then I would create a unique, well-known, key for > your concept and use that in your matchers. Then use that key to to store > an object that will manage the data associations. But without mail > attributes, you don't really have the infrastructure to do this cleanly. > > --- Noel > > -----Original Message----- > From: Martin Woolley [mailto:[EMAIL PROTECTED]] > Sent: Friday, January 17, 2003 2:19 > To: 'James Users List' > 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]> > > > -- > 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]>
