You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-user@james.apache.org by Martin Woolley <ma...@woolleynet.com> on 2003/01/16 22:03:25 UTC

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:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: ClassCastException / getAttribute

Posted by Martin Woolley <ma...@woolleynet.com>.
OK. Thanks Noel. Yes, I guess a few words on this in the docs would be a
good idea.

Hmmmm, now this has left me wondering how best to proceed. I could write one
big matcher with one big corresponding mailet but I was hoping to make
things a little more granular than that and to communicate state information
forward down the chain. If I use getAttribute/setAttribute as per my
original idea then the only scheme I can think of that would give me a
unique identifier would be formed by hashing some String derived from the
contents of the email and its recipients list. 'orrible! So I think I will
consign this idea to the bin before I even start!

You mentioned James 3. When is this expected to be available? Happy to be a
beta tester btw.

Apart from this, do you have any suggestions regarding the passing of
variable data from one matcher or mailet to another?

Regards

Martin

-----Original Message-----
From: Noel J. Bergman [mailto:noel@devtech.com]
Sent: 20 January 2003 16:57
To: James Users List
Subject: RE: ClassCastException / getAttribute


Martin,

Yes, there is a single MailetContext at the moment.  I think that we need to
revisit the issue of MailetContext attributes.  You raise an interesting
question that ought to be clarified in the Mailet API specification.  As for
synchronization, I would not trust anything not visible in the Mailet API,
so raise those issues explicitly with mention of the relevant methods.

	--- Noel

-----Original Message-----
From: Martin Woolley [mailto:martin@woolleynet.com]
Sent: Saturday, January 18, 2003 6:24
To: 'James Users List'
Subject: RE: ClassCastException / getAttribute


Hi

I'm really just experimenting at the moment. Can you explain the
MailetContext with respect to its scope please? You seem to be saying
there's a single global instance used by all instances of all mailets. Or
something like this anyway. And what are the key points to know regarding
multithreaded use/synchronisation?

Thanks in anticipation

-----Original Message-----
From: Noel J. Bergman [mailto:noel@devtech.com]
Sent: 17 January 2003 14:51
To: James Users List
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:martin@woolleynet.com]
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:noel@devtech.com]
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:martin@woolleynet.com]
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:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: ClassCastException / getAttribute

Posted by "Noel J. Bergman" <no...@devtech.com>.
Martin,

Yes, there is a single MailetContext at the moment.  I think that we need to
revisit the issue of MailetContext attributes.  You raise an interesting
question that ought to be clarified in the Mailet API specification.  As for
synchronization, I would not trust anything not visible in the Mailet API,
so raise those issues explicitly with mention of the relevant methods.

	--- Noel

-----Original Message-----
From: Martin Woolley [mailto:martin@woolleynet.com]
Sent: Saturday, January 18, 2003 6:24
To: 'James Users List'
Subject: RE: ClassCastException / getAttribute


Hi

I'm really just experimenting at the moment. Can you explain the
MailetContext with respect to its scope please? You seem to be saying
there's a single global instance used by all instances of all mailets. Or
something like this anyway. And what are the key points to know regarding
multithreaded use/synchronisation?

Thanks in anticipation

-----Original Message-----
From: Noel J. Bergman [mailto:noel@devtech.com]
Sent: 17 January 2003 14:51
To: James Users List
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:martin@woolleynet.com]
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:noel@devtech.com]
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:martin@woolleynet.com]
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:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: ClassCastException / getAttribute

Posted by Martin Woolley <ma...@woolleynet.com>.
Hi

I'm really just experimenting at the moment. Can you explain the
MailetContext with respect to its scope please? You seem to be saying
there's a single global instance used by all instances of all mailets. Or
something like this anyway. And what are the key points to know regarding
multithreaded use/synchronisation?

Thanks in anticipation

-----Original Message-----
From: Noel J. Bergman [mailto:noel@devtech.com]
Sent: 17 January 2003 14:51
To: James Users List
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:martin@woolleynet.com]
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:noel@devtech.com]
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:martin@woolleynet.com]
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:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: ClassCastException / getAttribute

Posted by "Noel J. Bergman" <no...@devtech.com>.
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:martin@woolleynet.com]
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:noel@devtech.com]
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:martin@woolleynet.com]
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:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: ClassCastException / getAttribute

Posted by Martin Woolley <ma...@woolleynet.com>.
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:noel@devtech.com]
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:martin@woolleynet.com]
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:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: ClassCastException / getAttribute

Posted by "Noel J. Bergman" <no...@devtech.com>.
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:martin@woolleynet.com]
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:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>