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

    Fields
    Modifier and Type
    Field
    Description
    static 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
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    Override to mimic JUnit's @After annotation.
    protected void
    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
    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 signatures
    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

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • 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 class jakarta.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 class jakarta.servlet.http.HttpServlet
      Throws:
      jakarta.servlet.ServletException
      IOException
    • beforeClass

      protected void beforeClass() throws Exception
      Override to mimic JUnit's @BeforeClass annotation.
      Throws:
      Exception
    • before

      protected void before() throws Exception
      Override to mimic JUnit's @Before annotation.
      Throws:
      Exception
    • after

      protected void after() throws Exception
      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

      public static String getResponse(URLConnection con) throws IOException
      HTTP convenience method for servlets to get a response from another servlet. Test clients should extend the TestClient class that has its own HTTP methods.
      Parameters:
      con - - the URLConnection
      Returns:
      String - response body
      Throws:
      IOException
    • sendPostData

      public static URLConnection sendPostData(URL url, Properties props) throws IOException
      HTTP convenience method for servlets to create a URLConnection and post properties to that connection. Test clients should extend the TestClient class that has its own HTTP methods.
      Parameters:
      url - - the URL to open a connection to
      props - - the properties to put into the connection input stream
      Returns:
      the connection for further testing
      Throws:
      IOException