[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Ruby Web Services Client

Peter Hollenbeck

1/22/2007 4:12:00 AM

I have a simple web services client written in Java. The essence of it
is about 30 lines of code. It sends an XML message of about 20 lines to
a web service and receives an XML response that may be as many as 8000
lines. I have searched the web and have bought the books Programming
Ruby and Agile Web Development with Rails but find nothing that leads me
to what I need.

I would appreciate suggestions.
Peter

--
Posted via http://www.ruby-....

10 Answers

Nicolas H. Modrzyk

1/22/2007 4:17:00 AM

0

Hey Peter,

I've done a similar thing before in Ruby. (In the exact same
situation, where I migrated my java client, to a lighter and faster
Ruby client)
What is the problem you're facing ?
-> creating the message ?
-> calling the web service ?
-> streaming the answer ?

Niko,

On Jan 22, 2007, at 1:12 PM, Peter Hollenbeck wrote:

> I have a simple web services client written in Java. The essence of it
> is about 30 lines of code. It sends an XML message of about 20
> lines to
> a web service and receives an XML response that may be as many as 8000
> lines. I have searched the web and have bought the books Programming
> Ruby and Agile Web Development with Rails but find nothing that
> leads me
> to what I need.
>
> I would appreciate suggestions.
> Peter
>
> --
> Posted via http://www.ruby-....
>


Peter Hollenbeck

1/22/2007 4:21:00 AM

0

Peter Hollenbeck wrote:
> I have a simple web services client written in Java. The essence of it
> is about 30 lines of code. It sends an XML message of about 20 lines to
> a web service and receives an XML response that may be as many as 8000
> lines. I have searched the web and have bought the books Programming
> Ruby and Agile Web Development with Rails but find nothing that leads me
> to what I need.
>
> I would appreciate suggestions.
> Peter

Clarification of my above entry:
It is implied but not stated that I want a Ruby program that does the
same as my existing Java program.
Peter

--
Posted via http://www.ruby-....

Nicolas H. Modrzyk

1/22/2007 4:25:00 AM

0

Actually, one more question we might be interested in are:
- what is the protocol ?

Niko,

On Jan 22, 2007, at 1:17 PM, Nicolas H. Modrzyk wrote:

> Hey Peter,
>
> I've done a similar thing before in Ruby. (In the exact same
> situation, where I migrated my java client, to a lighter and faster
> Ruby client)
> What is the problem you're facing ?
> -> creating the message ?
> -> calling the web service ?
> -> streaming the answer ?
>
> Niko,
>
> On Jan 22, 2007, at 1:12 PM, Peter Hollenbeck wrote:
>
>> I have a simple web services client written in Java. The essence
>> of it
>> is about 30 lines of code. It sends an XML message of about 20
>> lines to
>> a web service and receives an XML response that may be as many as
>> 8000
>> lines. I have searched the web and have bought the books Programming
>> Ruby and Agile Web Development with Rails but find nothing that
>> leads me
>> to what I need.
>>
>> I would appreciate suggestions.
>> Peter
>>
>> --
>> Posted via http://www.ruby-....
>>
>
>


Peter Hollenbeck

1/22/2007 4:35:00 AM

0

Peter Hollenbeck wrote:
> Peter Hollenbeck wrote:
>> I have a simple web services client written in Java. The essence of it
>> is about 30 lines of code. It sends an XML message of about 20 lines to
>> a web service and receives an XML response that may be as many as 8000
>> lines. I have searched the web and have bought the books Programming
>> Ruby and Agile Web Development with Rails but find nothing that leads me
>> to what I need.
>>
>> I would appreciate suggestions.
>> Peter
>
> Clarification of my above entry:
> It is implied but not stated that I want a Ruby program that does the
> same as my existing Java program.
> Peter

Niko,
I guess all of the above. I have done a little with Ruby on Rails and
would like to use it, but don'r want to proceed until I solve this
problem. In my web searching I find documentation of several Ruby
protocol implementations but some are quite old.

