Exemplo n.º 1
0
  @Override
  public void onHTTPRequest(IVHost vhost, IHTTPRequest req, IHTTPResponse resp) {
    int clientId;
    HashMap<String, HashMap<String, String>> returnMap =
        new HashMap<String, HashMap<String, String>>();
    HashMap<String, String> returnKeyValues = new HashMap<String, String>();
    String strClientId;

    if (!doHTTPAuthentication(vhost, req, resp) || req.getMethod().equalsIgnoreCase("get")) return;

    req.parseBodyForParams();
    strClientId = req.getParameter("clientId");
    returnKeyValues.put("type", null);
    returnKeyValues.put("msg", "Request unsuccessful");
    returnKeyValues.put("isPublic", "true");
    returnMap.put("error", returnKeyValues);

    if (strClientId != null) {
      WMSLoggerFactory.getLogger(null)
          .info("*** Attempting to stop stream with clientId " + strClientId);
      try {
        clientId = Integer.parseInt(strClientId);
        IClient client = vhost.getClient(clientId);
        if (client != null) {
          client.setShutdownClient(true);
          returnMap.remove("error");
          returnKeyValues.remove("type");
          returnKeyValues.remove("msg");
          returnKeyValues.remove("isPublic");
          returnKeyValues.put("result", "Id " + clientId + " killed");
          returnMap.put("success", returnKeyValues);
        }
      } catch (NumberFormatException e) {
        WMSLoggerFactory.getLogger(null).error("******* NaN: " + strClientId);
        returnKeyValues.put("type", "NumberFormatException");
        returnKeyValues.put("msg", "NaN: " + strClientId);
        returnKeyValues.put("isPublic", "true");
        returnMap.put("error", returnKeyValues);
      }
    }

    JSONSerializer serializer = new JSONSerializer().exclude("*.class");
    String returnJSONStr = serializer.serialize(returnMap);

    try {
      resp.setHeader("Content-Type", "application/json");
      OutputStream out = resp.getOutputStream();
      byte[] outBytes = returnJSONStr.getBytes();
      out.write(outBytes);
    } catch (Exception e) {
      WMSLoggerFactory.getLogger(null).error("*** HTTPProvider failed: " + e.toString());
    }
  }
Exemplo n.º 2
0
  public void onHTTPCupertinoEncryptionKeyRequest(
      HTTPStreamerSessionCupertino httpCupertinoStreamingSession,
      IHTTPRequest req,
      IHTTPResponse resp) {

    boolean isGood = true;
    String ipAddress = httpCupertinoStreamingSession.getIpAddress();
    String queryStr = req.getQueryString();
    String referrer = httpCupertinoStreamingSession.getReferrer();
    String cookieStr = httpCupertinoStreamingSession.getCookieStr();
    String userAgent = httpCupertinoStreamingSession.getUserAgent();
    String sessionId = httpCupertinoStreamingSession.getSessionId();
    IApplicationInstance appInstance = httpCupertinoStreamingSession.getAppInstance();
    String streamName = httpCupertinoStreamingSession.getStreamName();

    getLogger()
        .info(
            "ModuleEncryptionHandlerCupertinoStreaming.onHTTPCupertinoEncryptionKeyRequest["
                + appInstance.getContextStr()
                + "/"
                + httpCupertinoStreamingSession.getStreamName()
                + "]: accept:"
                + isGood);
    if (!isGood) {
      httpCupertinoStreamingSession.rejectSession();
    }
  }