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