예제 #1
0
  /**
   * @param aReq
   * @param aResp
   * @throws ServletException
   * @throws IOException
   */
  @Override
  protected void doPost(HttpServletRequest aReq, HttpServletResponse aResp)
      throws ServletException, IOException {
    String lAction = aReq.getParameter("action");
    String lSessionId = getSessionId(aReq);
    String lConnectorId = getConnectorId(aReq, lSessionId);
    if (null == lConnectorId) {
      sendMessage(400, "Missing 'connectionId' parameter value!", aResp);
      return;
    }

    if (!mConnectorsManager.connectorExists(lConnectorId)) {
      sendMessage(411, "Invalid connection state!", aResp);
      return;
    }

    if ("send".equals(lAction)) {
      processSend(lConnectorId, aReq, aResp);
    } else {
      sendMessage(404, "Invalid request!", aResp);
    }

    // session management
    updateSessionTimeout(lSessionId);
  }
예제 #2
0
 void updateSessionTimeout(String aSessionId) {
   mConnectorsManager
       .getSessionManager()
       .getReconnectionManager()
       .getSessionIdsTrash()
       .put(
           aSessionId,
           System.currentTimeMillis() + (mEngine.getConfiguration().getTimeout() * 60 * 1000));
 }
예제 #3
0
  /**
   * @param aReq
   * @param aResp
   * @throws ServletException
   * @throws IOException
   */
  @Override
  protected void doGet(HttpServletRequest aReq, HttpServletResponse aResp)
      throws ServletException, IOException {
    String lAction = aReq.getParameter("action");
    String lSessionId = getSessionId(aReq);
    String lConnectorId = getConnectorId(aReq, lSessionId);
    if (null == lConnectorId) {
      sendMessage(400, "Missing 'connectionId' parameter value!", aResp);
      return;
    }

    if ("sync".equals(lAction)) {
      processSync(lConnectorId, aReq, aResp);
    } else if ("open".equals(lAction)) {
      if (mConnectorsManager.connectorExists(lConnectorId)) {
        sendMessage(400, "Invalid connection state!", aResp);
        return;
      }

      processOpen(lSessionId, lConnectorId, aReq, aResp);
    } else {
      if (!mConnectorsManager.connectorExists(lConnectorId)) {
        sendMessage(400, "Invalid connection state!", aResp);
        return;
      }

      if ("login".equals(lAction)) {
        processLogin(lConnectorId, aReq, aResp);
      } else if ("logout".equals(lAction)) {
        processLogout(lConnectorId, aReq, aResp);
      } else if ("send".equals(lAction)) {
        processSend(lConnectorId, aReq, aResp);
      } else if ("download".equals(lAction)) {
        processDownload(lConnectorId, aReq, aResp);
      } else if ("close".equals(lAction)) {
        processClose(lConnectorId, aReq, aResp);
      } else {
        sendMessage(404, "Invalid request!", aResp);
      }
    }

    // session management
    updateSessionTimeout(lSessionId);
  }
예제 #4
0
  HTTPConnector getConnector(
      String aConnectorId,
      HttpServletRequest aReq,
      HttpServletResponse aResp,
      boolean aStartupConnection)
      throws Exception {
    HTTPConnector lConnector =
        (HTTPConnector) mConnectorsManager.getConnectorById(aConnectorId, aStartupConnection);
    lConnector.setRemoteHost(InetAddress.getByName(aReq.getRemoteHost()));
    lConnector.setSSL(aReq.getScheme().equals("https"));
    lConnector.setHttpResponse(aResp);

    return lConnector;
  }
예제 #5
0
  private void processSync(String aConnectorId, HttpServletRequest aReq, HttpServletResponse aResp)
      throws IOException {
    try {
      String lOrigin = aReq.getScheme() + "://" + aReq.getRemoteHost();
      if (!EngineUtils.isOriginValid(lOrigin, mEngine.getConfiguration().getDomains())) {
        sendMessage(401, "Origin not allowed!", aResp);
        return;
      }

      List<String> lPackets = mConnectorsManager.getPacketsQueue().dequeue(aConnectorId);

      sendMessage(200, JSONProcessor.objectToJSONString(lPackets), aResp);
    } catch (Exception lEx) {
      sendMessage(500, lEx.getLocalizedMessage(), aResp);
    }
  }
예제 #6
0
  private void processOpen(
      String aSessionId, String aConnectorId, HttpServletRequest aReq, HttpServletResponse aResp)
      throws IOException {
    try {
      String lOrigin = aReq.getScheme() + "://" + aReq.getRemoteHost();
      if (!EngineUtils.isOriginValid(lOrigin, mEngine.getConfiguration().getDomains())) {
        sendMessage(401, "Origin not allowed!", aResp);
        return;
      }

      mConnectorsManager.add(aSessionId, aConnectorId);
      HTTPConnector lConnector = getConnector(aConnectorId, aReq, aResp);
      lConnector.setRemoteHost(InetAddress.getByName(aReq.getRemoteHost()));

      // starting connector on request thread intentionally
      lConnector.startConnector();
    } catch (Exception lEx) {
      sendMessage(500, lEx.getLocalizedMessage(), aResp);
    }
  }