SlideShare a Scribd company logo
1 of 11
Download to read offline
Accessing MySQL from Ruby
Contents
1.      Introduction .................................................................................................................................... 2
2.      Prerequisites ................................................................................................................................... 2
3.      Setup ............................................................................................................................................... 2
     3.1.       Populate MySQL Database ...................................................................................................... 2
     3.2.       Set up ODBC Access ................................................................................................................ 3
4.      Discovery ......................................................................................................................................... 4
     4.1.       Web Service Creation using SOA Gateway ............................................................................. 4
     4.2.       Accessing the WSDL ................................................................................................................ 6
5.      Accessing a Web Service with Ruby ................................................................................................ 8
     Ruby Editor.......................................................................................................................................... 8
     Ruby Code ........................................................................................................................................... 8
     Debugging Code .................................................................................................................................. 9
6.      Conclusion ..................................................................................................................................... 10
7.      Appendix ....................................................................................................................................... 10




Accessing MySQL from Ruby                                                                              Author: John O’Mahony, Risaris Ltd
1. Introduction
In this tutorial we will show you how to build a Ruby application to access MySQL via the SOA
Gateway.


2. Prerequisites
It is assumed that you are running the 3 components, MySQL, Ruby and the SOA Gateway on
Windows.

It is assumed you already have a SOA Gateway server and Control Centre installed. See here for
more info about installing the SOA Gateway.


3. Setup
Download the latest binaries for Ruby from the Ruby downloads page, install it
according to the install.txt document in the Ruby distribution library. For this tutorial I downloaded
Ruby 1.8.6 One-Click Installer and followed the default options.

You will also need a MySQL database. Again, the Open Source version (known as the MySQL
Community Server) can be freely downloaded from the MySQL website. See this link for download,
and here to step you through the installation and configuration.

    3.1.Populate MySQL Database
    Now that you’ve got MySQL installed and configured, you will need to populate it with some
    demo data. For this we use the RisarisBank sample. This is available here.

           Save this file to “C:TempRisarisBank.sql”
           Connect to the MySQL Server using the mysql command.

            E.g shell> mysql –u root –p

            This command connects to the server using the MySQL root account to make sure that
            you'll have permission to create the RisarisBank database. The -p option tells mysql
            to prompt you for the root password. Enter the password when prompted. (Remember
            that the MySQL root account is not the same as the operating system root account
            and probably will have a different password.)

           Create the RisarisBank database.

            mysql> CREATE DATABASE RisarisBank;

            mysql> use RisarisBank;

           Load the contents of RisarisBank.sql into the RisarisBank database. E.g.

            mysql> SOURCE c:TempRisarisBank.sql

           After the SOURCE command finishes, you can view your new tables.




Accessing MySQL from Ruby                                          Author: John O’Mahony, Risaris Ltd
mysql> SHOW TABLES;

           mysql> DESCRIBE CustomerInformation;

           mysql> DESCRIBE Branch;

           etc …

   3.2.Set up ODBC Access
   The final thing to do with your MySQL Database is to set up an ODBC DSN which will be used by
   the SOA Gateway to access this database.

   Click Start, Control Panel, Administrative Tools, Data Sources (ODBC)

   From the resulting screen, choose the “System DSN” Tab.

   Click Add

   From the list of data source drivers, select “MySQL ODBC 3.51 Driver”.

       If you do not see this driver in the list, you need to install the MySQL Connector. See here for
       more information. We recommend installing v3.51.

   Click Finish, and a window will appear allowing you to enter the DSN information. Add the
   following:

       Data Source Name: RisarisBank

       Description: The Risaris Bank Sample in MySQL

       Server: localhost

       User: root

       Password: *** your MySQL root password ***

       Database: RisarisBank (select from the drop down list)




Accessing MySQL from Ruby                                          Author: John O’Mahony, Risaris Ltd
All other options can be left as-is. Click OK.


4. Discovery
At this stage you’ve got Ruby installed, and a MySQL database with some sample data in it. In this
section we’ll show you how to create web services from each of the MySQL tables. These web
services can be used by the Ruby language (and many others) to give you direct real-time access to
your MySQL Data.

   4.1.Web Service Creation using SOA Gateway
   Start your SOA Gateway Control Centre. See here for an introduction to the Control Centre.

   In your servers view, right click the entry which represents your local SOA Gateway Server. Select
   “Create New Web Services”.




Accessing MySQL from Ruby                                        Author: John O’Mahony, Risaris Ltd
From the next dialog, choose “MySQL Driver”. If you do not see have a MySQL Driver in the list,
   see how to create one here.




   Click Next.

   The next screen gives you the ability to add information about your DSN




