    <rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:admin="http://webns.net/mvcb/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:content="http://purl.org/rss/1.0/modules/content/">
     <channel>
        <title>ACCU  :: Patterns in the Web</title>
        <link>https://members.accu.org/index.php/articles/1246</link>
        <description>Professionalism in Programming</description>
        <dc:language>en-us</dc:language> 
        <dc:creator>Administrator</dc:creator> 
        <admin:generatorAgent rdf:resource="http://www.xaraya.org" /> 
        <admin:errorReportsTo rdf:resource="mailto:webeditor@accu.org" />
       <sy:updatePeriod>hourly</sy:updatePeriod>
       <sy:updateFrequency>1</sy:updateFrequency>
       <docs>http://backend.userland.com/rss</docs>




<div class="xar-mod-head"><span class="xar-mod-title">Internet Topics + CVu Journal Vol 15, #5 - Oct 2003</span></div>

<table border="0" cellpadding="1" cellspacing="0">
    <tbody>
    <tr>
        <td valign="top">
            Browse in :
       </td>
       <td valign="top">

                                            <a href="https://members.accu.org/index.php/articles/">All</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c13/">Topics</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c69/">Internet</a>
<br />

                                            <a href="https://members.accu.org/index.php/articles/">All</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c76/">Journals</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c77/">CVu</a>

                     &gt;                         <a href="https://members.accu.org/index.php/articles/c106/">155</a>
<br />

                                            <a href="https://members.accu.org/index.php/articles/c69-106/">Any of these categories</a>

                    -                        <a href="https://members.accu.org/index.php/articles/c69+106/">All of these categories</a>
<br />
</td>
   </tr>
   </tbody>
</table>




<div class="xar-error">
   <p>
 <strong>Note:</strong> when you create a new publication type,
the articles module will automatically use the templates
<em>user-display-[publicationtype].xt</em>
and <em>user-summary-[publicationtype].xt</em>.
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/<em>yourtheme</em>/modules/articles . The templates will get the extension .xt there. </p>
</div>
<div class="xar-norm xar-standard-box-padding">
   <h1><strong>Title:</strong>&nbsp;Patterns in the Web</h1>
<p><strong>Author:</strong>&nbsp;</p>
<p>
<strong>Date:</strong> 03 October 2003 13:16:00 +01:00 or Fri, 03 October 2003 13:16:00 +01:00</p>
<p><strong>Summary:</strong>&nbsp;<p>During the development of a an internet based GIS system we came across the problem of maintaining session state on two separate server entities...</p></p>
<p><strong>Body:</strong>&nbsp;<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e23" id="d0e23"></a></h2>
</div>
<p>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
<tt class="literal">SessionEnd</tt> event to log a user out.</p>
<p>A graceful solution to force both sessions to end was
needed.</p>
<p>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.</p>
<p>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.</p>
<p>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.</p>
<p>The final benefit is that we can implement simple load balancing
(there are potentially several mapping servers) inside the proxy by
using the ASP <tt class="literal">Application</tt> variable to
store the address of the next server to use.</p>
<p>The technique is of course not limited to Java applets - any
TCP/IP aware component can use it.</p>
<p>The design and code for the proxy is shown below in the style of
a GOF pattern.</p>
</div>
<div class="sect1" lang="en">
<div class="titlepage">
<h2><a name="d0e47" id="d0e47"></a>PROXY</h2>
</div>
<div class="sect2" lang="en">
<div class="titlepage">
<h3><a name="d0e51" id="d0e51"></a>Intent</h3>
</div>
<p>Provide a surrogate or placeholder for another object to
access.</p>
</div>
<div class="sect2" lang="en">
<div class="titlepage">
<h3><a name="d0e56" id="d0e56"></a>Also Known As</h3>
</div>
<div class="itemizedlist">
<ul type="disc">
<li>
<p>Surrogate</p>
</li>
<li>
<p>Ambassador</p>
</li>
</ul>
</div>
</div>
<div class="sect2" lang="en">
<div class="titlepage">
<h3><a name="d0e67" id="d0e67"></a>Motivation</h3>
</div>
<p>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.</p>
</div>
<div class="sect2" lang="en">
<div class="titlepage">
<h3><a name="d0e72" id="d0e72"></a>Applicability</h3>
</div>
<div class="orderedlist">
<ol type="1">
<li>
<p>A forwarding proxy provides a web page to a client while
forwarding the processing for that request to a different web
server.</p>
</li>
<li>
<p>A protecting proxy provides a web page that includes logic to
dictate when to allow access. (This could include changing port
numbers).</p>
</li>
</ol>
</div>
</div>
<div class="sect2" lang="en">
<div class="titlepage">
<h3><a name="d0e83" id="d0e83"></a>Structure</h3>
</div>
<div><img src="/var/uploads/journals/resources/structure.png"></div>
</div>
<div class="sect2" lang="en">
<div class="titlepage">
<h3><a name="d0e88" id=
"d0e88"></a>Collaborations</h3>
</div>
<p>Proxy forwards requests onto the real subject when appropriate,
depending on the kind of proxy.</p>
</div>
<div class="sect2" lang="en">
<div class="titlepage">
<h3><a name="d0e93" id="d0e93"></a>Consequences</h3>
</div>
<p>The PROXY pattern introduces a level of indirection when
accessing an object. In a web environment this can have large
(time) overheads.</p>
</div>
<div class="sect2" lang="en">
<div class="titlepage">
<h3><a name="d0e98" id="d0e98"></a>Sample Code</h3>
</div>
<p>Ensure that the response is not cached and that all output is
buffered. <span class="emphasis"><em>Note that it is <span class=
"bold"><b>very</b></span> important that the &lt;% 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.</em></span></p>
<pre class="programlisting">
&lt;%
  Response.Buffer = True
  Response.CacheControl = &quot;Private&quot;
  Response.Expires = 0
