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
- Write a Gosu class that extends the class gw.servlet.AbstractBasicAuthenticationServlet.
-
Add the
@Servletannotation on the line before your class definition:@Servlet( \ path : String ->path.matches("/test(/.*)?")) -
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. -
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 theWriterproperty of the response object.resp.Writer.append("I am the page " + req.PathInfo) -
Register the servlet class in the file:
PolicyCenter/configuration/config/servlet/servlets.xmlAdd 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
