I developed a web site using rails 2.3.8, and a IM server using openfire(java). I want to share some data between them, or exactly rails as provider, openfire as consumer. A possible way is using web service. But it seems that rails 2.x has deprecated the default SOAP support, I installed the gem activewebservice, but there is lack of documents to show how to using it. I googled an example in IBM's site, but there seems something wrong to follow this guide in rails 2.3.8. Can anyone give me an example?
I know there is another way to provide the web service is using rails' default RESTful-type web service, but how to configure the java side to support this?
Rails has support for RESTful web-services OOTB, so if you have developed your rails application using scaffold generator then your application is already providing a RESTful API. Now as your IM server is the consumer, all you have to do is to make your IM server call the RESTful API provided by the rails application.
Calling RESTful API means sending HTTP (GET/POST/PUT/DELETE) requests to the REST server(Rails App). So all you need to do, is plugin some java code to the openfire server which will send the HTTP requests adhering to the REST conventions and send/receive data in a suitable serialization format(XML/JSON/etc). There is a plugin mechanism in openfire which which probably may help you achieve this.
As far as RESTful calls are concerned, this can be achieved in any of the below methods:
Use a REST Client library provided by JAX-RS implementations like Jersey, Apache wink, etc.
Use any HTTP client library to send/receive HTTP requests/response and a XML/JSON/etc library to serialize/de-serialize the data.
Related
I have an existing RoR web application which currently uses Devise for authentication.
I am planning on adding API functionality in one manner or another for a mobile backend.
Would you recommend adding API functionality to the web application and using JWT, for example, to enable mobile authentication. Alternatively, would you have two separate applications, a web application and an API, sharing the same Postgres instance on Heroku?
I see pros and cons both ways, but it would seem to me that separating it into two applications would outweigh adding API functionality to the web app. Perhaps, it would make most sense to start over with just an API and add mobile app client and web application client functionality.
Creating a new API only backend might be easier at first, but you would have to copy all your app logic in the models over and keeping both sides up to date will be a pain. You can do it in the same rails app if you namespace the new API so that all calls are under a /api_v1 or something like that. Here is an article that show how you can have different versions of your API.
JWTs for authentication is a great way of doing it and Devise can support them by adding a gem like devise-jwt since adding a route and handling the creation and updating of tokens by yourself is a lot of work.
For the API itself you might want to consider using JSON:API with the jsonapi-rails gem or GraphQL with the graphql gem. This way when someone wants to use your API they can use an adapter for their framework that can talk to that kind of API and not have to worry about the structure of what it returns. There are adapters for both APIs that work with Andrioid, IOS, Ember, React, and all other major frontend frameworks.
We have a Rails app that acts HTTP API only. On the client side, Ember.js is currently used. We are not overly impressed by Ember and really like the approach Meteor.js takes. So we'd like to exchange the client side with Meteor.js and communicate with the Rails server via websockets that speak the Data Distribution Protocol (DDP), so we can keep using the models, mailers and controllers in Rails. Implementing server side of DDP should be easy.
However, we're unsure how to make Rails talk websockets. We found Reel, which seems to make it easy to accept websocket requests in a standalone environment. Reel seems great as we'd like to implement the DDP on top of the Celluloid stack anyway. But what about running Reel in the Rails environment? Would we need "rails runner" for that? And we'd like to keep using the existing controllers to dispatch incoming requests (like, to add/change/remove resources). Is that even possible without having the request coming through Rack?
Any input is appreciated.
It's a bit late, but I've implemented DDP in Ruby, you can check it out here:
https://github.com/d-snp/ruby-ddp-server
It includes an implementation of EJSON as well. It's built on top of celluloid-websocket, and can be ran simply as a rack app.
I've made an integration with RethinkDB that can be used as a reference to build your own collections implementation.
https://github.com/d-snp/ruby-ddp-server-rethinkdb
I've also made a sample chat application that can be found here:
https://github.com/d-snp/celluloid-rethinkdb-chat
It's something that I have been longing to do as well, to integrate old "legacy" Rails code. Here is the best way I have found:
Since you would not be using any of Rails router/controller/views, but just the ability to read data and push it to the client, I recommend you use Rails to create JSON apis to the database, and deploy the code, then in Meteor you can consume the data via the http package, this would happen on the server at a regular interval and populate the MongoDB with the normalized data you need, then it would serve the browser client.
I am working on such an application that will keep a normalized version of the data in Mongo, and a relational version of the data in mySql (through Rails) this way I can preserve the legacy Rails functionality that I dont want to rewrite in JS, and get the benefit of Meteor for the one page that I need it most.
Is it possible to write soap based web services using ruby on rails framework. If yes, can someone please point to a learning resource
Yes, you can write SOAP web services using Rails, However Rails is moving in favour of a REST web service approach. So my personal opinion is if you are starting a brand new Rails app with SOAP web services, consider some other programming language like JAVA, because that has more tools to easily create SOAP web services.
But nowadays all the webservices going towards REST, because of the simplicity it has. Almost all major sites has a REST API.
Furthermore if you are still planning to go ahead with Rails, savon is an interesting gem that you should probably look at.
I'm developing a new website which is going to include web API. What I want to know is how easy (or hard) is it to develop the server side oAUTH service into my new website?
I'm using OE11.0 WebSpeed in combination with Apache. Because I'be been doing Progress/OpenEdge 4GL/ABL development for over 10 years and nothing else I find very hard to translate existing code like, PHP, Python, Java etc.
I've read the RFC related to oAUTH and I find my self get lost in "key-varner".
Has anybody develop a oAUTH server side code in OpenEdge WebSpeed? If so, are you willing to share?
The CLR bridge works in OE 11 onwards now and we use .NET dll's in webspeed sucessfully.
I think your best bet is to do this outside of Webspeed / ABL, otherwise you are stuck re-inventing the wheel. The easiest solution would be to call a .NET library directly from your ABL code but I think that the CLR bridge doesn't work for Webspeed / Appserver apps.
One solution is to have a separate, non-Webspeed app just to handle these oAUTH requests, using a ProxyPass directive on your Apache server to pattern match the URIs and route the requests to the appropriate app.
You could use any non-Webspeed tech. you want, but since I know Ruby best, I will point out the excellent omniauth gem, which supports arbitrary authentication strategies, including oAUTH. You can create a custom gem for your specific provider by working off of any of these strategies (see the "Notes" section and look at any of them that cite "OAuth API" or "OAuth 2 API").
If you want to go whole hog and write the entire app in a different language (yet still using an OpenEdge database), I will toot my own horn and point out the Ruby adapter for OpenEdge databases. This would allow you to use the Ruby on Rails framework for your Web app.
I am successfully using Ruby with Savon to communicate with a set of SOAP services, but it turns out that in order to send and receive attachments the service expects them to use DIME encapsulation. Has anyone managed this using Ruby? If not, what would be a recommended way to approach this problem? This communication is only one part of a Rails application, so ideally the solution would be integrated with the rest of the application.