[英]Exception starting filter WebSocket filter netbeans 7.3 glassfish 4
我正在尝试使用java websocket api在两个html页面之间实现简单的视频传输。 网络摄像头服务器捕获网络摄像头并将其发送到服务器端点,该端点将广播到每个连接的客户端。 网络摄像头服务器代码
<video autoplay id="vid" style="display: none;"></video>
<canvas id="canvas" width="640" height="480" style="border: 1px solid #d3d3d3;"></canvas>
<div id="data1"></div>
<script>
var video = document.querySelector("#vid");
var canvas = document.querySelector('#canvas');
var ctx = canvas.getContext('2d');
var localMediaStream = null;
var ws = new WebSocket("ws://127.0.0.1:8080/WebApplication5/endpointwcv");
ws.onopen = function () {
console.log("Openened connection to websocket");
};
ws.onerror = function (evt) {
writeToScreen('<span style="color: red;">ERROR:</span> ' + evt.data);
};
var onCameraFail = function (e) {
console.log('Camera did not work.', e);
};
timer = setInterval(function () {
ctx.drawImage(video, 0, 0, 640, 480);
var data = canvas.toDataURL('image/jpeg', 1.0);
ws.send(data);
}, 255);
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia;
window.URL = window.URL || window.webkitURL;
navigator.getUserMedia({ video: true }, function (stream) {
video.src = window.URL.createObjectURL(stream);
}, onCameraFail);
服务器端点的代码/ *在此处导入* /
@ServerEndpoint("/endpointwcv")
public class NewWSEndpoint {
private static Set<Session> peers = Collections.synchronizedSet(new HashSet<Session>());
@OnMessage
public String onMessage( Session session,byte[] data) {
try {
System.out.println(data);
for(Session s:peers){
s.getBasicRemote().sendObject(data);
}
} catch (IOException | EncodeException e) {
System.out.println("Error in facedetection, ignoring message:" + e.getMessage());
}
return null;
}
public String onMessage( Session session,String data) {
try {
System.out.println(data);
for(Session s:peers){
s.getBasicRemote().sendText(data);
}
} catch (IOException e) {
System.out.println("Error in facedetection, ignoring message:" + e.getMessage());
}
return null;
}
@OnOpen
public void onOpen(Session session) throws IOException {
peers.add(session);
session.getBasicRemote().sendText("hiiiiiii");
}
@OnClose
public void onClose() {
System.out.println("Closed");
}
@OnError
public void onError(Session s, Throwable t) {
System.out.println("error");
}
}
并且有一个正在访问网络摄像头的接收客户
<div id="d1"></div>
<canvas id="target" width="640" height="480" style="border: 1px solid #d3d3d3;"></canvas>
<script>
var ws = new WebSocket("ws://127.0.0.1:8080/WebApplication5/endpointwcv");
var myURL = window.URL || window.webkitURL;
ws.onopen = function () {
console.log("Openened connection to websocket");
};
ws.onmessage=function (msg) {
var target = document.getElementById("target");
url=myURL.createObjectURL(msg);
target.src = url;
};
</script>
在使用Java ee 7 api在GlassFish 4.0上运行项目时,什么也没有发生。 请帮我,控制台上有警告
WARNING: Class 'javax.ejb.PostActivate' not found, interception based on it is not enabled
WARNING: Class 'javax.ejb.PrePassivate' not found, interception based on it is not enabled
.....
Exception starting filter WebSocket filter
java.lang.InstantiationException
at org.apache.catalina.core.ApplicationFilterConfig.(ApplicationFilterConfig.java:135)
at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:5297)
...
我在这里看到您的项目有几个问题。 首先,Struts和WebSocket之间有一个URL映射重叠。 您的WebSocket URL是/endpointwcv
。 您的Struts映射是/*
。 当我终于可以部署您的应用程序时,我从Struts那里得到了有关操作/endpointwcv
没有映射的错误。
如果将Struts过滤器servlet的映射更改为/struts/*
(并且我不得不将filter-class
更改为org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
以避免关于不赞成使用FilterDispatcher
错误消息),您可以通过访问http://localhost:8080/WebApplication5/Conference.html
来访问WebSocket端点。 在GlassFish4 server.log中,我看到了NewWSEndpoint
输出:
INFO: aaaa
INFO: error
INFO: error
INFO: error
...
INFO: Closed
转到http://localhost:8080/WebApplication5/ConferenceClient.html
,我在server.log中看到:
INFO: aaaa
我不是Struts专家,但是您似乎需要修复端点,然后弄清楚如何实现Struts前端,以免干扰WebSocket端点URL。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.