Hi Martin,

Unfortunately, there is no way to check if a certain context is active. Also, 
the websockets and CDI specs still don't align ( 
https://issues.jboss.org/browse/CDI-370 ). For now, I agree the only thing we 
can do is catch the exception, probably 
javax.enterprise.context.ContextNotActiveException, and hope the user does not 
need any Request-, Session- or ConversationScoped beans.

Best regards,
Emond

On Monday 09 February 2015 10:40:06 Martin Grigorov wrote:
> Hi,
> 
> The other day I've helped Sebastien with the task he explained at
> http://markmail.org/message/mmviy6tsv47g7rhr.
> 
> The problem we hit is that when an non-http thread needs to write to Native
> WebSockets connection it fails at Weld check for active context
> at ConversationPropagator#onRequestHandlerScheduled().
> 
> When Native WS creates the dummy RequestCycle at
> 
>  org.apache.wicket.protocol.ws.api.AbstractWebSocketProcessor.broadcastMessa
> ge(AbstractWebSocketProcessor.java:218)
> [wicket-native-websocket-core-7.0.0-SNAPSHOT.jar:7.0.0-SNAPSHOT]
> 
> it also calls
> org.apache.wicket.request.cycle.RequestCycle.scheduleRequestHandlerAfterCurr
> ent(RequestCycle.java:794) [wicket-core-7.0.0-SNAPSHOT.jar:7.0.0-SNAPSHOT]
> 
> that notifies all IRequestCycleListeners about the scheduled request
> handler.
> 
> https://github.com/apache/wicket/blob/master/wicket-cdi-1.1/src/main/java/or
> g/apache/wicket/cdi/ConversationPropagator.java#L130 checks whether the
> conversation is transient and this leads to the error below.
> 
> In the use case there is no usage of CDI in the non-http thread at all. It
> is just that ConversationPropagator as IRequestCycleListener is notified
> and it tries to do its checks.
> 
> As a workaround I've try/catched ConversationPropagator.java#L130 and
> returned null in case of exception.
> 
> Is there a better way to check for active context before trying to do: if
> (conversation.isTransient()) ?
> 
> 
> [0m [31m10:28:05,358 ERROR [org.apache.wicket.cdi.ConversationPropagator]
> (pool-5-thread-1) No context!:
> org.jboss.weld.context.ContextNotActiveException: WELD-001303: No active
> contexts for scope type javax.enterprise.context.RequestScoped
> at
> org.jboss.weld.manager.BeanManagerImpl.getContext(BeanManagerImpl.java:680)
> [weld-core-impl-2.1.2.Final.jar:2014-01-09 09:23]
> at
> org.jboss.weld.bean.proxy.ContextBeanInstance.getInstance(ContextBeanInstanc
> e.java:79) [weld-core-impl-2.1.2.Final.jar:2014-01-09 09:23]
> at
> org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:
> 99) [weld-core-impl-2.1.2.Final.jar:2014-01-09 09:23]
> at
> org.jboss.weld.proxies.Conversation$1224015424$Proxy$_$$_WeldClientProxy.isT
> ransient(Unknown Source)
> at
> org.apache.wicket.cdi.ConversationPropagator.onRequestHandlerScheduled(Conve
> rsationPropagator.java:132)
> [wicket-cdi-1.1-7.0.0-SNAPSHOT.jar:7.0.0-SNAPSHOT]
> at
> org.apache.wicket.request.cycle.RequestCycleListenerCollection$7.notify(Requ
> estCycleListenerCollection.java:182)
> [wicket-core-7.0.0-SNAPSHOT.jar:7.0.0-SNAPSHOT]
> at
> org.apache.wicket.request.cycle.RequestCycleListenerCollection$7.notify(Requ
> estCycleListenerCollection.java:178)
> [wicket-core-7.0.0-SNAPSHOT.jar:7.0.0-SNAPSHOT]
> at
> org.apache.wicket.util.listener.ListenerCollection.notify(ListenerCollection
> .java:80) [wicket-util-7.0.0-SNAPSHOT.jar:7.0.0-SNAPSHOT]
> at
> org.apache.wicket.request.cycle.RequestCycleListenerCollection.onRequestHand
> lerScheduled(RequestCycleListenerCollection.java:177)
> [wicket-core-7.0.0-SNAPSHOT.jar:7.0.0-SNAPSHOT]
> at
> org.apache.wicket.request.cycle.RequestCycleListenerCollection$7.notify(Requ
> estCycleListenerCollection.java:182)
> [wicket-core-7.0.0-SNAPSHOT.jar:7.0.0-SNAPSHOT]
> at
> org.apache.wicket.request.cycle.RequestCycleListenerCollection$7.notify(Requ
> estCycleListenerCollection.java:178)
> [wicket-core-7.0.0-SNAPSHOT.jar:7.0.0-SNAPSHOT]
> at
> org.apache.wicket.util.listener.ListenerCollection.notify(ListenerCollection
> .java:80) [wicket-util-7.0.0-SNAPSHOT.jar:7.0.0-SNAPSHOT]
> at
> org.apache.wicket.request.cycle.RequestCycleListenerCollection.onRequestHand
> lerScheduled(RequestCycleListenerCollection.java:177)
> [wicket-core-7.0.0-SNAPSHOT.jar:7.0.0-SNAPSHOT]
> at
> org.apache.wicket.request.cycle.RequestCycleListenerCollection$7.notify(Requ
> estCycleListenerCollection.java:182)
> [wicket-core-7.0.0-SNAPSHOT.jar:7.0.0-SNAPSHOT]
> at
> org.apache.wicket.request.cycle.RequestCycleListenerCollection$7.notify(Requ
> estCycleListenerCollection.java:178)
> [wicket-core-7.0.0-SNAPSHOT.jar:7.0.0-SNAPSHOT]
> at
> org.apache.wicket.util.listener.ListenerCollection.notify(ListenerCollection
> .java:80) [wicket-util-7.0.0-SNAPSHOT.jar:7.0.0-SNAPSHOT]
> at
> org.apache.wicket.request.cycle.RequestCycleListenerCollection.onRequestHand
> lerScheduled(RequestCycleListenerCollection.java:177)
> [wicket-core-7.0.0-SNAPSHOT.jar:7.0.0-SNAPSHOT]
> at
> org.apache.wicket.request.cycle.RequestCycle.scheduleRequestHandlerAfterCurr
> ent(RequestCycle.java:794) [wicket-core-7.0.0-SNAPSHOT.jar:7.0.0-SNAPSHOT]
> at
> org.apache.wicket.protocol.ws.api.AbstractWebSocketProcessor.broadcastMessag
> e(AbstractWebSocketProcessor.java:218)
> [wicket-native-websocket-core-7.0.0-SNAPSHOT.jar:7.0.0-SNAPSHOT]
> at
> org.apache.wicket.protocol.ws.api.AbstractWebSocketConnection.sendMessage(Ab
> stractWebSocketConnection.java:43)
> [wicket-native-websocket-core-7.0.0-SNAPSHOT.jar:7.0.0-SNAPSHOT]
> at quickstart.ws.WorkflowListener.onMessage(WorkflowListener.java:61)
> [classes:]
> at quickstart.ejb.WorkflowBean$1.run(WorkflowBean.java:85)
> [quickstart-ejb-1.0-SNAPSHOT.jar:]
> at quickstart.ejb.WorkflowBean.start(WorkflowBean.java:53)
> [quickstart-ejb-1.0-SNAPSHOT.jar:]
> at quickstart.ejb.WorkflowBean$Proxy$_$$_WeldClientProxy.start(Unknown
> Source) [quickstart-ejb-1.0-SNAPSHOT.jar:]
> at quickstart.HomePage$3.run(HomePage.java:80) [classes:]
> at quickstart.MyApplication$TasksRunnable.run(MyApplication.java:80)
> [classes:]
> at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
> [rt.jar:1.7.0_72]
> at java.util.concurrent.FutureTask.run(FutureTask.java:262)
> [rt.jar:1.7.0_72]
> at
> java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$
> 201(ScheduledThreadPoolExecutor.java:178) [rt.jar:1.7.0_72]
> at
> java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Sch
> eduledThreadPoolExecutor.java:292) [rt.jar:1.7.0_72]
> at
> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:11
> 45) [rt.jar:1.7.0_72]
> at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:6
> 15) [rt.jar:1.7.0_72]
> at java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_72]
> 
> 
> 
> Martin Grigorov
> Wicket Training and Consulting
> https://twitter.com/mtgrigorov

Reply via email to