Journal Articles
Browse in : |
All
> Journals
> CVu
> 155
(10)
All > Topics > Internet (35) Any of these categories - All of these categories |
Note: when you create a new publication type, the articles module will automatically use the templates user-display-[publicationtype].xt and user-summary-[publicationtype].xt. If those templates do not exist when you try to preview or display a new article, you'll get this warning :-) Please place your own templates in themes/yourtheme/modules/articles . The templates will get the extension .xt there.
Title: Patterns in the Web
Author: Administrator
Date: 03 October 2003 13:16:00 +01:00 or Fri, 03 October 2003 13:16:00 +01:00
Summary:
During the development of a an internet based GIS system we came across the problem of maintaining session state on two separate server entities...
Body:
During the development of a an internet based GIS system we came across the problem of maintaining session state on two separate server entities - the website (the application itself) and the mapping server through which the mapping component (a Java Applet embedded in the application) communicates. With our initial architecture, there was the possibility for the website session to timeout while the mapping session remained active. The consequence of this was the website session timeout had to be set to as high as possible a value to minimise the occurrence of this situation, which is a problem in our system due to the fact we are restricting clients to a certain number of concurrent logins and using the ASP SessionEnd event to log a user out.
A graceful solution to force both sessions to end was needed.
The solution came in the shape of the GOF PROXY pattern, which although it is a very simple and well known idea, its application is not immediately obvious in an IIS/ASP environment.
In summary the Java Applet makes requests to the proxy (an ASP page) which forwards the request on to the appropriate CGI programme on the mapping server and conversely feeds the response back to the applet. If the web session times out we can prevent requests going through the proxy. We can also return some text representing an error to the applet, which can close down gracefully.
This solution also has the benefit of allowing us to simplify general error handling in the applet itself. Any errors in making requests to the mapping server can be trapped inside the proxy page and fed to the applet in a more friendly or standardised way.
The final benefit is that we can implement simple load balancing (there are potentially several mapping servers) inside the proxy by using the ASP Application variable to store the address of the next server to use.
The technique is of course not limited to Java applets - any TCP/IP aware component can use it.
The design and code for the proxy is shown below in the style of a GOF pattern.
It may be a requirement to hive off some heavy processing from the main web server without losing the advantages of having a single web server as a point of contact.
-
A forwarding proxy provides a web page to a client while forwarding the processing for that request to a different web server.
-
A protecting proxy provides a web page that includes logic to dictate when to allow access. (This could include changing port numbers).
Proxy forwards requests onto the real subject when appropriate, depending on the kind of proxy.
The PROXY pattern introduces a level of indirection when accessing an object. In a web environment this can have large (time) overheads.
Ensure that the response is not cached and that all output is buffered. Note that it is very important that the <% be the first lines in the file, especially when binary data may be proxied, as any leading data may corrupt what you are trying to proxy.
<% Response.Buffer = True Response.CacheControl = "Private" Response.Expires = 0
Dimension all variables.
on error resume next dim xmlHttp set xmlHttp = Server.CreateObject( "Msxml2.ServerXMLHTTP")
Construct the url to proxy. This sample only proxies GET parameters, but could be easily modified to include POST.
dim url url = "http://a.n.other.webserver.com/scripts/gcis.dll" if(len(Request.ServerVariables( "QUERY_STRING")) <> 0) then url = url + "?" + Request.ServerVariables( "QUERY_STRING") end if
Get the request.
xmlHttp.open "GET", url, False xmlHttp.send
If no error and the status of the request was OK.
if Err.number = 0 and xmlHttp.Status = 200 then
Depending upon the data type; for textual data use;
' plain text response Response.ContentType = "text/plain" Response.write xmlHttp.responseText
For binary data (commented out for this example as the data is text);
' binary data (e.g. gif image) ' Response.ContentType = "image/gif" ' Response.binarywrite xmlHttp.responseBody
Otherwise handle any errors (you can respond with html, or even do a Server.Transfer operation).
else Response.write "Error" end if
Tidy up
set xmlHttp = Nothing
Send the response and ignore any other instructions on this page. This is especially important when sending binary data as any further data may corrupt what you are attempting to proxy.
Response.End %>
Notes:
More fields may be available via dynamicdata ..