You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@camel.apache.org by "Willem Jiang (JIRA)" <ji...@apache.org> on 2013/12/25 11:53:50 UTC

[jira] [Commented] (CAMEL-7089) The "context" attribute does not exist in Groovy ScriptContext

    [ https://issues.apache.org/jira/browse/CAMEL-7089?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13856568#comment-13856568 ] 

Willem Jiang commented on CAMEL-7089:
-------------------------------------

I checked the code of ScriptBuilder, it looks like the context is support out box.
{code}
        int scope = ScriptContext.ENGINE_SCOPE;
        context.setAttribute("context", exchange.getContext(), scope);
        context.setAttribute("camelContext", exchange.getContext(), scope);
        context.setAttribute("exchange", exchange, scope);
        Message in = exchange.getIn();
        context.setAttribute("request", in, scope);
        context.setAttribute("headers", in.getHeaders(), scope);
        context.setAttribute("body", in.getBody(), scope);
{code}
Can you try to use camelContext instead of context in your groovy script?


> The "context" attribute does not exist in Groovy ScriptContext
> --------------------------------------------------------------
>
>                 Key: CAMEL-7089
>                 URL: https://issues.apache.org/jira/browse/CAMEL-7089
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-groovy, camel-script
>    Affects Versions: 2.12.2
>            Reporter: John Yin
>            Priority: Minor
>             Fix For: 2.12.3, 2.13.0
>
>
> When using the "context" attribute in a language://groovy.resource.classpath: endpoint, I received the error below.  But since the "request" attribute is still available, there is an easy workaround to access the CamelContext via Message and Exchange.
> groovy.lang.MissingPropertyException: No such property: context for class: script1387662776758798628846
> 	at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:50)
> 	at org.codehaus.groovy.runtime.callsite.PogoGetPropertySite.getProperty(PogoGetPropertySite.java:49)
> 	at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:231)
> 	at script1387662776758798628846.run(script1387662776758798628846.groovy:93)
> 	at org.apache.camel.language.groovy.GroovyExpression.evaluate(GroovyExpression.java:52)
> 	at org.apache.camel.component.language.LanguageProducer.process(LanguageProducer.java:82)
> 	at org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61)
> 	at org.apache.camel.processor.SendProcessor.process(SendProcessor.java:110)
> 	at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:72)
> 	at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:398)
> 	at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)
> 	at org.apache.camel.processor.Pipeline.process(Pipeline.java:118)
> 	at org.apache.camel.processor.Pipeline.process(Pipeline.java:80)
> 	at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191)
> 	at org.apache.camel.component.file.GenericFileConsumer.processExchange(GenericFileConsumer.java:401)
> 	at org.apache.camel.component.file.GenericFileConsumer.processBatch(GenericFileConsumer.java:201)
> 	at org.apache.camel.component.file.GenericFileConsumer.poll(GenericFileConsumer.java:165)
> 	at org.apache.camel.impl.ScheduledPollConsumer.doRun(ScheduledPollConsumer.java:187)
> 	at org.apache.camel.impl.ScheduledPollConsumer.run(ScheduledPollConsumer.java:114)
> 	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
> 	at java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:351)
> 	at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:178)
> 	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:178)
> 	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
> 	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
> 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
> 	at java.lang.Thread.run(Thread.java:722)



--
This message was sent by Atlassian JIRA
(v6.1.5#6160)