Accessing MySQL from Ruby                                       Author: John O’Mahony, Risaris Ltd
Enter the above information and click Discover.

   The wizard will display all the tables it finds at this (RisarisBank) DSN.

   Click “Select All”, and click “Import”.

   The wizard will create web services from each one of these tables.




   You’ve just created 8 Web Services from your 8 MySQL Tables!



   4.2.Accessing the WSDL
   Web Service Description Language (WSDL) is a standard, XML-based language that is used to
   describe a Web Service.

   For each of the 8 web services you’ve created in the previous section, the SOA Gateway provides
   you with a WSDL to describe the Web Service. The WSDL itself is usually interpreted by a web



Accessing MySQL from Ruby                                            Author: John O’Mahony, Risaris Ltd
service client, such as Ruby, but it is useful to know where to find the WSDL for each of your
   Web Services.

   As WSDL is XML-based, it will open in your browser of choice. To see the WSDL for one of your
   Risaris Bank web services, do the following in your SOA Gateway Control Centre:

          Click on the web service you are interested in, for example the “branch” web service.
          The properties for this web service should appear in your Properties View. If you do not
           see the Properties view, select Window -> Show View -> Other -> General -> Properties
           and click OK.
          In the properties view, there is a link to your WSDL. Click it to open the WSDL in a
           browser.




Accessing MySQL from Ruby                                         Author: John O’Mahony, Risaris Ltd
You can view the WSDL for the other web services by clicking the link from their properties
       view.
       This WSDL is the starting point for using Web Services, and can be used time and again by
       different web service clients.




5. Accessing a Web Service with Ruby
We will use a Ruby script to access our new Risaris Bank Web Services via the WSDL. Those familiar
with Ruby will probably want to change the script provided but it can be run with minimum changes
described below. The whole script is provided in APPENDIX A.

    Ruby Editor
   Use the editor provided, SciTE.exe, which is located in folder scite where you installed Ruby.
   Copy the code from Appendix A and save the code as the filename RBCustomerTutorial.rb (as in
   example below).

   Hit F5 and the results will appear in the right-hand pane:




   Ruby Code
    Depending on your MySQL settings you will have to change the username/password provided in
   the on_simple_outbound method. In this example the user is root with no password.


   "<UsernameToken><Username>root</Username><Password></Password></UsernameToken>"



Accessing MySQL from Ruby                                       Author: John O’Mahony, Risaris Ltd
Note also the WSDL URL http://localhost:56000/customerinformation?WSDL. Again depending
   on your SOA Gateway configuration you may need to change the server/port number.

   In this example provided we are issuing a list request on the customer information table in the
   RisarisBank database. The list request can handle a wilcarded customer number key:

   param = {"CustomerNumber" => "1*"}

   result = soap.list(param)

   Finally we can query the result for the customer’s first name:

   for cust in (result. customerinformationRoot.customerinformationGroup)

    print(cust.firstName, "n")

   end

   Obviously this can be replaced by any of the column names in the customer information table.

   Debugging Code
   The code provided should work off the bat. However, depending on your MySQL configuration,
   the RisarisBank tables may not be in lowercase as in our example e.g. customerinformation
   versus CustomerInformation. If this is the case the code will not work as is and all occurrences of
   customerinformation should be replaced by CustomerInformation.

   The p and puts functions are useful for checking the content of variables. For example p result
   after the result = soap.list(param) call gives the following information and is useful for checking
   column names for adding new code.

   #<SOAP::Mapping::Object:0x3240c04
   {}customerinformationRoot=#<SOAP::Mapping::Object:0x3240ad8
   {}customerinformationGroup=[#<SOAP::Mapping::Object:0x32409ac
   {}CustomerNumber="1" {}FirstName="Casper" {}Surname="Ankergren"
   {}AddressLine1="34 Green Street" {}AddressLine2="Crosses Street"
   {}City="Mansfield" {}Postcode="MA5 9AJ" {}DateOfBirth="30/05/1978">,
   #<SOAP::Mapping::Object:0x323f4bc {}CustomerNumber="10"
   {}FirstName="Grenville" {}Surname="Dekker" {}AddressLine1="22 Uttoxter
   New Road" {}AddressLine2="Chaddesden" {}City="Leeds" {}Postcode="LS4
   9WB" {}DateOfBirth="21/10/1974">, #<SOAP::Mapping::Object:0x323e0b2
   {}CustomerNumber="11" {}FirstName="Jane" {}Surname="Freeman"
   {}AddressLine1="3 Portland Street" {}AddressLine2="Lichfield"
   {}City="Gloucester" {}Postcode="GL4 8KD" {}DateOfBirth="26/10/1980">,
   #<SOAP::Mapping::Object:0x323ccb2 {}CustomerNumber="12"
   {}FirstName="Dale" {}Surname="Rolling" {}AddressLine1="The Hunters Rest"
   {}AddressLine2="Branston" {}City="Preston" {}Postcode="PR4 4HG"
   {}DateOfBirth="06/12/1989">, #<SOAP::Mapping::Object:0x323b8b2
   {}CustomerNumber="13" {}FirstName="Arnold" {}Surname="Corrigan"
   {}AddressLine1="14 Anderson Street" {}AddressLine2="Allestree"
   {}City="Derby" {}Postcode="DE6 8FT" {}DateOfBirth="10/06/1970">,
   #<SOAP::Mapping::Object:0x323a4b2 {}CustomerNumber="14"
   {}FirstName="Alfred" {}Surname="Summerscale" {}AddressLine1="3701 S.



Accessing MySQL from Ruby                                           Author: John O’Mahony, Risaris Ltd
George Mason" {}AddressLine2="Melbourne" {}City="Bath" {}Postcode="BA6
   8UU" {}DateOfBirth="07/08/1982">, #<SOAP::Mapping::Object:0x32390b2
   {}CustomerNumber="15" {}FirstName="Peter" {}Surname="Spiegel"
   {}AddressLine1="11663 Charter Oak Co" {}AddressLine2="Foremark"
   {}City="Manchester" {}Postcode="M98 4GT" {}DateOfBirth="29/12/1971">,
   #<SOAP::Mapping::Object:0x3237cb2 {}CustomerNumber="16"
   {}FirstName="John" {}Surname="Sviridov" {}AddressLine1="3319 Rosemere
   Court" {}AddressLine2="Brailsford" {}City="Leeds" {}Postcode="LS8 5QQ"
   {}DateOfBirth="12/06/1984">, #<SOAP::Mapping::Object:0x32368b2
   {}CustomerNumber="17" {}FirstName="Sarah" {}Surname="Hall"
   {}AddressLine1="4 Denmark Lane" {}AddressLine2="East Bridgford"
   {}City="Portsmouth" {}Postcode="PO9 7QN" {}DateOfBirth="12/02/1983">,
   #<SOAP::Mapping::Object:0x32354b2 {}CustomerNumber="18"
   {}FirstName="Elspeth" {}Surname="Jones" {}AddressLine1="12375 W. Ohio
   Circle" {}AddressLine2="Risley" {}City="Birmingham" {}Postcode="B93 1IO"
   {}DateOfBirth="28/08/1986">, #<SOAP::Mapping::Object:0x32340b2
   {}CustomerNumber="19" {}FirstName="Nigel" {}Surname="Wyllis"
   {}AddressLine1="14 Borough Road" {}AddressLine2="Ockbrook"
   {}City="Leeds" {}Postcode="LS8 2WL" {}DateOfBirth="29/04/1981">]>>



