View Javadoc
1   package org.kuali.ole.sip2.servlet;
2   
3   
4   import org.apache.log4j.Logger;
5   import org.kuali.ole.sip2.constants.OLESIP2Constants;
6   import org.kuali.ole.sip2.service.OLESIP2HelperService;
7   import org.kuali.ole.sip2.service.impl.OLESIP2HelperServiceImpl;
8   
9   import javax.servlet.ServletException;
10  import javax.servlet.http.HttpServlet;
11  import javax.servlet.http.HttpServletRequest;
12  import javax.servlet.http.HttpServletResponse;
13  import java.io.IOException;
14  import java.io.PrintWriter;
15  import java.util.HashMap;
16  import java.util.Map;
17  
18  /**
19   * Created by sheiksalahudeenm on 12/26/14.
20   */
21  public class OLENettyServlet extends HttpServlet {
22  
23      OLESIP2HelperService OLESIP2HelperService = new OLESIP2HelperServiceImpl();
24  
25  
26      Logger LOG = Logger.getLogger(OLENettyServlet.class);
27  
28      @Override
29      public void init() throws ServletException {
30          super.init();
31      }
32  
33      @Override
34      protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
35          if(OLESIP2Constants.ALREADY_REQUEST_PROCESSING.equalsIgnoreCase("Y")){
36              StringBuffer responseString = new StringBuffer();
37              responseString.append(OLESIP2Constants.REFRESH_PAGE);
38              PrintWriter out = response.getWriter();
39              out.print(responseString.toString());
40          }else if (OLESIP2Constants.olesip2Server != null) {
41              if (!OLESIP2Constants.olesip2Server.isStopped()) {
42                  StringBuffer responseString = new StringBuffer();
43                  responseString.append(OLESIP2Constants.SERVER_RUNNING);
44                  PrintWriter out = response.getWriter();
45                  out.print(responseString.toString());
46              }
47          }
48      }
49  
50      @Override
51      protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
52          StringBuffer responseString = new StringBuffer();
53          PrintWriter out = response.getWriter();
54          Map<String, String[]> parameterMap = new HashMap<String, String[]>();
55  
56          parameterMap = request.getParameterMap();
57  
58          String action = parameterMap.get("action")[0];
59          if(OLESIP2Constants.ALREADY_REQUEST_PROCESSING.equalsIgnoreCase("N") && action.equalsIgnoreCase("start") && OLESIP2Constants.olesip2Server == null){
60                      OLESIP2Constants.ALREADY_REQUEST_PROCESSING = "Y";
61                      OLESIP2Constants.olesip2Server = OLESIP2HelperService.doActionForSocketServer(action, responseString, OLESIP2Constants.olesip2Server);
62                      OLESIP2Constants.ALREADY_REQUEST_PROCESSING = "N";
63                      out.write(responseString.toString());
64  
65          }else if(action.equalsIgnoreCase("start") && OLESIP2Constants.ALREADY_REQUEST_PROCESSING.equalsIgnoreCase("Y")){
66              responseString.append(OLESIP2Constants.REFRESH_PAGE);
67              out.print(responseString.toString());
68          }else if(action.equalsIgnoreCase("start")){
69              if (OLESIP2Constants.olesip2Server != null) {
70                  if (!OLESIP2Constants.olesip2Server.isStopped()) {
71                      responseString.append(OLESIP2Constants.SERVER_RUNNING);
72                      out.print(responseString.toString());
73                  }else{
74                      OLESIP2Constants.ALREADY_REQUEST_PROCESSING = "Y";
75                      OLESIP2Constants.olesip2Server = OLESIP2HelperService.doActionForSocketServer(action, responseString, OLESIP2Constants.olesip2Server);
76                      OLESIP2Constants.ALREADY_REQUEST_PROCESSING = "N";
77                      out.write(responseString.toString());
78                  }
79              }
80          }else{
81              OLESIP2Constants.olesip2Server = OLESIP2HelperService.doActionForSocketServer(action, responseString, OLESIP2Constants.olesip2Server);
82              out.write(responseString.toString());
83          }
84  
85  
86      }
87  
88  }