Example #1
0
def json_call(service, data, config):
    """Make a call to a Zato service from a set list with JSON POST data.

    The service URLs are configured in the SERVICE_URL module global
    dictionary with the service name as written in the header of the Zato
    service documentation page as the key.

    @params service: service name
    @param data: dictionary of data to send a JSON post data
    @param config: configuration dictionary as read from 'deploy.conf'

    """
    address = 'http://%s:%s' % (config.lb_host, config.lb_port)
    try:
        path = SERVICE_URLS[service]
    except KeyError:
        log.error("Unknown zato JSON service name: 5s", service)
        raise

    auth = (config.http_user, config.http_password)
    client = JSONClient(address, path, auth)
    log.debug("Invoking service at '%s' with data: %s", path, data)
    res = client.invoke(data)

    if not res.ok:
        raise JSONCallResponseError(
            "Zato non-successful result code: {}".format(res))

    return bunchify(res.data)
def get_rates():
    address = 'http://localhost:17010'
    path = '/local/tarif/getrates'
    
    client = JSONClient(address, path)
    response = client.invoke({'GetRates': '2015-06-03T12:30:00'})
    
    return response
def is_rate_presented():
    address = 'http://localhost:17010'
    path = '/local/tarif/isratepresented'
    
    client = JSONClient(address, path)
    response = client.invoke({'IsRatePresented': '2015-06-03T12:00:00'})
    
    return response
def get_currency_list():
    address = 'http://localhost:17010'
    path = '/local/tarif/getcurrencylist'
    
    client = JSONClient(address, path)
    response = client.invoke({'GetCurrencyList': ''})
    
    return response
def invoke_calculate():
    
#     logging.basicConfig(
#         filename='invoke-calculate.log', 
#         filemode='w', 
#         level=logging.DEBUG
#         )
    
    address = 'http://localhost:17010'
    path = '/local/tarif/calculate'
    calcParams = {
        'calcParams': {
            'OnDate':'2013-10-01T15:23:02.990Z', 
            'Route':{
                'FS':{
                    'Code':'100001'}, 
                'TS':{
                    'Code':'850204'}}, 
            'Shipment':{
                'OtprID':'3000', 
                'SendID':'6'}, 
            'Freight':{
                'SingleFreight':{
                    'Etsng':'211011'}}, 
            'Cont':{
                'ID':'135', 
                'Own':'2', 
                'OwnerFirm':'2', 
                'Count':'1', 
                'EqContID':'-1'}, 
            'Transp':{
                'ID':'140', 
                'Own':'2', 
                'OwnerFirm':'2', 
                'Count':'1'}, 
            'Traits':{
                'CustomControl':'false', 
                'IsContainerTrain':'false', 
                'SupportParams':{
                    'SupportType':'0', 
                    'ConductorCount':'0', 
                    'SupportWagonAxis':'0'}, 
                'VCGuard':'1'}}}
    
    client = JSONClient(address, path)
    response = client.invoke(calcParams)
    
    return response
# -*- coding: utf-8 -*-

# Zato
from zato.client import AnyServiceInvoker, JSONClient

# Our app
from settings import CLIENT_ADDRESS, CLIENT_CREDENTIALS, CLIENT_PATH_ANY, CLIENT_PATH_JSON

client_any = AnyServiceInvoker(CLIENT_ADDRESS, CLIENT_PATH_ANY, CLIENT_CREDENTIALS)
client_json = JSONClient(CLIENT_ADDRESS, CLIENT_PATH_JSON, CLIENT_CREDENTIALS)

class ZatoMiddleware(object):
    def process_request(self, req):
        req.client_any = client_any
        req.client_json = client_json