コード例 #1
0
ファイル: controller_verticle.py プロジェクト: parroit/mvc.x
def build_route():
    router=RouteMatcher()

    cfg = vertx.config()
    config=JsonObject(cfg).getObject("router")

    for route in config.getArray("routes"):
        controller_description = route.getString("controller")



        def controller_name(): return str(controller_description).split(".")[0]

        if not route.getString("get") is None:
            print("get:"+str(route))
            router.get( route.getString("get"),controller_renderer(config.getString("controller-path"),controller_name(),route.getString("view"),renderer(route,controller_description),cfg["session-dir"]))
        elif not route.getString("post") is None:
            print("post:"+str(route))
            router.post( route.getString("post"),controller_renderer(config.getString("controller-path"),controller_name(),route.getString("view"),renderer(route,controller_description),cfg["session-dir"]))
        elif not route.getString("static") is None:
            print("static:"+str(route))
            router.get(route.getString("static"),static_files_renderer(route.getString("folder")) )
    return router
コード例 #2
0
    else:
        #req.response.put_header('Expect', '404-Continue')
        req.response.status_code = 404
        req.response.end()

def file_info(req):
    def props_handler(err, props):
        if err:
            logger.error("Failed to retrieve file props: %s"% err)
        else:
            logger.info('File props are:')
            logger.info("Last accessed: %s"% props.symbolic_link)
            req.response.status_code = 200
            #req.response.status_message = props.symbolic_link
            
    name = "%s%s"% (path_symlink,req.params['filename'])
    logger.info(name)
    #fs.props(name, props_handler)

route_matcher.post('/upload', upload.upload_handler)
route_matcher.get('/dl/:uid/:filename', file_service.file_handler)
route_matcher.get('/', index_handler)

#set server
#server.set_send_buffer_size(4 * 1024)
#server.set_receive_buffer_size(100 * 1024)
#logger.info("send buffer: %s"% server.send_buffer_size)
#logger.info("receive buffer: %s"% server.receive_buffer_size)
#logger.info(server.use_pooled_buffers)
server.request_handler(route_matcher).listen(app_config['port'], app_config['host'])
コード例 #3
0
server = vertx.create_http_server()

route_matcher = RouteMatcher()
logger = vertx.logger()
fs = vertx.file_system()
app_config = vertx.config()
path_web = app_config['paths']['web']
#cros module variable
##TODO  
def index_handler(req):
    if ("js" in req.uri) or ("css" in req.uri) or ("images" in req.uri) or ("pages" in req.uri):
        #logger.info(req.uri)
        req.response.send_file("%spresenation/%s"% (path_web,req.uri))
    else:
        req.response.send_file( "%spresentation/index.html"% path_web)

@route_matcher.no_match 
def source_handler(req):
    if ("js" in req.uri) or ("css" in req.uri) or ("images" in req.uri) or ("pages" in req.uri):
        req.response.send_file("%spresentation/%s"% (path_web,req.uri))

route_matcher.get('/', index_handler)

#set server
#server.set_send_buffer_size(4 * 1024)
#server.set_receive_buffer_size(100 * 1024)
#logger.info("send buffer: %s"% server.send_buffer_size)
#logger.info("receive buffer: %s"% server.receive_buffer_size)
#logger.info(server.use_pooled_buffers)
server.request_handler(route_matcher).listen(8080, app_config['host'])
コード例 #4
0
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import vertx
from core.http import RouteMatcher

# Inspired from Sinatra / Express
rm = RouteMatcher()

def user_request_handler(req):
    req.response.end("User: %s ID: %s"% (req.params["user"],  req.params["id"]) ) 

# Extract the params from the uri
rm.get('/details/:user/:id', user_request_handler)

def request_handler(req):
    req.response.send_file("route_match/index.html")

# Catch all - serve the index page
rm.get_re('.*', request_handler)

vertx.create_http_server().request_handler(rm).listen(8080)
コード例 #5
0
def message_handler(message): # this is executed in event loop
    print 'Im worker and i got a message :'+str(message.body)
    time.sleep(5)
    # do some logic for data base transaction
    # populate return message
    message.reply('This is reply for message :'+str(message.body))

def reply_handler_logic(req,message):
	print 'im reply handler, i just invoked'
   	time.sleep(5)
	key = req.params['key']
   	req.response.end('event bus call is called and replied from reply_handler :'+ key +str(message.body))
        
EventBus.register_handler('call_bus',handler=message_handler)

def url_handler(req): # this is invoked by eventloop thread
        # read parameter from URI
        key = req.params['key']
        def reply_handler(message):
        	reply_handler_logic(req,message)
        print 'im url handler i will send message to event bus'
       	time.sleep(5)
       	print 'Im url handler. I just sent message to event bus'
        EventBus.send('call_bus',key,reply_handler)
                
route_matcher.get('/eventbus/:key',url_handler)

                
server.request_handler(route_matcher).listen(8000,'localhost')