def real_fun(self, *args, **kwargs): uri = self.locator.locate(tx) service = HessianProxy(uri, timeout=self.timeout) res = service.invoke(Object('net.butfly.bus.Request', tx=tx, version=version, args=args, extParamMap=kwargs)) if res.errorCode is not None: raise AlbusError(res.errorCode, res.errorMessage, res.errorStack) return res.resultCode, res.result
def _run_aqb_manager(self): res = self._db.Query("""SELECT source_database_connection_id FROM source_database_connection WHERE segment_id = %s AND report_data_table_access_ind = 'Y' """, (self._data['segment_id'], )) if res: source_db_conn = self._db.record[0] source_database_connection_id = source_db_conn['source_database_connection_id'] else: if not self._data['segment_id']: raise Exception("Connection to segment '%s' data base is not found" % self._data['segment_id']) self._db.Query("""SELECT name FROM segment WHERE segment_id = %s """, (self._data['segment_id'], )) segment_data = self._db.record[0] connection_name = "%s Report Data Connection" % segment_data['name'] res = self._db.Query("""INSERT INTO source_database_connection (name, report_data_table_access_ind, segment_id, allow_visual_editor_ind, infer_foreign_keys_ind, concurrent_threads_per_update_trigger_event, jdbc_driver_id, username, password, host_name, port, database_name, jdbc_string, jdbc_options) SELECT %s, 'Y', %s, 'Y', 'Y', 1, jdbc_driver_id, username, password, host_name, port, database_name, jdbc_string, jdbc_options FROM source_database_connection WHERE segment_id = 0 """, (connection_name, self._data['segment_id'])) if not res: raise Exception("Connection to segment '%s' data base is not found" % self._data['segment_id']) source_database_connection_id = self._db.lastInsertID try: aqb_service = HessianProxy(self._conf.aqb_metadata_manager_url) aqb_response = aqb_service.getMetadata({'connectionId': source_database_connection_id, 'refreshMetadata': True}) #self._logger.info('First access to aqb: %s' % aqb_response.success) except Exception, e: # try once again. due to lost db connection it might bwe necessary to invoke once again. try: aqb_service = HessianProxy(self._conf.aqb_metadata_manager_url) aqb_response = aqb_service.getMetadata({'connectionId': source_database_connection_id, 'refreshMetadata': True}) #self._logger.info('Second access to aqb: %s' % aqb_response.success) except Exception, e: self._logger.error('Cannot invoke AQB meta data manager: %s' % e)
def test_login(self): from mustaine.client import HessianProxy service = HessianProxy(self.hessian_proxy) device_info_dto = { 'clientType': 1, 'clientVer': '1.0', 'deviceName': 'LaoDuan\'s iphone', 'deviceId': 'xxx001', 'lastLat': 0.00, 'lastLng': 0.00, 'relativeId1': 'channel', 'relativeId2': 'user_id' } try: service.sellerLogin(None, self.phone_number, "000000", device_info_dto) except Exception, ex: print('Input: ' + self.phone_number + 'Error:' + ex.message)
def SaveDict(savedict,dataid): dataid=dataid ## if savedict['req'][0]['RequestType']== "string" : print r"API请求参数类型为"+savedict['req'][0]['RequestType'] dictlist=savedict['req'] urldata=dictlist[2]['parm'] service_get= dictlist[1]['url'].split('.',2) print urldata tcp_url=fronturl+service_get[0] print tcp_url service = HessianProxy(tcp_url) service.method= service_get[2] resplog="resplog=service."+service_get[1]+"(long(urldata[1]),urldata[0])."+service_get[2] print resplog exec(resplog) print resplog savelog(txtfile,dataid,urldata,resplog) elif savedict['req'][0]['RequestType']== "json" : print r"API请求参数类型为"+savedict['req'][0]['RequestType'] dictlist=savedict['req'] urldata=dictlist[2]['parm'] service_get= dictlist[1]['url'].split('.',2) print urldata tcp_url=fronturl+service_get[0] print tcp_url service = HessianProxy(tcp_url) service.method= service_get[1] resplog="resplog=service."+service_get[1]+"(urldata)."+service_get[2] print resplog exec(resplog) print resplog savelog(txtfile,dataid,urldata,resplog) elif savedict['req'][0]['RequestType']== "mix" : print r"API请求参数类型为"+savedict['req'][0]['RequestType'] dictlist=savedict['req'] urldata=dictlist[2]['parm'] service_get= dictlist[1]['url'].split('.',2) print urldata tcp_url=fronturl+service_get[0] print tcp_url service = HessianProxy(tcp_url) service.method= service_get[1] resplog="resplog=service."+service_get[1]+"(urldata[0],urldata[1],urldata[2],urldata[3],urldata[4])."+service_get[2] exec(resplog) print resplog savelog(txtfile,dataid,urldata,resplog)
#!/usr/bin/python # coding=utf-8 from mustaine.client import HessianProxy """ 参考文档:http://blog.csdn.net/haizhaopeng/article/details/47104897 我们只需要知道提供服务暴露的URL和服务接口即可,这里URL为http://10.95.3.74:8080/http_dubbo/search, 接口为org.shirdrn.platform.dubbo.service.rpc.api.SolrSearchService。 运行程序,可以调用提供方发布的服务。 """ serviceUrl = 'http://10.95.3.74:8080/http_dubbo/search' q = 'q=*:*&fl=*&fq=building_type:1' start = 0 rows = 10 resType = 'xml' collection = 'tinycollection' if __name__ == '__main__': proxy = HessianProxy(serviceUrl) result = proxy.search(collection, q, resType, start, rows) print result
# -*- coding: utf-8 -*- from mustaine.client import HessianProxy import urllib2 import json proxy = HessianProxy('http://webservice.build.index.com:9011/webservice/3gcms') class DocFetcher: def fetchDoc(self, channelid, ftime, ttime, offset, size): return proxy.get3GArticles(channelid, ftime, ttime, offset, size) def getDocByTopic(self, topicid, offset, size): docs = proxy.getTopicArticle(topicid, offset, size) for doc in docs: print 'id len: %d' % len(doc['docid']) doc['body'] = self.getBody(doc['docid']) print 'body len: %d, topicid: %s' % (len( doc['body']), doc['topicid']) return docs def getBody(self, docid): url = 'http://c.3g.163.com/nc/article/%s/full.html' % docid response = urllib2.urlopen(url) docInfo = response.read() docJson = json.loads(docInfo) if docJson[docid].has_key('body'): return docJson[docid]['body'] else:
from mustaine.client import HessianProxy service = HessianProxy("") print service.getEhrUserByUcid("")
import pymongo from mustaine.client import HessianProxy import mustaine from pymongo import Connection PAGESIZE = 500 connection = Connection() db = connection.vocab value_set_concepts = db.valueSetConcepts service = HessianProxy("http://phinvads.cdc.gov/vocabService/v2") def toBSON(o): ret = {} for k in dir(o): if k.startswith("_"): continue v = getattr(o, k) if type(v) == list: ret[k] = map(toBSON, v) elif type(v) == mustaine.protocol.Object: ret[k] = toBSON(v) else: ret[k] = v return ret codeSystems = {} for cs in db.codeSystems.find({}): codeSystems[cs['oid']] = cs
#!/usr/bin/env python #coding=utf-8 # -*- coding:utf-8 -*- ### ### Hessian client ### ######################################## #import hessianlib if __name__ == '__main__': #proxy = hessianlib.Hessian('http://localhost:8080/rmi-demo/remoting/userServiceImpl') from mustaine.client import HessianProxy proxy = HessianProxy('http://localhost:8080/rmi-demo/remoting/userServiceImpl') print proxy.findById(long(303)).name print 'Done',
from mustaine import protocol from mustaine.client import HessianProxy # Caucho's Hessian 2.0 reference service # interface: http://caucho.com/resin-javadoc/com/caucho/hessian/test/TestHessian2.html test = HessianProxy("http://hessian.caucho.com/test/test") ### BINARY ENCODING TESTS DISABLED # def test_encode_binary_0(): # assert test.argBinary_0(protocol.Binary("")) is True # # def test_encode_binary_1(): # assert test.argBinary_1(protocol.Binary("x")) is True # # def test_encode_binary_1023(): # assert test.argBinary_1023(protocol.Binary("x" * 1023)) is True # # def test_encode_binary_1024(): # assert test.argBinary_1024(protocol.Binary("x" * 1024)) is True # # def test_encode_binary_15(): # assert test.argBinary_15(protocol.Binary("x" * 15)) is True # # def test_encode_binary_16(): # assert test.argBinary_16(protocol.Binary("x" * 16)) is True # # def test_encode_binary_65536(): # assert test.argBinary_65536(protocol.Binary("x" * 65536)) is True ### DATE ENCODING TESTS DISABLED, UTC MADNESS
#!python # encoding: utf-8 ''' 使用Python语言实现远程调用 使用Python客户端来进行远程调用,我们可以从https://github.com/bgilmore/mustaine下载,然后安装Hessian的代理客户端Python实现库: git clone https://github.com/bgilmore/mustaine.git cd mustaine sudo python setup.py install http://san-yun.iteye.com/blog/1628405 http://pydoc.net/Python/mustaine/0.1.7/mustaine.parser/ https://github.com/Kingson4Wu/Frieza-revenge/blob/master/RPC-framework%2Fsrc%2Fmain%2Fjava%2Fapp%2Fdemo%2FBasicService.java ''' from mustaine.client import HessianProxy test = HessianProxy("http://localhost:8080/EasyHessian/hello") print test._headers print test.hello() print test.getUser() print test.getUser().userName user = test.getUser() print user.password test.setGreeting("Hessian Python") print test.hello()
def setUp(self): self.test = HessianProxy("http://hessian.caucho.com/test/test")
class Test(unittest.TestCase): def setUp(self): self.test = HessianProxy("http://hessian.caucho.com/test/test") def test_encode_double_0_0(self): self.assertTrue(self.test.argDouble_0_0(0.0)) def test_encode_double_0_001(self): self.assertTrue(self.test.argDouble_0_001(0.001)) def test_encode_double_1_0(self): self.assertTrue(self.test.argDouble_1_0(1.0)) def test_encode_double_127_0(self): self.assertTrue(self.test.argDouble_127_0(127.0)) def test_encode_double_128_0(self): self.assertTrue(self.test.argDouble_128_0(128.0)) def test_encode_double_2_0(self): self.assertTrue(self.test.argDouble_2_0(2.0)) def test_encode_double_3_14159(self): self.assertTrue(self.test.argDouble_3_14159(3.14159)) def test_encode_double_32767_0(self): self.assertTrue(self.test.argDouble_32767_0(32767.0)) def test_encode_double_65_536(self): self.assertTrue(self.test.argDouble_65_536(65.536)) def test_encode_double_m0_001(self): self.assertTrue(self.test.argDouble_m0_001(-0.001)) def test_encode_double_m128_0(self): self.assertTrue(self.test.argDouble_m128_0(-128.0)) def test_encode_double_m129_0(self): self.assertTrue(self.test.argDouble_m129_0(-129.0)) def test_encode_double_m32768_0(self): self.assertTrue(self.test.argDouble_m32768_0(-32768.0)) def test_encode_false(self): self.assertTrue(self.test.argFalse(False)) def test_encode_int_0(self): self.assertTrue(self.test.argInt_0(0)) def test_encode_int_0x30(self): self.assertTrue(self.test.argInt_0x30(0x30)) def test_encode_int_0x3ffff(self): self.assertTrue(self.test.argInt_0x3ffff(0x3ffff)) def test_encode_int_0x40000(self): self.assertTrue(self.test.argInt_0x40000(0x40000)) def test_encode_int_0x7ff(self): self.assertTrue(self.test.argInt_0x7ff(0x7ff)) def test_encode_int_0x7fffffff(self): self.assertTrue(self.test.argInt_0x7fffffff(0x7fffffff)) def test_encode_int_0x800(self): self.assertTrue(self.test.argInt_0x800(0x800)) def test_encode_int_1(self): self.assertTrue(self.test.argInt_1(1)) def test_encode_int_47(self): self.assertTrue(self.test.argInt_47(47)) def test_encode_int_m0x40000(self): self.assertTrue(self.test.argInt_m0x40000(-0x40000)) def test_encode_int_m0x40001(self): self.assertTrue(self.test.argInt_m0x40001(-0x40001)) def test_encode_int_m0x800(self): self.assertTrue(self.test.argInt_m0x800(-0x800)) def test_encode_int_m0x80000000(self): self.assertTrue(self.test.argInt_m0x80000000(-0x80000000)) def test_encode_int_m0x801(self): self.assertTrue(self.test.argInt_m0x801(-0x801)) def test_encode_int_m16(self): self.assertTrue(self.test.argInt_m16(-16)) def test_encode_int_m17(self): self.assertTrue(self.test.argInt_m17(-17)) def test_encode_long_0(self): self.assertTrue(self.test.argLong_0(0)) def test_encode_long_0x10(self): self.assertTrue(self.test.argLong_0x10(0x10)) def test_encode_long_0x3ffff(self): self.assertTrue(self.test.argLong_0x3ffff(0x3ffff)) def test_encode_long_0x40000(self): self.assertTrue(self.test.argLong_0x40000(0x40000)) def test_encode_long_0x7ff(self): self.assertTrue(self.test.argLong_0x7ff(0x7ff)) def test_encode_long_0x7fffffff(self): self.assertTrue(self.test.argLong_0x7fffffff(0x7fffffff)) def test_encode_long_0x800(self): self.assertTrue(self.test.argLong_0x800(0x800)) def test_encode_long_0x80000000(self): self.assertTrue(self.test.argLong_0x80000000(0x80000000)) def test_encode_long_1(self): self.assertTrue(self.test.argLong_1(1)) def test_encode_long_15(self): self.assertTrue(self.test.argLong_15(15)) def test_encode_long_m0x40000(self): self.assertTrue(self.test.argLong_m0x40000(-0x40000)) def test_encode_long_m0x40001(self): self.assertTrue(self.test.argLong_m0x40001(-0x40001)) def test_encode_long_m0x800(self): self.assertTrue(self.test.argLong_m0x800(-0x800)) def test_encode_long_m0x80000000(self): self.assertTrue(self.test.argLong_m0x80000000(-0x80000000)) def test_encode_long_m0x80000001(self): self.assertTrue(self.test.argLong_m0x80000001(-0x80000001)) def test_encode_long_m0x801(self): self.assertTrue(self.test.argLong_m0x801(-0x801)) def test_encode_long_m8(self): self.assertTrue(self.test.argLong_m8(-8)) def test_encode_long_m9(self): self.assertTrue(self.test.argLong_m9(-9)) def test_encode_null(self): self.assertTrue(self.test.argNull(None)) def test_encode_object_0(self): payload = protocol.Object('com.caucho.hessian.test.A0') self.assertTrue(self.test.argObject_0(payload)) def test_encode_object_1(self): payload = protocol.Object('com.caucho.hessian.test.TestObject', _value=0) self.assertTrue(self.test.argObject_1(payload)) def test_encode_object_16(self): payload = [ protocol.Object('com.caucho.hessian.test.A0'), protocol.Object('com.caucho.hessian.test.A1'), protocol.Object('com.caucho.hessian.test.A2'), protocol.Object('com.caucho.hessian.test.A3'), protocol.Object('com.caucho.hessian.test.A4'), protocol.Object('com.caucho.hessian.test.A5'), protocol.Object('com.caucho.hessian.test.A6'), protocol.Object('com.caucho.hessian.test.A7'), protocol.Object('com.caucho.hessian.test.A8'), protocol.Object('com.caucho.hessian.test.A9'), protocol.Object('com.caucho.hessian.test.A10'), protocol.Object('com.caucho.hessian.test.A11'), protocol.Object('com.caucho.hessian.test.A12'), protocol.Object('com.caucho.hessian.test.A13'), protocol.Object('com.caucho.hessian.test.A14'), protocol.Object('com.caucho.hessian.test.A15'), protocol.Object('com.caucho.hessian.test.A16') ] self.assertTrue(self.test.argObject_16(payload)) def test_encode_object_2(self): payload = [ protocol.Object('com.caucho.hessian.test.TestObject', _value=0), protocol.Object('com.caucho.hessian.test.TestObject', _value=1) ] self.assertTrue(self.test.argObject_2(payload)) def test_encode_object_2a(self): payload = protocol.Object('com.caucho.hessian.test.TestObject', _value=0) self.assertTrue(self.test.argObject_2a([payload, payload])) def test_encode_object_2b(self): payload = [ protocol.Object('com.caucho.hessian.test.TestObject', _value=0), protocol.Object('com.caucho.hessian.test.TestObject', _value=0) ] self.assertTrue(self.test.argObject_2b(payload)) ### argObject_3 causes a stack pop. BOOM, recursion. # def disabled_test_encode_object_3(self): # payload = protocol.Object('com.caucho.hessian.test.TestCons', _first = 'a', _rest = None) # payload._rest = payload # # self.assertTrue(self.test.argObject_3(payload)) def test_encode_string_0(self): self.assertTrue(self.test.argString_0("")) def test_encode_string_1(self): self.assertTrue(self.test.argString_1("0")) def test_encode_string_31(self): payload = "0123456789012345678901234567890" self.assertTrue(self.test.argString_31(payload)) def test_encode_string_32(self): payload = "01234567890123456789012345678901" self.assertTrue(self.test.argString_32(payload)) ### here, we have to generate big convoluted strings. later. # def test_encode_string_1023(self): # self.assertTrue(self.test.argString_1023("x" * 1023)) # # def test_encode_string_1024(self): # self.assertTrue(self.test.argString_1024("x" * 1024)) # # def test_encode_string_65536(self): # self.assertTrue(self.test.argString_65536("x" * 65536)) def test_encode_true(self): self.assertTrue(self.test.argTrue(True))
#!/usr/bin/python # coding=utf-8 from mustaine.client import HessianProxy serviceUrl = 'http://192.168.100.35:20880/com.edol.core.inf.rule.PromotionInterface' costType = 'BALANCE' messageType = 'BALANCE_LOTTERY_COUPON' numberFlag = 'true' if __name__ == '__main__': proxy = HessianProxy(serviceUrl) result = proxy.findTurntableLotteryByCostType(costType, messageType, numberFlag) print result