6. Conclusion
This tutorial shows how to access MySQL from Ruby using the SOA Gateway. As you can see, you
have built a powerful application that uses Web Services to retrieve information in real-time.


7. Appendix
require 'soap/wsdlDriver'

require 'soap/header/simplehandler'



# A handler to add authentication parameters to the SOAP header.

  class AutheticationHeaderHandler < SOAP::Header::SimpleHandler

      @@HEADER_NAME = 'Security'

     def initialize(namespace)

           super(XSD::QName.new(namespace, @@HEADER_NAME))

     end



     def on_simple_outbound

       #Change the username/password below to reflect your own environment


"<UsernameToken><Username>root</Username><Password></Password></UsernameTok
en>"




Accessing MySQL from Ruby                                      Author: John O’Mahony, Risaris Ltd
end

  end

wsdl_url = "http://localhost:56000/customerinformation?WSDL"



soap = SOAP::WSDLDriverFactory.new(wsdl_url).create_rpc_driver

soap.wiredump_file_base = "soapresult"

soap.headerhandler <<
AutheticationHeaderHandler.new("http://www.risaris.com/security")



param = {"CustomerNumber" => "1*"}



result = soap.list(param)

for cust in (result.customerinformationRoot.customerinformationGroup)

  print(cust.firstName, "n")

end




Accessing MySQL from Ruby                       Author: John O’Mahony, Risaris Ltd

More Related Content

What's hot

New Flash Builder 4 WSDL and HTTP Connectors
New Flash Builder 4 WSDL and HTTP ConnectorsNew Flash Builder 4 WSDL and HTTP Connectors
New Flash Builder 4 WSDL and HTTP Connectorsrtretola
 
Creating and connecting to odi master and work repositories
Creating and connecting to odi master and work repositoriesCreating and connecting to odi master and work repositories
Creating and connecting to odi master and work repositoriesAbdoulaye M Yansane
 
Session And Cookies In Servlets - Java
Session And Cookies In Servlets - JavaSession And Cookies In Servlets - Java
Session And Cookies In Servlets - JavaJainamParikh3
 
Java API for XML Web Services (JAX-WS)
Java API for XML Web Services (JAX-WS)Java API for XML Web Services (JAX-WS)
Java API for XML Web Services (JAX-WS)Peter R. Egli
 
