Package com.kurento.kmf.content.jsonrpc

Examples of com.kurento.kmf.content.jsonrpc.JsonRpcRequest


   */
  private void doRequest4JsonControlProtocol(AsyncContext asyncCtx,
      String contentId, HttpServletResponse resp)
      throws ServletException, IOException {

    JsonRpcRequest message = null;

    try {
      message = protocolManager.receiveJsonRequest(asyncCtx);

      if (message == null) {
        throw new KurentoMediaFrameworkException(
            "Null json message received", 10020);
      }

      AbstractContentSession contentSession = null;
      String sessionId = message.getParams() != null ? message
          .getParams().getSessionId() : null;

      if (sessionId == null && message.getMethod().equals(METHOD_START)) {
        // Session is created by a start request, we need to fill
        // asyncCtx associated to start requests.
        contentSession = createContentSession(asyncCtx, contentId);
        contentSessionManager.put(contentSession);
      } else if (sessionId == null
          && message.getMethod().equals(METHOD_EXECUTE)) {
        // Session is created by an execute request, the asyncCtx for
        // start requests must be set to null
        contentSession = createContentSession(null, contentId);
        contentSessionManager.put(contentSession);
      } else if (sessionId != null) {
        contentSession = contentSessionManager.get(sessionId);
        if (contentSession == null) {
          throw new KurentoMediaFrameworkException(
              "Could not find contentSession object associated to sessionId "
                  + sessionId, 10021);
        }
      } else {
        throw new KurentoMediaFrameworkException(
            "Could not find required sessionId field in request",
            10022);
      }

      Future<?> future = executor.getExecutor().submit(
          createAsyncRequestProcessor(contentSession, message,
              asyncCtx));

      // Store future for using it in ContentAsyncListener in case of
      // error
      asyncCtx.getRequest().setAttribute(
          ContentAsyncListener.FUTURE_REQUEST_PROCESSOR_ATT_NAME,
          future);
      asyncCtx.getRequest().setAttribute(
          ContentAsyncListener.CONTENT_REQUEST_ATT_NAME,
          contentSession);
      asyncCtx.getRequest()
          .setAttribute(
              ContentAsyncListener.CONTROL_PROTOCOL_REQUEST_MESSAGE_ATT_NAME,
              message);
    } catch (KurentoMediaFrameworkException ke) {
      int reqId = message != null ? message.getId() : 0;
      protocolManager.sendJsonError(
          asyncCtx,
          JsonRpcResponse.newError(
              ExceptionUtils.getJsonErrorCode(ke.getCode()),
              ke.getMessage(), reqId));
    } catch (Throwable t) {
      int reqId = message != null ? message.getId() : 0;
      protocolManager.sendJsonError(asyncCtx, JsonRpcResponse.newError(
          ExceptionUtils.getJsonErrorCode(1), t.getMessage(), reqId));
    }
  }
View Full Code Here


      }

      InputStreamReader isr = new InputStreamReader(
          new ByteArrayInputStream(baos.toByteArray()), encoding);

      JsonRpcRequest jsonRequest = gson.fromJson(isr,
          JsonRpcRequest.class);
      Assert.notNull(jsonRequest.getMethod());
      log.info("Received JsonRpc request ...\n " + jsonRequest.toString());
      return jsonRequest;
    } catch (IOException e) {
      // TODO: trace this exception and double check appropriate JsonRpc
      // answer is sent
      throw new KurentoMediaFrameworkException(
View Full Code Here

      future.cancel(true);
    }

    AbstractContentSession contentRequest = (AbstractContentSession) asyncContext
        .getRequest().getAttribute(CONTENT_REQUEST_ATT_NAME);
    JsonRpcRequest jsonRequest = (JsonRpcRequest) asyncContext.getRequest()
        .getAttribute(CONTROL_PROTOCOL_REQUEST_MESSAGE_ATT_NAME);
    if (contentRequest != null) {
      contentRequest.internalTerminateWithError(asyncContext, errorCode,
          msg, jsonRequest);
    }
View Full Code Here

TOP

Related Classes of com.kurento.kmf.content.jsonrpc.JsonRpcRequest

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.