1 Reply Latest reply on Mar 24, 2014 9:22 AM by Sueleyman Vurucu

    @SessionScoped and @Observes

    Sueleyman Vurucu Expert

      Hi guys,


      I have a Websocket. I fire a CDI-Event if I reive message on this socket:

      @ServerEndpoint(value = "/socketcontroller/{socketname}",
              decoders = {DataDecoder.class},
              encoders = {DataEncoder.class})
      public class SocketController implements Serializable {
          private static final Set<Session> sessions = Collections.synchronizedSet(new HashSet<Session>());
          private transient Logger logger;
          private Event<Data> event;
          public void onClose(Session session, CloseReason closeReason) {
              logger.info(getSocketname(session) + " closed");
          public void onError(Session session, Throwable thr) {
              logger.error(getSocketname(session) + " error "+thr.getMessage());
          public void onOpen(Session session, EndpointConfig config) {
          public void onMessage(Data message, Session session) {
              logger.info(session.getOpenSessions().size() + " " + message.toString());
              logger.warn("Fire CDI event started");
              event.fire(message);                                                            // Sending not works for @Sessionscoped beans
              logger.warn("Fire CDI event Finished");
          public void plcSocketEvenChannel(@Observes WMSManagementController.WMSSocketServiceRequest data) {  // Receive works here
              for(Session session:sessions){
                  session.getAsyncRemote().sendObject(new PLCSocketData());
          private String getSocketname(Session session) {
              return session.getPathParameters().get("socketname");


      So far so good. And my observer side is a Sessionscoped CDI bean. But CDI does't trugger my observer method. When I change the scope of the bean to @Dependant then everything works well but I need a sessionscoped bean for my usecase. Is there a limitation for receive CDI events and sessionscoped beans?


      I'm using Wildfly 8


      Nachricht geändert durch Sueleyman Vurucu