Ruby as Enterprise Glue
Listing 5. loc_service.wsdl
<definitions
name="LocServiceImplementationDescription"
targetNamespace="example.com/wsdl/loc_service.wsdl"
xmlns="http://schemas.xmlsoap.org/wsdl/"
>
<message name="locate_in">
<part name="street" type="xsd:string"/>
<part name="house_number" type="xsd:string"/>
<part name="postal_code" type="xsd:string"/>
<part name="city" type="xsd:string"/>
<part name="state" type="xsd:string"/>
</message>
<message name="locate_out">
<part name="longitude" type="xsd:double"/>
<part name="latitude" type="xsd:double"/>
</message>
<portType name="LocServiceInterface">
<operation name="locate">
<input message="tns:locate_in"/>
<output message="tns:locate_out"/>
</operation>
</portType>
<binding
name="LocServiceBinding"
type="tns:LocServiceInterface">
<soap:binding style="rpc"/>
<operation name="locate">
<soap:operation soapAction="locate"/>
<input>
<soap:body namespace="urn:LocService"/>
</input>
<output>
<soap:body
namespace="urn:LocService"
use="encoded"/>
</output>
</operation>
</binding>
<service name="LocalizationService">
<documentation>
Calculates coordinates of a given address.
</documentation>
<port
binding="tns:LocServiceBinding"
name="LocServicePort">
<soap:address
location="http://localhost:2000"/>
</port>
</service>
</definitions>
Ruby has excellent support for SOAP because of the SOAP4R library (see Resources). It implements version 1.1 of the SOAP specification and is easy to use. If you've worked with SOAP before, you probably know what to do with a WSDL file. Normally, you'd use it to create skeleton code for a SOAP server or client you're going to implement. SOAP4R comes with a tool called wsdl2ruby.rb that turns a WSDL file into Ruby code. It can create code both for accessing a service having the interface described in the file and for creating a server that implements the interface.
We need a client that uses the localization service, and we could generate the complete code from the WSDL file with wsdl2ruby.rb. But in a dynamic language like Ruby, we don't need this intermediate step. It's easier to derive the client from a WSDL file on the fly. Listing 6 demonstrates how to do this.
Listing 6. loc_service.rb
require 'soap/wsdlDriver'
include SOAP
class LocalizationService
def initialize(wsdl_file)
factory = WSDLDriverFactory.new(wsdl_file)
@loc_service = factory.create_rpc_driver
end
def locate(address)
@loc_service.locate(
address.street,
address.house_number,
address.postal_code,
address.city,
address.state
)
end
end
The initialize method expects a WSDL file and creates a driver factory from it. This factory creates a driver (a synonym for proxy) for every service binding that has been specified in the WSDL file. We choose the RPC driver and treat the instance variable @loc_service as if it were a local object of class LocalizationService. In the locate method, we simply delegate the work to the localization service.
You need to run a standalone SOAP server to make these examples work, as shown in Listing 7.
Listing 7. Standalone SOAP Server
require 'soap/rpc/standaloneServer'
class LocalizationServer < SOAP::RPC::StandaloneServer
def on_init
@log.level = Logger::Severity::DEBUG
add_method(
self,
'locate',
'street',
'house_number',
'postal_code',
'city',
'state'
)
end
def locate(street, house_number, postal_code, city, state)
[97.03, 32.90]
end
end
server = LocalizationServer.new(
'localization', 'urn:LocService', '0.0.0.0', 2000
)
trap(:INT) { server.shutdown }
server.start
In a final step, we build an HTTP server that returns the coordinates belonging to a particular address as an XML document. It takes some time to calculate the coordinates, and the localization service isn't free either. Hence, we calculate coordinates only if necessary and store them locally in our database.
Back in the old days of the Internet, you had to use standards like the Common Gateway Interface (CGI) to create dynamic Web sites. Whenever a client requested a nonstatic page, the Web server called an external program—often a Perl or bash script—to create the content. The server passed it the current environment, including the client's request parameters, and returned the script's output to the requesting client. This approach causes a severe performance overhead, because the scripts have to be started as separate processes.
CGI programs have more disadvantages. First, they cannot easily maintain a state, because they are shut down immediately after they have done their work. Second, they are often a security problem, because they run in a more or less uncontrolled environment.
With the advent of Java, an alternative technology became fairly popular—servlets. Servlets are little code snippets that are executed by a so-called servlet container. They are loaded into memory only once and can be reused as often as necessary. This increases performance tremendously, and it allows developers to manage state information in the servlets. Eventually, the servlet container controls the environment of the servlets and can prevent them from performing unwanted operations such as deleting files.
Ruby ships with WEBrick (see Resources), a fantastic framework for creating HTTP servers. It allows you to follow the more or less obsolete CGI approach, but it strongly encourages the use of Ruby servlets. In Listing 8, you can see a servlet that implements the main logic of our service.
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Sponsored by AMD
If you already use virtualized infrastructure, you are well on your way to leveraging the power of the cloud. Virtualization offers the promise of limitless resources, but how do you manage that scalability when your DevOps team doesn’t scale? In today’s hypercompetitive markets, fast results can make a difference between leading the pack vs. obsolescence. Organizations need more benefits from cloud computing than just raw resources. They need agility, flexibility, convenience, ROI, and control.
Stackato private Platform-as-a-Service technology from ActiveState extends your private cloud infrastructure by creating a private PaaS to provide on-demand availability, flexibility, control, and ultimately, faster time-to-market for your enterprise.
Sponsored by ActiveState
| Speed Up Your Web Site with Varnish | Jun 19, 2013 |
| Non-Linux FOSS: libnotify, OS X Style | Jun 18, 2013 |
| Containers—Not Virtual Machines—Are the Future Cloud | Jun 17, 2013 |
| Lock-Free Multi-Producer Multi-Consumer Queue on Ring Buffer | Jun 12, 2013 |
| Weechat, Irssi's Little Brother | Jun 11, 2013 |
| One Tail Just Isn't Enough | Jun 07, 2013 |
- Speed Up Your Web Site with Varnish
- Containers—Not Virtual Machines—Are the Future Cloud
- Linux Systems Administrator
- Lock-Free Multi-Producer Multi-Consumer Queue on Ring Buffer
- Non-Linux FOSS: libnotify, OS X Style
- Senior Perl Developer
- Technical Support Rep
- UX Designer
- Web & UI Developer (JavaScript & j Query)
- RSS Feeds
- Reply to comment | Linux Journal
17 min 41 sec ago - Reply to comment | Linux Journal
4 hours 17 min ago - Yeah, user namespaces are
5 hours 33 min ago - Cari Uang
9 hours 4 min ago - user namespaces
11 hours 58 min ago - yea
12 hours 24 min ago - One advantage with VMs
14 hours 52 min ago - about info
15 hours 26 min ago - info
15 hours 27 min ago - info
15 hours 27 min ago
Featured Jobs
| Linux Systems Administrator | Houston and Austin, Texas | Host Gator |
| Senior Perl Developer | Austin, Texas | Host Gator |
| Technical Support Rep | Houston and Austin, Texas | Host Gator |
| UX Designer | Austin, Texas | Host Gator |
| Web & UI Developer (JavaScript & j Query) | Austin, Texas | Host Gator |
Free Webinar: Hadoop
How to Build an Optimal Hadoop Cluster to Store and Maintain Unlimited Amounts of Data Using Microservers
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Some of key questions to be discussed are:
- What is the “typical” Hadoop cluster and what should be installed on the different machine types?
- Why should you consider the typical workload patterns when making your hardware decisions?
- Are all microservers created equal for Hadoop deployments?
- How do I plan for expansion if I require more compute, memory, storage or networking?