IBM Connect 2016 - Break out of the Box
IBM Connect 2016 - Break out of the BoxIBM Connect 2016 - Break out of the Box
IBM Connect 2016 - Break out of the BoxKarl-Henry Martinsson
 
Bt0083 server side programing
Bt0083 server side programing Bt0083 server side programing
Bt0083 server side programing Techglyphs
 
Servlet ppt by vikas jagtap
Servlet ppt by vikas jagtapServlet ppt by vikas jagtap
Servlet ppt by vikas jagtapVikas Jagtap
 
Java web services using JAX-WS
Java web services using JAX-WSJava web services using JAX-WS
Java web services using JAX-WSIndicThreads
 

What's hot (15)

New Flash Builder 4 WSDL and HTTP Connectors
New Flash Builder 4 WSDL and HTTP ConnectorsNew Flash Builder 4 WSDL and HTTP Connectors
New Flash Builder 4 WSDL and HTTP Connectors
 
Creating and connecting to odi master and work repositories
Creating and connecting to odi master and work repositoriesCreating and connecting to odi master and work repositories
Creating and connecting to odi master and work repositories
 
WebLogic FAQs
WebLogic FAQsWebLogic FAQs
WebLogic FAQs
 
Nick harris-sic-2011
Nick harris-sic-2011Nick harris-sic-2011
Nick harris-sic-2011
 
Session And Cookies In Servlets - Java
Session And Cookies In Servlets - JavaSession And Cookies In Servlets - Java
Session And Cookies In Servlets - Java
 
Java API for XML Web Services (JAX-WS)
Java API for XML Web Services (JAX-WS)Java API for XML Web Services (JAX-WS)
Java API for XML Web Services (JAX-WS)
 
JAX-WS Basics
JAX-WS BasicsJAX-WS Basics
JAX-WS Basics
 
IBM Connect 2016 - Break out of the Box
IBM Connect 2016 - Break out of the BoxIBM Connect 2016 - Break out of the Box
IBM Connect 2016 - Break out of the Box
 
Break out of The Box - Part 2
Break out of The Box - Part 2Break out of The Box - Part 2
Break out of The Box - Part 2
 
AD102 - Break out of the Box
AD102 - Break out of the BoxAD102 - Break out of the Box
AD102 - Break out of the Box
 
11-DWR-and-JQuery
11-DWR-and-JQuery11-DWR-and-JQuery
11-DWR-and-JQuery
 
Dwr
DwrDwr
Dwr
 
Bt0083 server side programing
Bt0083 server side programing Bt0083 server side programing
Bt0083 server side programing
 
Servlet ppt by vikas jagtap
Servlet ppt by vikas jagtapServlet ppt by vikas jagtap
Servlet ppt by vikas jagtap
 
Java web services using JAX-WS
Java web services using JAX-WSJava web services using JAX-WS
Java web services using JAX-WS
 

Viewers also liked

The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>tutorialsruby
 
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>tutorialsruby
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />tutorialsruby
 
Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0tutorialsruby
 
mapserver_install_linux
mapserver_install_linuxmapserver_install_linux
mapserver_install_linuxtutorialsruby
 

Viewers also liked (11)

The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
 
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
 
veracruz
veracruzveracruz
veracruz
 
perltut
perltutperltut
perltut
 
PHP-Nuke-HOWTO
PHP-Nuke-HOWTOPHP-Nuke-HOWTO
PHP-Nuke-HOWTO
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
 
javascript2
javascript2javascript2
javascript2
 
newsletter7
newsletter7newsletter7
newsletter7
 
Tutorial
TutorialTutorial
Tutorial
 
Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0
 
mapserver_install_linux
mapserver_install_linuxmapserver_install_linux
mapserver_install_linux
 

Similar to Accessing_MySQL_from_Ruby

Accessing my sql_from_java
Accessing my sql_from_javaAccessing my sql_from_java
Accessing my sql_from_javaTran Rean
 
Introduction to MySQL - Part 1
Introduction to MySQL - Part 1Introduction to MySQL - Part 1
Introduction to MySQL - Part 1webhostingguy
 
Introduction to MySQL - Part 1
Introduction to MySQL - Part 1Introduction to MySQL - Part 1
Introduction to MySQL - Part 1webhostingguy
 
Introduction to MySQL - Part 1
Introduction to MySQL - Part 1Introduction to MySQL - Part 1
Introduction to MySQL - Part 1webhostingguy
 
Introduction to MySQL - Part 1
Introduction to MySQL - Part 1Introduction to MySQL - Part 1
Introduction to MySQL - Part 1webhostingguy
 
My sql università di enna a.a. 2005-06
My sql   università di enna a.a. 2005-06My sql   università di enna a.a. 2005-06
My sql università di enna a.a. 2005-06YUCHENG HU
 
