Class TestServlet
java.lang.Object
jakarta.servlet.GenericServlet
jakarta.servlet.http.HttpServlet
ee.jakarta.tck.concurrent.framework.TestServlet
- All Implemented Interfaces:
jakarta.servlet.Servlet
,jakarta.servlet.ServletConfig
,Serializable
- Direct Known Subclasses:
AnnotationServlet
,ClassloaderServlet
,ContextServiceDefinitionFromEJBServlet
,ContextServiceDefinitionServlet
,DeploymentDescriptorServlet
,JNDIServlet
,JSPSecurityServlet
,ManagedExecutorDefinitionOnEJBServlet
,ManagedExecutorDefinitionServlet
,ManagedScheduledExecutorDefinitionOnEJBServlet
,ManagedScheduledExecutorDefinitionServlet
,ManagedThreadFactoryDefinitionOnEJBServlet
,ManagedThreadFactoryDefinitionServlet
,ProxyCreatorServlet
,SecurityServlet
,SecurityServlet
,SecurityServlet
,SecurityServlet
,TransactionServlet
,TransactionServlet
,TransactionServlet
,TransactionServlet
,VirtualThreadServlet
public class TestServlet
extends jakarta.servlet.http.HttpServlet
Standard superclass for test servlets that accepts a `testMethod` parameter
to the doGet / doPost methods that will attempt to run that method on the
subclass.
The doGet / doPost methods will append `SUCCESS` to the response if the test
is successfully. Otherwise, SUCCESS will not be appended to the response.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
static final String
static final String
static final String
Fields inherited from class jakarta.servlet.http.HttpServlet
LEGACY_DO_HEAD
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected void
after()
Override to mimic JUnit's@After
annotation.protected void
before()
Override to mimic JUnit's@Before
annotation.protected void
Override to mimic JUnit's@BeforeClass
annotation.protected void
doGet
(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) protected void
doPost
(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) static String
getResponse
(URLConnection con) HTTP convenience method for servlets to get a response from another servlet.protected void
invokeTest
(String method, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) Implement this method for custom test invocation, such as specific test method signaturesstatic URLConnection
sendPostData
(URL url, Properties props) HTTP convenience method for servlets to create a URLConnection and post properties to that connection.Methods inherited from class jakarta.servlet.http.HttpServlet
doDelete, doHead, doOptions, doPatch, doPut, doTrace, getLastModified, init, isSensitiveHeader, service, service
Methods inherited from class jakarta.servlet.GenericServlet
destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log
-
Field Details
-
nl
-
SUCCESS
- See Also:
-
FAILURE
- See Also:
-
TEST_METHOD
- See Also:
-
-
Constructor Details
-
TestServlet
public TestServlet()
-
-
Method Details
-
doPost
protected void doPost(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) throws jakarta.servlet.ServletException, IOException - Overrides:
doPost
in classjakarta.servlet.http.HttpServlet
- Throws:
jakarta.servlet.ServletException
IOException
-
doGet
protected void doGet(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) throws jakarta.servlet.ServletException, IOException - Overrides:
doGet
in classjakarta.servlet.http.HttpServlet
- Throws:
jakarta.servlet.ServletException
IOException
-
beforeClass
Override to mimic JUnit's@BeforeClass
annotation.- Throws:
Exception
-
before
Override to mimic JUnit's@Before
annotation.- Throws:
Exception
-
after
Override to mimic JUnit's@After
annotation.- Throws:
Exception
-
invokeTest
protected void invokeTest(String method, jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response) throws Exception Implement this method for custom test invocation, such as specific test method signatures- Throws:
Exception
-
getResponse
HTTP convenience method for servlets to get a response from another servlet. Test clients should extend theTestClient
class that has its own HTTP methods.- Parameters:
con
- - the URLConnection- Returns:
- String - response body
- Throws:
IOException
-
sendPostData
HTTP convenience method for servlets to create a URLConnection and post properties to that connection. Test clients should extend theTestClient
class that has its own HTTP methods.- Parameters:
url
- - the URL to open a connection toprops
- - the properties to put into the connection input stream- Returns:
- the connection for further testing
- Throws:
IOException
-