Hi Ard, Thanks for your answer. I hope you didn't go throw to much effort to give me this answer because got is running a few hours back -it was a real hard one to solve-. I didn't had the time to reports it back to this mailing list. I will study you solution to see if I can improve my own solution.
Thanks, Marcel -----Oorspronkelijk bericht----- Van: Ard Schrijvers [mailto:[EMAIL PROTECTED] Verzonden: woensdag 28 december 2005 13:25 Aan: [email protected] Onderwerp: RE: problems getting the BackgroundEnvironment working within a thread Hi Marcel, first of all, I notice a lot of people lately having more or less the same problem, including myself. I think it is way to hard in cocoon to call pipelines which were initiated from some background things. Anyway, think you should do something like: Make your class Contextualizable (which you probably already did) private org.apache.cocoon.environment.Context environmentContext; public void contextualize(Context ctx) throws ContextException { this.environmentContext = (org.apache.cocoon.environment.Context) ctx.get(Constants.CONTEXT_ENVIRONMENT_CONTEXT); } You will need import org.apache.avalon.framework.context.Context; import org.apache.avalon.framework.context.ContextException; import org.apache.avalon.framework.context.Contextualizable; and import org.apache.cocoon.Constants; Now, when you want the SourceResolver, do someting like: BackgroundEnvironment env = null; Processor processor = null; Object key = null; try { env = new BackgroundEnvironment(getLogger(), environmentContext); try { processor = (Processor) manager.lookup(Processor.ROLE); } catch (ServiceException e) { throw new CascadingRuntimeException("Couldn't look up the Processor",e); } env.startingProcessing(); key = CocoonComponentManager.startProcessing(env); CocoonComponentManager.enterEnvironment(env, new WrapperComponentManager(manager), processor); SourceResolver resolver = null; try { resolver = (SourceResolver) manager.lookup(SourceResolver.ROLE); Source inputSource = resolver.resolveURI("cocoon://foo"); InputStream sourceStream = inputSource.getInputStream(); try { // example what you could do with the inputStream DefaultHandler doHandler = new DefaultHandler(); SourceUtil.toSAX(inputSource, doHandler); } catch (ProcessingException e) { e.printStackTrace(); } finally { sourceStream.close(); } } catch (ServiceException e2) { // TODO Auto-generated catch block e2.printStackTrace(); } catch (MalformedURLException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } catch (SAXException e) { e.printStackTrace(); } finally { if(resolver!=null) manager.release(resolver); } } catch (MalformedURLException e) { e.printStackTrace(); } finally { CocoonComponentManager.leaveEnvironment(); CocoonComponentManager.endProcessing(env, key); if (processor != null) { manager.release(processor); } } Hope you can extract the parts you need, AS -----Original Message----- From: Marcel Rouwenhorst [mailto:[EMAIL PROTECTED] Posted At: zaterdag 24 december 2005 11:11 Posted To: Cocoon User List Conversation: problems getting the BackgroundEnvironment working within a thread Subject: problems getting the BackgroundEnvironment working within a thread Hi, I'm currently working on a mail daemon that sends mail from an oracle queue. (I don't want to use the cron block because it should be a continues thread in de background). I created a new daemon thread with the RunnableManager. This still works fine but when I want to call a pipeline with the SourceResolver from within the run method I get an exception that the cocoon protocol can't be used. I understood from some other mail in this mailing list that I should make a 'fake' environment with the BackgroundEnvironment. I'm trying to create a new instance of this class but that fails because I need a context. If I implement Contextualizable I get a Context - an Avalon context - but this one is incompatible with context - a Cocoon environment context - that the BackgroundEnvironment needs. What am I doing wrong here? Any help is appreciated! Thanks, Marcel --------------------------------------------------------------------- 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]
