org.kurento.jsonrpc.Session Java Examples

The following examples show how to use org.kurento.jsonrpc.Session. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RpcHandler.java    From openvidu with Apache License 2.0 6 votes vote down vote up
@Override
public void handleTransportError(Session rpcSession, Throwable exception) throws Exception {
	if (rpcSession != null) {
		log.error("Transport exception for WebSocket session: {} - Exception: {}", rpcSession.getSessionId(),
				exception.getMessage());
		if ("IOException".equals(exception.getClass().getSimpleName()) && exception.getCause() != null
				&& "Broken pipe".equals(exception.getCause().getMessage())) {
			log.warn("Parcipant with private id {} unexpectedly closed the websocket", rpcSession.getSessionId());
		}
		if ("EOFException".equals(exception.getClass().getSimpleName())) {
			// Store WebSocket connection interrupted exception for this web socket to
			// automatically evict the participant on "afterConnectionClosed" event
			this.webSocketEOFTransportError.put(rpcSession.getSessionId(), true);
		}
	}
}
 
Example #2
Source File: BidirectionalTest.java    From kurento-java with Apache License 2.0 6 votes vote down vote up
@Override
public void handleRequest(Transaction transaction, Request<Object> request) throws Exception {

  log.debug("Request id:" + request.getId());
  log.debug("Request method:" + request.getMethod());
  log.debug("Request params:" + request.getParams());

  transaction.sendResponse(request.getParams());

  final Session session = transaction.getSession();
  final Object params = request.getParams();

  new Thread() {
    @Override
    public void run() {
      asyncReverseSend(session, params);
    }
  }.start();
}
 
Example #3
Source File: BidirectionalMultiTest.java    From kurento-java with Apache License 2.0 6 votes vote down vote up
@Override
public void handleRequest(Transaction transaction, Request<Integer> request) throws Exception {

  log.debug("Request id:" + request.getId());
  log.debug("Request method:" + request.getMethod());
  log.debug("Request params:" + request.getParams());

  transaction.sendResponse(request.getParams());

  final Session session = transaction.getSession();
  final Object params = request.getParams();

  new Thread() {
    @Override
    public void run() {
      asyncReverseSend(session, params);
    }
  }.start();
}
 
Example #4
Source File: RpcNotificationService.java    From openvidu with Apache License 2.0 6 votes vote down vote up
public void sendNotification(final String participantPrivateId, final String method, final Object params) {
	RpcConnection rpcSession = rpcConnections.get(participantPrivateId);
	if (rpcSession == null || rpcSession.getSession() == null) {
		if (!isIpcamParticipant(participantPrivateId)) {
			log.error("No rpc session found for private id {}, unable to send notification {}: {}",
					participantPrivateId, method, params);
		}
		return;
	}
	Session s = rpcSession.getSession();

	try {
		s.sendNotification(method, params);
	} catch (Exception e) {
		log.error("Exception sending notification '{}': {} to participant with private id {}", method, params,
				participantPrivateId, e);
	}
}
 
Example #5
Source File: RpcNotificationService.java    From openvidu with Apache License 2.0 6 votes vote down vote up
public RpcConnection closeRpcSession(String participantPrivateId) {
	RpcConnection rpcSession = rpcConnections.remove(participantPrivateId);
	if (rpcSession == null || rpcSession.getSession() == null) {
		if (!isIpcamParticipant(participantPrivateId)) {
			log.error("No session found for private id {}, unable to cleanup", participantPrivateId);
		}
		return null;
	}
	Session s = rpcSession.getSession();
	try {
		s.close();
		log.info("Closed session for participant with private id {}", participantPrivateId);
		this.showRpcConnections();
		return rpcSession;
	} catch (IOException e) {
		log.error("Error closing session for participant with private id {}", participantPrivateId, e);
	}
	return null;
}
 
Example #6
Source File: CloseSessionTest.java    From kurento-java with Apache License 2.0 6 votes vote down vote up
@Override
public void handleRequest(final Transaction transaction, Request<String> request)
    throws Exception {

  Session session = transaction.getSession();

  if (session.isNew()) {
    transaction.sendResponse("new");
  } else {
    transaction.sendResponse("old");
  }

  if (counter == 2) {
    session.close();
  }
  counter++;
}
 
