Lua xavante WEB server实现xmlrpc服务器端

xavante

xavante是一个使用lua实现的遵守http1.1的web server,支持wsapi。

依赖库:

xavante核心 -- lua, copas(纯lua编写,网络连接coroutine处理), luasocket处理网络连接。

xavante file handler -- luaFileSystem

此项目属于kepler项目的一个子项目,见官网地址:

http://keplerproject.github.io/xavante/manual.html

github上维护开源代码:

https://github.com/keplerproject/xavante

xavante提供三类处理接口:

URL映射, 文件上传, 和 CGIlua调用,配置运行步骤 见官网介绍:

http://keplerproject.github.io/xavante/manual.html#install

xavante是以一个库的形式存在,如果想运行必须下载wsapi。

WSAPI

wsapi是从web应用中抽象出来的web server接口, 按照wsapi接口编程的web应用程序具有可移植性,

可以再不同的服务器上运行, 包括 CGI FASTCGI XAVANTE

主要负责,请求处理 和 输出缓存, 详情见官网:

http://keplerproject.github.io/wsapi/index.html

安装运行:

http://keplerproject.github.io/wsapi/manual.html

接口说明文档:

http://keplerproject.github.io/wsapi/libraries.html

实验 -- lua xml rpc 访问xavante提供的xmlrpc service

  • 下载安装 lua for windows

lua for windows 是一个包含了很多lua库的安装包,

包括 luaExpat luaSocket luaFileSystem Copas Rings 等库,

其中Copas为xavante依赖的库;

luaExpat 和 luaSocket为lua-xmlrpc依赖库。

http://code.google.com/p/luaforwindows/downloads/list

  • xavante安装
  • 将解压后的xavante文件夹中src的xavante目录拖到lua.exe同级,
  • 并文件夹中的xavante.lua拖出来与lua.exe同级。
  • wsapi安装
  • 将加压后的wsapi文件夹中的src的 wsapi 目录和 wsapi.lua 文件拖到lua.exe同级。
  • 将lua-xmlrpc加压后的 src文件放到 xmlrpc目录中(与lua.exe同级)
  • 将 lua-xmlrpc 的 client.lua 和 server-xavante.lua 添加add加法rpc调用,放到lua.exe同级。

代码:

client.lua

  • require("xmlrpc.http")
    
    -- hello_world
    local ok, res = xmlrpc.http.call("http://localhost:12345", "hello_world")
    assert(ok, string.format("XML-RPC call failed on client: %s", tostring(res))) print("Result: " .. tostring(res)) -- add number
    local ok, res = xmlrpc.http.call("http://localhost:12345", "add", 1, 2)
    assert(ok, string.format("XML-RPC call failed on client: %s", tostring(res))) print("Result: " .. tostring(res))

server_xavante.lua

xavante = require("xavante") wsapi = require("wsapi") wsapi.xavante = require("wsapi.xavante") wsapi.request = require("wsapi.request")

require("xmlrpc")

--- XML-RPC WSAPI handler
-- @param wsapi_env WSAPI environment
function wsapi_handler(wsapi_env)
   local headers = { ["Content-type"] = "text/xml" }
   local req = wsapi.request.new(wsapi_env) local method, arg_table = xmlrpc.srvDecode(req.POST.post_data)
   local func = xmlrpc.dispatch(method)
   local result = { pcall(func, unpack(arg_table or {})) }
   local ok = result[1]
   if not ok then
      result = { code = 3, message = result[2] }
   else
      table.remove(result, 1)
      if table.getn(result) == 1 then
         result = result[1]
      end
   end

   local r = xmlrpc.srvEncode(result, not ok)
   headers["Content-length"] = tostring(#r)

   local function xmlrpc_reply(wsapienv) coroutine.yield(r)
   end

   return 200, headers, coroutine.wrap(xmlrpc_reply)
end

-- XML-RPC exported functions
xmlrpc_exports = {}

--- Get simple string.
-- @return simple string
function xmlrpc_exports.hello_world()
   return "Hello World"
end

--- add two number function.
-- @return sum
function xmlrpc_exports.add(a, b)
   return a + b
end

local rules = {{ match = ".", with = wsapi.xavante.makeHandler(wsapi_handler) }} local config = { server = {host = "*", port = 12345}, defaultHost = { rules = rules} } xmlrpc.srvMethods(xmlrpc_exports) xavante.HTTP(config) xavante.start()

Lua xavante WEB server实现xmlrpc服务器端,布布扣,bubuko.com

时间: 2024-08-11 01:33:02

Lua xavante WEB server实现xmlrpc服务器端的相关文章

【轮子狂魔】抛弃IIS,打造个性的Web Server - WebAPI/Lua/MVC(附带源码)

小分享:我有几张阿里云优惠券,用券购买或者升级阿里云相应产品最多可以优惠五折!领券地址:https://promotion.aliyun.com/ntms/act/ambassador/sharetouser.html?userCode=ohmepe03 引言 此篇是<[轮子狂魔]抛弃IIS,向天借个HttpListener - 基础篇(附带源码)>的续篇,也可以说是提高篇,如果你对HttpListener不甚了解的话,建议先看下基础篇. 这次玩的东西有点多了,大致分为如下几个方向: 1.支持

The different between app server and web server

web server: handles http request app server: handle the business logic of the application 1) web server A Web server mainly deals with sending HTML for display in a Web browser.When a request comes into the Web server, the Web server simply passes th