The Java code looks like this:
String soapAction = args[0];
String sendmsg = soapAction+".xml";
String urlString = "http://dealer.patagonia.com/za/...
try {
URL url = new URL(urlString);
HttpURLConnection httpConnection =
(HttpURLConnection) url.openConnection();
httpConnection.setRequestProperty("SOAPAction", soapAction);
httpConnection.setDoOutput(true);
httpConnection.setDoInput(true);
httpConnection.setRequestMethod("POST");
httpConnection.setRequestProperty("Content-Type", "text/xml");
PrintStream httpout = new
PrintStream(httpConnection.getOutputStream());
BufferedReader in = new BufferedReader(new
InputStreamReader(fis));
/* Get first line of the outgoing message */
String line = in.readLine();
while (line != null) {
System.out.println(line);
/* Send the line to the http connection */
httpout.print(line);
line = in.readLine();
System.out.println("Reading the response stream ...");
BufferedReader in2 =
new BufferedReader(
new InputStreamReader(httpConnection.getInputStream()));
System.out.println("Response:");
String line = in2.readLine();
while (line != null) {
if (line.length() > 2)
System.out.println(line);
line = in2.readLine();

I have fumbled around with Ruby HTTP but am getting nowhere.
I would appreciate any direction you can give.
Peter




--
Posted via http://www.ruby-....

Jeremy McAnally

1/22/2007 5:15:00 AM

0

String sendmsg = soapAction+".xml";

Ah it looks like you're using SOAP; check out the soap4r project. :)

--Jeremy

On 1/21/07, Peter Hollenbeck <pwhbeck@comcast.net> wrote:
> Peter Hollenbeck wrote:
> > Peter Hollenbeck wrote:
> >> I have a simple web services client written in Java. The essence of it
> >> is about 30 lines of code. It sends an XML message of about 20 lines to
> >> a web service and receives an XML response that may be as many as 8000
> >> lines. I have searched the web and have bought the books Programming
> >> Ruby and Agile Web Development with Rails but find nothing that leads me
> >> to what I need.
> >>
> >> I would appreciate suggestions.
> >> Peter
> >
> > Clarification of my above entry:
> > It is implied but not stated that I want a Ruby program that does the
> > same as my existing Java program.
> > Peter
>
> Niko,
> I guess all of the above. I have done a little with Ruby on Rails and
> would like to use it, but don'r want to proceed until I solve this
> problem. In my web searching I find documentation of several Ruby
> protocol implementations but some are quite old.
>
> The Java code looks like this:
> String soapAction = args[0];
> String sendmsg = soapAction+".xml";
> String urlString = "http://dealer.patagonia.com/za/...
> try {
> URL url = new URL(urlString);
> HttpURLConnection httpConnection =
> (HttpURLConnection) url.openConnection();
> httpConnection.setRequestProperty("SOAPAction", soapAction);
> httpConnection.setDoOutput(true);
> httpConnection.setDoInput(true);
> httpConnection.setRequestMethod("POST");
> httpConnection.setRequestProperty("Content-Type", "text/xml");
> PrintStream httpout = new
> PrintStream(httpConnection.getOutputStream());
> BufferedReader in = new BufferedReader(new
> InputStreamReader(fis));
> /* Get first line of the outgoing message */
> String line = in.readLine();
> while (line != null) {
> System.out.println(line);
> /* Send the line to the http connection */
> httpout.print(line);
> line = in.readLine();
> System.out.println("Reading the response stream ...");
> BufferedReader in2 =
> new BufferedReader(
> new InputStreamReader(httpConnection.getInputStream()));
> System.out.println("Response:");
> String line = in2.readLine();
> while (line != null) {
> if (line.length() > 2)
> System.out.println(line);
> line = in2.readLine();
>
> I have fumbled around with Ruby HTTP but am getting nowhere.
> I would appreciate any direction you can give.
> Peter
>
>
>
>
> --
> Posted via http://www.ruby-....
>
>


--
My free Ruby e-book:
http://www.humblelittlerubybook...

My blogs:
http://www.mrneigh...
http://www.rubyinpra...

Nicolas H. Modrzyk

1/22/2007 5:26:00 AM

0

Hey Peter,

Mark Watson is the guy that put me on track the first time.
Did you read his article?
http://www.devx.com/enterprise/Article/28101/19...

He has a SOAP section as well. That would help.

Niko,

On Jan 22, 2007, at 1:34 PM, Peter Hollenbeck wrote:

> Peter Hollenbeck wrote:
>> Peter Hollenbeck wrote:
>>> I have a simple web services client written in Java. The essence
>>> of it
>>> is about 30 lines of code. It sends an XML message of about 20
>>> lines to
>>> a web service and receives an XML response that may be as many as
>>> 8000
>>> lines. I have searched the web and have bought the books Programming
>>> Ruby and Agile Web Development with Rails but find nothing that
>>> leads me
>>> to what I need.
>>>
>>> I would appreciate suggestions.
>>> Peter
>>
>> Clarification of my above entry:
>> It is implied but not stated that I want a Ruby program that does the
>> same as my existing Java program.
>> Peter
>
> Niko,
> I guess all of the above. I have done a little with Ruby on Rails and
> would like to use it, but don'r want to proceed until I solve this
> problem. In my web searching I find documentation of several Ruby
> protocol implementations but some are quite old.
>
> The Java code looks like this:
> String soapAction = args[0];
> String sendmsg = soapAction+".xml";
> String urlString = "http://dealer.patagonia.com/za/...
> try {
> URL url = new URL(urlString);
> HttpURLConnection httpConnection =
> (HttpURLConnection) url.openConnection();
> httpConnection.setRequestProperty("SOAPAction", soapAction);
> httpConnection.setDoOutput(true);
> httpConnection.setDoInput(true);
> httpConnection.setRequestMethod("POST");
> httpConnection.setRequestProperty("Content-Type", "text/xml");
> PrintStream httpout = new
> PrintStream(httpConnection.getOutputStream());
> BufferedReader in = new BufferedReader(new
> InputStreamReader(fis));
> /* Get first line of the outgoing message */
> String line = in.readLine();
> while (line != null) {
> System.out.println(line);
> /* Send the line to the http connection */
> httpout.print(line);
> line = in.readLine();
> System.out.println("Reading the response stream ...");
> BufferedReader in2 =
> new BufferedReader(
> new InputStreamReader(httpConnection.getInputStream()));
> System.out.println("Response:");
> String line = in2.readLine();
> while (line != null) {
> if (line.length() > 2)
> System.out.println(line);
> line = in2.readLine();
>
> I have fumbled around with Ruby HTTP but am getting nowhere.
> I would appreciate any direction you can give.
> Peter
>
>
>
>
> --
> Posted via http://www.ruby-....
>


Peter Hollenbeck

1/22/2007 5:43:00 AM

0

Nicolas H. Modrzyk wrote:
> Hey Peter,
>
> Mark Watson is the guy that put me on track the first time.
> Did you read his article?
> http://www.devx.com/enterprise/Article/28101/19...
>
> He has a SOAP section as well. That would help.
>
> Niko,

Thanks for the reference. I read the article, but it talks about web
services, not clients. Maybe one can be inferred from the other but I'm
not able to.
Peter

--
Posted via http://www.ruby-....

Peter Hollenbeck

1/22/2007 5:44:00 AM

0

Jeremy McAnally wrote:
> String sendmsg = soapAction+".xml";
>
> Ah it looks like you're using SOAP; check out the soap4r project. :)
>
> --Jeremy
>
> On 1/21/07, Peter Hollenbeck <pwhbeck@comcast.net> wrote:
>> >> Peter
>> protocol implementations but some are quite old.
>> httpConnection.setDoOutput(true);
>> System.out.println(line);
>> if (line.length() > 2)
>> --
>> Posted via http://www.ruby-....
>>
>>
>
>
> --
> My free Ruby e-book:
> http://www.humblelittlerubybook...
>
> My blogs:
> http://www.mrneigh...

Thanks. I still don't see how to send and XML message and get an XML
response. Maybe it's beyond me.
Peter

> http://www.rubyinpra...


--
Posted via http://www.ruby-....

brabuhr

1/22/2007 6:01:00 PM

0

On 1/22/07, Peter Hollenbeck <pwhbeck@comcast.net> wrote:
> Jeremy McAnally wrote:
> > String sendmsg = soapAction+".xml";
> >
> > Ah it looks like you're using SOAP; check out the soap4r project. :)
>
> Thanks. I still don't see how to send and XML message and get an XML
> response. Maybe it's beyond me.

Do you have a WSDL for the service?

http://www.zorched.net/2006/02/09/ruby-soap4r-for-web...
service = SOAP::WSDLDriverFactory.new(WSDL_URL).create_rpc_driver
service.wiredump_dev = STDOUT if $DEBUG

p service.SearchContacts(:search => 'some_name')

http://www.pranavbihari.com/articles/2005/12/02/testing-paypal-web-services-with-r...
http://www.brendonwilson.com/blog/2006/04/02/ruby-soap4r...

Peter Hollenbeck

1/22/2007 6:47:00 PM

0

Thanks to everyone for trying to help this old man. For the moment I am
giving up on this approach. I am going to have Ruby on Rails send a
request to the Java code via a file and get the response via a file. Not
elegant but it should satisfy my low volume needs - and I think I know
how to do it.

Thanks,
Peter


--
Posted via http://www.ruby-....