我不知道我的应用程序使用websocket(Tyrus 1.1)无法调用任何CDI或EJB bean。我正在使用Server-Sent Event,Websocket 1.1等运行Glassfish 4.1
当我从我的websocket应用程序调用JSF托管bean(CDI)时,它显示“错误:WELD-001303:没有活动上下文的范围类型org.omnifaces.cdi.ViewScoped”。
如果我从我的websocket应用程序调用EJB无状态bean,它会显示如下消息:
Warning: A system exception occurred during an invocation on EJB ChatSessionBean, method: public com.mnik.chat.entity.ChatInfo com.mnik.chat.ejb.ChatSessionBean.findRoomId(java.lang.String)
Warning: javax.ejb.EJBException
at com.sun.ejb.containers.EJBContainerTransactionManager.processSystemException(EJBContainerTransactionManager.java:750)
at com.sun.ejb.containers.EJBContainerTransactionManager.checkExceptionNoTx(EJBContainerTransactionManager.java:640)
at com.sun.ejb.containers.EJBContainerTransactionManager.postInvokeTx(EJBContainerTransactionManager.java:482)
at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:4566)
at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:2074)
at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:2044)
at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:220)
at com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:88)
at com.sun.proxy.$Proxy427.findRoomId(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.jboss.weld.util.reflection.Reflections.invokeAndUnwrap(Reflections.java:414)
at org.jboss.weld.bean.proxy.EnterpriseBeanProxyMethodHandler.invoke(EnterpriseBeanProxyMethodHandler.java:127)
at org.jboss.weld.bean.proxy.EnterpriseTargetBeanInstance.invoke(EnterpriseTargetBeanInstance.java:56)
at org.jboss.weld.bean.proxy.InjectionPointPropagatingEnterpriseTargetBeanInstance.invoke(InjectionPointPropagatingEnterpriseTargetBeanInstance.java:65)
at org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:100)
at com.mnik.chat.ejb.LocalChatSessionBean$59891376$Proxy$_$$_Weld$EnterpriseProxy$.findRoomId(Unknown Source)
at com.mnik.chat.server.ChatServer.startChatChannel(ChatServer.java:103) ...
Caused by: org.apache.shiro.UnavailableSecurityManagerException: No SecurityManager accessible to the calling code, either bound to the org.apache.shiro.util.ThreadContext or as a vm static singleton. This is an invalid application configuration.
at org.apache.shiro.SecurityUtils.getSecurityManager(SecurityUtils.java:123)
at org.apache.shiro.subject.Subject$Builder.<init>(Subject.java:627)
at org.apache.shiro.SecurityUtils.getSubject(SecurityUtils.java:56)
at com.mnik.intercept.ShiroSecurityInterceptor.interceptShiroSecurity(ShiroSecurityInterceptor.java:37)
at sun.reflect.GeneratedMethodAccessor111.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:883)
at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:822)
at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:608)
at org.jboss.weld.ejb.AbstractEJBRequestScopeActivationInterceptor.aroundInvoke(AbstractEJBRequestScopeActivationInterceptor.java:46)
at org.jboss.weld.ejb.SessionBeanInterceptor.aroundInvoke(SessionBeanInterceptor.java:52)
at sun.reflect.GeneratedMethodAccessor109.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:883)
at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:822)
at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:608)
at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.doCall(SystemInterceptorProxy.java:163)
at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.aroundInvoke(SystemInterceptorProxy.java:140)
at sun.reflect.GeneratedMethodAccessor110.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:883)
at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:822)
at com.sun.ejb.containers.interceptors.InterceptorManager.intercept(InterceptorManager.java:369)
at com.sun.ejb.containers.BaseContainer.__intercept(BaseContainer.java:4758)
at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:4746)
at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:212)
... 49 more
如果您有任何建议,请与我们分享。谢谢。
注意:这些是我的ChatServer(websocket)类:
...
import javax.websocket.OnError;
import javax.websocket.OnMessage;
import javax.websocket.OnOpen;
import javax.websocket.Session;
import javax.websocket.server.PathParam;
import javax.websocket.server.ServerEndpoint;
import javax.websocket.server.ServerEndpointConfig;
@ServerEndpoint(value = "/chat-server/{roomNumbers}",
subprotocols = {"chat"},
decoders = {ChatDecoder.class},
encoders = {ChatEncoder.class},
configurator = ChatServerHttpSSConfig.class)
public class ChatServer {
public ChatServer() {
this.dateFormat = new SimpleDateFormat("HH:mm:ss");
}
private final static String USERNAME_KEY = "USERNAME";
private final static String USERNAMES = "USERNAMES";
private final static String INCREASED = "INCREASED";
private final SimpleDateFormat dateFormat;
private final static String ASSOCIATED_HTTPSESSION = "WEBSOCKET_HTTP_SESSION";
private final static String ROOMNUMBERS = "ROOMNUMBERS";
private final static String USERTYPE = "USERTYPE";
private final static String AGENT = "AGENT";
private final static String CLIENT = "CLIENT";
private HttpSession httpSession;
private Session session;
@Inject
private LocalChatSessionBean localChatSS;
@Inject
private SSEAnnounce sseAnnounce;
@Inject
private ProductMsgStates productMsgStates;
@OnOpen
public void startChatChannel(@PathParam("roomNumbers") final String roomNumbers, final Session session, EndpointConfig epc) {
//for forward-backward html page.
ServerEndpointConfig endpointConfig = (ServerEndpointConfig) epc;
ChatServerHttpSSConfig cshSSC = (ChatServerHttpSSConfig) endpointConfig.getConfigurator();
//to associate with httpSession
this.httpSession = (HttpSession) epc.getUserProperties().get(ChatServerHttpSSConfig.CHAT_HTTP_SESSION);
this.session = session;
this.session.getUserProperties().put(ASSOCIATED_HTTPSESSION, this.httpSession);
//normal operation
this.session.getUserProperties().put(ROOMNUMBERS, roomNumbers);
System.out.println("Roomnumber at " + this.getClass() + ", ID: " + roomNumbers);
//when calling to EJB or JSF managed bean, it showed error. In this example code, it calls EJB.
ChatInfo chatInfo = localChatSS.findRoomId(roomNumbers);
String productname = chatInfo.getProductname();
SessionInfo ssInfo = new SessionInfo();
ssInfo.setSessionId(this.session.getId());
ssInfo.setChatInfo(chatInfo);
chatInfo.getSessionsIds().add(ssInfo);
...