[ANN] Spring Websocket Plugin 1.0.0.M1

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

[ANN] Spring Websocket Plugin 1.0.0.M1

zyro
hi,

on the heels of grails-2.4.0.M1, i bumped the spring-websocket plugin
from 0.1.BUILD-SNAPSHOT to 1.0.0.M1 (so now listed in the plugin portal,
too).

this plugin aims at making the new messaging-/websocket-stack of spring
4 easily accessible to grails applications.

http://grails.org/plugin/spring-websocket

https://github.com/zyro23/grails-spring-websocket

feedback and contributions are welcome, of course :)

zyro

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: [ANN] Spring Websocket Plugin 1.0.0.M1

Graeme Rocher-2
Nice work!

On Tue, Mar 4, 2014 at 8:59 PM, zyro <[hidden email]> wrote:

> hi,
>
> on the heels of grails-2.4.0.M1, i bumped the spring-websocket plugin from
> 0.1.BUILD-SNAPSHOT to 1.0.0.M1 (so now listed in the plugin portal, too).
>
> this plugin aims at making the new messaging-/websocket-stack of spring 4
> easily accessible to grails applications.
>
> http://grails.org/plugin/spring-websocket
>
> https://github.com/zyro23/grails-spring-websocket
>
> feedback and contributions are welcome, of course :)
>
> zyro
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>



--
Graeme Rocher
Grails Project Lead
SpringSource

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: [ANN] Spring Websocket Plugin 1.0.0.M1

d.tamm
In reply to this post by zyro
Hey zyro,

