Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix SockJSSocket handler_id, return java_obj.writeHandlerID() directly #42

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

fregaham
Copy link
Contributor

@fregaham fregaham commented Jul 5, 2014

The current SockJSSocket handler_id() code is definitely wrong, as the self.handler_id replaces the handler_id method. I assume there is no reason why not to return java_obj.writeHandlerID() directly, so this patch does that. I also assume the handler_id should be a method and not a property.

To reproduce the issue

server.py:

import functools
import vertx
from core.event_bus import EventBus
from core.buffer import Buffer

server = vertx.create_http_server()

@server.request_handler
def request_handler(req):
    file = ''
    if req.path == '/':
        file = 'index.html'
    elif '..' not in req.path:
        file = req.path[1:]
    req.response.send_file(file)

sockJSServer = vertx.create_sockjs_server(server)
bridge = sockJSServer.bridge({'prefix' : '/eventbus'},
    [],
    [])


@bridge.socket_created_handler
def bridge_socket_created_handler(socket):
    print "my socket created, address: " + `socket.handler_id()`
    EventBus.send(socket.handler_id(), Buffer.create_from_str('{"address":"some-address","body":"Hello, world"}'))

server.listen(8080, 'localhost')

index.html:

<!DOCTYPE html>
<html>
<head>
    <title>Hello</title>
    <script src="http://cdn.sockjs.org/sockjs-0.3.4.min.js"></script>
    <script src='vertxbus-2.1.js'></script>
<script>
    var eb = new vertx.EventBus('http://localhost:8080/eventbus');
    eb.onopen = function() {
      eb.registerHandler('some-address', function(message) {
        console.log('received a message: ' + JSON.stringify(message));
      });
    }
</script>
</head>
<body>
</body>
</html>

Signed-off-by: Marek Schmidt <fregaham@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant