paulb@654 | 1 | <?xml version="1.0" encoding="iso-8859-1"?> |
paulb@349 | 2 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
paulb@556 | 3 | <html xmlns="http://www.w3.org/1999/xhtml"><head> |
paulb@654 | 4 | <title>Writing Adapters</title> |
paulb@556 | 5 | <link href="styles.css" rel="stylesheet" type="text/css" /></head> |
paulb@330 | 6 | <body> |
paulb@330 | 7 | <h1>Writing Adapters</h1> |
paulb@361 | 8 | <p>Depending on how "simple" the |
paulb@361 | 9 | adapter code is allowed to be for a |
paulb@349 | 10 | given |
paulb@361 | 11 | server environment (see the <a href="#table">table</a> |
paulb@361 | 12 | for a |
paulb@330 | 13 | summary), you will either need to write a small piece of code which |
paulb@349 | 14 | initialises and deploys your application, or to produce a more |
paulb@349 | 15 | complicated |
paulb@330 | 16 | piece of code which satisfies some more demanding server requirements.</p> |
paulb@361 | 17 | <h2>Simple Adapters - Using the |
paulb@361 | 18 | deploy Function</h2> |
paulb@361 | 19 | <p>When deploying an application, |
paulb@361 | 20 | it is possible to use a one-shot |
paulb@349 | 21 | deployment |
paulb@654 | 22 | function for BaseHTTPRequestServer, CGI, Django, Java Servlet, mod_python, Twisted and WSGI configurations. The |
paulb@361 | 23 | <code>deploy</code> |
paulb@361 | 24 | function is called as follows:</p> |
paulb@349 | 25 | <pre>deploy(resource)<br />deploy(resource, authenticator) # where authenticators are used</pre> |
paulb@361 | 26 | <p>For some frameworks, an address |
paulb@361 | 27 | may be specified:</p> |
paulb@349 | 28 | <pre>deploy(resource, address=(host_string, port_integer))<br />deploy(resource, authenticator, address=(host_string, port_integer))</pre> |
paulb@556 | 29 | <p>And for some frameworks, the return value of the function is important:</p><pre>something = deploy(resource)<br />something, something_else = deploy(resource, authenticator)</pre><p>Here is a summary of which |
paulb@654 | 30 | frameworks require address information and which produce important return values from the <code>deploy</code> function:</p> |
paulb@330 | 31 | <table border="1" cellpadding="5" cellspacing="0"> |
paulb@330 | 32 | <tbody> |
paulb@330 | 33 | <tr> |
paulb@330 | 34 | <th>Framework</th> |
paulb@556 | 35 | <th>Address Information</th><th>Return Values</th> |
paulb@330 | 36 | </tr> |
paulb@330 | 37 | <tr> |
paulb@330 | 38 | <td>BaseHTTPRequestHandler</td> |
paulb@556 | 39 | <td>Supported</td><td align="undefined" valign="undefined"></td> |
paulb@330 | 40 | </tr> |
paulb@330 | 41 | <tr> |
paulb@330 | 42 | <td>CGI</td> |
paulb@556 | 43 | <td>Ignored</td><td align="undefined" valign="undefined"></td> |
paulb@330 | 44 | </tr> |
paulb@556 | 45 | <tr><td align="undefined" valign="undefined">Django</td><td align="undefined" valign="undefined">Ignored</td><td align="undefined" valign="undefined">Handler function</td></tr><tr><td align="undefined" valign="undefined">Java Servlet</td><td align="undefined" valign="undefined">Ignored</td><td align="undefined" valign="undefined">Servlet class</td></tr><tr><td align="undefined" valign="undefined">mod_python</td><td align="undefined" valign="undefined">Ignored</td><td align="undefined" valign="undefined">Handler function and authenticator function (a 2-tuple)</td></tr><tr> |
paulb@330 | 46 | <td>Twisted</td> |
paulb@361 | 47 | <td>Supported (<code>host_string</code> |
paulb@556 | 48 | is ignored)</td><td align="undefined" valign="undefined"></td> |
paulb@330 | 49 | </tr> |
paulb@556 | 50 | <tr><td align="undefined" valign="undefined">Webware (> 0.8.1)</td><td align="undefined" valign="undefined">Ignored</td><td align="undefined" valign="undefined">URL context object</td></tr><tr> |
paulb@330 | 51 | <td>WSGI</td> |
paulb@556 | 52 | <td>Ignored</td><td align="undefined" valign="undefined"></td> |
paulb@330 | 53 | </tr> |
paulb@330 | 54 | </tbody> |
paulb@330 | 55 | </table> |
paulb@361 | 56 | <h3>Debugging Applications</h3> |
paulb@361 | 57 | <p>Sometimes, when resources throw unhandled exceptions when processing |
paulb@361 | 58 | requests, it is desirable to see the details of the exceptions either |
paulb@361 | 59 | in the Web browser or in the console from which the application was |
paulb@654 | 60 | started. For such purposes, a parameter to the <code>deploy</code> |
paulb@361 | 61 | function can be used:</p> |
paulb@361 | 62 | <pre>deploy(resource, handle_errors=0)</pre> |
paulb@654 | 63 | <p>The <code>handle_errors</code> parameter, if specified with a |
paulb@361 | 64 | false value, will not supress unhandled exceptions with an "internal |
paulb@361 | 65 | server error" response, but will instead provide the underlying server |
paulb@361 | 66 | environment's report of such exceptions.</p> |
paulb@361 | 67 | <h2><a name="table">Complicated Adapters - |
paulb@361 | 68 | Providing |
paulb@361 | 69 | Framework-Specific Objects</a></h2> |
paulb@361 | 70 | <p>The remaining frameworks (Java |
paulb@361 | 71 | Servlet, |
paulb@361 | 72 | mod_python, Webware and |
paulb@349 | 73 | Zope) do |
paulb@361 | 74 | not support the <code>deploy</code> |
paulb@361 | 75 | function due to the way |
paulb@349 | 76 | applications are |
paulb@349 | 77 | typically integrated into the various server mechanisms. In these |
paulb@349 | 78 | cases, it |
paulb@349 | 79 | may be worth investigating the examples provided and using their |
paulb@349 | 80 | adapter code |
paulb@349 | 81 | as a template for the code for your own applications. Here is a summary |
paulb@349 | 82 | which |
paulb@349 | 83 | indicates the server environments or frameworks which need most work:</p> |
paulb@349 | 84 | <table border="1" cellpadding="5" cellspacing="0"> |
paulb@349 | 85 | <tbody> |
paulb@349 | 86 | <tr> |
paulb@349 | 87 | <th>Framework</th> |
paulb@349 | 88 | <th>Adapter Code Requirements</th> |
paulb@349 | 89 | <th>Deployment Process</th> |
paulb@349 | 90 | </tr> |
paulb@349 | 91 | <tr> |
paulb@349 | 92 | <td>BaseHTTPRequestHandler</td> |
paulb@349 | 93 | <td>Simple - see above</td> |
paulb@361 | 94 | <td>Run the adapter code |
paulb@361 | 95 | directly</td> |
paulb@349 | 96 | </tr> |
paulb@349 | 97 | <tr> |
paulb@349 | 98 | <td>CGI</td> |
paulb@349 | 99 | <td>Simple - see above</td> |
paulb@361 | 100 | <td>Web server runs the |
paulb@361 | 101 | adapter code</td> |
paulb@349 | 102 | </tr> |
paulb@556 | 103 | <tr><td align="undefined" valign="undefined">Django</td><td align="undefined" valign="undefined">Simple - see above</td><td align="undefined" valign="undefined">The adapter prepares the handler function</td></tr><tr> |
paulb@349 | 104 | <td>Java Servlet</td> |
paulb@556 | 105 | <td><span style="font-family: monospace;"></span><code></code>Simple - see above</td> |
paulb@556 | 106 | <td>The adapter prepares the servlet class</td> |
paulb@349 | 107 | </tr> |
paulb@349 | 108 | <tr> |
paulb@349 | 109 | <td>mod_python</td> |
paulb@556 | 110 | <td><span style="font-family: monospace;"></span><code></code>Simple - see above</td> |
paulb@556 | 111 | <td>The adapter prepares the handler function</td> |
paulb@349 | 112 | </tr> |
paulb@349 | 113 | <tr> |
paulb@349 | 114 | <td>Twisted</td> |
paulb@349 | 115 | <td>Simple - see above</td> |
paulb@361 | 116 | <td>Run the adapter code |
paulb@361 | 117 | directly</td> |
paulb@349 | 118 | </tr> |
paulb@349 | 119 | <tr> |
paulb@349 | 120 | <td>Webware</td> |
paulb@361 | 121 | <td><= 0.8.1: Must |
paulb@361 | 122 | implement <code>InstallInWebKit</code> |
paulb@349 | 123 | function<br /> |
paulb@556 | 124 | > 0.8.1: Simple - see above</td> |
paulb@361 | 125 | <td>Application must be |
paulb@361 | 126 | deployed within WebKit</td> |
paulb@349 | 127 | </tr> |
paulb@349 | 128 | <tr> |
paulb@349 | 129 | <td>WSGI</td> |
paulb@349 | 130 | <td>Simple - see above</td> |
paulb@361 | 131 | <td>Web server runs the |
paulb@361 | 132 | adapter code</td> |
paulb@349 | 133 | </tr> |
paulb@349 | 134 | <tr> |
paulb@349 | 135 | <td>Zope</td> |
paulb@361 | 136 | <td>Must provide lots of |
paulb@361 | 137 | Zope administative classes and functions</td> |
paulb@361 | 138 | <td>Application must be |
paulb@361 | 139 | deployed within Zope</td> |
paulb@349 | 140 | </tr> |
paulb@349 | 141 | </tbody> |
paulb@349 | 142 | </table> |
paulb@361 | 143 | <p>See <a href="deploying-applications.html">"Deploying an |
paulb@361 | 144 | Application"</a> |
paulb@349 | 145 | for more details of the deployment process for each environment.</p> |
paulb@654 | 146 | </body></html> |