Skip to content

Commit

Permalink
adding soap modification example
Browse files Browse the repository at this point in the history
  • Loading branch information
shyal committed Dec 8, 2016
1 parent 80bd17b commit 3b5b325
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
57 changes: 57 additions & 0 deletions examples/soap/modify_payload.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/env python

import sys
import json
import logging
import random
import traceback
from lxml import objectify
from lxml import etree


logging.basicConfig(filename='middleware.log', level=logging.DEBUG)
logging.debug('Middleware "modify_request" called')


def main():
data = sys.stdin.readlines()
payload = data[0]
payload_dict = json.loads(payload)

if "response" in payload_dict and "body" in payload_dict["response"]:
body = payload_dict["response"]["body"]
try:
root = objectify.fromstring(str(body))
ns = "{http://ws.cdyne.com/}"
logging.debug("transforming")
root.Body[
ns +
"ResolveIPResponse"][
ns +
"ResolveIPResult"].City = "New York"

objectify.deannotate(
root.Body[
ns +
"ResolveIPResponse"][
ns +
"ResolveIPResult"].City)
etree.cleanup_namespaces(
root.Body[
ns +
"ResolveIPResponse"][
ns +
"ResolveIPResult"].City)

payload_dict["response"]["body"] = etree.tostring(root)

logging.debug(etree.tostring(root))

except Exception:
pass
# logging.debug(traceback.format_exc())

print(json.dumps(payload_dict))

if __name__ == "__main__":
main()
22 changes: 22 additions & 0 deletions examples/soap/soapModify.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/python

from hoverpy import HoverPy
import pysimplesoap
import requests

from argparse import ArgumentParser

parser = ArgumentParser(description="Perform proxy testing/URL list creation")
parser.add_argument("--capture", help="capture the data", action="store_true")
args = parser.parse_args()


with HoverPy(modify=True, middleware="python examples/soap/modify_payload.py"):
ipAddress = requests.get("http://ip.jsontest.com/myip").json()["ip"]
pysimplesoap.transport.set_http_wrapper("urllib2")

client = pysimplesoap.client.SoapClient(
wsdl='http://ws.cdyne.com/ip2geo/ip2geo.asmx?WSDL'
)

print(client.ResolveIP(ipAddress=ipAddress, licenseKey="0"))

0 comments on commit 3b5b325

Please sign in to comment.