You May Like






Subscribe to RSS through Email:

Enter your email address:



RSS Subscription

Home
Rails to Java via REST Print E-mail
Tag it:
Delicious
Digg
RedDot
Spurl
Reddit
YahooMyWeb
Technorati
Stumble

Rails to Java via REST - By Brian Leonard

Brian Leonard has written "Rails to Java via REST," detailing how he used Netbeans to write a REST service for a JPA entity bean, and used it from a Rails application: 

Since I've been studying the Rails framework, I've had an interest in integration with Java. Yes, JRuby is one possible solution, but if you have some large Java system that you want to integrate with, it' unlikely that you're just going to get the jar files to access that system's APIs. More likely is that system will expose itself as a service, and the service type du jour is REST.

So, in this entry I'm going to expose an entity class as a RESTful web service and then create a Rails client for that entity.

Setting Things Up

  • Download and install NetBeans 6.0 M10. Grab the Full distribution so you can get the Java IDE, Ruby and GlassFish.
  • Download and install the SWDP to GlassFish. This is required to create the RESTful web service.

Creating the RESTful Web Service

Here we'll expose the manufacturer table as a RESTful web service.

Create the Manufacturer Entity Class

  • Start NetBeans 6.0 and create a new Web Application named Manufacturers.
  • Right-click the project and select Entity Classes from Database.
  • Select jdbc/sample as the Data Source and MANUFACTURER as the Table (your list of available tables will be different then mine, but you should have MANUFACTURER):

  • Click Next and set the package to model.
  • Click the Create Persistence Unit button and then Create on the Create Persistence Unit dialog:

  • Click Finish to generate the Manufacturer entity class.

Create the REST Web Service from the Entity Class

  1. Right-click the project and select REST Web Services from Entity Classes
  2. Select the Manufacturer Entity Class and click Next.
  3. Set the package to rest and click Finish.

Test the REST Services

  1. Right-click the project and choose Test REST Services.
  2. This will deploy the Manufacturers application to GlassFish and launch a Test REST Services tool:

This tool is very handy for working with the RESTful interface.

The Completed Project

Manufacturers.zip

Creating the Rails REST Client

If you know REST then you know that its operations are basically the HTTP methods: POST, GET, UPDATE and DELETE, which correspond nicely to SQL's Create, Read, Update and Delete. I will implement each one in turn.

GET the Manufacturers

Create the Project

Create a new Ruby on Rails Application named manufacturer_client.

Create a Model to Represent the Manufacturer

The Manufacturer entity contains a bunch of fields. For the purposes of this tutorial, we're only going to work with a handful of them: name, email and phone.

  1. Since we're not using ActiveRecord, we're not going to run the model generator. Instead, right-click the Models folder and select New > Ruby Class.
  2. Name the class Manufacturer.
  3. Add the following code:
Read more...

 

  No Comments.

Discuss...
Next >



Who's Online

We have 13 guests online

Subscribe To

 Subscribe in RSS

Follow me...

Top 10 Most Downloaded

HTML5 Games for Phone & Tablet

Job Vacancies

  • Lowongan Kerja Sales Engineer
    Pengalaman 1-3 tahun di sales B2C dan B2BBerumur 20-32 tahunMemiliki kemampuan negosiasi dan komunikasi yang baikDapat mengikuti perkembangan pembeliBerorientasi pada targetDapat menggunakan komputer dan MS Office dengan baikDapat bekerja secara indpenden di dalam timMempunyai kepribadian ...
  • Lowongan Kerja Sales Taking Order wilayah Jakarta
    Pria/Wanita maks. 35 tahunMin. SMA/SMK/SederajatTinggal di JakartaMemiliki SIM C dan Motor PribadiMemiliki Paklaring diutamakanBerpengalaman marketing Consumer Goods min.1 tahunMempunyai BPKB Motor
  • Lowongan Kerja Sales - Banjarnegara Sigaluh
    Usia maks. 28 tahunPendidikan minimal SMK/SMA dengan nilai UAN rata-rata gt650Memiliki SIM A/CDiutamakan yang mampu mengendarai mobilTertarik dalam dunia penjualan dan pemasaranDapat bekerja dibawah tekananLokasi penempatan sesuai tempat tinggalLulusan baru silahkan melamarBersedia ditempatkan di BanjarnegaraArea ...