01: /**
02: * Copyright 2007 Jens Dietrich Licensed under the Apache License, Version 2.0 (the "License");
03: * you may not use this file except in compliance with the License.
04: * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
05: * Unless required by applicable law or agreed to in writing, software distributed under the
06: * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
07: * either express or implied. See the License for the specific language governing permissions
08: * and limitations under the License.
09: */package example.nz.org.take.compiler.userv.server;
10:
11: import java.io.*;
12: import java.net.*;
13: import javax.servlet.*;
14: import javax.servlet.http.*;
15:
16: /**
17: * Servlet implementing a very simple web service for DUI COnviction lookup.
18: * The driver id is passed to the servlet, and it returns true or false (in plain text).
19: * Drivers with an id containing 42 have a DUI conviction.
20: * @author <a href="http://www-ist.massey.ac.nz/JBDietrich/">Jens Dietrich</a>
21: */
22: public class DUILookupServlet extends HttpServlet {
23:
24: /**
25: * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
26: * @param request servlet request
27: * @param response servlet response
28: */
29: protected void doGet(HttpServletRequest request,
30: HttpServletResponse response) throws ServletException,
31: IOException {
32: response.setContentType("text/plain");
33: PrintWriter out = response.getWriter();
34: String id = request.getParameter("id");
35: out.print((id != null && id.contains("42")) ? "true" : "false");
36: }
37:
38: /**
39: * Handles the HTTP <code>POST</code> method.
40: * @param request servlet request
41: * @param response servlet response
42: */
43: protected void doPost(HttpServletRequest request,
44: HttpServletResponse response) throws ServletException,
45: IOException {
46: response.sendError(response.SC_METHOD_NOT_ALLOWED);
47: }
48:
49: /**
50: * Returns a short description of the servlet.
51: */
52: public String getServletInfo() {
53: return "servlet for DUI information lookup";
54: }
55: // </editor-fold>
56: }
|