小测几种python web server的性能

http://blog.csdn.net/raptor/article/details/8038476 因为换了nginx就不再使用mod_wsgi来跑web.py应用了,现在用的是gevent-wsgi,效果还不错.但还是想试试别的,比如传说中超级猛的meinheld什么的. 软硬件环境 硬件: 一台04年初购置的IBM X235服务器,CPU为Xeon 2.4G两颗,内存1G,100M网卡. 软件: Ubuntu Server 10.04 LTSApache 2.2.14Nginx 0.7.

Web Server 配置安全

常见 Web Server:Apache Httpd.Nginx.LightHttp.Web Server 安全:自身是否安全 + 是否提供了可用的安全功能. Apache 安全 Apache 的漏洞大多是 Apache 的 module 造成,其核心高危漏洞几乎没有.默认启动的 Module 出现过的高危漏洞很少,大多数高危漏洞集中在默认没有安装或启用的 Module 上. 检查 Apache 安全的第一件事就是检查 Module 的安装情况,根据 "最小权限原则",应该尽可能减少不

[转载] 学会使用Web Service上(服务器端访问)~~~

http://www.360doc.com/content/10/0712/12/541242_38461863.shtml# 关于什么是Web Service,相信在很多地方都会有介绍.简单的讲,Web Service就是为Web应用程序之间彼此共享资源提供了一种可能.采取的方式是将相应的类及其中 的方法暴露出来,然后调用者就可以直接调用这些类中的方法,达到访问远程资源的目的.本文只是想告诉,如果去使用Web Service.我主要从服务器端访问Web Service.客户端访问Web Ser

使用Nginx+Lua实现Web项目的灰度发布

使用Nginx+Lua实现Web项目的灰度发布 Nginx编译安装Lua模块 一.安装LUA环境及相关库 官方网站:https://github.com/openresty/lua-nginx-module 1.LuaJIT wget http://luajit.org/download/LuaJIT-2.0.2.tar.gz make && make install PREFIX=/usr/local/LuaJIT # vim /etc/profile export LUAJIT_LIB

Using OAuth 2.0 for Web Server Applications, verifying a user&#39;s Android in-app subscription

在写本文之前先说些题外话. 前段时间游戏急于在GoolePlay上线,明知道如果不加Auth2.0的校验是不安全的还是暂时略过了这一步,果然没几天就发现后台记录与玩家实际付费不太一致,怀疑有玩家盗刷游戏元宝等,并且真实的走过了GooglePlay的所有支付流程完成道具兑换,时间一长严重性可想而知.经过查阅大量google官方文档后把代码补上,并在这里记录下OAuth 2.0 的使用,Google提供了OAuth2.0的好几种使用用途,每种使用方法都有些不同,具体可以看下这篇博客.在这里只写OAu

Apache Web Server 本地推送命令

/*****openssl 系统命令    x509输入文件类型       -in 是参数输入文件   -inform本地文件     -out是参数  是生成文件  ***/ openssl    x509  -in  *.cer  -inform  der  -out *.pem openssl  pkcs12  -nocets  -out  *.pem  -in  *.p12 /*****   >是 表示连接   ****/ cat  *.pem  *.pem  >  *.pem 在终

The web application you are attempting to access on this web server is currently unavailable.......

今天去服务器安装了个.net 4.0 framework(原本有1.0和2.0的),配置好站点后,选择版本为4.0,访问出错,错误代码如下 Server Application Unavailable The web application you are attempting to access on this web server is currently unavailable.  Please hit the "Refresh" button in your web brows