Java WebSocket 1.1 working with Grails Tomcat7 OK, NOT bootrun

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Java WebSocket 1.1 working with Grails Tomcat7 OK, NOT bootrun

Anders Kristian Andersen
Hi

I have migrated the Tomcat sample EchoAnnotation to my Grails 3.0.1 helloworld.

It works fine via war --> tomcat 7 deployment

Statement:
@ServerEndpoint("/websocket/echoAnnotation")

does the work.
Javascript clients can use url "ws://localhost:8080/helloworld/websocket/echoAnnotation"

But from gradle bootrun it does not work
It gives code 1006

I observe 2 things
a) javax.websocket:javax.websocket-api:1.1 is NOT needed as a dependency in Grails. This means that the classes is onboard Grails.
When I did a test outside Grails on a pure gradle war project I found out that javax.websocket:javax.websocket-api must NEVER be in WEB-INF/lib
The would cause code 1006 as well.

b) bootRun must some how respect @ServerEndpoint("/websocket/echoAnnotation").
And I think that I probably have to add some thing some where ???

--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/e64a9045-6a73-4647-adb9-f8f1b4d7e39e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Java WebSocket 1.1 working with Grails Tomcat7 OK, NOT bootrun

Anders Kristian Andersen
I think I have solved how to add support for web-socket.
My first approach was using the raw Java WebSocket 1.1 API defined by JSR-356
But this seems to be a little implementation specific to Tomcat/Jetty etc.

Therefore I have change approach to using Spring-Websocket.
Hereby Spring solves the problem of dealing with the right implementation of Web-Socket 
Spring web socket support also enables more sophisticated protocols.

Therefore I have followed http://docs.spring.io/spring/docs/current/spring-framework-reference/html/websocket.html
(the code sample from here works fine...)

There is one issue
Grails application.groovy 
must have added @ComponentScan("helloworld")
Then it starts to work...
And the spring controllers cannot be located in grails-app/controllers/helloworld....
This gives a duplicate Request mapping.
This is another issue. (to be discussed somewhere else)



--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/c95a6844-bfea-4482-88d5-136e2813764e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Java WebSocket 1.1 working with Grails Tomcat7 OK, NOT bootrun

vahid
Hey Anders

I have created a demo project here:


https://github.com/vahidhedayati/testwebsocket-grails3

This does a basic echo test between front/back end. It is all working too...


From what I understand neither of these i.e. your post and this post are the real answer to the actual question in subject and I doubt there is a real fix for those wish to remain with the default tomcat websocket.

At this rate for me to migrate my default websocket plugins, would really mean a rewrite to use spring websocket...


https://github.com/spring-projects/spring-boot/blob/master/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/main/java/samples/websocket/echo/EchoWebSocketHandler.java  as the folder states websocket-tomcat but the java files are nothing like a default tomcat websocket. Maybe this is for sockets running under tomcat rather than default tomcat websockets..


Confused yet join the club :)



On Sunday, April 26, 2015 at 10:12:40 AM UTC+1, Anders Kristian Andersen wrote:
I think I have solved how to add support for web-socket.
My first approach was using the raw Java WebSocket 1.1 API defined by <a href="http://www.jcp.org/en/jsr/detail?id=356" target="_blank" rel="nofollow" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Fwww.jcp.org%2Fen%2Fjsr%2Fdetail%3Fid%3D356\46sa\75D\46sntz\0751\46usg\75AFQjCNFa9KM7mtdVygQNRoW2ClPXebhM9Q';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Fwww.jcp.org%2Fen%2Fjsr%2Fdetail%3Fid%3D356\46sa\75D\46sntz\0751\46usg\75AFQjCNFa9KM7mtdVygQNRoW2ClPXebhM9Q';return true;">JSR-356
But this seems to be a little implementation specific to Tomcat/Jetty etc.

Therefore I have change approach to using Spring-Websocket.
Hereby Spring solves the problem of dealing with the right implementation of Web-Socket 
Spring web socket support also enables more sophisticated protocols.

Therefore I have followed <a href="http://docs.spring.io/spring/docs/current/spring-framework-reference/html/websocket.html" target="_blank" rel="nofollow" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Fdocs.spring.io%2Fspring%2Fdocs%2Fcurrent%2Fspring-framework-reference%2Fhtml%2Fwebsocket.html\46sa\75D\46sntz\0751\46usg\75AFQjCNHYv77-rF6GHwo29f3Mr5axODqhqA';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Fdocs.spring.io%2Fspring%2Fdocs%2Fcurrent%2Fspring-framework-reference%2Fhtml%2Fwebsocket.html\46sa\75D\46sntz\0751\46usg\75AFQjCNHYv77-rF6GHwo29f3Mr5axODqhqA';return true;">http://docs.spring.io/spring/docs/current/spring-framework-reference/html/websocket.html
(the code sample from here works fine...)

There is one issue
Grails application.groovy 
must have added @ComponentScan("helloworld")
Then it starts to work...
And the spring controllers cannot be located in grails-app/controllers/helloworld....
This gives a duplicate Request mapping.
This is another issue. (to be discussed somewhere else)



--
You received this message because you are subscribed to the Google Groups "Grails Dev Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/grails-dev-discuss/4d979688-113e-4090-88e4-837bbf604b14%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.