Spring boot-application
Spring boot-applicationSpring boot-application
Spring boot-applicationParag Patil
 
Guide - Migrating from Heroku to AWS using CloudFormation
Guide - Migrating from Heroku to AWS using CloudFormationGuide - Migrating from Heroku to AWS using CloudFormation
Guide - Migrating from Heroku to AWS using CloudFormationRob Linton
 
Mysqlppt3510
Mysqlppt3510Mysqlppt3510
Mysqlppt3510Anuja Lad
 
How To Create RDS Database for WordPress in AWS on RHEL 7 or CentOS 7
How To Create RDS Database for WordPress in AWS on RHEL 7 or CentOS 7How To Create RDS Database for WordPress in AWS on RHEL 7 or CentOS 7
How To Create RDS Database for WordPress in AWS on RHEL 7 or CentOS 7VCP Muthukrishna
 
SULTHAN's PHP, MySQL & wordpress
SULTHAN's PHP, MySQL & wordpressSULTHAN's PHP, MySQL & wordpress
SULTHAN's PHP, MySQL & wordpressSULTHAN BASHA
 
MySQL Shell - The Best MySQL DBA Tool
MySQL Shell - The Best MySQL DBA ToolMySQL Shell - The Best MySQL DBA Tool
MySQL Shell - The Best MySQL DBA ToolMiguel Araújo
 

Similar to Accessing_MySQL_from_Ruby (20)

Accessing my sql_from_java
Accessing my sql_from_javaAccessing my sql_from_java
Accessing my sql_from_java
 
Introduction to MySQL - Part 1
Introduction to MySQL - Part 1Introduction to MySQL - Part 1
Introduction to MySQL - Part 1
 
Introduction to MySQL - Part 1
Introduction to MySQL - Part 1Introduction to MySQL - Part 1
Introduction to MySQL - Part 1
 
Introduction to MySQL - Part 1
Introduction to MySQL - Part 1Introduction to MySQL - Part 1
Introduction to MySQL - Part 1
 
Introduction to MySQL - Part 1
Introduction to MySQL - Part 1Introduction to MySQL - Part 1
Introduction to MySQL - Part 1
 
My sql università di enna a.a. 2005-06
My sql   università di enna a.a. 2005-06My sql   università di enna a.a. 2005-06
My sql università di enna a.a. 2005-06
 
Mysql tutorial
Mysql tutorialMysql tutorial
Mysql tutorial
 
Spring boot-application
Spring boot-applicationSpring boot-application
Spring boot-application
 
MySQL Shell for DBAs
MySQL Shell for DBAsMySQL Shell for DBAs
MySQL Shell for DBAs
 
Guide - Migrating from Heroku to AWS using CloudFormation
Guide - Migrating from Heroku to AWS using CloudFormationGuide - Migrating from Heroku to AWS using CloudFormation
Guide - Migrating from Heroku to AWS using CloudFormation
 
Sql installation
Sql installationSql installation
Sql installation
 
Mysql tutorial 5257
Mysql tutorial 5257Mysql tutorial 5257
Mysql tutorial 5257
 
Mysqlppt3510
Mysqlppt3510Mysqlppt3510
Mysqlppt3510
 
Mysqlppt3510
Mysqlppt3510Mysqlppt3510
Mysqlppt3510
 
How To Create RDS Database for WordPress in AWS on RHEL 7 or CentOS 7
How To Create RDS Database for WordPress in AWS on RHEL 7 or CentOS 7How To Create RDS Database for WordPress in AWS on RHEL 7 or CentOS 7
How To Create RDS Database for WordPress in AWS on RHEL 7 or CentOS 7
 
My sql basic
My sql basicMy sql basic
My sql basic
 
AWS essentials EC2
AWS essentials EC2AWS essentials EC2
AWS essentials EC2
 
SULTHAN's PHP, MySQL & wordpress
SULTHAN's PHP, MySQL & wordpressSULTHAN's PHP, MySQL & wordpress
SULTHAN's PHP, MySQL & wordpress
 
MySQL Shell - The Best MySQL DBA Tool
MySQL Shell - The Best MySQL DBA ToolMySQL Shell - The Best MySQL DBA Tool
MySQL Shell - The Best MySQL DBA Tool
 
rails.html
rails.htmlrails.html
rails.html
 

More from tutorialsruby

&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />tutorialsruby
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />tutorialsruby
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />tutorialsruby
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269tutorialsruby
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269tutorialsruby
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008tutorialsruby
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008tutorialsruby
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheetstutorialsruby
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheetstutorialsruby
 
Winter%200405%20-%20Advanced%20Javascript
Winter%200405%20-%20Advanced%20JavascriptWinter%200405%20-%20Advanced%20Javascript
Winter%200405%20-%20Advanced%20Javascripttutorialsruby
 
