I have a Struts2 web application running on Tomcat 7.0.43 that uses Rest and Convention plugins to map all requests. Struts tries to map all requests by itself.
JSR 356 defines server end points using annotations like
@ServerEndpoint(value = "/websocket/chat")
Now when the broswer tries to connect to ws:/127.0.0.1:8080/websocket/chat
, the request fails because the Struts mapper intercepts the request.
Is there anything I can specify in the XML files, such that the request reaches the right place?
EDIT:
As suggested, I added
<constant name="struts.action.excludePattern" value="/websocket.*?" />
to my Struts configuration, after which the URL /websocket/chat started reaching a 404 error.
Later I learnt that I need to configure a ServerApplicationConfig
implementation. After doing that the websocket starts working fine but the rest of my application fails to load giving an error:
SEVERE: Error configuring application listener of class org.springframework.web.context.ContextLoaderListener
java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
Here is my class:
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;
}
}
How can I get everything to work together in Harmony?
Note: I am using Struts Spring Plugin for Dependency Injection of Spring Security.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…