Comments
I too don't understand
I too don't understand why:
ERROR SOAP::WSDLDriverFactory::FactoryError: no ports have soap:address
/usr/lib/ruby/1.8/soap/wsdlDriver.rb:75:in `find_port'
/usr/lib/ruby/1.8/soap/wsdlDriver.rb:37:in `create_rpc_driver'
./loc_service.rb:6:in `initialize'
./servlet.rb:11:in `initialize'
/usr/lib/ruby/1.8/webrick/httpservlet/abstract.rb:23:in `get_instance'
/usr/lib/ruby/1.8/webrick/httpserver.rb:102:in `service'
/usr/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
/usr/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'
/usr/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'
/usr/lib/ruby/1.8/webrick/server.rb:95:in `start'
/usr/lib/ruby/1.8/webrick/server.rb:92:in `start'
/usr/lib/ruby/1.8/webrick/server.rb:23:in `start'
/usr/lib/ruby/1.8/webrick/server.rb:82:in `start'
server.rb:8
Please say me why there wrong?
Thanks!
ERROR SOAP::WSDLDriverFactory
I get this error from my soap server (from listing 7) but I don't understand why:
ERROR SOAP::WSDLDriverFactory::FactoryError: no ports have soap:address
/usr/lib/ruby/1.8/soap/wsdlDriver.rb:75:in `find_port'
/usr/lib/ruby/1.8/soap/wsdlDriver.rb:37:in `create_rpc_driver'
./loc_service.rb:6:in `initialize'
./servlet.rb:11:in `initialize'
/usr/lib/ruby/1.8/webrick/httpservlet/abstract.rb:23:in `get_instance'
/usr/lib/ruby/1.8/webrick/httpserver.rb:102:in `service'
/usr/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
/usr/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'
/usr/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'
/usr/lib/ruby/1.8/webrick/server.rb:95:in `start'
/usr/lib/ruby/1.8/webrick/server.rb:92:in `start'
/usr/lib/ruby/1.8/webrick/server.rb:23:in `start'
/usr/lib/ruby/1.8/webrick/server.rb:82:in `start'
server.rb:8
Thanks.
ERROR SOAP::WSDLDriverFactory
I get this error from my soap server (from listing 7) but I don't understand why:
ERROR SOAP::WSDLDriverFactory::FactoryError: no ports have soap:address
/usr/lib/ruby/1.8/soap/wsdlDriver.rb:75:in `find_port'
/usr/lib/ruby/1.8/soap/wsdlDriver.rb:37:in `create_rpc_driver'
./loc_service.rb:6:in `initialize'
./servlet.rb:11:in `initialize'
/usr/lib/ruby/1.8/webrick/httpservlet/abstract.rb:23:in `get_instance'
/usr/lib/ruby/1.8/webrick/httpserver.rb:102:in `service'
/usr/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
/usr/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'
/usr/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'
/usr/lib/ruby/1.8/webrick/server.rb:95:in `start'
/usr/lib/ruby/1.8/webrick/server.rb:92:in `start'
/usr/lib/ruby/1.8/webrick/server.rb:23:in `start'
/usr/lib/ruby/1.8/webrick/server.rb:82:in `start'
server.rb:8
Thanks.
Don't know but probably this
Don't know but probably this can help you:
http://www.thescripts.com/forum/thread509677.html