Issue #2563 added packet extension to openfire plugin

openfire plugin now sends configuration in packet extension
legacy method of putting config in chat message still supported by default
added configuration to web gui to toggle legacy message method


Former-commit-id: 04e7c2f749 [formerly 2e53fcbccb] [formerly 04e7c2f749 [formerly 2e53fcbccb] [formerly a2c709fb34 [formerly a26eeaae28de6e41fdc49a2b75ad6814ece478cd]]]
Former-commit-id: a2c709fb34
Former-commit-id: b366f38199 [formerly b42d2f5528]
Former-commit-id: d028af1800
This commit is contained in:
Brian Clements 2014-01-07 09:49:11 -06:00
parent 0f7a533d73
commit 55467fe96e
10 changed files with 374 additions and 74 deletions

View file

@ -1,4 +1,5 @@
source.. = src/
source.. = java/
output.. = bin/
bin.includes = META-INF/,\
.
.,\
plugin.xml

View file

@ -1,27 +1,44 @@
/**
* @author bkowal
*/
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.openfire.plugin.configuration.collaboration;
import java.io.File;
import java.net.InetAddress;
import java.net.UnknownHostException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.TaskEngine;
import org.apache.commons.configuration.ConfigurationException;
import org.jivesoftware.openfire.MessageRouter;
import org.jivesoftware.openfire.XMPPServer;
import org.jivesoftware.openfire.container.Plugin;
import org.jivesoftware.openfire.container.PluginManager;
import org.jivesoftware.openfire.event.SessionEventDispatcher;
import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.TaskEngine;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xmpp.packet.JID;
import org.apache.commons.configuration.ConfigurationException;
import com.raytheon.openfire.plugin.configuration.collaboration.configuration.ConfigurationPacket;
import com.raytheon.openfire.plugin.configuration.collaboration.configuration.HttpdCollaborationConfiguration;
import com.raytheon.openfire.plugin.configuration.collaboration.httpd.HttpdCollaborationStatusMonitor;
import com.raytheon.openfire.plugin.configuration.collaboration.httpd.HttpdCollaborationConfReader;
import com.raytheon.openfire.plugin.configuration.collaboration.httpd.HttpdCollaborationStatusMonitor;
import com.raytheon.openfire.plugin.configuration.collaboration.listener.HttpdCollaborationSessionEventListener;
/**
@ -34,7 +51,9 @@ import com.raytheon.openfire.plugin.configuration.collaboration.listener.HttpdCo
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Aug 7, 2012 bkowal Initial creation
* Aug 07, 2012 bkowal Initial creation
* Jan 06, 2013 2563 bclement replaced TaskEngine shutdown with cancel task
* added legacy format setter/accessor
*
* </pre>
*
@ -84,7 +103,10 @@ public class HttpdCollaborationConfigurationPlugin implements Plugin {
}
if ((this.monitorTaskEngine == null) == false) {
this.monitorTaskEngine.shutdown();
// we don't want to shutdown the engine since it is a singleton
// if we do, we can't reload the plugin
this.monitorTaskEngine
.cancelScheduledTask(this.httpdCollaborationStatusMonitor);
this.monitorTaskEngine = null;
}
}
@ -189,24 +211,24 @@ public class HttpdCollaborationConfigurationPlugin implements Plugin {
.cancelScheduledTask(this.httpdCollaborationStatusMonitor);
}
/**
* Sets the configurable installation location of awips2-httpd-collaboration
*
* @param _location
* the location of awips2-httpd-collaboration
*/
public void setHttpdCollaborationLocation(String _location) {
JiveGlobals.setProperty(LOCATION, _location);
}
/**
* Sets the configurable installation location of awips2-httpd-collaboration
*
* @param _location
* the location of awips2-httpd-collaboration
*/
public void setHttpdCollaborationLocation(String _location) {
JiveGlobals.setProperty(LOCATION, _location);
}
/**
* Returns the installation location of awips2-httpd-collaboration from the
* openfire configuration
*
* @return the installation root of awips2-httpd-collaboration
*/
/**
* Returns the installation location of awips2-httpd-collaboration from the
* openfire configuration
*
* @return the installation root of awips2-httpd-collaboration
*/
public String getHttpdCollaborationLocation() {
return JiveGlobals.getProperty(LOCATION, DEFAULT_LOCATION);
return JiveGlobals.getProperty(LOCATION, DEFAULT_LOCATION);
}
/**
@ -234,4 +256,23 @@ public class HttpdCollaborationConfigurationPlugin implements Plugin {
public long getHttpdMonitorInterval() {
return JiveGlobals.getLongProperty(INTERVAL, DEFAULT_INTERVAL_MS);
}
/**
* Sets the global value for toggling pre 14.3 message format support
*
* @param legacy
*/
public void setLegacySupport(boolean legacy) {
JiveGlobals.setProperty(ConfigurationPacket.LEGACY_KEY,
Boolean.toString(legacy));
}
/**
* @return true if configured to support pre 14.3 message format
*/
public boolean hasLegacySupport() {
return JiveGlobals.getBooleanProperty(ConfigurationPacket.LEGACY_KEY,
true);
}
}