nice work so far! I just tried it out with the grails 2.4.0.M1 but i cant get it working. followed the instructions in your example, but nothing works so far :( is there an mistake in your example?

dominik
Reply | Threaded
Open this post in threaded view
|

Re: [ANN] Spring Websocket Plugin 1.0.0.M1

zyro
hello dominik,

i just created a fresh 2.4.0.m1 app, copy/pasted the readme parts
regarding BuildConfig, ExampleController and example/index.gsp and it
works as expected.

are you getting any errors or does your browser give any hint (network
panel of firebug/devtools/etc.)?

zyro

-------- Original Message  --------
Subject: [grails-user] Re: [ANN] Spring Websocket Plugin 1.0.0.M1
From: d.tamm <[hidden email]>
To: [hidden email]
Date: Wed, 5 Mar 2014 11:22:24 -0800 (pst)

> Hey zyro,
>
> nice work so far! I just tried it out with the grails 2.4.0.M1 but i cant
> get it working. followed the instructions in your example, but nothing works
> so far :( is there an mistake in your example?
>
> dominik
>
>
>
> --
> View this message in context: http://grails.1312388.n4.nabble.com/ANN-Spring-Websocket-Plugin-1-0-0-M1-tp4654667p4654724.html
> Sent from the Grails - user mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>      http://xircles.codehaus.org/manage_email
>
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: [ANN] Spring Websocket Plugin 1.0.0.M1

d.tamm
hey zyro,

okay, the example (rendering content from controller) works for me now. but the service example doenst work :-(

i also noticed, taht it wont work with IE8? any information on this one yet? (only asking, because some of my clients work with IE8... holy cow, i know! but i cant change things 'bout that... ;-))

dominik
Reply | Threaded
Open this post in threaded view
|

Re: [ANN] Spring Websocket Plugin 1.0.0.M1

Ken Siprell
Hi Zyro,

Do you think spring4, sockjs, and stomp can replace the atmosphere framework in a grails app, especially if used with an external message broker? I see a lot of advantages in using it with grails. However, could you comment on the following?

It looks like there's no native client disconnect event, which would preclude use of something like the atmosphere broadcaster cache. I suppose an external message broker could handle pushing the missed messages after a client reconnects, but how could this be handled with the internal simple broker? Would we need a couple of extra classes in your plugin?

It looks like an external message broker would be the best course of action for a production app since the simple broker doesn't support clustering. If this is the case, would your plugin need some extra configuration options to ease integration with say ActiveMQ or RabbitMQ?

It seems almost too easy with annotations on controller methods (@MessageMapping), but would it be a better practice to have separate messaging controllers or services?

Does your plugin support the spring security plugin and the "/user/{principal}" endpoint out of the box? I saw https://github.com/zyro23/grails-spring-websocket/blob/master/grails-app/conf/DefaultSpringWebsocketConfig.groovy#L10 in the default config but wasn't sure if this is all that's needed.

I'm glad you got ahead of the 2.4 release curve. I was considering a similar plugin since I hadn't seen this one on the plugin portal, but yours is better than I could have delivered.

Ken
Reply | Threaded
Open this post in threaded view
|

Re: [ANN] Spring Websocket Plugin 1.0.0.M1

zyro
In reply to this post by d.tamm
hi dominik,

glad you got the controller example working.

i copy/pasted the service from the readme into a
grails-app/services/example/ExampleService and injected it into the
ExampleController (def exampleService). then i included a a call to
exampleService.hello() in the method. result:

"hello from service!""hello from controller!"

so it works for me.

ie8: well the point about sock.js is that it does fallback to
non-websocket push/polling variants depending on the server and client
capabilities.

i got the example (controller and service) working with ie6 (!)

zyro

-------- Original Message  --------
Subject: [grails-user] Re: [ANN] Spring Websocket Plugin 1.0.0.M1
From: d.tamm <[hidden email]>
To: [hidden email]
Date: Thu, 6 Mar 2014 03:52:04 -0800 (pst)

> hey zyro,
>
> okay, the example (rendering content from controller) works for me now. but
> the service example doenst work :-(
>
> i also noticed, taht it wont work with IE8? any information on this one yet?
> (only asking, because some of my clients work with IE8... holy cow, i know!
> but i cant change things 'bout that... ;-))
>
> dominik
>
>
>
> --
> View this message in context: http://grails.1312388.n4.nabble.com/ANN-Spring-Websocket-Plugin-1-0-0-M1-tp4654667p4654740.html
> Sent from the Grails - user mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>      http://xircles.codehaus.org/manage_email
>
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: [ANN] Spring Websocket Plugin 1.0.0.M1

zyro
In reply to this post by Ken Siprell
hi ken,

yes i do think so. especially with an external broker.

client disconnect / message cache: a very good point. tbh did not look
into that matter yet. but i doubt that the map-based broker impl is
currently capable of caching and a real message broker should be the way
to go.

message broker: are you missing any config options regarding a real
broker? the only one i got not mapped at the moment is the broker
heartbeat interval, but else than that, the settings of the stompRelay
part _is_ your broker connection. activemq and rabbitmq both work. you
just have to make sure you install the respective stomp plugin.

separate controllers: makes much sense. i even consider it kind of ugly
to have to put a modifier in front of the method (protected/private)
because of how spring handles actions (@XyzMapping) vs. how grails
handles actions (public methods) ...
but well, until now the focus was almost exclusively to make spring
functionality available, not to enhance groovy-ish use of it.

user-destinations: sending to those destinations is supported. e.g.

client.subscribe("/user/queue/hello", function(message){
     doIt();
});
client.send("/app/hello", {}, "");

@MessageMapping("/hello")
@SendToUser("/queue/hello")
protected String hello() {
     return "hello user!"
}

or sending directly via the brokerMessagingTemplate bean:

brokerMessagingTemplate.convertAndSendToUser "myPrincipal",
"/queue/hello", "hello user!"

(the brokerMessagingTemplate is actually a
http://docs.spring.io/spring/docs/4.0.2.RELEASE/javadoc-api/org/springframework/messaging/simp/SimpMessagingTemplate.html)

you also have the option to define a java.security.Principal typed
argument on the controller method. Spring will give you the principal of
the originating http-request that started the websocket. Usually spring
security takes care of wrapping the request so that the principal will
actually be your Authentication object.


zyro

-------- Original Message  --------
Subject: [grails-user] Re: [ANN] Spring Websocket Plugin 1.0.0.M1
From: Ken Siprell <[hidden email]>
To: [hidden email]
Date: Thu, 6 Mar 2014 03:56:50 -0800 (pst)

> Hi Zyro,
>
> Do you think spring4, sockjs, and stomp can replace the atmosphere framework
> in a grails app, especially if used with an external message broker? I see a
> lot of advantages in using it with grails. However, could you comment on the
> following?
>
> It looks like there's no native client disconnect event, which would
> preclude use of something like the atmosphere broadcaster cache. I suppose
> an external message broker could handle pushing the missed messages after a
> client reconnects, but how could this be handled with the internal simple
> broker? Would we need a couple of extra classes in your plugin?
>
> It looks like an external message broker would be the best course of action
> for a production app since the simple broker doesn't support clustering. If
> this is the case, would your plugin need some extra configuration options to
> ease integration with say ActiveMQ or RabbitMQ?
>
> It seems almost too easy with annotations on controller methods
> (@MessageMapping), but would it be a better practice to have separate
> messaging controllers or services?
>
> Does your plugin support the spring security plugin and the
> "/user/{principal}" endpoint out of the box? I saw
> https://github.com/zyro23/grails-spring-websocket/blob/master/grails-app/conf/DefaultSpringWebsocketConfig.groovy#L10
> in the default config but wasn't sure if this is all that's needed.
>
> I'm glad you got ahead of the 2.4 release curve. I was considering a similar
> plugin since I hadn't seen this one on the plugin portal, but yours is
> better than I could have delivered.
>
> Ken
>
>
>
> --
> View this message in context: http://grails.1312388.n4.nabble.com/ANN-Spring-Websocket-Plugin-1-0-0-M1-tp4654667p4654741.html
> Sent from the Grails - user mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>      http://xircles.codehaus.org/manage_email
>
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: [ANN] Spring Websocket Plugin 1.0.0.M1

smaldini
I strongly support this impl, congrats btw ! Its a much more clean and mature approach than grails-events-push afaik. There are some limitations (tomcat 8, binary support, and a few tiny things) but the Stomp design gives an opportunity to derisk the client from being tied to Grails in such situation. E.G. RabbitMQ supports STOMP. But there are advantages in doing this at app level for a loads of use cases, top to mind is GORM events hook.


On Thu, Mar 6, 2014 at 1:07 PM, zyro <[hidden email]> wrote:
hi ken,

yes i do think so. especially with an external broker.

client disconnect / message cache: a very good point. tbh did not look into that matter yet. but i doubt that the map-based broker impl is currently capable of caching and a real message broker should be the way to go.

message broker: are you missing any config options regarding a real broker? the only one i got not mapped at the moment is the broker heartbeat interval, but else than that, the settings of the stompRelay part _is_ your broker connection. activemq and rabbitmq both work. you just have to make sure you install the respective stomp plugin.

separate controllers: makes much sense. i even consider it kind of ugly to have to put a modifier in front of the method (protected/private) because of how spring handles actions (@XyzMapping) vs. how grails handles actions (public methods) ...
but well, until now the focus was almost exclusively to make spring functionality available, not to enhance groovy-ish use of it.

user-destinations: sending to those destinations is supported. e.g.

client.subscribe("/user/queue/hello", function(message){
    doIt();
});
client.send("/app/hello", {}, "");

@MessageMapping("/hello")
@SendToUser("/queue/hello")
protected String hello() {
    return "hello user!"
}

or sending directly via the brokerMessagingTemplate bean:

brokerMessagingTemplate.convertAndSendToUser "myPrincipal", "/queue/hello", "hello user!"

(the brokerMessagingTemplate is actually a http://docs.spring.io/spring/docs/4.0.2.RELEASE/javadoc-api/org/springframework/messaging/simp/SimpMessagingTemplate.html)

you also have the option to define a java.security.Principal typed argument on the controller method. Spring will give you the principal of the originating http-request that started the websocket. Usually spring security takes care of wrapping the request so that the principal will actually be your Authentication object.



zyro

-------- Original Message  --------
Subject: [grails-user] Re: [ANN] Spring Websocket Plugin 1.0.0.M1
From: Ken Siprell <[hidden email]>
To: [hidden email]
Date: Thu, 6 Mar 2014 03:56:50 -0800 (pst)

Hi Zyro,

Do you think spring4, sockjs, and stomp can replace the atmosphere framework
in a grails app, especially if used with an external message broker? I see a
lot of advantages in using it with grails. However, could you comment on the
following?

It looks like there's no native client disconnect event, which would
preclude use of something like the atmosphere broadcaster cache. I suppose
an external message broker could handle pushing the missed messages after a
client reconnects, but how could this be handled with the internal simple
broker? Would we need a couple of extra classes in your plugin?

It looks like an external message broker would be the best course of action
for a production app since the simple broker doesn't support clustering. If
this is the case, would your plugin need some extra configuration options to
ease integration with say ActiveMQ or RabbitMQ?

It seems almost too easy with annotations on controller methods
(@MessageMapping), but would it be a better practice to have separate
messaging controllers or services?

Does your plugin support the spring security plugin and the
"/user/{principal}" endpoint out of the box? I saw
https://github.com/zyro23/grails-spring-websocket/blob/master/grails-app/conf/DefaultSpringWebsocketConfig.groovy#L10
in the default config but wasn't sure if this is all that's needed.

I'm glad you got ahead of the 2.4 release curve. I was considering a similar
plugin since I hadn't seen this one on the plugin portal, but yours is
better than I could have delivered.

Ken



--
View this message in context: http://grails.1312388.n4.nabble.com/ANN-Spring-Websocket-Plugin-1-0-0-M1-tp4654667p4654741.html
Sent from the Grails - user mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

     http://xircles.codehaus.org/manage_email



---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email





--
Stéphane
--

Reply | Threaded
Open this post in threaded view
|

Re: [ANN] Spring Websocket Plugin 1.0.0.M1

smaldini
Talking about limitiations, this overly emotive blog post http://movingfulcrum.tumblr.com/post/78696653156/a-guide-around-spring-4s-buggy-websocket-support talks about them.


On Thu, Mar 6, 2014 at 2:27 PM, Stephane Maldini <[hidden email]> wrote:
I strongly support this impl, congrats btw ! Its a much more clean and mature approach than grails-events-push afaik. There are some limitations (tomcat 8, binary support, and a few tiny things) but the Stomp design gives an opportunity to derisk the client from being tied to Grails in such situation. E.G. RabbitMQ supports STOMP. But there are advantages in doing this at app level for a loads of use cases, top to mind is GORM events hook.


On Thu, Mar 6, 2014 at 1:07 PM, zyro <[hidden email]> wrote:
hi ken,

yes i do think so. especially with an external broker.

client disconnect / message cache: a very good point. tbh did not look into that matter yet. but i doubt that the map-based broker impl is currently capable of caching and a real message broker should be the way to go.

message broker: are you missing any config options regarding a real broker? the only one i got not mapped at the moment is the broker heartbeat interval, but else than that, the settings of the stompRelay part _is_ your broker connection. activemq and rabbitmq both work. you just have to make sure you install the respective stomp plugin.

separate controllers: makes much sense. i even consider it kind of ugly to have to put a modifier in front of the method (protected/private) because of how spring handles actions (@XyzMapping) vs. how grails handles actions (public methods) ...
but well, until now the focus was almost exclusively to make spring functionality available, not to enhance groovy-ish use of it.

user-destinations: sending to those destinations is supported. e.g.

client.subscribe("/user/queue/hello", function(message){
    doIt();
});
client.send("/app/hello", {}, "");

@MessageMapping("/hello")
@SendToUser("/queue/hello")
protected String hello() {
    return "hello user!"
}

or sending directly via the brokerMessagingTemplate bean:

brokerMessagingTemplate.convertAndSendToUser "myPrincipal", "/queue/hello", "hello user!"

(the brokerMessagingTemplate is actually a http://docs.spring.io/spring/docs/4.0.2.RELEASE/javadoc-api/org/springframework/messaging/simp/SimpMessagingTemplate.html)

you also have the option to define a java.security.Principal typed argument on the controller method. Spring will give you the principal of the originating http-request that started the websocket. Usually spring security takes care of wrapping the request so that the principal will actually be your Authentication object.



zyro

-------- Original Message  --------
Subject: [grails-user] Re: [ANN] Spring Websocket Plugin 1.0.0.M1
From: Ken Siprell <[hidden email]>
To: [hidden email]
Date: Thu, 6 Mar 2014 03:56:50 -0800 (pst)

Hi Zyro,

Do you think spring4, sockjs, and stomp can replace the atmosphere framework
in a grails app, especially if used with an external message broker? I see a
lot of advantages in using it with grails. However, could you comment on the
following?

It looks like there's no native client disconnect event, which would
preclude use of something like the atmosphere broadcaster cache. I suppose
an external message broker could handle pushing the missed messages after a
client reconnects, but how could this be handled with the internal simple
broker? Would we need a couple of extra classes in your plugin?

It looks like an external message broker would be the best course of action
for a production app since the simple broker doesn't support clustering. If
this is the case, would your plugin need some extra configuration options to
ease integration with say ActiveMQ or RabbitMQ?

It seems almost too easy with annotations on controller methods
(@MessageMapping), but would it be a better practice to have separate
messaging controllers or services?

Does your plugin support the spring security plugin and the
"/user/{principal}" endpoint out of the box? I saw
https://github.com/zyro23/grails-spring-websocket/blob/master/grails-app/conf/DefaultSpringWebsocketConfig.groovy#L10
in the default config but wasn't sure if this is all that's needed.

I'm glad you got ahead of the 2.4 release curve. I was considering a similar
plugin since I hadn't seen this one on the plugin portal, but yours is
better than I could have delivered.

Ken



--
View this message in context: http://grails.1312388.n4.nabble.com/ANN-Spring-Websocket-Plugin-1-0-0-M1-tp4654667p4654741.html
Sent from the Grails - user mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

     http://xircles.codehaus.org/manage_email



---------------------------------------------------------------------
To unsubscribe from this list, please visit:

   http://xircles.codehaus.org/manage_email





--
Stéphane
--




--
Stéphane
--

Reply | Threaded
Open this post in threaded view
|

Re: [ANN] Spring Websocket Plugin 1.0.0.M1

d.tamm
In reply to this post by zyro
One thing i noticed so far is, that the return value is a string. Is there any chance to return my value as JSON or Map to the JavaScript? Or shall my nd parse the string to json (this would mean I would have to adapt some of my code to convert the string to JSON).
Reply | Threaded
Open this post in threaded view
|

Re: [ANN] Spring Websocket Plugin 1.0.0.M1

zyro
so,

message conversion:

http://docs.spring.io/spring/docs/4.0.2.RELEASE/spring-framework-reference/html/websocket.html#websocket-stomp-handle-annotations

"The return value from an @MessageMapping method is converted with a
org.springframework.messaging.converter.MessageConverter and used as the
body of a new message that is then sent [...]"

you could override/replace:

https://github.com/spring-projects/spring-framework/blob/master/spring-messaging/src/main/java/org/springframework/messaging/simp/config/AbstractMessageBrokerConfiguration.java#L255

however, i think currently the way to go on the client side (no matter
what you marshall on the server) is to parse a string:

http://jmesnil.net/stomp-websocket/doc/#json

using grails built-in marshalling, inside a converter or as return
statement,
([my: "map"] as JSON).toString()
looks fine for me, too?

of course, a whole different story are use-cases like binary streaming,
but afaik smaldini is more into that matter...

zyro

-------- Original Message  --------
Subject: [grails-user] Re: [ANN] Spring Websocket Plugin 1.0.0.M1
From: d.tamm <[hidden email]>
To: [hidden email]
Date: Wed, 19 Mar 2014 13:25:07 -0700 (pdt)

> One thing i noticed so far is, that the return value is a string. Is there
> any chance to return my value as JSON or Map to the JavaScript? Or shall my
> nd parse the string to json (this would mean I would have to adapt some of
> my code to convert the string to JSON).
>
>
>
> --
> View this message in context: http://grails.1312388.n4.nabble.com/ANN-Spring-Websocket-Plugin-1-0-0-M1-tp4654667p4655229.html
> Sent from the Grails - user mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>      http://xircles.codehaus.org/manage_email
>
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: [ANN] Spring Websocket Plugin 1.0.0.M1

d.tamm
This post was updated on .
Hi zyro,

looks good so fare for me to convert my strings into JSON, worked for me now! But i got one more (hopefully last) question:

As stomp supports header information (http://jmesnil.net/stomp-websocket/doc/#send), like client.send("/app/hello", {test: 123}, "");... is there any chance to read those header information in the declared controller method?
i am suggesting a change from events-push to spring-websocket plugin (also changing current version of grails to 2.4), due to heavy problems in one of my projects with events push (not working like it should... in another project it's working fine, strange!)... and in my send-methods in my javascript, i send some information to the server, like an database_record ID i just started to work on (locking this record for any other person who views it) etc... any hint on this one?

my code in my current application for this:

Webinterface.grailsEvents.send("customerLocked", {userId: Login.benutzerId, customerId: parseInt(customerId)});

And i want to read the "userId" and "customerId" part in this controller method:

@MessageMapping("/customerLocked")
@SendTo("/topic/customerLocked")
protected String hello() {
    //read information here to lock the database record
    return //whatever
}

Dominik
Reply | Threaded
Open this post in threaded view
|

Re: [ANN] Spring Websocket Plugin 1.0.0.M1

d.tamm
This post was updated on .
Nearly got this one working now by changing the method to this:

@MessageMapping("/hello")
@SendTo("/topic/hello")
protected String hello(def test) {
    def stringOfBytes = "${test}"
    def byteValues = teststring.substring(1, teststring.size() - 1).split(", ")
    def bytes = new byte[byteValues.size()]
    def i = 0, len = bytes.size()
    while(i<len) {
        bytes[i] = Byte.valueOf(byteValues[i].trim())
        i++
    }
    def jsonMap = JSON.parse(new String(bytes))
    def mapTest = ["contentOne": 123, "nextContent": "TestController"]
    return (mapTest as JSON)?.toString()
}

Working with client.send("/app/hello", {}, '{"name": "Test"}');!

Btw: what about mapping those topic (like in the events-push-plugin) just to get it working with services? i like this approach very much, since i dont have to declare an extra controller to use the brokerMessagingTemplate and just could let the service handle all the sent messages (and afterwards the onging traffic).
Reply | Threaded
Open this post in threaded view
|

Re: [ANN] Spring Websocket Plugin 1.0.0.M1

d.tamm
In reply to this post by zyro
Seems like i am not doing the right thing or the IE8 is just a b**** :-) with the code of your example i cant get my IE8 sending messages via:

$("#helloButton").click(function() {
    client.send("/app/hello", {}, '{"name": "Test"}');
});

The Server gives me the following stacktrace:

Error |
2014-04-11 15:24:35,388 [http-nio-8080-exec-6] ERROR messaging.StompSubProtocolHandler  - Failed to parse WebSocket message as STOMP frame
Message: null
    Line | Method
->> 1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|    615 | run       in java.util.concurrent.ThreadPoolExecutor$Worker
^    744 | run . . . in java.lang.Thread
Reply | Threaded
Open this post in threaded view
|

Re: [ANN] Spring Websocket Plugin 1.0.0.M1

zyro
In reply to this post by d.tamm
for access to header information check
http://docs.spring.io/spring/docs/current/spring-framework-reference/html/websocket.html#websocket-stomp-handle-annotations

zyro

-------- Original Message  --------
Subject: [grails-user] Re: [ANN] Spring Websocket Plugin 1.0.0.M1
From: d.tamm <[hidden email]>
To: [hidden email]
Date: Fri, 11 Apr 2014 05:24:00 -0700 (pdt)

> Hi zyro,
>
> looks good so fare for me to convert my strings into JSON, worked for me
> now! But i got one more (hopefully last) question:
>
> As stomp supports header information
> (http://jmesnil.net/stomp-websocket/doc/#send), like
> client.send("/app/hello", {test: 123}, "");... is there any chance to read
> those header information in the declared controller method?
> i am suggesting a change from events-push to spring-websocket plugin (also
> changing current version of grails to 2.4), due to heavy problems in one of
> my projects with events push (not working like it should... in another
> project it's working fine, strange!)... and in my send-methods in my
> javascript, i send some information to the server, like an database_record
> ID i just started to work on (locking this record for any other person who
> views it) etc... any hint on this one?
>
> my code in my current application for this:
>
> Webinterface.grailsEvents.send("customerLocked", {userId: Login.benutzerId,
> customerId: parseInt(customerId)});
>
> Dominik
>
>
>
> --
> View this message in context: http://grails.1312388.n4.nabble.com/ANN-Spring-Websocket-Plugin-1-0-0-M1-tp4654667p4655945.html
> Sent from the Grails - user mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>      http://xircles.codehaus.org/manage_email
>
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: [ANN] Spring Websocket Plugin 1.0.0.M1

zyro
In reply to this post by d.tamm
the point is that the plugin in its current state integrates with the
underlying spring infrastructure but not (yet) with grails data binding.

this means, again as the spring docs state, that
- org.springframework.messaging.converter.MessageConverter beans are
used for payload conversion (method argument and return value)
- org.springframework.core.convert.converter.Converter beans are used
for @Headers annotated arguments.

by default, spring will register and apply a
MappingJackson2MessageConverter bean for conversion.

that means for your case, atm easiest way would be to type your method
argument as Map - then, the stringified json object payload just gets
deserialized straight into it.

zyro

-------- Original Message  --------
Subject: [grails-user] Re: [ANN] Spring Websocket Plugin 1.0.0.M1
From: d.tamm <[hidden email]>
To: [hidden email]
Date: Fri, 11 Apr 2014 06:02:18 -0700 (pdt)

> Nearly got this one working now by changing the method to this:
>
> @MessageMapping("/hello")
> @SendTo("/topic/hello")
> protected String hello(def test) {
>      def stringOfBytes = "${test}"
>      def byteValues = teststring.substring(1, teststring.size() - 1).split(",
> ")
>      def bytes = new byte[byteValues.size()]
>      def i = 0, len = bytes.size()
>      while(i<len) {
>          bytes[i] = Byte.valueOf(byteValues[i].trim())
>          i++
>      }
>      def jsonMap = JSON.parse(new String(bytes))
>      def mapTest = ["contentOne": 123, "nextContent": "TestController"]
>      return (mapTest as JSON)?.toString()
> }
>
> But somehow i get this one here now:
>
> Error |
> Exception in thread "clientInboundChannel-1"
> Error |
> java.lang.NullPointerException
> Error |
> at
> org.springframework.messaging.simp.broker.SimpleBrokerMessageHandler.sendMessageToSubscribers(SimpleBrokerMessageHandler.java:150)
> Error |
> at
> org.springframework.messaging.simp.broker.SimpleBrokerMessageHandler.handleMessageInternal(SimpleBrokerMessageHandler.java:132)
> Error |
> at
> org.springframework.messaging.simp.broker.AbstractBrokerMessageHandler.handleMessage(AbstractBrokerMessageHandler.java:142)
> Error |
> at
> org.springframework.messaging.support.ExecutorSubscribableChannel$1.run(ExecutorSubscribableChannel.java:70)
> Error |
> at
> java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
> Error |
> at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
> Error |
> at java.lang.Thread.run(Thread.java:744)
>
> Too bad, actually! Btw: what about mapping those topic (like in the
> events-push-plugin) just to get it working with services? i like this
> approach very much, since i dont have to declare an extra controller to use
> the brokerMessagingTemplate and just could let the service handle all the
> sent messages (and afterwards the onging traffic).
>
>
>
> --
> View this message in context: http://grails.1312388.n4.nabble.com/ANN-Spring-Websocket-Plugin-1-0-0-M1-tp4654667p4655947.html
> Sent from the Grails - user mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>      http://xircles.codehaus.org/manage_email
>
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email