Create a servlet that provides basic authentication

You can write a servlet that uses basic authentication to log in to PolicyCenter. You test this servlet in another procedure.

Procedure

  1. Write a Gosu class that extends the class gw.servlet.AbstractBasicAuthenticationServlet.
  2. Add the @Servlet annotation on the line before your class definition:
    @Servlet( \ path : String ->path.matches("/test(/.*)?"))
  3. Override the applicable REST method, for example, the doGet method, to do your actual work. Your method takes a servlet request object (HttpServletRequest) and a servlet response object (HttpServletResponse) as parameters.
  4. In your method, determine what work to do using the servlet request object.
    In your doGet method, write an HTTP response using the servlet response object. The following simple response sets the content MIME type and the status of the response (OK):
    resp.ContentType = "text/plain"
    resp.setStatus(HttpServletResponse.SC_OK)
    To write output text or binary data, use the Writer property of the response object.
    resp.Writer.append("I am the page " + req.PathInfo)
  5. Register the servlet class in the file:
    PolicyCenter/configuration/config/servlet/servlets.xml

    Add one <servlet> element that references the fully qualified name of your class:

    servlets xmlns="http://guidewire.com/servlet">
      <servlet class="mycompany.test.servlets.TestingServlet"/>
    servlets>

What to do next

See also