Reputation: 749
I want to open a websocket connection in my Spring MVC apllication, using SockJS,STOMP. The problem I have is similar to this question. but answer will not work for me. I have followed tutorials from here. As said here my app is returning a 404 to the browser when calling the webapp/socket.do mapping. javascript code is as below :
socket = new SockJS('webapp/socket.do');
stompClient = Stomp.over(socket);
stompClient.connect({}, function(frame) {...
My servlet mapping in web.xml file is as below:
`<servlet-mapping>
<servlet-name>dispatch-servlet</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>`
Now I tried changing url mapping from "*.do" to "/" and using other resource url patterns as suggested here by @Gofier this ("/")made a connection open but not render some resources properly.(webpages dont load properly).
Is there any way I can still use "*.do" and allow a websocket connection with "/info" at the same time ?? Please suggest any possible ways to fix this issue. Thanks.
Update: Showing controller code and config file
@Configuration
@EnableScheduling
@EnableWebMvc
@ComponentScan(basePackages="com.package")
@EnableWebSocketMessageBroker
public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer {
@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/socket.do").withSockJS();
}
@Override
public void configureMessageBroker(MessageBrokerRegistry registry) {
registry.enableSimpleBroker("/queue/", "/topic/");
registry.setApplicationDestinationPrefixes("/app");
}
}
Controller code:
@MessageMapping("/hello")
@SendTo("/topic/greetings")
public Greeting greeting(HelloMessage message) throws Exception {
Thread.sleep(3000); // simulated delay
return new Greeting("Hello, " + message.getName() + "!");
}
Upvotes: 0
Views: 812
Reputation: 25
How about...
<servlet-mapping>
<servlet-name>dispatch-servlet</servlet-name>
<url-pattern>*.do</url-pattern>
<url-pattern>/hello/*</url-pattern>
</servlet-mapping>
this?
Upvotes: 0