RE: Reading resources within a mailet
Mitchell, I'm in favor of implementing MailetContext.getRealPath(String), with the same caveat mentioned by Craig for ServletContext.getRealpath(String): http://w6.metronet.com/~wjm/tomcat/2001/Feb/msg00294.html For James v3, another approach would be to put the resource into a JNDI context, but for something as simple as your request, requiring JNDI is like bringing a nuke to a knifefight. By the way, you should not be placing mailets into james.sar as of the next release. James v2.2 (test versions already available) and later allow mailets to be placed in SAR-INF/classes (class files) or SAR-INF/lib (jars). It wouldn't take more than a few minutes to add MailetContext.getRealPath(String) to James, but since that is a change in the published API, it really should be approved in advance, rather than subject to lazy consensus. If Danny, Serge and other developers don't notice this thread within a day or so, we should post a formal proposal on [EMAIL PROTECTED] --- Noel -Original Message- From: Mitchell Morris [mailto:[EMAIL PROTECTED] Sent: Thursday, June 05, 2003 18:45 To: James Users List Subject: RE: Reading resources within a mailet I don't know enough to know if that's the best thing to ask for. What I would like (eventually) is to be able to package this mailet up into "james.sar" such that it doesn't require editing the path to the configuration file if it gets unpacked into a different location. If something like getRealPath is the least intrusive (to James and mailets, not to my codebase) way to get there, then I'm +1. If the answer really is write more code so I can use "file://" references, then I can do that too but I don't know where to go RTFM to figure out how to do that. If the answer is more code to do variable substitution like "${app.base}", then once again I don't know which FM to read to know what I should be writing (except the obvious BeanScriptingFramework+JavaShell). I don't want to make trouble, I just want to point to a file with a relative path. On the third hand, if there's yet another way (that's more in keeping with being a good James/mailet/Avalon citizen) to skin this cat, then I'm all ears. +Mitchell -Original Message- From: Noel J. Bergman [mailto:[EMAIL PROTECTED] Sent: Thursday, June 05, 2003 6:27 PM To: James Users List Subject: RE: Reading resources within a mailet There is a service, but it isn't exposed to the Mailet API. James uses it, itself, as you can see from all of the file:// references. Are you asking for the equivalent of ServletContext.getRealPath(String), e.g., MailetContext.getRealPath(String)? I don't have a problem with it. I've been mulling it over for a while, since I have written several matchers and mailets that also need data from the file system. I don't think that I'd expose the whole selector-based approach that James uses. --- Noel -Original Message- From: Mitchell Morris [mailto:[EMAIL PROTECTED] Sent: Thursday, June 05, 2003 17:50 To: [EMAIL PROTECTED] Subject: Reading resources within a mailet My question: how do I refer to plain ol' file resources from within a mailet without hard-coding the full pathname? Failing that, is there an interpolation service available to a mailet? I have written a simple mailet to wrap an existing external service. The service object originally expected to fetch all of its configuration information from a resource (via getClass().getClassLoader().getResourceAsStream()). This didn't work, but in an unusual fashion: the InputStream was either null or empty, depending on whether or not the resource was found. That is, it didn't seem to read the resource file, but returned end-of-file immediately. After changing the service to fetch its configuration via reading a file, I now have to configure the mailet with a path to the service configuration file like so: /jakarta/james-2.1.3/apps/james/SAR-INF/gateway-config.xml The problem here is that the full path is hard-coded. I tried various interpolated bits, like "${app.base}/SAR-INF/gateway-config.xml", but there doesn't seem to be any interpolation performed when the config.xml file is parsed. The frustrating bit is that various repositories use URLs like "file://var/mail" to refer to relative locations but I can't spelunk fast enough to figure out how to implement the same feature in my mailet. So now what do I do? - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Reading resources within a mailet
> Noel J. Bergman wrote: > > By the way, you should not be placing mailets into james.sar as > of the next > > release. James v2.2 (test versions already available) and later allow > > mailets to be placed in SAR-INF/classes (class files) or > SAR-INF/lib (jars). Confirmed. When I upgraded to James 2.2.0a3, the Anti SPAM mailet worked just by dropping the BayesianAnalysisAntiSpammer.jar in the SAR-INF/lib... Thanks guys, this'll make maillet deployment etc. a much, much easier task! -Chris - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Reading resources within a mailet
I don't know enough to know if that's the best thing to ask for. What I would like (eventually) is to be able to package this mailet up into "james.sar" such that it doesn't require editing the path to the configuration file if it gets unpacked into a different location. If something like getRealPath is the least intrusive (to James and mailets, not to my codebase) way to get there, then I'm +1. If the answer really is write more code so I can use "file://" references, then I can do that too but I don't know where to go RTFM to figure out how to do that. If the answer is more code to do variable substitution like "${app.base}", then once again I don't know which FM to read to know what I should be writing (except the obvious BeanScriptingFramework+JavaShell). I don't want to make trouble, I just want to point to a file with a relative path. On the third hand, if there's yet another way (that's more in keeping with being a good James/mailet/Avalon citizen) to skin this cat, then I'm all ears. +Mitchell -Original Message- From: Noel J. Bergman [mailto:[EMAIL PROTECTED] Sent: Thursday, June 05, 2003 6:27 PM To: James Users List Subject: RE: Reading resources within a mailet There is a service, but it isn't exposed to the Mailet API. James uses it, itself, as you can see from all of the file:// references. Are you asking for the equivalent of ServletContext.getRealPath(String), e.g., MailetContext.getRealPath(String)? I don't have a problem with it. I've been mulling it over for a while, since I have written several matchers and mailets that also need data from the file system. I don't think that I'd expose the whole selector-based approach that James uses. --- Noel -Original Message- From: Mitchell Morris [mailto:[EMAIL PROTECTED] Sent: Thursday, June 05, 2003 17:50 To: [EMAIL PROTECTED] Subject: Reading resources within a mailet My question: how do I refer to plain ol' file resources from within a mailet without hard-coding the full pathname? Failing that, is there an interpolation service available to a mailet? I have written a simple mailet to wrap an existing external service. The service object originally expected to fetch all of its configuration information from a resource (via getClass().getClassLoader().getResourceAsStream()). This didn't work, but in an unusual fashion: the InputStream was either null or empty, depending on whether or not the resource was found. That is, it didn't seem to read the resource file, but returned end-of-file immediately. After changing the service to fetch its configuration via reading a file, I now have to configure the mailet with a path to the service configuration file like so: /jakarta/james-2.1.3/apps/james/SAR-INF/gateway-config.xml The problem here is that the full path is hard-coded. I tried various interpolated bits, like "${app.base}/SAR-INF/gateway-config.xml", but there doesn't seem to be any interpolation performed when the config.xml file is parsed. The frustrating bit is that various repositories use URLs like "file://var/mail" to refer to relative locations but I can't spelunk fast enough to figure out how to implement the same feature in my mailet. So now what do I do? - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Reading resources within a mailet
There is a service, but it isn't exposed to the Mailet API. James uses it, itself, as you can see from all of the file:// references. Are you asking for the equivalent of ServletContext.getRealPath(String), e.g., MailetContext.getRealPath(String)? I don't have a problem with it. I've been mulling it over for a while, since I have written several matchers and mailets that also need data from the file system. I don't think that I'd expose the whole selector-based approach that James uses. --- Noel -Original Message- From: Mitchell Morris [mailto:[EMAIL PROTECTED] Sent: Thursday, June 05, 2003 17:50 To: [EMAIL PROTECTED] Subject: Reading resources within a mailet My question: how do I refer to plain ol' file resources from within a mailet without hard-coding the full pathname? Failing that, is there an interpolation service available to a mailet? I have written a simple mailet to wrap an existing external service. The service object originally expected to fetch all of its configuration information from a resource (via getClass().getClassLoader().getResourceAsStream()). This didn't work, but in an unusual fashion: the InputStream was either null or empty, depending on whether or not the resource was found. That is, it didn't seem to read the resource file, but returned end-of-file immediately. After changing the service to fetch its configuration via reading a file, I now have to configure the mailet with a path to the service configuration file like so: /jakarta/james-2.1.3/apps/james/SAR-INF/gateway-config.xml The problem here is that the full path is hard-coded. I tried various interpolated bits, like "${app.base}/SAR-INF/gateway-config.xml", but there doesn't seem to be any interpolation performed when the config.xml file is parsed. The frustrating bit is that various repositories use URLs like "file://var/mail" to refer to relative locations but I can't spelunk fast enough to figure out how to implement the same feature in my mailet. So now what do I do? - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Reading resources within a mailet
Noel J. Bergman wrote: By the way, you should not be placing mailets into james.sar as of the next release. James v2.2 (test versions already available) and later allow mailets to be placed in SAR-INF/classes (class files) or SAR-INF/lib (jars). It wouldn't take more than a few minutes to add MailetContext.getRealPath(String) to James, but since that is a change in the published API, it really should be approved in advance, rather than subject to lazy consensus. If Danny, Serge and other developers don't notice this thread within a day or so, we should post a formal proposal on [EMAIL PROTECTED] I think the classloader should allow you to get a resource. Especially with the new classloader that's specific for mailets & matchers to allow separate bundling, it's very common to store default configuration, resource messages, and other information within the jar. getRealPath(String) is ok I guess. I'm not sure where it would point to though. It's clear in a webserver since that is the doc root, but we don't have that. -- Serge Knystautas President Lokitech >> software . strategy . design >> http://www.lokitech.com p. 301.656.5501 e. [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]