View file

@ -0,0 +1,167 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.openfire.plugin.configuration.collaboration.configuration;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
import org.apache.commons.lang.StringUtils;
import org.dom4j.Element;
import org.jivesoftware.util.JiveGlobals;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xmpp.packet.Message;
import org.xmpp.packet.PacketExtension;
/**
* Packet extension for collaboration configuration messages to clients
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Dec 20, 2013 bclement Initial creation
*
* </pre>
*
* @author bclement
* @version 1.0
*/
public class ConfigurationPacket extends PacketExtension {
private static final Logger log = LoggerFactory
.getLogger(ConfigurationPacket.class);
// format property file
public static final String CONFIG_FILE_KEY = "plugin.collaboration.packet.format.file";
private static final String DEFAULT_PLUGIN_CONFIG_FILE = "conf"
+ File.separator + "configurationPacketFormat.properties";
private static final Properties properties = new Properties();
static {
String confFile = JiveGlobals.getProperty(CONFIG_FILE_KEY,
DEFAULT_PLUGIN_CONFIG_FILE);
File f = new File(JiveGlobals.getHomeDirectory(), confFile);
if (f.exists()) {
try {
properties.load(new FileInputStream(f));
} catch (IOException e) {
// defaults will be used
log.error("Problem loading packet format configuration file: "
+ f.getAbsolutePath(), e);
}
} else {
log.info("Using default config packet format since there was no format file at "
+ f.getAbsolutePath());
}
}
// property keys
public static final String XMLNS_KEY = "plugin.collaboration.packet.xmlns";
public static final String ELEMENT_KEY = "plugin.collaboration.packet.element";
public static final String ATTRIBUTES_KEY = "plugin.collaboration.packet.attributes";
public static final String LEGACY_KEY = "plugin.collaboration.packet.legacy";
// property value defaults
public static final String XMLNS_DEFAULT = "urn:uf:viz:collaboration";
public static final String ELEMENT_DEFAULT = "SessionData";
public static final String ATTRIBUTES_DEFAULT = "payloadtype=Config,encoding=STRING";
// legacy
private static final String LEGACY_PREAMBLE = "[[CONFIG#";
private static final String LEGACY_SUFFIX = "]]";
/**
* @param element
*/
public ConfigurationPacket(Element element) {
super(element);
}
/**
* @param body
* configuration payload for packet
*/
public ConfigurationPacket(String body) {
super(create(body));
}
/**
* Create packet extension element
*
* @param body
* configuration payload for packet
* @return
*/
private static Element create(String body) {
String element = properties.getProperty(ELEMENT_KEY, ELEMENT_DEFAULT);
String xmlns = properties.getProperty(XMLNS_KEY, XMLNS_DEFAULT);
Element rval = docFactory.createElement(element, xmlns);
String attributes = properties.getProperty(ATTRIBUTES_KEY,
ATTRIBUTES_DEFAULT);
for (String keyval : StringUtils.split(attributes, ',')) {
String[] separated = StringUtils.split(keyval, '=');
if (separated.length != 2) {
log.error("Malformed key-value pair in configuration: "
+ keyval);
continue;
}
rval.addAttribute(separated[0].trim(), separated[1].trim());
}
rval.addText(body);
return rval;
}
/**
* Create extended message packet with configuration payload
*
* @param body
* configuration payload for packet
* @return
*/
public static Message createMessage(String body) {
Message rval = new Message();
rval.addExtension(new ConfigurationPacket(body));
// pre 14.3 message format support
if (JiveGlobals.getBooleanProperty(LEGACY_KEY, true)) {
rval.setBody(LEGACY_PREAMBLE + body + LEGACY_SUFFIX);
}
return rval;
}
}

View file

@ -1,9 +1,24 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
*/
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.openfire.plugin.configuration.collaboration.configuration;
import com.raytheon.openfire.plugin.configuration.collaboration.util.HttpdCollaborationUtil;
/**
* Used to store and format the information retrieved from the
@ -15,7 +30,8 @@ import com.raytheon.openfire.plugin.configuration.collaboration.util.HttpdCollab
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Aug 7, 2012 bkowal Initial creation
* Aug 07, 2012 bkowal Initial creation
* Jan 06, 2013 2563 bclement removed config preamble
*
* </pre>
*
@ -41,9 +57,7 @@ public class HttpdCollaborationConfiguration {
@Override
public String toString() {
return HttpdCollaborationUtil.CONFIG_PREAMBLE + URL_PARAMETER_NAME
+ " : " + this.getHttpdCollaborationURL()
+ HttpdCollaborationUtil.DIRECTIVE_SUFFIX;
return URL_PARAMETER_NAME + " : " + this.getHttpdCollaborationURL();
}
public String getHttpdCollaborationURL() {

View file

@ -1,6 +1,22 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
*/
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.openfire.plugin.configuration.collaboration.httpd;
import org.apache.commons.configuration.ConfigurationException;

