Hello, Now I load my java app, as a James side module, I would like to log some informations for debug and information, like James :
INFO 16:42:31,246 | org.apache.james.container.spring.JamesServerApplicationContext | Refreshing org.apache.james.container.spring.JamesServerApplicationContext@27e59128: startup date [Mon Jan 24 16:42:31 CET 2011]; root of context hierarchy INFO 16:42:31,859 | org.apache.james.container.spring.JamesServerApplicationContext | Closing org.apache.james.container.spring.JamesServerApplicationContext@27e59128: startup date [Mon Jan 24 16:42:31 CET 2011]; root of context hierarchy I tried to make a log : Log log = LogFactory.getLog(Main.class.getName()); But I got : log4j:WARN No appenders could be found for logger (com.kiengi.recup.POP.Main). log4j:WARN Please initialize the log4j system properly. So the only solution I have is : System.out.println("String to write to the console..."); Which is a little bit archaic... So do you have any clue about how to log properly to the Java (or Eclipse) console? Thx Luc. 2011/1/21 Norman Maurer <nor...@apache.org> > So you want to store a MimeMessage instance in the Mailbox ? > > You could use the MimeMessageInputStream class for this: > > > http://svn.apache.org/viewvc/james/server/trunk/core/src/main/java/org/apache/james/core/MimeMessageInputStream.java?view=markup > > Bye, > Norman > > > 2011/1/21 Luc Saulière <luc.sauli...@gmail.com>: > > It worked, that was a weird eclipse behaviour... > > You are very helpful, may I bother you one more time? maybe the last... > > maybe not :) > > > > Now I can easily store my messages in the db, ok, but the source of my > > messages is an inputStream. > > I don't know how to make an Inputstream from a mail message (as > javax.Mail, > > MimeMessage or Message...) cause each try I made gave me a "bad header > > message...". > > I see in James code the MessageResultImpl class which looks like a > Message > > def but with Content type instead of MimeMessage... > > I will try to parse every ppty of the message and make a new > MessageResult > > and find a way to extract the damned InputStream I need... > > > > Thx > > > > > > > > 2011/1/21 Norman Maurer <nor...@apache.org> > > > >> Maybe some nice classpath problem with eclipse or something like > >> that.. maybe just rename your beans config to something else and use > >> it in the Main class. Just to be sure it not use the wrong one.. > >> > >> Bye, > >> Norman > >> > >> > >> 2011/1/21 Luc Saulière <luc.sauli...@gmail.com>: > >> > Thx, it works perfectly with only only 7 beans. > >> > Just one weird thing, in my J3M2 project which worked perfectly > >> yesterday, I > >> > have now a XmlBeanDefinitionStoreException, which specify the > >> > spring-beans.xml line number 1770!!?! > >> > weird, isn't it? > >> > > >> > 2011/1/20 Norman Maurer <nor...@apache.org> > >> > > >> >> Hi there, > >> >> > >> >> exactly. In fact you will prolly only need to instance the needed > >> >> MailboxManager/SubscriptionManager/Authenticator implementation you > >> >> want to use in your code or just wire these implementations via > >> >> spring. Everything else should not be needed. > >> >> > >> >> Bye, > >> >> Norman > >> >> > >> >> > >> >> 2011/1/20 Luc Saulière <luc.sauli...@gmail.com>: > >> >> > Ok it works, I didnt know how to inject beans in my main class... > >> >> > It loads all the james app before sending one mail to the bdd, but > it > >> >> works > >> >> > :) In fact I hacked all the spring-bean.xml (from J3M2) without > >> deleting > >> >> any > >> >> > bean... I just have to select those I need. > >> >> > > >> >> > Thanks for your help, > >> >> > Luc > >> >> > > >> >> > 2011/1/20 Eric Charles <e...@apache.org> > >> >> > > >> >> >> Hi, > >> >> >> > >> >> >> Yes, direct injection does not work in main class because it is > not > >> >> fetched > >> >> >> from spring context. > >> >> >> > >> >> >> 1. you can create a bean and move the @Resource within, define the > >> bean > >> >> in > >> >> >> spring xml context, spring should inject the mailboxmanager in > your > >> >> bean. > >> >> >> You can get your bean with context.getBean("mybean") in main > class. > >> >> >> > >> >> >> 2. or simply call from the main class > >> context.getBean("mailboxmanager"), > >> >> it > >> >> >> should give you the mailboxmanager,... but it seems you had an > >> exception > >> >> (if > >> >> >> such, could you provide the stack trace ?). > >> >> >> > >> >> >> Tks, > >> >> >> > >> >> >> Eric > >> >> >> > >> >> >> > >> >> >> > >> >> >> On 20/01/2011 15:42, Luc Saulière wrote: > >> >> >> > >> >> >>> Hello Eric, > >> >> >>> That was quite the code I tested yesterday, but I got still the > same > >> >> >>> exception, because the MailboxManager is not initialized (null > >> pointer > >> >> >>> exception). > >> >> >>> I tried the @Resource annotation, I got 'null pointer' and I > tried > >> the > >> >> >>> BeanFactory way but I got a 'bean creation exception'... > >> >> >>> I think the first method is the good one, but I'm still looking > >> after > >> >> the > >> >> >>> magic method to instantiate my MailboxManager. > >> >> >>> > >> >> >>> Thx, > >> >> >>> Luc. > >> >> >>> > >> >> >>> > >> >> >>> 2011/1/20 Eric Charles<e...@apache.org> > >> >> >>> > >> >> >>> Hi, > >> >> >>>> > >> >> >>>> Probably you did not instantiate spring context. > >> >> >>>> > >> >> >>>> As first shot, you could copy Main to YourMain > >> >> >>>> > >> >> >>>> > >> >> >>>> > >> >> > >> > https://svn.apache.org/repos/asf/james/server/trunk/container-spring/src/main/java/org/apache/james/container/spring/Main.java > >> >> >>>> > >> >> >>>> and hack it with for example with code sample in [1]. > >> >> >>>> > >> >> >>>> You can also hack the spring context xml files if you don't want > to > >> >> load > >> >> >>>> all the beans, but you will still need a few of them to access > the > >> >> >>>> mailbox. > >> >> >>>> > >> >> >>>> Obviously, we could discuss the following: > >> >> >>>> 1. Add some code simple samples for basic operations on mailbox. > >> >> >>>> 2. Have a spring context for mailbox that could be used as a > >> >> stand-alone > >> >> >>>> (and also be imported in server). > >> >> >>>> > >> >> >>>> Tks, > >> >> >>>> > >> >> >>>> Eric > >> >> >>>> > >> >> >>>> [1] code sample (non compiling). > >> >> >>>> > >> >> >>>> public class YourMain { > >> >> >>>> > >> >> >>>> private static Log log = > >> LogFactory.getLog(Main.class.getName()); > >> >> >>>> > >> >> >>>> @Ressource(name="mailboxmanager") > >> >> >>>> private static MailboxManager; > >> >> >>>> > >> >> >>>> public static void main(String[] args) throws IOException { > >> >> >>>> > >> >> >>>> final JamesServerApplicationContext context = new > >> >> >>>> JamesServerApplicationContext(new String[] { > >> >> >>>> "context/james-server-context.xml" }); > >> >> >>>> context.registerShutdownHook(); > >> >> >>>> > >> >> >>>> // Bad code practice - Refactor it!!! > >> >> >>>> > >> >> >>>> MailboxPath mailboxPath = MailboxPath.inbox("userName"); > >> >> >>>> > >> >> >>>> MailboxSession mailboxSession = > >> >> >>>> mailboxManager.createSystemSession(userName30, log) > >> >> >>>> mailboxManager.startProcessingRequest(mailboxSession); > >> >> >>>> try { > >> >> >>>> mailboxManager.createMailbox(mailboxPath, > >> >> mailboxSession); > >> >> >>>> } > >> >> >>>> catch (MailboxExistsException e) { > >> >> >>>> // Do nothing, the mailbox already exists. > >> >> >>>> } > >> >> >>>> > >> >> >>>> mailboxManager.endProcessingRequest(mailboxSession); > >> >> >>>> > >> >> >>>> > >> >> >>>> MessageManager messageManager = > >> >> >>>> mailboxManager.getMailbox("mailboxPath", mailboxSession); > >> >> >>>> > >> >> >>>> // instanciate an input stream that contains your email > >> content > >> >> >>>> (body, header,...) > >> >> >>>> > >> >> >>>> messageManager.appendMessage(your-input-stream, > >> >> >>>> new Date(), > >> >> >>>> mailboxSession, > >> >> >>>> isRecent, > >> >> >>>> flags); > >> >> >>>> > mailboxManager.endProcessingRequest(mailboxSession); > >> >> >>>> } > >> >> >>>> > >> >> >>>> } > >> >> >>>> > >> >> >>>> } > >> >> >>>> > >> >> >>>> > >> >> >>>> > >> >> >>>> On 19/01/2011 20:07, Luc Saulière wrote: > >> >> >>>> > >> >> >>>> Thx for answering so quickly, I tried this in a new package > inside > >> >> >>>>> james-server-container-spring project... > >> >> >>>>> I have a public static void main(String[] args) containing my > >> private > >> >> >>>>> staticMailboxManager mailboxManager which > >> >> >>>>> > >> >> >>>>> is injected with the annotation > @Resource(name="mailboxmanager") > >> from > >> >> >>>>> the > >> >> >>>>> spring-bean.xml. > >> >> >>>>> But it does not succeed in initializing the variable and I get > a > >> >> >>>>> NullPointerException as soon as I use it... > >> >> >>>>> How can I initialize my beans without running the entire James > >> app? > >> >> >>>>> > >> >> >>>>> Tks. > >> >> >>>>> > >> >> >>>>> > >> >> >>>>> 2011/1/19 Eric Charles<e...@apache.org> > >> >> >>>>> > >> >> >>>>> Hi Luc, > >> >> >>>>> > >> >> >>>>>> Yes, code has changed in trunk since M2 (we don't use > MailServer > >> >> >>>>>> anymore). > >> >> >>>>>> In M2, or in trunk, the way to store mail is the same. > >> >> >>>>>> If you are deploying the your code/class in the james spring > >> >> container, > >> >> >>>>>> you > >> >> >>>>>> need to inject the mailboxmanager (with > >> >> >>>>>> @Resources(name="mailboxmanager") > >> >> >>>>>> and have a block of code such as: > >> >> >>>>>> > >> >> >>>>>> MailboxPath mailboxPath = MailboxPath.inbox(userName30); > >> >> >>>>>> MailboxSession mailboxSession = > >> >> >>>>>> mailboxManager.createSystemSession(userName30, log) > >> >> >>>>>> MessageManager messageManager = > >> >> mailboxManager.getMailbox(mailboxPath, > >> >> >>>>>> mailboxSession); > >> >> >>>>>> messageManager.appendMessage(your-input-stream, > >> >> >>>>>> new Date(), > >> >> >>>>>> mailboxSession, > >> >> >>>>>> isRecent, > >> >> >>>>>> flags); > >> >> >>>>>> > >> mailboxManager.endProcessingRequest(mailboxSession); > >> >> >>>>>> } > >> >> >>>>>> > >> >> >>>>>> I just realize I can't find a simple test case to in trunk to > >> show > >> >> this > >> >> >>>>>> (or > >> >> >>>>>> maybe I didn't look good). > >> >> >>>>>> If we don't have this, maybe you could open a jira so we can > >> further > >> >> >>>>>> provide test samples. > >> >> >>>>>> (this comes from the fact that all our tests were made from > an > >> >> "imap > >> >> >>>>>> perspective", we moved the imap test to another project, but > we > >> >> >>>>>> probably > >> >> >>>>>> should further enrich the pure mailbox test cases/samples). > >> >> >>>>>> > >> >> >>>>>> Tks, > >> >> >>>>>> > >> >> >>>>>> Eric > >> >> >>>>>> > >> >> >>>>>> > >> >> >>>>>> > >> >> >>>>>> > >> >> >>>>>> On 19/01/2011 18:04, Luc Sauličre wrote: > >> >> >>>>>> > >> >> >>>>>> Hello, > >> >> >>>>>> > >> >> >>>>>>> I'm developing with Math on the same mail app. We didn't > succeed > >> in > >> >> >>>>>>> storing > >> >> >>>>>>> mail as james3 does. In fact the SieveMailet class does not > have > >> a > >> >> >>>>>>> setUsersRepo method, I think you're dealing with a newer > version > >> of > >> >> >>>>>>> James3... > >> >> >>>>>>> We are developing with the M2 one and SieveMailet have a > >> >> setMailserver > >> >> >>>>>>> method instead. > >> >> >>>>>>> So, is there any way to store a mail (from another IMAP > >> connection > >> >> for > >> >> >>>>>>> instance) in the James3 mySQL db, as James3 does (i.e. > filling > >> >> >>>>>>> correctly > >> >> >>>>>>> all > >> >> >>>>>>> the appropriate tables...)? > >> >> >>>>>>> > >> >> >>>>>>> Thx for helping. > >> >> >>>>>>> Luc. > >> >> >>>>>>> > >> >> >>>>>>> 2011/1/17 Eric Charles<e...@apache.org> > >> >> >>>>>>> > >> >> >>>>>>> Hi, > >> >> >>>>>>> > >> >> >>>>>>> The mails store magic occurs in LocalDelivery where the > >> >> >>>>>>>> MailboxManager > >> >> >>>>>>>> is > >> >> >>>>>>>> injected. > >> >> >>>>>>>> (more precise, LocalDelivery uses the SieveMailet > initialized > >> with > >> >> >>>>>>>> the > >> >> >>>>>>>> MailboxManager) > >> >> >>>>>>>> sieveMailet.setUsersRepository(usersRepository); > >> >> >>>>>>>> sieveMailet.setMailboxManager(mailboxManager); > >> >> >>>>>>>> sieveMailet.init(m); > >> >> >>>>>>>> sieveMailet.setQuiet(true); > >> >> >>>>>>>> ... > >> >> >>>>>>>> if (mail.getState() != Mail.GHOST) { > >> >> >>>>>>>> sieveMailet.service(mail); > >> >> >>>>>>>> } > >> >> >>>>>>>> > >> >> >>>>>>>> You only need to know that *MailRepository is not for users' > >> mail > >> >> >>>>>>>> storage > >> >> >>>>>>>> http://james.apache.org/server/3/feature-persistence.html > >> >> >>>>>>>> > >> >> >>>>>>>> Both topics (mailet usage for delivery + separate mail > stores) > >> are > >> >> >>>>>>>> subject > >> >> >>>>>>>> to discussion will certainly change. > >> >> >>>>>>>> > >> >> >>>>>>>> Tks, > >> >> >>>>>>>> > >> >> >>>>>>>> Eric > >> >> >>>>>>>> > >> >> >>>>>>>> > >> >> >>>>>>>> > >> >> >>>>>>>> On 17/01/2011 11:43, math math wrote: > >> >> >>>>>>>> > >> >> >>>>>>>> Hello everybody, > >> >> >>>>>>>> > >> >> >>>>>>>> I am developping a web mail project using james 3M2. I'm > >> trying > >> >> to > >> >> >>>>>>>>> store > >> >> >>>>>>>>> mails in a "james3" way with an external application using > >> MySql > >> >> DB. > >> >> >>>>>>>>> I've > >> >> >>>>>>>>> tried to store mails using mysq database repositories for a > >> few > >> >> days > >> >> >>>>>>>>> now > >> >> >>>>>>>>> but > >> >> >>>>>>>>> i didn't succeed to do so... I 've traced the store method > of > >> >> >>>>>>>>> JDBCMailRepository class and also the ToRepository one. But > >> still > >> >> >>>>>>>>> don't > >> >> >>>>>>>>> know > >> >> >>>>>>>>> how James 3 is storing mails in the DB. > >> >> >>>>>>>>> > >> >> >>>>>>>>> I would be very glad if someone could help me in this task. > >> >> >>>>>>>>> > >> >> >>>>>>>>> Thanks, > >> >> >>>>>>>>> Mat > >> >> >>>>>>>>> > >> >> >>>>>>>>> > >> >> >>>>>>>>> > >> >> >>>>>>>>> > >> >> > --------------------------------------------------------------------- > >> >> >>>>>>>>> > >> >> >>>>>>>>> To unsubscribe, e-mail: > >> server-dev-unsubscr...@james.apache.org > >> >> >>>>>>>> For additional commands, e-mail: > >> server-dev-h...@james.apache.org > >> >> >>>>>>>> > >> >> >>>>>>>> > >> >> >>>>>>>> > >> >> >>>>>>>> > >> >> >>>>>>>> > >> >> > --------------------------------------------------------------------- > >> >> >>>>>>>> > >> >> >>>>>>> To unsubscribe, e-mail: > server-dev-unsubscr...@james.apache.org > >> >> >>>>>> For additional commands, e-mail: > >> server-dev-h...@james.apache.org > >> >> >>>>>> > >> >> >>>>>> > >> >> >>>>>> > >> >> >>>>>> > >> >> > --------------------------------------------------------------------- > >> >> >>>> To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org > >> >> >>>> For additional commands, e-mail: > server-dev-h...@james.apache.org > >> >> >>>> > >> >> >>>> > >> >> >>>> > >> >> >> > >> >> >> > --------------------------------------------------------------------- > >> >> >> To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org > >> >> >> For additional commands, e-mail: server-dev-h...@james.apache.org > >> >> >> > >> >> >> > >> >> > > >> >> > >> >> --------------------------------------------------------------------- > >> >> To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org > >> >> For additional commands, e-mail: server-dev-h...@james.apache.org > >> >> > >> >> > >> > > >> > >> --------------------------------------------------------------------- > >> To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org > >> For additional commands, e-mail: server-dev-h...@james.apache.org > >> > >> > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org > For additional commands, e-mail: server-dev-h...@james.apache.org > >