Example #7
Source File: RpcHandler.java    From openvidu with Apache License 2.0 6 votes vote down vote up
@Override
public void afterConnectionEstablished(Session rpcSession) throws Exception {
	log.info("After connection established for WebSocket session: {}", rpcSession.getSessionId());
	if (rpcSession instanceof WebSocketServerSession) {
		InetAddress address;
		HttpHeaders headers = ((WebSocketServerSession) rpcSession).getWebSocketSession().getHandshakeHeaders();
		if (headers.containsKey("x-real-ip")) {
			address = InetAddress.getByName(headers.get("x-real-ip").get(0));
		} else {
			address = ((WebSocketServerSession) rpcSession).getWebSocketSession().getRemoteAddress().getAddress();
		}
		rpcSession.getAttributes().put("remoteAddress", address);

		HttpSession httpSession = (HttpSession) ((WebSocketServerSession) rpcSession).getWebSocketSession()
				.getAttributes().get("httpSession");
		rpcSession.getAttributes().put("httpSession", httpSession);
	}
}
 
Example #8
Source File: JsonRpcNotificationService.java    From kurento-room with Apache License 2.0 6 votes vote down vote up
@Override
public void sendNotification(final String participantId, final String method, final Object params) {
  SessionWrapper sw = sessions.get(participantId);
  if (sw == null || sw.getSession() == null) {
    log.error("No session found for id {}, unable to send notification {}: {}", participantId,
        method, params);
    return;
  }
  Session s = sw.getSession();

  try {
    s.sendNotification(method, params);
  } catch (Exception e) {
    log.error("Exception sending notification '{}': {} to user id {}", method, params,
        participantId, e);
  }
}
 
Example #9
Source File: JsonRpcNotificationService.java    From kurento-room with Apache License 2.0 6 votes vote down vote up
@Override
public void closeSession(ParticipantRequest participantRequest) {
  if (participantRequest == null) {
    log.error("No session found for null ParticipantRequest object, " + "unable to cleanup");
    return;
  }
  String sessionId = participantRequest.getParticipantId();
  SessionWrapper sw = sessions.get(sessionId);
  if (sw == null || sw.getSession() == null) {
    log.error("No session found for id {}, unable to cleanup", sessionId);
    return;
  }
  Session s = sw.getSession();
  try {
    ParticipantSession ps = null;
    if (s.getAttributes().containsKey(ParticipantSession.SESSION_KEY)) {
      ps = (ParticipantSession) s.getAttributes().get(ParticipantSession.SESSION_KEY);
    }
    s.close();
    log.info("Closed session for req {} (userInfo:{})", participantRequest, ps);
  } catch (IOException e) {
    log.error("Error closing session for req {}", participantRequest, e);
  }
  sessions.remove(sessionId);
}
 
Example #10
Source File: JsonRpcHandlerManager.java    From kurento-java with Apache License 2.0 5 votes vote down vote up
public void afterReconnection(Session session) {
	if (handler != null) {
		try {
			handler.afterReconnection(session);
		} catch (Exception e) {
			try {
				handler.handleUncaughtException(session, e);
			} catch (Exception e2) {
				log.error("Exception while executing handleUncaughtException", e2);
			}
		}
	}
}
 
Example #11
Source File: JsonRpcHandlerManager.java    From kurento-java with Apache License 2.0 5 votes vote down vote up
public void afterConnectionEstablished(Session session) {

    try {
      if (handler != null) {
        handler.afterConnectionEstablished(session);
      }
    } catch (Exception e) {
      try {
        handler.handleUncaughtException(session, e);
      } catch (Exception e2) {
        log.error("Exception while executing handleUncaughtException", e2);
      }
    }
  }
 
Example #12
Source File: JsonRpcHandlerManager.java    From kurento-java with Apache License 2.0 5 votes vote down vote up
public void afterConnectionClosed(Session session, String reason) {
  if (handler != null) {
    try {
      handler.afterConnectionClosed(session, reason);
    } catch (Exception e) {
      try {
        handler.handleUncaughtException(session, e);
      } catch (Exception e2) {
        log.error("Exception while executing handleUncaughtException", e2);
      }
    }
  }
}
 
