SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 323 | Next

Ola Bini

"Practical JRuby on Rails Web 2.0 Projects: Bringing Ruby on Rails to Java"

apache.org/commons/
XmlSchema/download.cgi. Also, download JDOM 1.0 from http://www.ibiblio.org/maven/
jdom/jars and Commons HTTPClient from http://www.ibiblio.org/maven/
commons-httpclient/jars. Commons HTTPClient requires Commons Codec from
http://www.ibiblio.org/maven/commons-codec/jars.
Dynamic Generation
XFire shares the same problem as SOAP4R regarding generating arbitrarily nested objects as
arguments. Because that??™s the case, we??™ll instead implement a small web service client that
fetches the conversion rates between two currencies. This code won??™t look too different from
the SOAP4R code, in fact:
require 'java'
require 'xfire-all-1.2.6.jar'
import org.codehaus.xfire.client.Client
client = Client.new(java.net.URL.new(
"http://www.webservicex.net/CurrencyConvertor.asmx?WSDL"))
results = client.invoke("ConversionRate", ["USD","SEK"].to_java)
puts 'Conversion rate: %.2f' % results[0]
This code depends on you having the xfire-all-1.2.6.jar file in the current directory.
Modify as needed. You require 'java' to get hold of the JRuby Java integration features and
then import the XFire Client class. You then create a new Client based on a URL object that
points to the WSDL file in question. Notice that the WSDL you??™re using here points to a
Microsoft .NET assembly. Isn??™t that bridging the gaps? Using Ruby to drive Java classes to
communicate with a .NET service??”neat.
You then invoke the method ConversionRate and send it a primitive Java array containing
the two currencies you want to get the rate for.


Pages:
311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335