View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.syncope.fit.buildtools;
20  
21  import java.io.IOException;
22  import java.io.PrintWriter;
23  import javax.servlet.ServletException;
24  import javax.servlet.annotation.WebServlet;
25  import javax.servlet.http.HttpServlet;
26  import javax.servlet.http.HttpServletRequest;
27  import javax.servlet.http.HttpServletResponse;
28  
29  /**
30   * Just used to verify a connector request timeout.
31   */
32  @WebServlet(urlPatterns = "/services/")
33  public class ServiceTimeoutServlet extends HttpServlet {
34  
35      private static final long serialVersionUID = -1467488672392710293L;
36  
37      /**
38       * Processes requests for both HTTP
39       * {@code GET} and
40       * {@code POST} methods.
41       *
42       * @param request servlet request
43       * @param response servlet response
44       * @throws ServletException if a servlet-specific error occurs
45       * @throws IOException if an I/O error occurs
46       */
47      protected static void processRequest(final HttpServletRequest request, final HttpServletResponse response)
48              throws ServletException, IOException {
49  
50          response.setContentType("text/html;charset=UTF-8");
51  
52          try {
53              Thread.sleep(60000);
54          } catch (InterruptedException ignore) {
55              // ignore
56          }
57  
58          try (PrintWriter out = response.getWriter()) {
59              out.println("OK");
60          }
61      }
62  
63      /**
64       * Handles the HTTP
65       * {@code GET} method.
66       *
67       * @param request servlet request
68       * @param response servlet response
69       * @throws ServletException if a servlet-specific error occurs
70       * @throws IOException if an I/O error occurs
71       */
72      @Override
73      protected void doGet(final HttpServletRequest request, final HttpServletResponse response)
74              throws ServletException, IOException {
75  
76          processRequest(request, response);
77      }
78  
79      /**
80       * Handles the HTTP
81       * {@code POST} method.
82       *
83       * @param request servlet request
84       * @param response servlet response
85       * @throws ServletException if a servlet-specific error occurs
86       * @throws IOException if an I/O error occurs
87       */
88      @Override
89      protected void doPost(final HttpServletRequest request, final HttpServletResponse response)
90              throws ServletException, IOException {
91  
92          processRequest(request, response);
93      }
94  
95      /**
96       * Returns a short description of the servlet.
97       *
98       * @return a String containing servlet description
99       */
100     @Override
101     public String getServletInfo() {
102         return "Service Timeout";
103     }
104 }