*/
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));
}
}