Winter%200405%20-%20Advanced%20Javascript
Winter%200405%20-%20Advanced%20JavascriptWinter%200405%20-%20Advanced%20Javascript
Winter%200405%20-%20Advanced%20Javascripttutorialsruby
 

More from tutorialsruby (20)

&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
 
xhtml_basics
xhtml_basicsxhtml_basics
xhtml_basics
 
xhtml_basics
xhtml_basicsxhtml_basics
xhtml_basics
 
xhtml-documentation
xhtml-documentationxhtml-documentation
xhtml-documentation
 
xhtml-documentation
xhtml-documentationxhtml-documentation
xhtml-documentation
 
CSS
CSSCSS
CSS
 
CSS
CSSCSS
CSS
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
 
HowTo_CSS
HowTo_CSSHowTo_CSS
HowTo_CSS
 
HowTo_CSS
HowTo_CSSHowTo_CSS
HowTo_CSS
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheets
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheets
 
Winter%200405%20-%20Advanced%20Javascript
Winter%200405%20-%20Advanced%20JavascriptWinter%200405%20-%20Advanced%20Javascript
Winter%200405%20-%20Advanced%20Javascript
 
Winter%200405%20-%20Advanced%20Javascript
Winter%200405%20-%20Advanced%20JavascriptWinter%200405%20-%20Advanced%20Javascript
Winter%200405%20-%20Advanced%20Javascript
 
eng2u3less38
eng2u3less38eng2u3less38
eng2u3less38
 

Recently uploaded

AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 

Recently uploaded (20)

AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 

