Merge "Omaha #3078 collaboration shared display data over private chat" into omaha_14.4.1

Former-commit-id: 764f977bf6 [formerly a2783be56a [formerly 4468390aaf89456e93b45fca20aeca7fb96d8c12]]
Former-commit-id: a2783be56a
Former-commit-id: 344a6b80ef
This commit is contained in:
Nate Jensen 2014-06-17 18:09:33 -05:00 committed by Gerrit Code Review
commit 7299d9ccb8
2 changed files with 51 additions and 27 deletions

View file

@ -65,6 +65,7 @@ import com.raytheon.uf.viz.collaboration.comm.provider.user.UserId;
* Feb 24, 2014 2756 bclement moved xmpp objects to new packages
* Apr 14, 2014 2903 bclement moved from session subpackage to connection
* Jun 17, 2014 3078 bclement routing for private chat messages
* Jun 17, 2014 3078 bclement only accept config from server, don't route data without sessionId
*
* </pre>
*
@ -113,8 +114,13 @@ public class PeerToPeerCommHelper implements PacketListener {
if (packet instanceof Message) {
Message msg = (Message) packet;
String fromStr = msg.getFrom();
if (fromStr == null) {
// from server
/*
* Messages coming from the server will either have a null
* 'from' address or it will be the host name of the server.
* Normalize so that it is always just the name of the server.
*/
UserId account = CollaborationConnection.getConnection()
.getUser();
fromStr = account.getHost();
@ -133,7 +139,7 @@ public class PeerToPeerCommHelper implements PacketListener {
// TODO Legacy config support
body = body.substring(Tools.CONFIG_PREAMBLE.length(),
body.length() - Tools.DIRECTIVE_SUFFIX.length());
this.handleConfiguration(body);
this.handleConfiguration(fromStr, body);
} else {
// anything else pass to the normal text
routeMessage(msg);
@ -144,11 +150,11 @@ public class PeerToPeerCommHelper implements PacketListener {
if (payload != null) {
switch (payload.getPayloadType()) {
case Command:
routeData(payload,
(String) msg.getProperty(Tools.PROP_SESSION_ID));
routeData(payload, msg);
break;
case Config:
handleConfiguration(payload.getData().toString());
handleConfiguration(fromStr, payload.getData()
.toString());
break;
default:
// do nothing
@ -158,28 +164,40 @@ public class PeerToPeerCommHelper implements PacketListener {
}
}
/**
* Post data as event either to associated session, or general event bus
* Post data as event to associated session
*
* @param payload
* @param sessionId
* @param msg
*/
private void routeData(SessionPayload payload, String sessionId) {
private void routeData(SessionPayload payload, Message msg) {
String sessionId = (String) msg.getProperty(Tools.PROP_SESSION_ID);
Object object = payload.getData();
if (object != null) {
if (sessionId == null) {
manager.postEvent(object);
if (object != null && sessionId != null) {
// Ok, we have a session id.
ISession session = manager.getSession(sessionId);
if (session != null) {
/*
* TODO 14.4 sends objects using venue handles, pre-14.4 uses
* actual user IDs. Once all clients are using venue handles, we
* should validate that the message is coming from a participant
* in the venue session. See Omaha #3294
*/
session.postEvent(object);
} else {
// Ok, we have a session id.
ISession session = manager.getSession(sessionId);
if (session != null) {
session.postEvent(object);
} else {
statusHandler.handle(Priority.PROBLEM,
"ERROR: Unknown sessionid [" + sessionId + "]");
}
statusHandler.handle(Priority.PROBLEM,
"ERROR: Unknown sessionid [" + sessionId + "]");
}
} else {
String warning = "Received null for the following: ";
if (object == null) {
warning += "payload data, ";
}
if (sessionId == null) {
warning += "session ID, ";
}
warning += "from " + msg.getFrom();
statusHandler.debug(warning);
}
}
@ -226,9 +244,18 @@ public class PeerToPeerCommHelper implements PacketListener {
/**
* Parse server configuration and notify general event bus of config event
*
* @param from
* used the validate that the configuration comes from the server
* @param body
*/
private void handleConfiguration(String body) {
private void handleConfiguration(String from, String body) {
/* ignore config that doesn't come from server */
UserId account = CollaborationConnection.getConnection().getUser();
if (!from.equals(account.getHost())) {
statusHandler.debug("Ignoring config message from " + from + ": "
+ body);
return;
}
// Determine if an error has occurred.
if (IHttpXmppMessage.configErrorPattern.matcher(body).matches()) {
statusHandler.handle(

View file

@ -107,6 +107,7 @@ import com.raytheon.uf.viz.collaboration.comm.provider.user.VenueParticipant;
* May 09, 2014 3107 bclement default to trust transfer event when verify errors out
* May 14, 2014 3061 bclement added better checks for when to send invite/session payloads
* Jun 16, 2014 3288 bclement feed venue configuration changes
* Jun 17, 2014 3078 bclement peer to peer communication uses private chat
*
* </pre>
*
@ -236,11 +237,7 @@ public class SharedDisplaySession extends VenueSession implements
* break backwards compatibility
*/
boolean doSend = true;
UserId userid = getVenue().getParticipantUserid(participant);
if (userid == null) {
log.warn("Attempted to send object to peer when actual userid is unknown");
doSend = false;
} else if (hasRole(SharedDisplayRole.DATA_PROVIDER)
if (hasRole(SharedDisplayRole.DATA_PROVIDER)
&& !isSharedDisplayClient(participant)) {
/*
* data provider (leader) sends the bulk of the peer to peer
@ -253,7 +250,7 @@ public class SharedDisplaySession extends VenueSession implements
if (doSend) {
SessionPayload payload = new SessionPayload(PayloadType.Command,
obj);
Message msg = new Message(userid.getFQName(), Type.normal);
Message msg = new Message(participant.getFQName(), Type.normal);
msg.addExtension(payload);
msg.setFrom(conn.getUser());
msg.setProperty(Tools.PROP_SESSION_ID, getSessionId());