Hi, folks! I''m putting together a Rails application that uses a Java server for a lot of its application logic and model retrieval. The Java server provides calls over HTTP that return XML documents. The documents either contain model information in a form like <user id="9BE15D1E-1D51-468F-9D7F-01A543A84DF8"> <firstName>Evan</firstName> <lastName>DiBiase</lastName> <email>edibiase-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org</email> </user> or they contain result information, like <error type="NoSuchUser" /> I''m putting together the framework for interacting with this server, and I''d like to learn as much as possible from others who have done similar things or who are more experienced with models and controllers in Rails than I am. For example, what''s the appropriate Rails class to handle communication with the server? Classically, I''d put that kind of functionality in a controller-esque class, but Rails clearly has a different notion of "controller" than I mean. Is the right thing to create a ServerController class that doesn''t extend ActionController and that lives in the lib directory? Also, I''m not quite sure what to do about model classes. I love the design of ActiveRecord, but it seems unsuitable for communicating in a read-only way with a Java server over HTTP that provides XML. Should the model classes know about my proposed ServerController, or should all calls to acquire a model go through ServerController from other controllers only? I have a lot of questions, and find myself not holding very many of the answers. Any advice would be appreciated! Thanks, Evan
Evan- I use a few model that communicate in a read only way from a remote cgi server that sounds similar to what you want to do. Here is what a model for your needs could look like: require ''net/http'' require ''uri'' class Page < ActiveRecord::Base def self.fetch(page, limit=5) begin data = Net::HTTP.get_response(URI.parse("http:// yourjavaserver.com/#{page}")) rescue Exception => e limit -= 1 limit > 0 ? retry : raise end return data.body end end Put the filke (page.rb) in your models directory. This will attempt to fetch the xml data from your java http xml server 5 times before giving up. You can override the limit by adding and extra parameter to the call to Page.fetch Then in your controller you can use it like this: class PageController < ApplicationController def java_xml_data @xml = Page.fetch("java/xml/server/page") # Process your @xml data here and send @xml to the view end end This way you stay in the general rails style of model/controller/ view. HTH - -Ezra Zygmuntowicz Yakima Herald-Republic WebMaster 509-577-7732 ezra-gdxLOakOTQ9oetBuM9ipNAC/G2K4zDHf@public.gmane.org On Sep 9, 2005, at 10:58 AM, Evan DiBiase wrote:> Hi, folks! > > I''m putting together a Rails application that uses a Java server > for a lot of its application logic and model retrieval. The Java > server provides calls over HTTP that return XML documents. The > documents either contain model information in a form like > > <user id="9BE15D1E-1D51-468F-9D7F-01A543A84DF8"> > <firstName>Evan</firstName> > <lastName>DiBiase</lastName> > <email>edibiase-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org</email> > </user> > > or they contain result information, like > > <error type="NoSuchUser" /> > > I''m putting together the framework for interacting with this > server, and I''d like to learn as much as possible from others who > have done similar things or who are more experienced with models > and controllers in Rails than I am. > > For example, what''s the appropriate Rails class to handle > communication with the server? Classically, I''d put that kind of > functionality in a controller-esque class, but Rails clearly has a > different notion of "controller" than I mean. Is the right thing to > create a ServerController class that doesn''t extend > ActionController and that lives in the lib directory? > > Also, I''m not quite sure what to do about model classes. I love the > design of ActiveRecord, but it seems unsuitable for communicating > in a read-only way with a Java server over HTTP that provides XML. > Should the model classes know about my proposed ServerController, > or should all calls to acquire a model go through ServerController > from other controllers only? > > I have a lot of questions, and find myself not holding very many of > the answers. Any advice would be appreciated! > > Thanks, > Evan > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
On more note on the solution I sent earlier. You do not need to inherit from ActiveRecord::Base. the Page < ActiveRecord::Base model coould just be class Page. HTH -Ezra On Sep 9, 2005, at 10:58 AM, Evan DiBiase wrote:> Hi, folks! > > I''m putting together a Rails application that uses a Java server > for a lot of its application logic and model retrieval. The Java > server provides calls over HTTP that return XML documents. The > documents either contain model information in a form like > > <user id="9BE15D1E-1D51-468F-9D7F-01A543A84DF8"> > <firstName>Evan</firstName> > <lastName>DiBiase</lastName> > <email>edibiase-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org</email> > </user> > > or they contain result information, like > > <error type="NoSuchUser" /> > > I''m putting together the framework for interacting with this > server, and I''d like to learn as much as possible from others who > have done similar things or who are more experienced with models > and controllers in Rails than I am. > > For example, what''s the appropriate Rails class to handle > communication with the server? Classically, I''d put that kind of > functionality in a controller-esque class, but Rails clearly has a > different notion of "controller" than I mean. Is the right thing to > create a ServerController class that doesn''t extend > ActionController and that lives in the lib directory? > > Also, I''m not quite sure what to do about model classes. I love the > design of ActiveRecord, but it seems unsuitable for communicating > in a read-only way with a Java server over HTTP that provides XML. > Should the model classes know about my proposed ServerController, > or should all calls to acquire a model go through ServerController > from other controllers only? > > I have a lot of questions, and find myself not holding very many of > the answers. Any advice would be appreciated! > > Thanks, > Evan > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-Ezra Zygmuntowicz Yakima Herald-Republic WebMaster 509-577-7732 ezra-gdxLOakOTQ9oetBuM9ipNAC/G2K4zDHf@public.gmane.org
I''d approach this by writing a class like ActiveRecord::Base which wraps around the server and provides ruby objects which resemble the java data model. Then define models for the objects (to add application logic to them, if any), and reference them using the model meta-method in the controllers in which they are relevant. I would try and encapsulate the java/xml server as much as possible and make your model objects appear much like any others in rails. The controller/view don''t really make assumptions about what model objects are, but it will increase clarity all around if the interface for accessing these objects is relatively consistent (i.e. MySpecialRecord::Base#find, etc.) Small world, by the way. Brian On 9/9/05, Evan DiBiase <edibiase-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, folks! > > I''m putting together a Rails application that uses a Java server for > a lot of its application logic and model retrieval. The Java server > provides calls over HTTP that return XML documents. The documents > either contain model information in a form like > > <user id="9BE15D1E-1D51-468F-9D7F-01A543A84DF8"> > <firstName>Evan</firstName> > <lastName>DiBiase</lastName> > <email>edibiase-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org</email> > </user> > > or they contain result information, like > > <error type="NoSuchUser" /> > > I''m putting together the framework for interacting with this server, > and I''d like to learn as much as possible from others who have done > similar things or who are more experienced with models and > controllers in Rails than I am. > > For example, what''s the appropriate Rails class to handle > communication with the server? Classically, I''d put that kind of > functionality in a controller-esque class, but Rails clearly has a > different notion of "controller" than I mean. Is the right thing to > create a ServerController class that doesn''t extend ActionController > and that lives in the lib directory? > > Also, I''m not quite sure what to do about model classes. I love the > design of ActiveRecord, but it seems unsuitable for communicating in > a read-only way with a Java server over HTTP that provides XML. > Should the model classes know about my proposed ServerController, or > should all calls to acquire a model go through ServerController from > other controllers only? > > I have a lot of questions, and find myself not holding very many of > the answers. Any advice would be appreciated! > > Thanks, > Evan > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- The years ahead pick up their dark bags. They move closer. There''s a slight rise in the silence then nothing. -- (If you''re receiving this in response to mail sent to bluczkie-OM76b2Iv3yLQjUSlxSEPGw@public.gmane.org, don''t be concerned This is my new address, but mail will be forwarded here indefinitely)