├── .gitignore
├── Procfile
├── README.md
├── app.py
├── requirements.txt
├── static
├── SoapApi.js
└── normalize.css
└── templates
├── 403.html
├── 404.html
├── 410.html
├── 500.html
└── index.html
/.gitignore:
--------------------------------------------------------------------------------
1 | build
2 | venv
3 | *.pyc
4 |
--------------------------------------------------------------------------------
/Procfile:
--------------------------------------------------------------------------------
1 | web: python app.py
2 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # flask-soap-server
2 |
3 | A simple example of how to use SOAP with Flask.
4 |
5 | With this project you have a base soap server written in python with a javascript client.
6 |
7 | ## Dependencies
8 |
9 | All dependencies are written in requirements.txt and you can install them with:
10 |
11 | ```bash
12 | pip install -r requirements.txt
13 | ```
14 |
15 | You may need to install these libraries for a correct installation of all dependencies:
16 |
17 | libxsl1-dev
18 | libxml2-dev
19 |
20 | **Note**: libraries refer on Ubuntu package name, please search an equivalent for yours OS.
21 |
22 | ## How to test
23 |
24 | Just type the command below in the main directory:
25 |
26 | ```bash
27 | honcho start
28 | ```
29 |
30 | You can see the example page at `http://localhost:5000/` with your browser.
31 | WSDL generated on `http://localhost:5000/soap?wsdl`.
32 |
33 | **Note**: internet connection is required to download jquery library.
34 |
35 | ## Authors
36 |
37 | [Gabriele](https://github.com/Gabriele91)
38 | [Mirco](https://github.com/MircoT)
39 |
40 | ## License
41 |
42 | The MIT License (MIT)
43 |
44 | Copyright (C) 2013 Gabriele Di Bari, Mirco Tracolli
45 |
46 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
47 |
48 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
49 |
50 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
51 |
--------------------------------------------------------------------------------
/app.py:
--------------------------------------------------------------------------------
1 | #python lib
2 | import os
3 | #flask lib
4 | from flaskext.enterprise import Enterprise
5 | from flask import Flask, render_template
6 |
7 | #config Flask
8 | app = Flask(__name__)
9 |
10 | #config Flask Enterprise
11 | enterprise = Enterprise(app)
12 | String = enterprise._sp.String
13 | Integer = enterprise._sp.Integer
14 | Boolean = enterprise._sp.Boolean
15 | Array = enterprise._scls.Array
16 |
17 | class Service(enterprise.SOAPService):
18 | """Soap Service Class
19 |
20 | Attributes:
21 | __soap_target_namespace__ : namespace for soap service
22 | __soap_server_address__ : address of soap service
23 | """
24 | __soap_target_namespace__ = 'MyNS'
25 | __soap_server_address__ = '/soap'
26 |
27 | @enterprise.soap(String, _returns=String)
28 | def echo(self, mystring):
29 | """ Function that return the string in args
30 |
31 | Args:
32 | mystring : string
33 |
34 | Returns:
35 | return a string
36 | """
37 | return mystring
38 |
39 | @enterprise.soap(Integer, Integer, _returns=Integer)
40 | def sum(self, x, y):
41 | """ Function to sum two integer
42 |
43 | Args:
44 | x : int
45 | y : int
46 |
47 | Returns:
48 | return an int
49 | """
50 | return x+y
51 |
52 | @enterprise.soap(Integer, Integer, _returns=Boolean)
53 | def equal(self, x, y):
54 | """ Function to compare two integer
55 |
56 | Args:
57 | x : int
58 | y : int
59 |
60 | Returns:
61 | return a boolean
62 | """
63 | return x==y
64 |
65 | @enterprise.soap(Integer, _returns=Array(Integer))
66 | def createArray(self, lenA):
67 | """ Function to create an array of integer
68 |
69 | Args:
70 | lenA : int
71 |
72 | Returns:
73 | return an array
74 | """
75 | return [int(x) for x in range(1,lenA+1)]
76 |
77 | @app.route('/')
78 | def pageIndex():
79 | """ The index page
80 | """
81 | return render_template("index.html")
82 |
83 | @app.errorhandler(404)
84 | def page_not_found(e):
85 | """ Error 404
86 | """
87 | return render_template("404.html"), 404
88 |
89 | @app.errorhandler(403)
90 | def forbidden(e):
91 | """ Error 403
92 | """
93 | return render_template("403.html"), 403
94 |
95 | @app.errorhandler(410)
96 | def gone(e):
97 | """ Error 410
98 | """
99 | return render_template("410.html"), 410
100 |
101 | @app.errorhandler(500)
102 | def internal_server_error(e):
103 | """ Error 500
104 | """
105 | return render_template("500.html"), 500
106 |
107 | if __name__ == '__main__':
108 | # Bind to PORT if defined, otherwise default to 5000.
109 | port = int(os.environ.get('PORT', 5000))
110 | app.debug = True
111 | app.run(host='0.0.0.0', port=port)
112 |
--------------------------------------------------------------------------------
/requirements.txt:
--------------------------------------------------------------------------------
1 | Flask==2.3.2
2 | Flask-Enterprise==1.0
3 | Jinja2==2.11.3
4 | Werkzeug==2.2.3
5 | argparse==1.2.1
6 | distribute
7 | honcho==0.3.1
8 | lxml
9 | pytz==2013b
10 | soaplib==2.0.0-beta2
11 | suds==1.0.0
12 | wsgiref==0.1.2
13 |
--------------------------------------------------------------------------------
/static/SoapApi.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Function that convert an xml to json
3 | * @author http://davidwalsh.name/convert-xml-json
4 | * @param {string} xml an xml object string
5 | * @return {string} obj a json dictionary
6 | * @fileoverview Simple function to convert xml to json
7 | */
8 | function xmlToJson(xml) {
9 | // Create the return object
10 | var obj = {};
11 | if (xml.nodeType == 1) { // element
12 | // do attributes
13 | if (xml.attributes.length > 0) {
14 | obj["@attributes"] = {};
15 | for (var j = 0; j < xml.attributes.length; j++) {
16 | var attribute = xml.attributes.item(j);
17 | obj["@attributes"][attribute.nodeName] = attribute.nodeValue;
18 | }
19 | }
20 | } else if (xml.nodeType == 3) { // text
21 | obj = xml.nodeValue;
22 | }
23 | // do children
24 | if (xml.hasChildNodes()) {
25 | for(var i = 0; i < xml.childNodes.length; i++) {
26 | var item = xml.childNodes.item(i);
27 | var nodeName = item.nodeName;
28 | if (typeof(obj[nodeName]) == "undefined") {
29 | obj[nodeName] = xmlToJson(item);
30 | } else {
31 | if (typeof(obj[nodeName].push) == "undefined") {
32 | var old = obj[nodeName];
33 | obj[nodeName] = [];
34 | obj[nodeName].push(old);
35 | }
36 | obj[nodeName].push(xmlToJson(item));
37 | }
38 | }
39 | }
40 | return obj;
41 | };
42 | /**
43 | * Function to call to write soap messages on console
44 | * @param {String} title
45 | * @return {String} messageXML : can be a string or an xml object
46 | */
47 | function messageLog(title,messageXML) {
48 | var xml = $.parseXML(messageXML);
49 | if (xml == null) {
50 | var message = JSON.stringify(xmlToJson(messageXML),null," ");
51 | console.log(title+" = "+message);
52 | }
53 | else{
54 | var message = JSON.stringify(xmlToJson(xml),null," ");
55 | console.log(title+" = "+message);
56 | }
57 | }
58 | /**
59 | * @author Gabriele Di Bari
60 | * @author Mirco Tracolli
61 | * @fileoverview JQUERY is required
62 | */
63 | /**
64 | * site web url
65 | * defaultUrl : according do app.py __soap_server_address__
66 | */
67 | var defaultUrl = window.location.protocol+"//"+window.location.host+"/soap";
68 | /**
69 | * Class that contain Soap functions
70 | * @param {string} urlSoapServer the url of the soap web server
71 | * @constructor
72 | */
73 | function SoapApi(urlSoapServer) {
74 | /**
75 | * Constructor for a singleton
76 | */
77 | if ( SoapApi.prototype._singletonInstance ){
78 | if(!(typeof urlSoapServer === 'undefined' || urlSoapServer==null))
79 | this.SOAPSERVER = urlSoapServer;
80 | return SoapApi.prototype._singletonInstance;
81 | }
82 | /**
83 | * first call save object in singleton istance
84 | */
85 | SoapApi.prototype._singletonInstance = new objectSoapApi(urlSoapServer);
86 | return SoapApi.prototype._singletonInstance;
87 | /**
88 | * An object that can manage soap
89 | * @param {string} urlSoapServer the url of the soap web server
90 | */
91 | function objectSoapApi(urlSoapServer){
92 | /**
93 | * if is not def set default url
94 | */
95 | if(!(typeof urlSoapServer === 'undefined' || urlSoapServer==null))
96 | this.SOAPSERVER = urlSoapServer;
97 | else
98 | this.SOAPSERVER = defaultUrl
99 | /**
100 | * Some constant variables with parameters that will be replaced
101 | * @constant
102 | * @type String
103 | */
104 | this.METHODE = "
What you were looking for is not accessible. 9 |
go somewhere nice 10 | 11 | -------------------------------------------------------------------------------- /templates/404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 |What you were looking for is just not there. 9 |
go somewhere nice 10 | 11 | -------------------------------------------------------------------------------- /templates/410.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 |What you were looking for is no longer avaible. 9 |
go somewhere nice 10 | 11 | -------------------------------------------------------------------------------- /templates/500.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 |There are some errors, please contact the administrators! 9 |
go to home page 10 | 11 | -------------------------------------------------------------------------------- /templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 |