</pre>
<p>Dimension all variables.</p>
<pre class="programlisting">
on error resume next

dim xmlHttp
set xmlHttp
     = Server.CreateObject(
           &quot;Msxml2.ServerXMLHTTP&quot;)
</pre>
<p>Construct the url to proxy. This sample only proxies <tt class=
"literal">GET</tt> parameters, but could be easily modified to
include <tt class="literal">POST</tt>.</p>
<pre class="programlisting">
dim url
url = &quot;http://a.n.other.webserver.com/scripts/gcis.dll&quot;
if(len(Request.ServerVariables(
                      &quot;QUERY_STRING&quot;)) &lt;&gt; 0) then
  url = url + &quot;?&quot; + Request.ServerVariables(
                      &quot;QUERY_STRING&quot;)
end if
</pre>
<p>Get the request.</p>
<pre class="programlisting">
xmlHttp.open &quot;GET&quot;, url, False
xmlHttp.send
</pre>
<p>If no error and the status of the request was OK.</p>
<pre class="programlisting">
if Err.number = 0 and xmlHttp.Status = 200 then
</pre>
<p>Depending upon the data type; for textual data use;</p>
<pre class="programlisting">
  ' plain text response
  Response.ContentType = &quot;text/plain&quot;
  Response.write xmlHttp.responseText
</pre>
<p>For binary data (commented out for this example as the data is
text);</p>
<pre class="programlisting">
  ' binary data (e.g. gif image)
  ' Response.ContentType = &quot;image/gif&quot;
  ' Response.binarywrite xmlHttp.responseBody
</pre>
<p>Otherwise handle any errors (you can respond with html, or even
do a <tt class="literal">Server.Transfer</tt> operation).</p>
<pre class="programlisting">
  else
    Response.write &quot;Error&quot;
  end if
</pre>
<p>Tidy up</p>
<pre class="programlisting">
  set xmlHttp = Nothing
</pre>
<p>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.</p>
<pre class="programlisting">
  Response.End
%&gt;
</pre></div>
<div class="sect2" lang="en">
<div class="titlepage">
<h3><a name="d0e155" id="d0e155"></a>Related
Patterns</h3>
</div>
<div class="itemizedlist">
<ul type="disc">
<li>
<p>ADAPTER</p>
</li>
<li>
<p>DECORATOR</p>
</li>
</ul>
</div>
</div>
</div>
</p>
<p><strong>Notes:</strong>&nbsp;</p>
<p><em>More fields may be available via dynamicdata ..</em></p>
</div>
</channel>
</rss>
