How to access SwitchYard Context properties from a @Named CDI bean in SwitchYard Camel route
Issue
- I would like to access SwitchYard Context properties in a
@NamedCDI bean for gettingCamelFileNamefrom the SFTP service binding. - I tried Injecting the
Contextobject into the named bean as follows:
import org.apache.camel.Message;
@Named
public class MyAction {
@Inject
private Context context;
public void displayMessage(Message message) {
System.out.println("File name is " + context.getProperty("CamelFileName").getValue());
}
- However, I got the following error:
Caused by: java.lang.IllegalStateException: SWITCHYARD030422: Illegal call to get the SwitchYard Context; must be called within the execution of an ExchangeHandler chain.
at org.switchyard.component.bean.internal.context.ContextProxy.getContext(ContextProxy.java:156) [switchyard-component-bean-1.1.1-p5-redhat-1.jar:1.1.1-p5-redhat-1]
at org.switchyard.component.bean.internal.context.ContextProxy.getProperty(ContextProxy.java:42) [switchyard-component-bean-1.1.1-p5-redhat-1.jar:1.1.1-p5-redhat-1]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.6.0_07]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [rt.jar:1.6.0_07]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [rt.jar:1.6.0_07]
at java.lang.reflect.Method.invoke(Method.java:597) [rt.jar:1.6.0_07]
at org.jboss.weld.bean.proxy.AbstractBeanInstance.invoke(AbstractBeanInstance.java:45) [weld-core-1.1.13.Final-redhat-1.jar:1.1.13.Final-redhat-1]
at org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:105) [weld-core-1.1.13.Final-redhat-1.jar:1.1.13.Final-redhat-1]
at org.jboss.weld.proxies.Context$1366014918$Proxy$_$$_WeldClientProxy.getProperty(Context$1366014918$Proxy$_$$_WeldClientProxy.java) [weld-core-1.1.13.Final-redhat-1.jar:]
at com.example.myapp.actions.MyAction.displayMessage(MyAction.java:21) [my-application.jar:]
- How can I access Context properties from a named CDI bean in SwitchYard?
Environment
- Red Hat JBoss Fuse Service Works (FSW)
- 6.x
Subscriber exclusive content
A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.