You are not logged in Log in Join
You are here: Home » Members » antonio » How to get an external page or piece of content (given the URL) included to your template (DTML or ZPT) with a timeout in seconds.

Log in
Name

Password

 

How to get an external page or piece of content (given the URL) included to your template (DTML or ZPT) with a timeout in seconds.

This how-to will help you get external content to you Zope on request without struggling with XMLRPC or SOAP (which in some cases are overkill techonolgies). This approach is very simple and does not offers the fexibility of XMLRPC/SOAP but gives you a simple way to recieve information from other servers to your server with a simple call and timeout. We use of course HTTP as transport protocol.

I'll give you a practical example. Suppose you have one webserver showing some information about your company's affiliates. And another server showing contact information and accomodations in the neighberhood of the affiliates cities. You don't have direct access to the DB where this information is stored. Then you can create a dtml-document/method that contains both informations in the same page:

<dtml-var "URLSuck('http://server1/companyaffiliates',5)">
<dtml-var "URLSuck('http://server2/companyaccomodation',5)">

This code will result in a page where both the companies affiliates adresses is shown and below the accomodation info. All in a single page, without the need of frames, rewriting database queries or redo any already present buesneess logic. What we do is integration and presentation of splittered information that from a user point of view should be together.

The second argument means 5 second timeout. We wait 5 seconds for the response.

If timeout occurs (404 or any other remote servers errors) than empty string is returned. You can then check the empty string and show timeout information if you like.

To avoid timeout you can allways configure the cache (see the Zope RAM Cache Manager) on your server so that later retrievial are much faster

The timeout works thanks to the implementation of urllib2.urlopen in a threaded version. See the source code of attached library (URLSucker.py) for more details.

With this approach you can show any result from any external server on your pages!