def test_parse_object_2b(self): expected = ( protocol.object_factory('com.caucho.hessian.test.TestObject', _value=0), protocol.object_factory('com.caucho.hessian.test.TestObject', _value=0), ) reply = self.client.replyObject_2b() self.assertEqual(expected, reply)
def test_encode_object_2(client): payload = [ protocol.object_factory('com.caucho.hessian.test.TestObject', _value=0), protocol.object_factory('com.caucho.hessian.test.TestObject', _value=1), ] response = client.argObject_2(payload) assert response is True, "Debug response: %s" % response
def test_encode_object_2b(self): payload = [ protocol.object_factory('com.caucho.hessian.test.TestObject', _value=0), protocol.object_factory('com.caucho.hessian.test.TestObject', _value=0), ] response = self.client.argObject_2b(payload) self.assertEqual(response, True, "Debug response: %s" % response)
def test_parse_object_2b(client): expected = ( protocol.object_factory('com.caucho.hessian.test.TestObject', _value=0), protocol.object_factory('com.caucho.hessian.test.TestObject', _value=0), ) reply = client.replyObject_2b() assert reply == expected
def test_parse_object_3(self): expected = protocol.object_factory('com.caucho.hessian.test.TestCons', _first='a', _rest=None) expected._rest = expected reply = self.client.replyObject_3() self.assertEqual(expected, reply)
def test_parse_list_of_lists_with_ref(client): obj = protocol.object_factory('com.caucho.hessian.test.TestObject', _value=0) l = (obj, obj) expected = (l, l) reply = client.replyListOfListWithRefs() assert reply == expected
def __init__(self,url,header,interface,method,param,**kwargs): self.url=url self.header= header self.interface=interface self.method=method self.param=param self.interfaceparam=protocol.object_factory(self.param,**kwargs)
def test_parse_object_3(client): expected = protocol.object_factory('com.caucho.hessian.test.TestCons', _first='a', _rest=None) expected._rest = expected reply = client.replyObject_3() assert reply == expected
def test_encode_object_3(self): payload = protocol.object_factory('com.caucho.hessian.test.TestCons', _first='a', _rest=None) payload._rest = payload response = self.client.argObject_3(payload) self.assertEqual(response, True, "Debug response: %s" % response)
def dubbo_api(url, interface, method, param_obj, **kwargs): ''' :param url: url地址 :param interface: 接口名称,因为这里可能还有别的服务要测,接口名不一样,这里定义成变量 :param method: 调用哪个方法 :param param_obj: 入参的对象 :param kwargs: 这个用关键字参数,因为每个接口的参数都不一样,不固定,所以这里用关键字参数 :return: ''' req_param = protocol.object_factory(param_obj, **kwargs) #这个是用来构造二进制的入参的,也就是把入参序列化 try: #用try捕捉一下异常 req_obj = HessianProxy(url + interface) #这个req是生成一个请求对象 res = getattr(req_obj, method)(req_param) #getattr是python的内置方法,获取对象的方法,咱们从构造的请求对象里面获取到方法,然后调用,把前面生成的 #序列化好的参数传进去,然后获取到返回的数据 except Exception as e: print('有异常了,异常信息是:%s' % e) res = {"msg": "异常:%s" % e, "code": 300} #这个是自己定义的异常,如果调用出错了,就返回这个 return res
def test_parse_object_0(self): expected = protocol.object_factory('com.caucho.hessian.test.A0') reply = self.client.replyObject_0() self.assertEqual(expected, reply)
# -*- coding:utf-8 -*- from pyhessian.client import HessianProxy from pyhessian import protocol import json def InvokeHessian(service,interface,method,req,retcode='200'): try: url='http://192.168.100.35:20880/'+service+'.'+interface print 'URL:\t%s'%url print 'Method:\t%s'%method print 'Req:\t%s'%req res=getattr(HessianProxy(url),method)(req) print 'Res:\t%s'%json.dumps(res,ensure_ascii=False) except Exception,e: print e if __name__ == '__main__': service='core_service' interface='com.edol.core.inf.rule.PromotionInterface' method='findTurntableLotteryByCostType' req=protocol.object_factory('com.edol.core.inf.rule.PromotionInterface.findTurntableLotteryByCostType', costType='BALANCE',messageType='BALANCE_LOTTERY_COUPON',numberFlag='true') InvokeHessian(service, interface, method,req)
def test_hessian(self): # hessian接口调用demo method = 'delete' req = protocol.object_factory('com.service.dubbo.base.req.BaseRequest') id = 123456789 HessianUtil.Invoke(method, req, id)
def test_encode_object_16(self): payload = [ protocol.object_factory('com.caucho.hessian.test.A0'), protocol.object_factory('com.caucho.hessian.test.A1'), protocol.object_factory('com.caucho.hessian.test.A2'), protocol.object_factory('com.caucho.hessian.test.A3'), protocol.object_factory('com.caucho.hessian.test.A4'), protocol.object_factory('com.caucho.hessian.test.A5'), protocol.object_factory('com.caucho.hessian.test.A6'), protocol.object_factory('com.caucho.hessian.test.A7'), protocol.object_factory('com.caucho.hessian.test.A8'), protocol.object_factory('com.caucho.hessian.test.A9'), protocol.object_factory('com.caucho.hessian.test.A10'), protocol.object_factory('com.caucho.hessian.test.A11'), protocol.object_factory('com.caucho.hessian.test.A12'), protocol.object_factory('com.caucho.hessian.test.A13'), protocol.object_factory('com.caucho.hessian.test.A14'), protocol.object_factory('com.caucho.hessian.test.A15'), protocol.object_factory('com.caucho.hessian.test.A16'), ] response = self.client.argObject_16(payload) self.assertEqual(response, True, "Debug response: %s" % response)
def test_parse_object_16(self): expected = ( protocol.object_factory('com.caucho.hessian.test.A0'), protocol.object_factory('com.caucho.hessian.test.A1'), protocol.object_factory('com.caucho.hessian.test.A2'), protocol.object_factory('com.caucho.hessian.test.A3'), protocol.object_factory('com.caucho.hessian.test.A4'), protocol.object_factory('com.caucho.hessian.test.A5'), protocol.object_factory('com.caucho.hessian.test.A6'), protocol.object_factory('com.caucho.hessian.test.A7'), protocol.object_factory('com.caucho.hessian.test.A8'), protocol.object_factory('com.caucho.hessian.test.A9'), protocol.object_factory('com.caucho.hessian.test.A10'), protocol.object_factory('com.caucho.hessian.test.A11'), protocol.object_factory('com.caucho.hessian.test.A12'), protocol.object_factory('com.caucho.hessian.test.A13'), protocol.object_factory('com.caucho.hessian.test.A14'), protocol.object_factory('com.caucho.hessian.test.A15'), protocol.object_factory('com.caucho.hessian.test.A16'), ) reply = self.client.replyObject_16() self.assertEqual(expected, reply)
def test_encode_object_0(client): payload = protocol.object_factory('com.caucho.hessian.test.A0') response = client.argObject_0(payload) assert response is True, "Debug response: %s" % response
def test_parse_object_2a(client): payload = protocol.object_factory('com.caucho.hessian.test.TestObject', _value=0) expected = (payload, payload) reply = client.replyObject_2a() assert reply == expected
def test_parse_object_16(client): expected = ( protocol.object_factory('com.caucho.hessian.test.A0'), protocol.object_factory('com.caucho.hessian.test.A1'), protocol.object_factory('com.caucho.hessian.test.A2'), protocol.object_factory('com.caucho.hessian.test.A3'), protocol.object_factory('com.caucho.hessian.test.A4'), protocol.object_factory('com.caucho.hessian.test.A5'), protocol.object_factory('com.caucho.hessian.test.A6'), protocol.object_factory('com.caucho.hessian.test.A7'), protocol.object_factory('com.caucho.hessian.test.A8'), protocol.object_factory('com.caucho.hessian.test.A9'), protocol.object_factory('com.caucho.hessian.test.A10'), protocol.object_factory('com.caucho.hessian.test.A11'), protocol.object_factory('com.caucho.hessian.test.A12'), protocol.object_factory('com.caucho.hessian.test.A13'), protocol.object_factory('com.caucho.hessian.test.A14'), protocol.object_factory('com.caucho.hessian.test.A15'), protocol.object_factory('com.caucho.hessian.test.A16'), ) reply = client.replyObject_16() assert reply == expected
def test_parse_object_0(client): expected = protocol.object_factory('com.caucho.hessian.test.A0') reply = client.replyObject_0() assert reply == expected
# -*- coding:utf-8 -*- from pyhessian.client import HessianProxy from pyhessian import protocol import json def InvokeHessian(service, interface, method, req, retcode='000000'): try: url = 'http://192.168.0.1:10883/' + service + '.' + interface print 'URL:\t%s' % url print 'Method:\t%s' % method print 'Req:\t%s' % req res = getattr(HessianProxy(url), method)(req) print 'Res:\t%s' % json.dumps(res, ensure_ascii=False) except Exception, e: print e if __name__ == '__main__': service = 'com.service.common.api.service' interface = 'TestHessianService' method = 'testHessian' req = protocol.object_factory( 'com.service.common.api.service.model.req.TestHessianRequest', spuId=813576647191044096L, updateBy="autotestwang", reason="个人爱好自动化") InvokeHessian(service, interface, method, req)
def test_encode_object_3(client): payload = protocol.object_factory('com.caucho.hessian.test.TestCons', _first='a', _rest=None) payload._rest = payload response = client.argObject_3(payload) assert response is True, "Debug response: %s" % response
def test_parse_object_2a(self): payload = protocol.object_factory('com.caucho.hessian.test.TestObject', _value=0) expected = (payload, payload) reply = self.client.replyObject_2a() self.assertEqual(expected, reply)
def InvokeHessian(service, interface, method, req, retcode='000000'): url = 'dubbo://10.0.23.66:20882/' + service + '.' + interface print('URL:\t%s' % url) print('Method:\t%s' % method) res = getattr(HessianProxy(url), method)(req) print('Res:\t%s' % json.dumps(res, ensure_ascii=False)) if __name__ == '__main__': service = 'com.xinyan.channel.facade' interface = 'AuthBankCardFacade' method = 'authBankCardService' req = protocol.object_factory('com.xinyan.channel.facade.AuthBankCardFacade', channelId='1104901110', reqTransId_length='32', accNo='6212262610002607004', certificateType='123', cardType='101', idNo='612730198501061126', idName='高利娜', mobile='', validTime='', cvv2='') InvokeHessian(service, interface, method, req)
def test_encode_object_0(self): payload = protocol.object_factory('com.caucho.hessian.test.A0') response = self.client.argObject_0(payload) self.assertEqual(response, True, "Debug response: %s" % response)
def test_encode_list_of_lists_with_ref(client): obj = protocol.object_factory('com.caucho.hessian.test.TestObject', _value=0) l = (obj, obj) arg = (l, l) response = client.argListOfListWithRefs(arg) assert response is True, "Debug response: %s" % response