Skip to content

Instantly share code, notes, and snippets.

@dsuch
dsuch / gist:5693064
Last active December 17, 2015 23:59
{
"security": {
"name": "my security",
"type": "wss",
"username": "my user",
"password": "my password",
},
"outconns": {
"my external app": {
"type": "soap",
@dsuch
dsuch / get-exchange-rates-dream.py
Last active December 18, 2015 11:29
What should be needed to invoke any web services
request = {'from':'EUR', 'to':'HRK'}
response = get_exchange_rate(request)
print(response.rate)
# 1 EUR = 7.4680 HRK as of Jun 13, 2013, 5:00PM GMT
from django.template.response import TemplateResponse
def home(req):
# A dictionary of input data read from HTTP GET. If no input was given
# we translate from EUR to HRK.
to = req.GET.get('to', 'HRK')
request = {'from':'EUR', 'to':to}
# Pass the dictionary into the client's invoke method along with the name
from zato.client import AnyServiceInvoker
class ZatoMiddleware(object):
def process_request(self, req):
req.zato_client = AnyServiceInvoker('http://localhost:17010',
'/django/sample', ('django-app', 'django-password'))
@dsuch
dsuch / rates.html
Last active December 18, 2015 13:29
<form action="." method="get">
From EUR to
<input type="text" name="to" value="{{ to }}" />
<input type="submit" value="Get exchange rates" />
</form>
<table id="rates">
<tr>
<th>Provider</th>
<th>Rate</th>
# -*- coding: utf-8 -*-
from __future__ import absolute_import, division, print_function, unicode_literals
# stdlib
from datetime import datetime
from traceback import format_exc
# anyjson
from anyjson import loads
$ zato service invoke /opt/server1/ zato.security.basic-auth.get-list \
--payload '{"cluster_id":1}'
[{u'username': u'admin.invoke', u'is_active': True,
u'realm': u'Zato admin invoke', u'id': 1L, u'name': u'admin.invoke'},
{u'username': u'pubapi', u'is_active': True, u'realm': u'Zato public API',
u'id': 2L, u'name': u'pubapi'}]
$
$ zato service invoke /opt/server1 zato.security.basic-auth.get-list \
--data-format xml \
--payload '<zato_security_basic_auth_get_list_request><cluster_id>1</cluster_id>\
</zato_security_basic_auth_get_list_request>'
<zato_security_basic_auth_get_list_response xmlns="https://zato.io/ns/20130518">
<zato_env>
<cid>K034857440351657368008263132215876374901</cid>
<result>ZATO_OK</result>
</zato_env>
from zato.server.service import Service
class MyService(Service):
def handle(self):
# JMS WebSphere MQ
self.outgoing.jms_wmq.conn.send(self.request.payload, 'JMS MQ app', 'QUEUE.1')
# AMQP
self.outgoing.amqp.conn.send(self.request.payload, 'AMQP app', 'EXCH.1', '/')
@dsuch
dsuch / stockmarket.py
Created July 6, 2013 10:38
Code for Zato article on InfoQ http://www.infoq.com/articles/zato
# anyjson
from anyjson import loads
# bunch
from bunch import bunchify
# decimal
from decimal import Decimal
# lxml