Message-ID: <1380192922.4843.1369476204966.JavaMail.email@example.com> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_4842_1615901612.1369476204966" ------=_Part_4842_1615901612.1369476204966 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html
The jetty infrastructure can be use to test servlets with an embedded se= rver configured by the ServletTester class. The HTTP requests and responses for testing can b= e generated and parsed with the HttpTester class.
The embedded server uses a special local connector, and thus avoids the = need to open sockets in order to test the servlet.
An example of a test harness that uses these classes is ServletTest.= p>
The ServletTester= a> can configure a single context. Servlets and Filters may be added to the= context by class name or class instance. Context attributes, a resource b= ase or a classloader may optionally be set. eg.
The ServletTester takes a string containing requests and
returns a string containing the corresponding responses (eventually byte ar= rays will be supported for testing character encoding and binary content). = More than one request can be pipelined and multiple responses will be retu= rned if persistent connection conditions are met. eg.
Dealing with raw HTTP can be a bit verbose and difficult to test non pro= tocol aspects. The HttpTe= ster class allows for simple generation of requests and parsing of resp= onse (it can also parse requests and generate responses). eg.
Once setup, the HttpTester instances may be reused and only the parts th=
at change need to be
set for subsequent requests. eg.