View file

@ -1,6 +1,22 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
*/
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.openfire.plugin.configuration.collaboration.httpd;
import java.io.File;
@ -10,13 +26,22 @@ import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.PropertiesConfiguration;
/**
* This class was created because version 1.6 of commons configuration does not
* allow you to decide whether you want to allow includes or not. There is a
* 'setIncludesAllowed' method; however, it is protected.
*
* <pre>
*
* SOFTWARE HISTORY
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Aug 2012 bkowal Initial creation
*
* </pre>
*
* @author bkowal
*
* This class was created because version 1.6 of commons configuration
* does not allow you to decide whether you want to allow includes or
* not. There is a 'setIncludesAllowed' method; however, it is
* protected.
*
* @version 1.0
*/
public class HttpdCollaborationPropertiesConfiguration extends PropertiesConfiguration {
/**

View file

@ -23,24 +23,25 @@ import java.io.File;
import java.io.IOException;
import java.util.TimerTask;
import org.jivesoftware.openfire.SessionManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xmpp.packet.Message;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.http.HttpStatus;
import org.jivesoftware.openfire.SessionManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xmpp.packet.Message;
import com.raytheon.openfire.plugin.configuration.collaboration.configuration.ConfigurationPacket;
import com.raytheon.openfire.plugin.configuration.collaboration.exception.HttpdCollaborationNotRunningException;
import com.raytheon.openfire.plugin.configuration.collaboration.exception.HttpdCollaborationStatusException;
import com.raytheon.openfire.plugin.configuration.collaboration.util.HttpdCollaborationUtil;
/**
* Runs a series of checks to determine if httpd-collaboration is still
* running on-demand and on a scheduled basis. The checks include:
* verifying that a pid file exists for httpd-collaboration and
* executing an http GET request against the httpd-collaboration server.
* Runs a series of checks to determine if httpd-collaboration is still running
* on-demand and on a scheduled basis. The checks include: verifying that a pid
* file exists for httpd-collaboration and executing an http GET request against
* the httpd-collaboration server.
*
* <pre>
*
@ -48,7 +49,8 @@ import com.raytheon.openfire.plugin.configuration.collaboration.util.HttpdCollab
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Jul 26, 2012 bkowal Initial creation
* Jul 26, 2012 bkowal Initial creation
* Jan 06, 2013 2563 bclement replaced chat message with packet extension
*
* </pre>
*
@ -141,7 +143,7 @@ public class HttpdCollaborationStatusMonitor extends TimerTask {
@Override
public void run() {
logger.info("Verifying that httpd-collaboration is still available ...");
logger.debug("Verifying that httpd-collaboration is still available ...");
String errorMessage = null;
try {
@ -172,8 +174,7 @@ public class HttpdCollaborationStatusMonitor extends TimerTask {
}
private synchronized void broadcastMessage(String body) {
Message message = new Message();
message.setBody(body);
Message message = ConfigurationPacket.createMessage(body);
this.sessionManager.broadcast(message);
}
}

View file

@ -1,23 +1,40 @@
/**
* This software was developed and / or modified by Raytheon Company,
* pursuant to Contract DG133W-05-CQ-1067 with the US Government.
*
*/
* U.S. EXPORT CONTROLLED TECHNICAL DATA
* This software product contains export-restricted data whose
* export/transfer/disclosure is restricted by U.S. law. Dissemination
* to non-U.S. persons whether in the United States or abroad requires
* an export license or other authorization.
*
* Contractor Name: Raytheon Company
* Contractor Address: 6825 Pine Street, Suite 340
* Mail Stop B8
* Omaha, NE 68106
* 402.291.0100
*
* See the AWIPS II Master Rights File ("Master Rights File.pdf") for
* further licensing information.
**/
package com.raytheon.openfire.plugin.configuration.collaboration.listener;
import java.util.TimerTask;
import org.jivesoftware.openfire.MessageRouter;
import org.jivesoftware.openfire.event.SessionEventListener;
import org.jivesoftware.openfire.session.Session;
import org.jivesoftware.util.TaskEngine;
import org.jivesoftware.openfire.MessageRouter;
import org.xmpp.packet.JID;
import org.xmpp.packet.Message;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xmpp.packet.JID;
import org.xmpp.packet.Message;
import com.raytheon.openfire.plugin.configuration.collaboration.util.HttpdCollaborationUtil;
import com.raytheon.openfire.plugin.configuration.collaboration.httpd.HttpdCollaborationStatusMonitor;
import com.raytheon.openfire.plugin.configuration.collaboration.configuration.ConfigurationPacket;
import com.raytheon.openfire.plugin.configuration.collaboration.exception.HttpdCollaborationNotRunningException;
import com.raytheon.openfire.plugin.configuration.collaboration.exception.HttpdCollaborationStatusException;
import com.raytheon.openfire.plugin.configuration.collaboration.httpd.HttpdCollaborationStatusMonitor;
import com.raytheon.openfire.plugin.configuration.collaboration.util.HttpdCollaborationUtil;
/**
* Impelements @{link SessionEventListener} to wait for new users to connect to
@ -29,7 +46,8 @@ import com.raytheon.openfire.plugin.configuration.collaboration.exception.HttpdC
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Aug 7, 2012 bkowal Initial creation
* Aug 07, 2012 bkowal Initial creation
* Jan 06, 2013 2563 bclement replaced chat message with packet extension
*
* </pre>
*
@ -111,10 +129,10 @@ public class HttpdCollaborationSessionEventListener implements
*/
@Override
public void sessionCreated(Session session) {
final Message message = new Message();
final Message message = ConfigurationPacket.createMessage(this
.composeMessageBody());
message.setTo(session.getAddress());
message.setFrom(this.serverAddress);
message.setBody(this.composeMessageBody());
TimerTask messageTask = new TimerTask() {
@Override

View file

@ -20,28 +20,27 @@
package com.raytheon.openfire.plugin.configuration.collaboration.util;
import java.io.File;
/**
* Various utility methods that are utilized by the Httpd Collaboration plugin
* that do not require a class to be instantiated.
*
* <pre>
*
*
* SOFTWARE HISTORY
*
*
* Date Ticket# Engineer Description
* ------------ ---------- ----------- --------------------------
* Aug 7, 2012 bkowal Initial creation
*
* Aug 07, 2012 bkowal Initial creation
* Jan 06, 2013 2563 bclement removed config preamble
*
* </pre>
*
*
* @author bkowal
* @version 1.0
* @version 1.0
*/
public abstract class HttpdCollaborationUtil {
public static final String CONFIG_PREAMBLE = "[[CONFIG#";
public static final String DIRECTIVE_SUFFIX = "]]";
public static String encodeErrorMessage(Throwable e) {
String content = e.getMessage();
@ -50,7 +49,7 @@ public abstract class HttpdCollaborationUtil {
content = e.toString();
}
return CONFIG_PREAMBLE + "error : " + content + DIRECTIVE_SUFFIX;
return "error : " + content;
}
public static String endPathIfNecessary(String _path) {
@ -60,4 +59,5 @@ public abstract class HttpdCollaborationUtil {
return _path + File.separator;
}
}

View file

@ -16,19 +16,21 @@
// Currently, users are not allowed to modify the httpd-collaboration location
// because the rpm is not relocatable.
long interval = ParamUtils.getLongParameter(request, "txtInterval", DEFAULT_INTERVAL_S);
boolean legacy = ParamUtils.getBooleanParameter(request, "chkLegacy", false);
HttpdCollaborationConfigurationPlugin plugin = (HttpdCollaborationConfigurationPlugin) XMPPServer.getInstance().getPluginManager().getPlugin("com.raytheon.openfire.plugin.configuration.collaboration");
if (save)
{
plugin.setHttpdMonitorInterval(interval * 1000);
plugin.setLegacySupport(legacy);
response.sendRedirect("httpd-collaboration-monitor-admin.jsp?settingsSaved=true");
return;
}
String location = plugin.getHttpdCollaborationLocation();
interval = (plugin.getHttpdMonitorInterval() / 1000);
String legacyChkValue = plugin.hasLegacySupport() ? "checked" : "";
%>
<html>
@ -118,6 +120,21 @@
</tr>
</tbody>
</table>
</br></br></br>
<p>
Legacy message format support. If enabled, configuration is sent in chat message to support clients older than version 14.3.
</p>
<table cellpadding="3" cellspacing="0" border="0" width="100%">
<tbody>
<tr>
<td width="15%" valign="top">legacy message format:&nbsp;</td>
<td width="85%">
<input type="checkbox" id="chkLegacy" name="chkLegacy" value="true" <%= legacyChkValue %> >
</td>
</tr>
</tbody>
</table>
</div>
<input id="btnSubmit" type="submit" value="Save Settings" />
</form>