Accessing_MySQL_from_Ruby

  • 1. Accessing MySQL from Ruby Contents 1. Introduction .................................................................................................................................... 2 2. Prerequisites ................................................................................................................................... 2 3. Setup ............................................................................................................................................... 2 3.1. Populate MySQL Database ...................................................................................................... 2 3.2. Set up ODBC Access ................................................................................................................ 3 4. Discovery ......................................................................................................................................... 4 4.1. Web Service Creation using SOA Gateway ............................................................................. 4 4.2. Accessing the WSDL ................................................................................................................ 6 5. Accessing a Web Service with Ruby ................................................................................................ 8 Ruby Editor.......................................................................................................................................... 8 Ruby Code ........................................................................................................................................... 8 Debugging Code .................................................................................................................................. 9 6. Conclusion ..................................................................................................................................... 10 7. Appendix ....................................................................................................................................... 10 Accessing MySQL from Ruby Author: John O’Mahony, Risaris Ltd
  • 2. 1. Introduction In this tutorial we will show you how to build a Ruby application to access MySQL via the SOA Gateway. 2. Prerequisites It is assumed that you are running the 3 components, MySQL, Ruby and the SOA Gateway on Windows. It is assumed you already have a SOA Gateway server and Control Centre installed. See here for more info about installing the SOA Gateway. 3. Setup Download the latest binaries for Ruby from the Ruby downloads page, install it according to the install.txt document in the Ruby distribution library. For this tutorial I downloaded Ruby 1.8.6 One-Click Installer and followed the default options. You will also need a MySQL database. Again, the Open Source version (known as the MySQL Community Server) can be freely downloaded from the MySQL website. See this link for download, and here to step you through the installation and configuration. 3.1.Populate MySQL Database Now that you’ve got MySQL installed and configured, you will need to populate it with some demo data. For this we use the RisarisBank sample. This is available here.  Save this file to “C:TempRisarisBank.sql”  Connect to the MySQL Server using the mysql command. E.g shell> mysql –u root –p This command connects to the server using the MySQL root account to make sure that you'll have permission to create the RisarisBank database. The -p option tells mysql to prompt you for the root password. Enter the password when prompted. (Remember that the MySQL root account is not the same as the operating system root account and probably will have a different password.)  Create the RisarisBank database. mysql> CREATE DATABASE RisarisBank; mysql> use RisarisBank;  Load the contents of RisarisBank.sql into the RisarisBank database. E.g. mysql> SOURCE c:TempRisarisBank.sql  After the SOURCE command finishes, you can view your new tables. Accessing MySQL from Ruby Author: John O’Mahony, Risaris Ltd
  • 3. mysql> SHOW TABLES; mysql> DESCRIBE CustomerInformation; mysql> DESCRIBE Branch; etc … 3.2.Set up ODBC Access The final thing to do with your MySQL Database is to set up an ODBC DSN which will be used by the SOA Gateway to access this database. Click Start, Control Panel, Administrative Tools, Data Sources (ODBC) From the resulting screen, choose the “System DSN” Tab. Click Add From the list of data source drivers, select “MySQL ODBC 3.51 Driver”. If you do not see this driver in the list, you need to install the MySQL Connector. See here for more information. We recommend installing v3.51. Click Finish, and a window will appear allowing you to enter the DSN information. Add the following: Data Source Name: RisarisBank Description: The Risaris Bank Sample in MySQL Server: localhost User: root Password: *** your MySQL root password *** Database: RisarisBank (select from the drop down list) Accessing MySQL from Ruby Author: John O’Mahony, Risaris Ltd
  • 4. All other options can be left as-is. Click OK. 4. Discovery At this stage you’ve got Ruby installed, and a MySQL database with some sample data in it. In this section we’ll show you how to create web services from each of the MySQL tables. These web services can be used by the Ruby language (and many others) to give you direct real-time access to your MySQL Data. 4.1.Web Service Creation using SOA Gateway Start your SOA Gateway Control Centre. See here for an introduction to the Control Centre. In your servers view, right click the entry which represents your local SOA Gateway Server. Select “Create New Web Services”. Accessing MySQL from Ruby Author: John O’Mahony, Risaris Ltd
  • 5. From the next dialog, choose “MySQL Driver”. If you do not see have a MySQL Driver in the list, see how to create one here. Click Next. The next screen gives you the ability to add information about your DSN Accessing MySQL from Ruby Author: John O’Mahony, Risaris Ltd
  • 6. Enter the above information and click Discover. The wizard will display all the tables it finds at this (RisarisBank) DSN. Click “Select All”, and click “Import”. The wizard will create web services from each one of these tables. You’ve just created 8 Web Services from your 8 MySQL Tables! 4.2.Accessing the WSDL Web Service Description Language (WSDL) is a standard, XML-based language that is used to describe a Web Service. For each of the 8 web services you’ve created in the previous section, the SOA Gateway provides you with a WSDL to describe the Web Service. The WSDL itself is usually interpreted by a web Accessing MySQL from Ruby Author: John O’Mahony, Risaris Ltd
  • 7. service client, such as Ruby, but it is useful to know where to find the WSDL for each of your Web Services. As WSDL is XML-based, it will open in your browser of choice. To see the WSDL for one of your Risaris Bank web services, do the following in your SOA Gateway Control Centre:  Click on the web service you are interested in, for example the “branch” web service.  The properties for this web service should appear in your Properties View. If you do not see the Properties view, select Window -> Show View -> Other -> General -> Properties and click OK.  In the properties view, there is a link to your WSDL. Click it to open the WSDL in a browser. Accessing MySQL from Ruby Author: John O’Mahony, Risaris Ltd
  • 8. You can view the WSDL for the other web services by clicking the link from their properties view. This WSDL is the starting point for using Web Services, and can be used time and again by different web service clients. 5. Accessing a Web Service with Ruby We will use a Ruby script to access our new Risaris Bank Web Services via the WSDL. Those familiar with Ruby will probably want to change the script provided but it can be run with minimum changes described below. The whole script is provided in APPENDIX A. Ruby Editor Use the editor provided, SciTE.exe, which is located in folder scite where you installed Ruby. Copy the code from Appendix A and save the code as the filename RBCustomerTutorial.rb (as in example below). Hit F5 and the results will appear in the right-hand pane: Ruby Code Depending on your MySQL settings you will have to change the username/password provided in the on_simple_outbound method. In this example the user is root with no password. "<UsernameToken><Username>root</Username><Password></Password></UsernameToken>" Accessing MySQL from Ruby Author: John O’Mahony, Risaris Ltd
  • 9. Note also the WSDL URL http://localhost:56000/customerinformation?WSDL. Again depending on your SOA Gateway configuration you may need to change the server/port number. In this example provided we are issuing a list request on the customer information table in the RisarisBank database. The list request can handle a wilcarded customer number key: param = {"CustomerNumber" => "1*"} result = soap.list(param) Finally we can query the result for the customer’s first name: for cust in (result. customerinformationRoot.customerinformationGroup) print(cust.firstName, "n") end Obviously this can be replaced by any of the column names in the customer information table. Debugging Code The code provided should work off the bat. However, depending on your MySQL configuration, the RisarisBank tables may not be in lowercase as in our example e.g. customerinformation versus CustomerInformation. If this is the case the code will not work as is and all occurrences of customerinformation should be replaced by CustomerInformation. The p and puts functions are useful for checking the content of variables. For example p result after the result = soap.list(param) call gives the following information and is useful for checking column names for adding new code. #<SOAP::Mapping::Object:0x3240c04 {}customerinformationRoot=#<SOAP::Mapping::Object:0x3240ad8 {}customerinformationGroup=[#<SOAP::Mapping::Object:0x32409ac {}CustomerNumber="1" {}FirstName="Casper" {}Surname="Ankergren" {}AddressLine1="34 Green Street" {}AddressLine2="Crosses Street" {}City="Mansfield" {}Postcode="MA5 9AJ" {}DateOfBirth="30/05/1978">, #<SOAP::Mapping::Object:0x323f4bc {}CustomerNumber="10" {}FirstName="Grenville" {}Surname="Dekker" {}AddressLine1="22 Uttoxter New Road" {}AddressLine2="Chaddesden" {}City="Leeds" {}Postcode="LS4 9WB" {}DateOfBirth="21/10/1974">, #<SOAP::Mapping::Object:0x323e0b2 {}CustomerNumber="11" {}FirstName="Jane" {}Surname="Freeman" {}AddressLine1="3 Portland Street" {}AddressLine2="Lichfield" {}City="Gloucester" {}Postcode="GL4 8KD" {}DateOfBirth="26/10/1980">, #<SOAP::Mapping::Object:0x323ccb2 {}CustomerNumber="12" {}FirstName="Dale" {}Surname="Rolling" {}AddressLine1="The Hunters Rest" {}AddressLine2="Branston" {}City="Preston" {}Postcode="PR4 4HG" {}DateOfBirth="06/12/1989">, #<SOAP::Mapping::Object:0x323b8b2 {}CustomerNumber="13" {}FirstName="Arnold" {}Surname="Corrigan" {}AddressLine1="14 Anderson Street" {}AddressLine2="Allestree" {}City="Derby" {}Postcode="DE6 8FT" {}DateOfBirth="10/06/1970">, #<SOAP::Mapping::Object:0x323a4b2 {}CustomerNumber="14" {}FirstName="Alfred" {}Surname="Summerscale" {}AddressLine1="3701 S. Accessing MySQL from Ruby Author: John O’Mahony, Risaris Ltd
  • 10. George Mason" {}AddressLine2="Melbourne" {}City="Bath" {}Postcode="BA6 8UU" {}DateOfBirth="07/08/1982">, #<SOAP::Mapping::Object:0x32390b2 {}CustomerNumber="15" {}FirstName="Peter" {}Surname="Spiegel" {}AddressLine1="11663 Charter Oak Co" {}AddressLine2="Foremark" {}City="Manchester" {}Postcode="M98 4GT" {}DateOfBirth="29/12/1971">, #<SOAP::Mapping::Object:0x3237cb2 {}CustomerNumber="16" {}FirstName="John" {}Surname="Sviridov" {}AddressLine1="3319 Rosemere Court" {}AddressLine2="Brailsford" {}City="Leeds" {}Postcode="LS8 5QQ" {}DateOfBirth="12/06/1984">, #<SOAP::Mapping::Object:0x32368b2 {}CustomerNumber="17" {}FirstName="Sarah" {}Surname="Hall" {}AddressLine1="4 Denmark Lane" {}AddressLine2="East Bridgford" {}City="Portsmouth" {}Postcode="PO9 7QN" {}DateOfBirth="12/02/1983">, #<SOAP::Mapping::Object:0x32354b2 {}CustomerNumber="18" {}FirstName="Elspeth" {}Surname="Jones" {}AddressLine1="12375 W. Ohio Circle" {}AddressLine2="Risley" {}City="Birmingham" {}Postcode="B93 1IO" {}DateOfBirth="28/08/1986">, #<SOAP::Mapping::Object:0x32340b2 {}CustomerNumber="19" {}FirstName="Nigel" {}Surname="Wyllis" {}AddressLine1="14 Borough Road" {}AddressLine2="Ockbrook" {}City="Leeds" {}Postcode="LS8 2WL" {}DateOfBirth="29/04/1981">]>> 6. Conclusion This tutorial shows how to access MySQL from Ruby using the SOA Gateway. As you can see, you have built a powerful application that uses Web Services to retrieve information in real-time. 7. Appendix require 'soap/wsdlDriver' require 'soap/header/simplehandler' # A handler to add authentication parameters to the SOAP header. class AutheticationHeaderHandler < SOAP::Header::SimpleHandler @@HEADER_NAME = 'Security' def initialize(namespace) super(XSD::QName.new(namespace, @@HEADER_NAME)) end def on_simple_outbound #Change the username/password below to reflect your own environment "<UsernameToken><Username>root</Username><Password></Password></UsernameTok en>" Accessing MySQL from Ruby Author: John O’Mahony, Risaris Ltd
  • 11. end end wsdl_url = "http://localhost:56000/customerinformation?WSDL" soap = SOAP::WSDLDriverFactory.new(wsdl_url).create_rpc_driver soap.wiredump_file_base = "soapresult" soap.headerhandler << AutheticationHeaderHandler.new("http://www.risaris.com/security") param = {"CustomerNumber" => "1*"} result = soap.list(param) for cust in (result.customerinformationRoot.customerinformationGroup) print(cust.firstName, "n") end Accessing MySQL from Ruby Author: John O’Mahony, Risaris Ltd