带Glassfish 3.1.2和Grizzly的WebSocket-意外响应代码:405

带Glassfish 3.1.2和Grizzly的WebSocket-意外响应代码:405,glassfish,websocket,grizzly,Glassfish,Websocket,Grizzly,我正在尝试在本地Glassfish 3.1.2服务器安装中使用WebSocket。我在Maven项目中使用了Grizzly 2.2: org.glassfish.grizzly 网格网袋 2.2 WebSocketsServlet.java import org.glassfish.grizzly.grizzly; 导入java.util.logging.Logger; 导入org.glassfish.grizzly.websockets.WebSocketEngine; 导入javax.s

我正在尝试在本地Glassfish 3.1.2服务器安装中使用WebSocket。我在Maven项目中使用了Grizzly 2.2:


org.glassfish.grizzly
网格网袋
2.2
WebSocketsServlet.java

import org.glassfish.grizzly.grizzly;
导入java.util.logging.Logger;
导入org.glassfish.grizzly.websockets.WebSocketEngine;
导入javax.servlet.ServletConfig;
导入javax.servlet.ServletException;
导入javax.servlet.http.HttpServlet;
公共类WebSocketservlet扩展了HttpServlet{
私有静态最终记录器=Grizzly.Logger(WebSocketsServlet.class);
私人最终视频共享应用程序=新视频共享应用程序();
@凌驾
public void init(ServletConfig config)抛出ServletException{
logger.log(Level.SEVERE,“注册”);
WebSocketEngine.getEngine().register(config.getServletContext().getContextPath()+“/videosharing”,app);
}
@凌驾
公共空间销毁(){
WebSocketEngine.getEngine()。取消注册(应用程序);
}
}
VideoSharingWebSocket.java

import java.util.logging.Logger;
导入org.glassfish.grizzly.websockets.DefaultWebSocket;
导入org.glassfish.grizzly.websockets.ProtocolHandler;
导入org.glassfish.grizzly.websockets.WebSocketListener;
导入org.glassfish.grizzly.grizzly;
公共类VideoSharingWebSocket扩展了DefaultWebSocket{
私有静态最终记录器=Grizzly.Logger(VideoSharingWebSocket.class);
公共视频共享WebSocket(ProtocolHandler处理程序、WebSocketListener…侦听器){
超级(处理器、侦听器);
}
}
VideoSharingApplication.java

import java.util.logging.Level;
导入java.util.logging.Logger;
导入org.glassfish.grizzly.grizzly;
导入org.glassfish.grizzly.websockets.ProtocolHandler;
导入org.glassfish.grizzly.websockets.WebSocket;
导入org.glassfish.grizzly.websockets.WebSocketApplication;
导入org.glassfish.grizzly.websockets.WebSocketListener;
导入org.glassfish.grizzly.http.HttpRequestPacket;
公共类视频共享应用程序扩展了WebSocketApplication{
私有静态最终记录器=Grizzly.Logger(VideoSharingApplication.class);
@凌驾
公共WebSocket createSocket(ProtocolHandler处理程序、WebSocketListener…侦听器){
logger.log(Level.SEVERE,“createSocket”);
返回新的VideoSharingWebSocket(处理程序、侦听器);
}
@凌驾
公共布尔isApplicationRequest(HttpRequestPacket请求){
logger.log(Level.SEVERE,“isApplicationRequest”);
返回“/videosharing.equals(request.getRequestURI());
}
@凌驾
消息上的公共void(WebSocket套接字、字符串数据){
logger.log(Level.SEVERE,“onMessage”);
对于(WebSocket WebSocket:GetWebSocket()){
if(套接字!=webSocket){
发送(数据);
}
}
}
}
我使用以下命令在Glassfish中启用WebSocket支持:

asadmin set configs.config.server-config.network-config.protocols.protocol.http-listener-1.http.websockets-support-enabled=true
客户端代码,app.js:

var网络=函数(){
返回{
初始化:函数(){
var url='ws://localhost:8080/monApp/videosharing';
var websocket=新的websocket(url);
websocket.name=APP.id;
websocket.onopen=函数(evt){
警报(“开启”);
};
websocket.onerror=函数(evt){
警报(“onerror”);
};
websocket.onmessage=函数(evt){
警报(“onmessage”);
var命令=JSON.parse(evt.data);
如果(command.type==“暂停”){
APP.pauseVideo();
}else if(command.type==“播放”){
APP.playVideo();
}else if(command.type==“seek”){
APP.seekVideo(command.currentTime);
}否则{
警报(“未知命令”+命令);
}
};
websocket.onclose=函数()
{
警报('onclose');
};
},
发送:功能(命令){
发送(命令);
}
}
};
变量应用={
id:Math.floor(Math.random()*10000),
网络:网络(),
//更新window.onload后无法在此处使用“this”(见下文)
初始化:函数(){
APP.network.initialize();
var video=APP.getVideo();
video.addEventListener(“播放”,
功能(事件){
警惕(“玩”);
var命令={type:“play”};
APP.network.send(JSON.stringify(command));
},
假);
video.addEventListener('pause',
功能(事件){
警惕(“暂停”);
var命令={type:“pause”};
APP.network.send(JSON.stringify(command));
},
假);
video.addEventListener('seek',
功能(事件){
警惕(“寻找”);
var命令={type:“seek”,
currentTime:APP.getVideo().currentTime};
APP.network.send(JSON.stringify(command));
},
假);
},
getVideo:函数(){
返回文档.getElementsByTagName(“视频”)[0];
},
pauseVideo:函数(){
var video=this.getVideo();
video.pause();
},
播放视频:函数(){
var video=this.getVideo();
video.play();
},
seekVideo:功能(当前时间){
var video=this.getVideo();
video.currentTime=currentTime;
}
};
window.onload=APP.initialize;
我正在Mac上用Chrome18.0.1025.165测试这个。在页面加载时,我遇到以下错误:

Unexpected response code: 405
在服务器日志中没有错误,只显示我的“注册”(WebSocketsServlet)日志。