Example #13
Source File: JsonRpcHandlerManager.java    From kurento-java with Apache License 2.0 5 votes vote down vote up
public void handleTransportError(Session session, Throwable exception) {
  if (handler != null) {
    try {
      handler.handleTransportError(session, exception);
    } catch (Exception e) {
      try {
        handler.handleUncaughtException(session, e);
      } catch (Exception e2) {
        log.error("Exception while executing handleUncaughtException", e2);
      }
    }
  }
}
 
Example #14
Source File: ServerEventsTest.java    From kurento-java with Apache License 2.0 5 votes vote down vote up
@Override
public void afterConnectionEstablished(Session session) throws Exception {

  session.setReconnectionTimeout(500);

  log.debug("Connection established with sessionId: " + session.getSessionId());
  afterConnectionEstablishedLatch.countDown();
}
 
Example #15
Source File: ReconnectionTest.java    From kurento-java with Apache License 2.0 5 votes vote down vote up
@Override
public void handleRequest(final Transaction transaction, Request<String> request)
    throws Exception {

  Session session = transaction.getSession();

  if (session.isNew()) {
    transaction.sendResponse("new");
  } else {
    transaction.sendResponse("old");
  }
}
 
Example #16
Source File: RoomJsonRpcHandler.java    From kurento-room with Apache License 2.0 5 votes vote down vote up
@Override
public final void afterConnectionClosed(Session session, String status) throws Exception {
  ParticipantSession ps = null;
  if (session.getAttributes().containsKey(ParticipantSession.SESSION_KEY)) {
    ps = (ParticipantSession) session.getAttributes().get(ParticipantSession.SESSION_KEY);
  }
  String sid = session.getSessionId();
  log.debug("CONN_CLOSED: sessionId={}, participant in session: {}", sid, ps);
  ParticipantRequest preq = new ParticipantRequest(sid, null);
  updateThreadName(sid + "|wsclosed");
  userControl.leaveRoom(null, null, preq);
  updateThreadName(HANDLER_THREAD_NAME);
}
 
Example #17
Source File: JsonRpcNotificationService.java    From kurento-room with Apache License 2.0 5 votes vote down vote up
public Session getSession(String sessionId) {
  SessionWrapper sw = sessions.get(sessionId);
  if (sw == null) {
    return null;
  }
  return sw.getSession();
}
 
Example #18
Source File: PerSessionJsonRpcHandler.java    From kurento-java with Apache License 2.0 5 votes vote down vote up
@Override
public void afterConnectionEstablished(Session session) throws Exception {
  JsonRpcHandler<T> handler = this.provider.createBean();
  this.handlers.put(session, handler);

  try {
    handler.afterConnectionEstablished(session);
  } catch (Exception e) {
    handler.handleUncaughtException(session, e);
  }
}
 
Example #19
Source File: JsonRpcUserControl.java    From kurento-room with Apache License 2.0 5 votes vote down vote up
public ParticipantSession getParticipantSession(Transaction transaction) {
  Session session = transaction.getSession();
  ParticipantSession participantSession = (ParticipantSession) session.getAttributes().get(
      ParticipantSession.SESSION_KEY);
  if (participantSession == null) {
    participantSession = new ParticipantSession();
    session.getAttributes().put(ParticipantSession.SESSION_KEY, participantSession);
  }
  return participantSession;
}
 
Example #20
Source File: PerSessionJsonRpcHandler.java    From kurento-java with Apache License 2.0 5 votes vote down vote up
@Override
public void afterConnectionClosed(Session session, String status) throws Exception {
  try {
    JsonRpcHandler<T> handler = getHandler(session);
    try {
      handler.afterConnectionClosed(session, status);
    } catch (Exception e) {
      handler.handleUncaughtException(session, e);
    }
  } finally {
    destroy(session);
  }
}
 
Example #21
Source File: PerSessionJsonRpcHandler.java    From kurento-java with Apache License 2.0 5 votes vote down vote up
@Override
public void afterReconnection(Session session) throws Exception {
	JsonRpcHandler<T> handler = null;
	try {
		handler = getHandler(session);
		handler.afterReconnection(session);
	} catch (Exception e) {
		handler.handleUncaughtException(session, e);
	}
}
 
