Java 将WebSocket API与Struts 2结合使用
我有一个运行在Tomcat7.0.43上的Struts2 web应用程序,它使用Rest和约定插件映射所有请求。Struts试图自己映射所有请求 JSR356使用如下注释定义服务器端点Java 将WebSocket API与Struts 2结合使用,java,spring,struts2,websocket,tomcat7,Java,Spring,Struts2,Websocket,Tomcat7,我有一个运行在Tomcat7.0.43上的Struts2 web应用程序,它使用Rest和约定插件映射所有请求。Struts试图自己映射所有请求 JSR356使用如下注释定义服务器端点 @ServerEndpoint(value = "/websocket/chat") 现在,当broswer尝试连接到ws:/127.0.0.1:8080/websocket/chat时,请求失败,因为Struts映射器截获了请求 在XML文件中是否有我可以指定的内容,以便请求到达正确的位置 编辑: 正如我建议
@ServerEndpoint(value = "/websocket/chat")
现在,当broswer尝试连接到ws:/127.0.0.1:8080/websocket/chat
时,请求失败,因为Struts映射器截获了请求
在XML文件中是否有我可以指定的内容,以便请求到达正确的位置
编辑:
正如我建议的那样,我补充道
<constant name="struts.action.excludePattern" value="/websocket.*?" />
这是我的班级:
public class Socket implements ServerApplicationConfig {
@Override
public Set<ServerEndpointConfig> getEndpointConfigs(Set<Class<? extends Endpoint>> scanned) {
Set<ServerEndpointConfig> result = new HashSet<ServerEndpointConfig>();
return result;
}
@Override
public Set<Class<?>> getAnnotatedEndpointClasses(Set<Class<?>> scanned) {
Set<Class<?>> results = new HashSet<Class<?>>();
for (Class<?> clazz : scanned) {
results.add(clazz);
}
return results;
}
}
公共类套接字实现ServerApplicationConfig{
@凌驾
公共集合getEndpointConfigs(集合>扫描){
Set>();
用于(类别分类:扫描){
结果:添加(clazz);
}
返回结果;
}
}
我怎样才能让一切都协调一致
注意:我使用Struts-Spring插件进行Spring安全性的依赖注入。您可以配置Struts过滤器,通过正则表达式模式排除一些URL。您应该在
struts.xml
<constant name="struts.action.excludePattern" value="^ws://.+$"/>
添加了常量,但现在ws-request导致404错误。你知道如何让它进入聊天类/阅读注释吗?编写一个服务器端点并将其与应用程序一起部署,我没有使用WebSocket,但你可以在中找到示例。分区问题将帮助你更快地获得答案。正如您所发现的,在目前没有struts2/websocket集成之后,您可以阻止struts尝试对某些URL进行操作。这两种技术都是面向前端的(在服务器的最前端),并且几乎没有交互。但将两者结合成一个问题将减少听众。让事情协调工作的答案是在服务层开发业务逻辑,s2和ws都将使用这些逻辑。我也面临着问题@Manu你有什么解决方案吗?如果有,请告诉我。提前谢谢。
<constant name="struts.action.excludePattern" value="^ws://.+$"/>