Enterprise Integration with Ruby 1st Edition Maik Schmidt - The ebook in PDF format is available for download
Enterprise Integration with Ruby 1st Edition Maik Schmidt - The ebook in PDF format is available for download
com
https://ebookname.com/product/enterprise-integration-with-
ruby-1st-edition-maik-schmidt/
OR CLICK HERE
DOWLOAD EBOOK
https://ebookname.com/product/service-oriented-java-business-
integration-enterprise-service-bus-integration-solutions-for-
java-developers-1st-ed-edition-binildas/
https://ebookname.com/product/cloning-internet-applications-with-
ruby-1st-edition-sheong/
https://ebookname.com/product/enterprise-integration-patterns-
designing-building-and-deploying-messaging-solutions-1st-edition-
hohpe/
https://ebookname.com/product/chinese-women-writers-and-the-
feminist-imagination-1905-1948-asia-s-transformations-1st-
edition-yan-haiping/
Décompression Zeh
https://ebookname.com/product/decompression-zeh/
https://ebookname.com/product/crime-and-culpability-a-theory-of-
criminal-law-1st-edition-larry-alexander/
https://ebookname.com/product/handbook-of-cognition-1st-edition-
dr-koen-lamberts/
https://ebookname.com/product/biology-of-northern-krill-1st-
edition-geraint-a-tarling-eds/
https://ebookname.com/product/the-nonprofit-manager-s-resource-
directory-second-edition-landskroner-r-a/
Interacting with Objects Language Materiality and
Social Activity 1st Edition Maurice Nevile (Ed.)
https://ebookname.com/product/interacting-with-objects-language-
materiality-and-social-activity-1st-edition-maurice-nevile-ed/
Enterprise Integration with Ruby
A Pragmatic Guide
Maik Schmidt
B o o k s h e l f
Many of the designations used by manufacturers and sellers to distinguish their products
are claimed as trademarks. Where those designations appear in this book, and The
Pragmatic Programmers, LLC was aware of a trademark claim, the designations have
been printed in initial capital letters or in all capitals. The Pragmatic Starter Kit, The
Pragmatic Programmer, Pragmatic Programming, Pragmatic Bookshelf and the linking g
device are trademarks of The Pragmatic Programmers, LLC.
Every precaution was taken in the preparation of this book. However, the publisher
assumes no responsibility for errors or omissions, or for damages that may result from
the use of information (including program listings) contained herein.
Our Pragmatic courses, workshops, and other products can help you and your team
create better software and have more fun. For more information, as well as the latest
Pragmatic titles, please visit us at
http://www.pragmaticprogrammer.com
ISBN 0-9766940-6-9
Printed on acid-free paper with 85% recycled, 30% post-consumer content.
First printing, March 2006
Version: 2006-5-4
Für meine Eltern.
Ihr seid die Giganten, auf deren Schultern ich stehe!
For my parents.
You are the giants on whose shoulders I stand!
Contents
Foreword viii
1 Introduction 1
1.1 What Is Enterprise Software? . . . . . . . . . . . . . . . . 2
1.2 What Is Enterprise Integration? . . . . . . . . . . . . . . 3
1.3 Why Ruby? . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.4 Who Should Read This Book? . . . . . . . . . . . . . . . 5
1.5 PragBouquet . . . . . . . . . . . . . . . . . . . . . . . . . 5
1.6 Acknowledgments . . . . . . . . . . . . . . . . . . . . . . 6
2 Databases 8
2.1 The Coupon Application . . . . . . . . . . . . . . . . . . . 9
2.2 Database Interface (DBI) . . . . . . . . . . . . . . . . . . 25
2.3 Object-Relational Mappers . . . . . . . . . . . . . . . . . 28
2.4 Lightweight Directory Access Protocol (LDAP) . . . . . . 51
3 Processing XML 79
3.1 A Short XML Reminder . . . . . . . . . . . . . . . . . . . 81
3.2 Generating XML Documents . . . . . . . . . . . . . . . . 83
3.3 Processing XML Documents . . . . . . . . . . . . . . . . 95
3.4 Validating XML Documents . . . . . . . . . . . . . . . . . 127
3.5 Are There Alternatives to XML? . . . . . . . . . . . . . . 132
A Resources 321
A.1 Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . 321
Foreword
A few years ago, I came across the Ruby programming language, and I fell in
love. Somehow, it just seemed to work the way my brain works—I can express
myself in Ruby more naturally and with less intervening fluff than in any other
language I know. I liked it so much I persuaded Andy Hunt to coauthor a book
about it.
That was back in 1999. Since then, a lot has happened in the Ruby world.
The language went from release 1.6 to 1.8, and the standard library matured
into something world class. It gained a standardized documentation system, a
standard library distribution mechanism, and a fine build tool. I produced a
second edition of Programming Ruby to celebrate.
And now, for the first time, I can seriously say that Ruby is ready for the
enterprise. The language is stable, the libraries are great, and there is a growing
pool of talented and enthusiastic Ruby developers, all rising to the challenge.
We see companies such as Amazon and EarthLink using Ruby for both internal-
and external-facing projects.
Now the situation has changed. With Enterprise Integration with Ruby, Maik
has done something I would have thought impossible. Not only has he doc-
umented just how to use Ruby to create new enterprise solutions and to knit
together existing applications, but he has also documented the backgrounds to
all the technologies, along with how and when to use each.
I consider this book a worthy partner to Programming Ruby. With it, you’ll
exploit the power and flexibility of Ruby to create new solutions for your com-
pany in record time.
Dave Thomas
The Pragmatic Programmers
There are two types of complex systems: those that have
grown out of simpler systems and those that do not work.
Unknown
Chapter 1
Introduction
Have you ever worked for a big enterprise? Do you remember your
expectations as you walked into work on that first day? Whistling as
the sun shone brightly, you might have been thinking, “It will be great
to work for <company name here>. They will have a professional envi-
ronment where coffee is free and where every system has been specified
accurately, implemented carefully, and tested thoroughly. Hmmmm...
I wonder which database and programming language they use.”
After your fifth cup of free coffee (around 9:07) you came to realize that
the real world looks completely different from your expectations. Typi-
cal enterprises use dozens, hundreds, and sometimes even thousands
of applications, components, services, and databases. Many of them
were custom-built in-house or by third parties, some were bought, oth-
ers are based on open source projects, and the origin of a few—usually
the most critical ones—is completely unknown. A lot of applications
are very old, some are fairly new, and seemingly no two of them were
written using the same tools. They run on heterogeneous operating sys-
tems and hardware, they use databases and messaging systems from
various vendors, and they were written in completely different program-
ming languages.
The reasons for this are manifold. You can find countless books that
explain why the situation is so bad. You can even find books claim-
ing that they help you prevent such chaos. This book uses another
approach. We will not help you clean up this mess, but we will help
you deal with the problems pragmatically. Instead of complaining that
valuable data is spread across different database schemas or across
databases from several vendors, we will write code that integrates it. We
will take it even a step further and write new applications that aggregate
W HAT I S E NTERPRISE S OFTWARE ? 2
1 http://www.rubyforge.org
2 http://raa.ruby-lang.org
W HO S HOULD R EAD T HIS B OOK ? 5
1.5 PragBouquet
To make things more interesting and tangible, we’ve founded an imag-
inary company called PragBouquet. It sells flowers from a web shop.
Customers from all over the world can order flowers and send them to
people living in the United States.
PragBouquet’s business demands a lot of components and services. It
depends on several partners, too. Their current infrastructure is shown
in Figure 1.1, on the following page. Customers place orders in the web
shop. The shop communicates with the central order system. Because
A CKNOWLEDGMENTS 6
1.6 Acknowledgments
First, I’d like to thank Dave Thomas and Andy Hunt for giving me the
opportunity to write this book for the Pragmatic Bookshelf. Working
with them has been both an honor and a pleasure. I couldn’t imagine
better or more professional working conditions.
It would be impossible to write a book about software for enterprise
integration without the software itself. The following gentlemen kindly
made their ingenious work public for free and have always responded
quickly and accurately to all my questions: Yukihiro “Matz” Matsumoto,
Will Drewry, arton (the author of Rjb), Sean Russel, Ian Macdonald,
Takaaki Tateishi, Thomas Uehlinger, Jim Weirich, Nikolai Lugovoi, Matt
Mower, Daniel Berger, why the lucky stiff, Minero Aoki, Michael Neu-
A CKNOWLEDGMENTS 7
* * * * *
For the next two months the colonel divided his time between
Ganado and San Francisco, that he might be near San Quentin, where
Custer was held pending the day of execution. Mrs. Pennington, broken
in health by the succession of blows that she had sustained, was sorely
in need of his companionship and help. Eva was rapidly regaining her
strength and some measure of her spirit. She had begun to realize how
useless and foolish her attempt at self-destruction had been, and to see
that the braver and nobler course would have been to give Guy the
benefit of her moral support in his time of need.
The colonel, who had wormed from Custer the full story of his
conviction upon the liquor charge, was able to convince her that Guy
had not played a dishonorable part, and that of the two he had
suffered more than Custer. Her father did not condone or excuse Guy’s
wrong-doing, but he tried to make her understand that it was no
indication of a criminal inclination, but rather the thoughtless act of an
undeveloped boy.
During the two months they saw little or nothing of Shannon. She
remained in Los Angeles, and when she made the long trip to San
Quentin to see Custer, or when they chanced to see her, they could not
but note how thin and drawn she was becoming. The roses had left her
cheeks, and there were deep lines beneath her eyes, in which there
was constantly an expression of haunting fear.
As the day of the execution drew nearer, the gloom that had
hovered over Ganado for months settled like a dense pall upon them
all. On the day before the execution the colonel left for San Francisco,
to say good-by to his son for the last time. Custer had insisted that his
mother and Eva must not come, and they had acceded to his wish.
On the afternoon when the colonel arrived at San Quentin, he was
permitted to see his son for the last time. The two conversed in low
tones, Custer asking questions about his mother and sister, and about
the little everyday activities of the ranch. Neither of them referred to
the event of the following morning.
“Has Shannon been here to-day?” the colonel asked.
Custer shook his head.
“I haven’t seen her this week,” he said. “I suppose she dreaded
coming. I don’t blame her. I should like to have seen her once more,
though!”
Presently they stood in silence for several moments.
“You’d better go, dad,” said the boy. “Go back to mother and Eva.
Don’t take it too hard. It isn’t so bad, after all. I have led a bully life,
and I have never forgotten once that I am a Pennington. I shall not
forget it to-morrow.”
The father could not speak. They clasped hands once, the older
man turned away, and the guards led Custer back to the death cell for
the last time.
CHAPTER XXXVII
It was morning when the colonel reached the ranch. He found
his wife and Eva sitting in Custer’s room. They knew the hour, and
they were waiting there to be as near him as they could. They were
weeping quietly. In the kitchen across the patio they could hear
Hannah sobbing.
They sat there for a long time in silence. Suddenly they heard a
door slam in the patio, and the sound of some one running.
“Colonel Pennington! Colonel Pennington!” a voice cried.
The colonel stepped to the door of Custer’s room. It was the
bookkeeper calling him.
“What is it?” he asked. “Here I am.”
“The Governor has granted a stay of execution. There is new
evidence. Miss Burke is on her way here now. She has found the
man who killed Crumb!”
What more he said the colonel did not hear, for he had turned
back into the room, and, collapsing on his son’s bed, had broken into
tears—he who had gone through those long weeks like a man of
iron.
It was nearly noon before Shannon arrived. She had been driven
from Los Angeles by an attaché of the district attorney’s office. The
Penningtons had been standing on the east porch, watching the
road with binoculars, so anxious were they for confirmation of their
hopes.
She was out of the car before it had stopped and was running
toward them. The man who had accompanied her followed, and
joined them on the porch. Shannon threw her arms around Mrs.
Pennington’s neck.
“He is safe!” she cried. “Another has confessed, and has satisfied
the district attorney of his guilt.”
“Who was it?” they asked.
Shannon turned toward Eva.
“It is going to be another blow to you all,” she said; “but wait
until I’m through, and you will understand that it could not have
been otherwise. It was Guy who killed Wilson Crumb.”
“Guy? Why should he have done it?”
“That was it. That was why suspicion was never directed toward
him. Only he knew the facts that prompted him to commit the deed.
It was Allen who suggested to me the possibility that it might have
been Guy. I have spent nearly two months at the sanatorium with
this gentleman from the district attorney’s office, in an effort to
awaken Guy’s sleeping intellect to a realization of the past, and of
the present necessity for recalling it. He has been improving steadily,
but it was only yesterday that memory returned to him. We worked
on the theory that if he could be made to realize that Eva lived, the
cause of his mental sickness would be removed. We tried everything,
and we had almost given up hope when, almost like a miracle, his
memory returned, while he was looking at a kodak picture of Eva
that I had shown him. The rest was easy, especially after he knew
that she had recovered. Instead of the necessity for confession
resulting in a further shock, it seemed to inspirit him. His one
thought was of Custer, his one hope that we would be in time to
save him.”
“Why did he kill Crumb?” asked Eva.
“Because Crumb killed Grace. He told me the whole story
yesterday.”
Very carefully Shannon related all that Guy had told of Crumb’s
relations with his sister, up to the moment of Grace’s death.
“I am glad he killed him!” said Eva. “I would have had no respect
for him if he hadn’t done it.”
“Guy told me that the evening before he killed Crumb he had
been looking over a motion picture magazine, and he had seen there
a picture of Crumb which tallied with the photograph he had taken
from Grace’s dressing table—a portrait of the man who, as she told
him, was responsible for her trouble. Guy had never been able to
learn this man’s identity, but the picture in the magazine, with his
name below it, was a reproduction of the same photograph. There
was no question as to the man’s identity. The scarfpin, and a lock of
hair falling in a peculiar way over the forehead, marked the pictures
as identical. Though Guy had never seen Crumb, he knew from
conversations that he had heard here that it was Wilson Crumb who
was directing the picture that was to be taken on Ganado. He
immediately got his pistol, saddled his horse, and rode up to the
camp in search of Crumb. It was he whom one of the witnesses
mistook for Custer. He then did what the district attorney attributed
to Custer. He rode to the mouth of Jackknife, and saw the lights of
Crumb’s car up near El Camino Largo. While he was in Jackknife, Eva
must have ridden down Sycamore from her meeting with Crumb,
passing Jackknife before Guy rode back into Sycamore. He rode up
to where Crumb was attempting to crank his engine. Evidently the
starter had failed to work, for Crumb was standing in front of the
car, in the glare of the headlights, attempting to crank it. Guy
accosted him, charged him with the murder of Grace, and shot him.
He then started for home by way of El Camino Largo. Half a mile up
the trail he dismounted and hid his pistol and belt in a hollow tree.
Then he rode home.
“He told me that while he never for an instant regretted his act,
he did not sleep all that night, and was in a highly nervous condition
when the shock of Eva’s supposed death unbalanced his mind;
otherwise he would gladly have assumed the guilt of Crumb’s death
at the time when Custer and I were accused.
“After we had obtained Guy’s confession, Allen gave us further
information tending to prove Custer innocent. He said he could not
give it before without incriminating himself; and as he had no love
for Custer, he did not intend to hang for a crime he had not
committed. He knew that he would surely hang if he confessed the
part that he had played in formulating the evidence against Custer.
“Crumb had been the means of sending Allen to the county jail,
after robbing him of several thousand dollars. The day before Crumb
was killed, Allen’s sentence expired. The first thing he did was to
search for Crumb, with the intention of killing the man. He learned
at the studio where Crumb was, and he followed him immediately.
He was hanging around the camp out of sight, waiting for Crumb,
when he heard the shot that killed him. His investigation led him to
Crumb’s body. He was instantly overcome by the fear, induced by his
guilty conscience, that the crime would be laid at his door. In casting
about for some plan by which he might divert suspicion from himself,
he discovered an opportunity to turn it against a man whom he
hated. The fact that he had been a stableman on Ganado, and was
familiar with the customs of the ranch, made it an easy thing for him
to go to the stables, saddle the Apache, and ride him up Sycamore
to Crumb’s body. Here he deliberately pulled off the fore shoe from
the horse and hid it under Crumb’s body. Then he rode back to the
stable, unsaddled the Apache, and made his way to the village.
“The district attorney said that we need have no fear but that
Custer will be exonerated and freed. And, Eva”—she turned to the
girl with a happy smile—“I have it very confidentially that there is
small likelihood that any jury in southern California will convict Guy,
if he bases his defense upon a plea of insanity.”
Eva smiled bravely and said:
“One thing I don’t understand, Shannon, is what you were doing
brushing the road with a bough from a tree, on the morning after
the killing of Crumb, if you weren’t trying to obliterate some one’s
tracks.”
“That’s just what I was trying to do,” said Shannon. “Ever since
Custer taught me something about tracking, it has held a certain
fascination for me, so that I often try to interpret the tracks I see
along the trails in the hills. It was because of this, I suppose, that I
immediately recognized the Apache’s tracks around the body of
Crumb. I immediately jumped to the conclusion that Custer had
killed him, and I did what I could to remove this evidence. As it
turned out, my efforts did more harm than good, until Allen’s
explanation cleared up the matter.”
“And why,” asked the colonel, “did Allen undergo this sudden
change of heart?”
Shannon turned toward him, her face slightly flushed, though
she looked him straight in the eyes as she spoke.
“It is a hard thing for me to tell you,” she said. “Allen is a bad
man—a very bad man; yet in the worst of man there is a spark of
good. Allen told me this morning, in the district attorney’s office,
what it was that had kindled to life the spark of good in him. He is
my father.”
THE END
Transcriber’s Notes
Punctuation, hyphenation, and spelling were made
consistent when a predominant preference was found in
the original book; otherwise they were not changed.
Simple typographical errors were corrected;
unbalanced quotation marks were remedied when the
change was obvious, and otherwise left unbalanced.
Transcriber removed redundant half-title page.
Page 60: “some one’s else happiness” was printed
that way.
Page 78: “an unkind face” was printed that way; may
be a typographical error for “fate”.
Page 79: “the possessor a quiet humor” was printed
that way, likely omitting an “of”.
Page 87: “Half an hour later he emerged” originally
was printed as “merged”.
Page 189: “which had arisen in his mind and would
not down.” was printed that way; probably should be “go
down.”
Page 200: “she cared about just then” originally was
printed as “just them”.
Page 248: “There’s be a whole regiment” was printed
that way.
Page 263: “she was purposely avoiding her” was
printed that way, but “she” perhaps should be “he”.
Page 310: “leap of the murderer’s horse” originally
was printed as “murder’s”.
Page 319: “pulled off the fore shoe” originally was
printed as “the off”.
*** END OF THE PROJECT GUTENBERG EBOOK THE GIRL FROM
HOLLYWOOD ***
1.D. The copyright laws of the place where you are located also
govern what you can do with this work. Copyright laws in most
countries are in a constant state of change. If you are outside
the United States, check the laws of your country in addition to
the terms of this agreement before downloading, copying,
displaying, performing, distributing or creating derivative works
based on this work or any other Project Gutenberg™ work. The
Foundation makes no representations concerning the copyright
status of any work in any country other than the United States.
1.E.6. You may convert to and distribute this work in any binary,
compressed, marked up, nonproprietary or proprietary form,
including any word processing or hypertext form. However, if
you provide access to or distribute copies of a Project
Gutenberg™ work in a format other than “Plain Vanilla ASCII” or
other format used in the official version posted on the official
Project Gutenberg™ website (www.gutenberg.org), you must,
at no additional cost, fee or expense to the user, provide a copy,
a means of exporting a copy, or a means of obtaining a copy
upon request, of the work in its original “Plain Vanilla ASCII” or
other form. Any alternate format must include the full Project
Gutenberg™ License as specified in paragraph 1.E.1.
• You pay a royalty fee of 20% of the gross profits you derive
from the use of Project Gutenberg™ works calculated using the
method you already use to calculate your applicable taxes. The
fee is owed to the owner of the Project Gutenberg™ trademark,
but he has agreed to donate royalties under this paragraph to
the Project Gutenberg Literary Archive Foundation. Royalty
payments must be paid within 60 days following each date on
which you prepare (or are legally required to prepare) your
periodic tax returns. Royalty payments should be clearly marked
as such and sent to the Project Gutenberg Literary Archive
Foundation at the address specified in Section 4, “Information
about donations to the Project Gutenberg Literary Archive
Foundation.”
• You comply with all other terms of this agreement for free
distribution of Project Gutenberg™ works.
1.F.
Most people start at our website which has the main PG search
facility: www.gutenberg.org.
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebookname.com