Integrating Google SearchWhat can you do if you need to replace one component of a complex, integrated web site? This demonstration shows how you can use ZXTM to completely outsource the search application of a website to Google, without requiring any modifications to the website content or URLs. It showcases lots of features of ZXTM in one go - TrafficScript rules, XML processing, protocol translation, request and response rewriting. OverviewComplex web sites are built from a number of different components, and lots of work goes into ensuring that a single, integrated site is presented to the customer. A web site may contain several dynamic content sources, a search application, agents to query databases and other discrete applications. Imagine a scenario where, due to a security vulnerability in one component, or because of a resourcing, acquisition or outsourcing decision, it was necessary to replace one tightly integrated component in a website. In this worked example, we're going to replace the search application running on www.zeus.com, and outsource our searches to Google instead. The demonstration will illustrate request and response inspection and rewriting, request routing, XML processing and protocol translation.
We will load-balance traffic to www.zeus.com, intercepting requests to the online search system and replacing them with SOAP requests to Google's search system (restricted to site:www.zeus.com). The SOAP XML responses are XSLTed and XPathed, then inserted into a template to give branded search results. Before you begin...This example assumes that you have access to a ZXTM machine, which has access to the internet. If you want to set this up quickly, you can skip down to the quick setup guide. You'll find it useful to upload the following files to your $ZEUSHOME/zxtm/conf/extra directory on your ZXTM machine:
You should also create a new pool, called ' Step 1 - Create the virtual serverCreate an HTTP virtual server load-balancing traffic onto
Traffic to this virtual server returns a '
This is because of our unusual 'forward proxy' configuration. Step 2 - Sort out the 'forward proxy' configurationZXTM is typically deployed as a 'reverse proxy' (i.e., right in front of the servers), and listens for traffic on behalf of the servers. In this case, we can't update the DNS for
You can now browse the site through ZXTM. ZXTM will load-balance requests across the two back-end servers, and you can even use the search application through ZXTM:
Step 3 - Send searches to googleNow, add the Intercept search request rule as a request rule.
This:
Try a search - you'll see the XML response from the google search servers in your browser.
Step 4 - Reformat the XML responseWe've converted an HTTP request to a SOAP request; we now need to convert the response back again. Add the Format google response as a response rule, and move it so that it runs before the Rewrite response links rule.
This rule:
Reload the search - you'll see a correctly formatted HTML response, in the style of www.zeus.com:
SummaryIn this example, we've illustrated a great many capabilities of ZXTM:
All made possible by the power and flexibility of ZXTM's TrafficScript language. Fast deploymentIf you want to run through this demonstration quickly, download this tar file and issue the following command:
This will create a virtual server listening on port 8000, preconfigured with the necesary rules. Verify that the virtual server is running in your Admin interface, then try browsing via port 8000 (for example, http://localhost:8000/). Use the Admin interface to disable the 'Intercept search request' and 'Format Google response' rules, and observe the effects on the search system. Comments:This public messageboard is not a forum for technical support. To report technical support problems, please contact our dedicated Support team using the instructions at the bottom of this page.
Comment from:
Ben Pinnick [Visitor]
Is it possible to insert the transformed content (eg the Google results) into a dynamic page returned from one of the "normal" application/web servers in the cluster the ZXTM is managing? I would luke to be able to insert branded XML transformed content from a distributed system into the middle of my page as shown in the example but the page itself being dynamic with placeholders to show where the remote content should go.
Many thanks
Comment from:
Owen Garrett [Zeus Dev Team]
Yes - ZXTM gives you everything you need to do something like this!
For example, get your webservers to return an html page with some sort of 'insert here' placeholder tag where you want the additional content to go. Then, use a TrafficScript response rule to process this response page:
# We only want to process html responses if( http.getResponseHeader( "Content-Type" ) != "text/html" ) break; $body = http.getResponseBody(); if( ! string.contains( $body, "<!--INSERT HERE-->" ) ) break;Note that if we call 'break', this just breaks out of the current rule. ZXTM will then send the existing response back to the client (or will process the next response rule). Let's suppose that you can retrieve your additional XML content using an HTTP GET request to http://10.100.1.1/content.aspx, and that you need to provide the original cookie data in a Cookie header: # Get the original request cookie $cookie = http.getHeader( "Cookie" ); # Send the special request to get the XML content $xml = http.request.get( "http://10.100.1.1/content.aspx", "Cookie: ".$cookie ); # Check that the remote server sent a '200 OK' response if( $1 != 200 ) break;Do whatever transformation is appropriate to the XML data, then insert the new text into the original response body: # $xsl is the XSLT stylesheet $replacement = xml.xslt.transform( $xml, $xsl ); $body = string.regexsub( $body, "<!--INSERT HERE-->", $replacement ); http.setResponseBody( $body );A couple of things to think about:
Comment from:
Eddy [Visitor]
· http://www.world-warcraft-gold.com
nicely wrriten, thanks for your info
Comment from:
Mike [Visitor]
· http://www.cheaperholidays.com/
Hello
We need to set up rewrite rules in htccess
so that http://www.cheaperholidays.com/holiday_guides.php?id=9 is made search engine friendly.
Can you advse how to convert the apache code below to the Zeus equivelent.
Options +FollowSymLinks
RewriteEngine on
RewriteRule holiday_guides-id-(.*)\.htm$ holiday_guides.php?id=$1
Thank you
Comment from:
Owen Garrett [Zeus Dev Team]
Hi Mike, The following TrafficScript rule will do the trick:
$url = http.getPath();
if( string.regexMatch( $url, "^/holiday_guides-id-(.*)\\.htm$" ) ) {
$newurl = "/holiday_guides.php?id=".string.escape( $1 );
http.setPath( $newurl );
}
Here, we use a regular expression match to test if the incoming request looks like '/holiday_guides-id-foo.htm'. If it does, we extract the 'foo' bit into the We then URL-escape the foo bit and set the URL to the new value (with 'id=foo'). So, external links (seen by a search engine) look like '/holiday_guides-id-foo.htm', but internal links (seen by your web application) look like '/holiday_guides.php?id=foo'. Note - it you're using Zeus Web Server (not ZXTM), then you'll want to look at ZWS's Request Rewriting language. Head over to the ZWS support site and take a look at the Request Rewriting examples.
Comment from:
Owen Garrett [Zeus Dev Team]
We've just updated www.zeus.com and replaced the search system (with one rather similar to the one in this article), so this demo does not work so well any more - sorry! Hang about a bit and we'll see if we can sort out a replacement target site... |
Recently...
Other Resources
|