Example #22
Source File: PerSessionJsonRpcHandler.java    From kurento-java with Apache License 2.0 5 votes vote down vote up
private void destroy(Session session) {
  JsonRpcHandler<T> handler = this.handlers.remove(session);
  try {
    if (handler != null) {
      this.provider.destroy(handler);
    }
  } catch (Throwable t) {
    logger.warn("Error while destroying handler", t);
  }
}
 
Example #23
Source File: PerSessionJsonRpcHandler.java    From kurento-java with Apache License 2.0 5 votes vote down vote up
@Override
public void handleTransportError(Session session, Throwable exception) throws Exception {
  JsonRpcHandler<T> handler = getHandler(session);
  try {
    handler.handleTransportError(session, exception);
  } catch (Exception e) {
    handler.handleUncaughtException(session, e);
  }
}
 
Example #24
Source File: RpcHandler.java    From openvidu with Apache License 2.0 5 votes vote down vote up
@Override
public void afterConnectionClosed(Session rpcSession, String status) throws Exception {
	log.info("After connection closed for WebSocket session: {} - Status: {}", rpcSession.getSessionId(), status);

	String rpcSessionId = rpcSession.getSessionId();
	String message = "";

	if ("Close for not receive ping from client".equals(status)) {
		message = "Evicting participant with private id {} because of a network disconnection";
	} else if (status == null) { // && this.webSocketBrokenPipeTransportError.remove(rpcSessionId) != null)) {
		try {
			Participant p = sessionManager.getParticipant(rpcSession.getSessionId());
			if (p != null) {
				message = "Evicting participant with private id {} because its websocket unexpectedly closed in the client side";
			}
		} catch (OpenViduException exception) {
		}
	}

	if (!message.isEmpty()) {
		RpcConnection rpc = this.notificationService.closeRpcSession(rpcSessionId);
		if (rpc != null && rpc.getSessionId() != null) {
			io.openvidu.server.core.Session session = this.sessionManager.getSession(rpc.getSessionId());
			if (session != null && session.getParticipantByPrivateId(rpc.getParticipantPrivateId()) != null) {
				log.info(message, rpc.getParticipantPrivateId());
				leaveRoomAfterConnClosed(rpc.getParticipantPrivateId(), EndReason.networkDisconnect);
			}
		}
	}

	if (this.webSocketEOFTransportError.remove(rpcSessionId) != null) {
		log.warn(
				"Evicting participant with private id {} because a transport error took place and its web socket connection is now closed",
				rpcSession.getSessionId());
		this.leaveRoomAfterConnClosed(rpcSessionId, EndReason.networkDisconnect);
	}
}
 
Example #25
Source File: AbstractTransaction.java    From kurento-java with Apache License 2.0 4 votes vote down vote up
@Override
public Session getSession() {
  return session;
}
 
Example #26
Source File: PerSessionJsonRpcHandler.java    From kurento-java with Apache License 2.0 4 votes vote down vote up
private JsonRpcHandler<T> getHandler(Session session) {
  JsonRpcHandler<T> handler = this.handlers.get(session);
  Assert.isTrue(handler != null, "JsonRpcHandler not found for " + session);
  return handler;
}
 
Example #27
Source File: AbstractTransaction.java    From kurento-java with Apache License 2.0 4 votes vote down vote up
public AbstractTransaction(Session session, Request<?> request) {
  super();
  this.session = session;
  this.request = request;
}
 
Example #28
Source File: TransactionImpl.java    From kurento-java with Apache License 2.0 4 votes vote down vote up
public TransactionImpl(Session session, Request<?> request, ResponseSender responseSender) {
  super(session, request);
  this.responseSender = responseSender;
}
 
Example #29
Source File: PerSessionJsonRpcHandler.java    From kurento-java with Apache License 2.0 4 votes vote down vote up
@Override
public void handleUncaughtException(Session session, Exception exception) {
  logger.error("Uncaught exception while execution PerSessionJsonRpcHandler", exception);
}
 
Example #30
Source File: ServerEventsTest.java    From kurento-java with Apache License 2.0 4 votes vote down vote up
@Override
public void afterConnectionClosed(Session session, String status) throws Exception {

  log.debug("Connection closed: " + status);
  afterConnectionClosedLatch.countDown();
}