From 4ac0e4956d27565ab73f9f76e47237850df195d2 Mon Sep 17 00:00:00 2001 From: Lloyd Watkin Date: Tue, 2 Sep 2014 17:24:50 +0100 Subject: [PATCH 01/13] Perform discovery for 'home user' on startup --- src/main/java/com/buddycloud/mediaserver/Main.java | 2 +- .../com/buddycloud/mediaserver/xmpp/XMPPToolBox.java | 7 +++++-- .../buddycloud/mediaserver/xmpp/pubsub/PubSubClient.java | 9 ++++++++- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/buddycloud/mediaserver/Main.java b/src/main/java/com/buddycloud/mediaserver/Main.java index 92ccdd7..e758382 100644 --- a/src/main/java/com/buddycloud/mediaserver/Main.java +++ b/src/main/java/com/buddycloud/mediaserver/Main.java @@ -132,7 +132,7 @@ private static boolean startXMPPToolBox(Properties configuration) { return false; } - XMPPToolBox.getInstance().start(component, connection); + XMPPToolBox.getInstance().start(component, connection, configuration); LOGGER.info("Buddycloud Media Server XMPP component started!"); diff --git a/src/main/java/com/buddycloud/mediaserver/xmpp/XMPPToolBox.java b/src/main/java/com/buddycloud/mediaserver/xmpp/XMPPToolBox.java index 2f5aefb..529196f 100644 --- a/src/main/java/com/buddycloud/mediaserver/xmpp/XMPPToolBox.java +++ b/src/main/java/com/buddycloud/mediaserver/xmpp/XMPPToolBox.java @@ -15,8 +15,11 @@ */ package com.buddycloud.mediaserver.xmpp; +import java.util.Properties; + import com.buddycloud.mediaserver.commons.exception.XMPPException; import com.buddycloud.mediaserver.xmpp.pubsub.PubSubClient; + import org.jivesoftware.smack.XMPPConnection; public class XMPPToolBox { @@ -36,10 +39,10 @@ public static XMPPToolBox getInstance() { } public void start(MediaServerComponent component, - XMPPConnection connection) { + XMPPConnection connection, Properties configuration) { if (!started) { authClient = new AuthVerifier(component); - pubSubClient = new PubSubClient(connection); + pubSubClient = new PubSubClient(connection, configuration); started = true; } diff --git a/src/main/java/com/buddycloud/mediaserver/xmpp/pubsub/PubSubClient.java b/src/main/java/com/buddycloud/mediaserver/xmpp/pubsub/PubSubClient.java index cd77fa8..73bdeac 100644 --- a/src/main/java/com/buddycloud/mediaserver/xmpp/pubsub/PubSubClient.java +++ b/src/main/java/com/buddycloud/mediaserver/xmpp/pubsub/PubSubClient.java @@ -15,6 +15,7 @@ */ package com.buddycloud.mediaserver.xmpp.pubsub; +import com.buddycloud.mediaserver.commons.MediaServerConfiguration; import com.buddycloud.mediaserver.xmpp.pubsub.capabilities.CapabilitiesDecorator; import com.buddycloud.mediaserver.xmpp.util.AccessModel; import com.buddycloud.mediaserver.xmpp.util.ConfigurationForm; @@ -44,6 +45,7 @@ import java.util.Iterator; import java.util.List; import java.util.Map; +import java.util.Properties; /** * XMPP client that handles PubSub (XEP-0060) operations. @@ -61,9 +63,11 @@ public class PubSubClient { private Map pubSubManagersCache = new HashMap(); private Map serversCache = new HashMap(); private Connection connection; + private Properties configuration; - public PubSubClient(Connection connection) { + public PubSubClient(Connection connection, Properties configuration) { this.connection = connection; + this.configuration = configuration; init(); } @@ -81,6 +85,9 @@ private void init() { PubSubNamespace.BASIC.getXmlns()); ProviderManager.getInstance().addExtensionProvider("affiliation", PubSubNamespace.OWNER.getXmlns(), affiliationProvider); + + JID user = new JID(configuration.getProperty(MediaServerConfiguration.XMPP_CONNECTION_USERNAME)); + getChannelServerAddress(configuration.getProperty(user.getDomain())); } private Node getNode(String entityId) { From a74c1af5830794c2aa2ae5165b5d008ccc4172a4 Mon Sep 17 00:00:00 2001 From: Lloyd Watkin Date: Wed, 3 Sep 2014 10:02:48 +0100 Subject: [PATCH 02/13] Perform discovery for local server on startup --- pom.xml | 7 ++- .../business/util/PubSubManagerFactory.java | 17 ++++++ .../mediaserver/xmpp/pubsub/PubSubClient.java | 26 +++++++-- .../xmpp/pubsub/PubSubClientTest.java | 53 +++++++++++++++++++ 4 files changed, 99 insertions(+), 4 deletions(-) create mode 100644 src/main/java/com/buddycloud/mediaserver/business/util/PubSubManagerFactory.java create mode 100644 src/test/java/com/buddycloud/mediaserver/xmpp/pubsub/PubSubClientTest.java diff --git a/pom.xml b/pom.xml index 0b0eac9..9f198b0 100644 --- a/pom.xml +++ b/pom.xml @@ -46,7 +46,12 @@ easymock 3.2 - + + org.mockito + mockito-all + 1.9.0 + test + javax.servlet diff --git a/src/main/java/com/buddycloud/mediaserver/business/util/PubSubManagerFactory.java b/src/main/java/com/buddycloud/mediaserver/business/util/PubSubManagerFactory.java new file mode 100644 index 0000000..b0b8d07 --- /dev/null +++ b/src/main/java/com/buddycloud/mediaserver/business/util/PubSubManagerFactory.java @@ -0,0 +1,17 @@ +package com.buddycloud.mediaserver.business.util; + +import org.jivesoftware.smack.Connection; +import org.jivesoftware.smackx.pubsub.PubSubManager; + +public class PubSubManagerFactory { + + private Connection connection; + + public PubSubManagerFactory(Connection connection) { + this.connection = connection; + } + + public PubSubManager create(String domain) { + return new PubSubManager(connection, domain); + } +} \ No newline at end of file diff --git a/src/main/java/com/buddycloud/mediaserver/xmpp/pubsub/PubSubClient.java b/src/main/java/com/buddycloud/mediaserver/xmpp/pubsub/PubSubClient.java index 73bdeac..59cda8f 100644 --- a/src/main/java/com/buddycloud/mediaserver/xmpp/pubsub/PubSubClient.java +++ b/src/main/java/com/buddycloud/mediaserver/xmpp/pubsub/PubSubClient.java @@ -15,6 +15,7 @@ */ package com.buddycloud.mediaserver.xmpp.pubsub; +import com.buddycloud.mediaserver.business.util.PubSubManagerFactory; import com.buddycloud.mediaserver.commons.MediaServerConfiguration; import com.buddycloud.mediaserver.xmpp.pubsub.capabilities.CapabilitiesDecorator; import com.buddycloud.mediaserver.xmpp.util.AccessModel; @@ -64,12 +65,31 @@ public class PubSubClient { private Map serversCache = new HashMap(); private Connection connection; private Properties configuration; + private PubSubManagerFactory pubsubManagerFactory; - public PubSubClient(Connection connection, Properties configuration) { + public PubSubClient(Connection connection, Properties configuration, PubSubManagerFactory factory) { this.connection = connection; this.configuration = configuration; + if (null != factory) { + setPubSubManagerFactory(factory); + } init(); } + + public PubSubClient(Connection connection, Properties configuration) { + this(connection, configuration, null); + } + + private PubSubManagerFactory getPubSubManagerFactory() { + if (null == pubsubManagerFactory) { + pubsubManagerFactory = new PubSubManagerFactory(connection); + } + return pubsubManagerFactory; + } + + public void setPubSubManagerFactory(PubSubManagerFactory factory) { + this.pubsubManagerFactory = factory; + } private void init() { Object affiliationsProvider = ProviderManager.getInstance() @@ -95,7 +115,7 @@ private Node getNode(String entityId) { String serverAddress = getChannelServerAddress(entityJID.getDomain()); Node node = null; if (serverAddress != null) { - PubSubManager manager = pubSubManagersCache.get(serverAddress); + PubSubManager manager = getPubSubManagerFactory().create(serverAddress); if (manager == null) { manager = new PubSubManager(connection, serverAddress); pubSubManagersCache.put(serverAddress, manager); @@ -121,7 +141,7 @@ private boolean isChannelServerIdentity(DiscoverInfo.Identity identity) { private String discoverDomainServer(String domain) { ServiceDiscoveryManager discoManager = ServiceDiscoveryManager .getInstanceFor(connection); - PubSubManager pubSubManager = new PubSubManager(connection, domain); + PubSubManager pubSubManager = getPubSubManagerFactory().create(domain); DiscoverItems discoverItems; try { diff --git a/src/test/java/com/buddycloud/mediaserver/xmpp/pubsub/PubSubClientTest.java b/src/test/java/com/buddycloud/mediaserver/xmpp/pubsub/PubSubClientTest.java new file mode 100644 index 0000000..3dcc180 --- /dev/null +++ b/src/test/java/com/buddycloud/mediaserver/xmpp/pubsub/PubSubClientTest.java @@ -0,0 +1,53 @@ +package com.buddycloud.mediaserver.xmpp.pubsub; + +import static org.junit.Assert.*; + +import java.util.Properties; + +import org.jivesoftware.smack.Connection; +import org.jivesoftware.smack.XMPPException; +import org.jivesoftware.smackx.packet.DiscoverItems; +import org.jivesoftware.smackx.pubsub.PubSubManager; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; + +import com.buddycloud.mediaserver.business.util.PubSubManagerFactory; +import com.buddycloud.mediaserver.commons.MediaServerConfiguration; + +public class PubSubClientTest { + + private Properties configuration; + private Connection connection; + private PubSubManagerFactory factory; + private PubSubManager manager; + private DiscoverItems items; + + @Before + public void setUp() throws Exception { + connection = Mockito.mock(Connection.class); + configuration = Mockito.mock(Properties.class); + factory = Mockito.mock(PubSubManagerFactory.class); + } + + @After + public void tearDown() throws Exception { + } + + @Test(expected=NullPointerException.class) + public void discoverIsAttemptedOnConnection() throws Exception { + String jid = "marty@mcfly.org"; + String domain = "mcfly.org"; + + Mockito.when( + configuration + .getProperty(MediaServerConfiguration.XMPP_CONNECTION_USERNAME)) + .thenReturn(jid); + Mockito.when(factory.create(domain)).thenReturn(null); + + PubSubClient client = new PubSubClient(connection, configuration, factory); + + } + +} From c973dafad0ccdfd993ffcd7598f00399f30f57bc Mon Sep 17 00:00:00 2001 From: Lloyd Watkin Date: Wed, 3 Sep 2014 10:19:38 +0100 Subject: [PATCH 03/13] Fix JID reference --- .../com/buddycloud/mediaserver/xmpp/pubsub/PubSubClient.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/buddycloud/mediaserver/xmpp/pubsub/PubSubClient.java b/src/main/java/com/buddycloud/mediaserver/xmpp/pubsub/PubSubClient.java index 59cda8f..5798666 100644 --- a/src/main/java/com/buddycloud/mediaserver/xmpp/pubsub/PubSubClient.java +++ b/src/main/java/com/buddycloud/mediaserver/xmpp/pubsub/PubSubClient.java @@ -107,7 +107,7 @@ private void init() { PubSubNamespace.OWNER.getXmlns(), affiliationProvider); JID user = new JID(configuration.getProperty(MediaServerConfiguration.XMPP_CONNECTION_USERNAME)); - getChannelServerAddress(configuration.getProperty(user.getDomain())); + getChannelServerAddress(user.getDomain()); } private Node getNode(String entityId) { From fdf23ad6ca3951a05100870cb909ff20e3f07c52 Mon Sep 17 00:00:00 2001 From: Lloyd Watkin Date: Wed, 3 Sep 2014 10:56:05 +0100 Subject: [PATCH 04/13] Clean up --- .../mediaserver/xmpp/pubsub/PubSubClient.java | 20 ++++++++++--------- .../xmpp/pubsub/PubSubClientTest.java | 15 +++----------- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/src/main/java/com/buddycloud/mediaserver/xmpp/pubsub/PubSubClient.java b/src/main/java/com/buddycloud/mediaserver/xmpp/pubsub/PubSubClient.java index 5798666..b61eb69 100644 --- a/src/main/java/com/buddycloud/mediaserver/xmpp/pubsub/PubSubClient.java +++ b/src/main/java/com/buddycloud/mediaserver/xmpp/pubsub/PubSubClient.java @@ -67,7 +67,8 @@ public class PubSubClient { private Properties configuration; private PubSubManagerFactory pubsubManagerFactory; - public PubSubClient(Connection connection, Properties configuration, PubSubManagerFactory factory) { + public PubSubClient(Connection connection, Properties configuration, + PubSubManagerFactory factory) { this.connection = connection; this.configuration = configuration; if (null != factory) { @@ -75,18 +76,18 @@ public PubSubClient(Connection connection, Properties configuration, PubSubManag } init(); } - + public PubSubClient(Connection connection, Properties configuration) { - this(connection, configuration, null); + this(connection, configuration, null); } - + private PubSubManagerFactory getPubSubManagerFactory() { if (null == pubsubManagerFactory) { pubsubManagerFactory = new PubSubManagerFactory(connection); } return pubsubManagerFactory; } - + public void setPubSubManagerFactory(PubSubManagerFactory factory) { this.pubsubManagerFactory = factory; } @@ -105,9 +106,9 @@ private void init() { PubSubNamespace.BASIC.getXmlns()); ProviderManager.getInstance().addExtensionProvider("affiliation", PubSubNamespace.OWNER.getXmlns(), affiliationProvider); - - JID user = new JID(configuration.getProperty(MediaServerConfiguration.XMPP_CONNECTION_USERNAME)); - getChannelServerAddress(user.getDomain()); + + getChannelServerAddress(configuration + .getProperty(MediaServerConfiguration.XMPP_CONNECTION_SERVICENAME)); } private Node getNode(String entityId) { @@ -115,7 +116,8 @@ private Node getNode(String entityId) { String serverAddress = getChannelServerAddress(entityJID.getDomain()); Node node = null; if (serverAddress != null) { - PubSubManager manager = getPubSubManagerFactory().create(serverAddress); + PubSubManager manager = getPubSubManagerFactory().create( + serverAddress); if (manager == null) { manager = new PubSubManager(connection, serverAddress); pubSubManagersCache.put(serverAddress, manager); diff --git a/src/test/java/com/buddycloud/mediaserver/xmpp/pubsub/PubSubClientTest.java b/src/test/java/com/buddycloud/mediaserver/xmpp/pubsub/PubSubClientTest.java index 3dcc180..8c510d1 100644 --- a/src/test/java/com/buddycloud/mediaserver/xmpp/pubsub/PubSubClientTest.java +++ b/src/test/java/com/buddycloud/mediaserver/xmpp/pubsub/PubSubClientTest.java @@ -1,13 +1,8 @@ package com.buddycloud.mediaserver.xmpp.pubsub; -import static org.junit.Assert.*; - import java.util.Properties; import org.jivesoftware.smack.Connection; -import org.jivesoftware.smack.XMPPException; -import org.jivesoftware.smackx.packet.DiscoverItems; -import org.jivesoftware.smackx.pubsub.PubSubManager; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -21,9 +16,6 @@ public class PubSubClientTest { private Properties configuration; private Connection connection; private PubSubManagerFactory factory; - private PubSubManager manager; - private DiscoverItems items; - @Before public void setUp() throws Exception { connection = Mockito.mock(Connection.class); @@ -37,16 +29,15 @@ public void tearDown() throws Exception { @Test(expected=NullPointerException.class) public void discoverIsAttemptedOnConnection() throws Exception { - String jid = "marty@mcfly.org"; String domain = "mcfly.org"; Mockito.when( configuration - .getProperty(MediaServerConfiguration.XMPP_CONNECTION_USERNAME)) - .thenReturn(jid); + .getProperty(MediaServerConfiguration.XMPP_CONNECTION_SERVICENAME)) + .thenReturn(domain); Mockito.when(factory.create(domain)).thenReturn(null); - PubSubClient client = new PubSubClient(connection, configuration, factory); + new PubSubClient(connection, configuration, factory); } From 744e6f6ea76411e2d20a1b10e730726eaf856617 Mon Sep 17 00:00:00 2001 From: Lloyd Watkin Date: Thu, 18 Sep 2014 14:48:04 +0100 Subject: [PATCH 05/13] Choose full image based on smallest size --- .../com/buddycloud/mediaserver/business/util/ImageUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/buddycloud/mediaserver/business/util/ImageUtils.java b/src/main/java/com/buddycloud/mediaserver/business/util/ImageUtils.java index 7bbe229..fc0473e 100644 --- a/src/main/java/com/buddycloud/mediaserver/business/util/ImageUtils.java +++ b/src/main/java/com/buddycloud/mediaserver/business/util/ImageUtils.java @@ -105,7 +105,7 @@ public static BufferedImage createImagePreview(BufferedImage img, public static BufferedImage cropMaximumSquare(BufferedImage img) throws IOException { int smallerSide = img.getHeight() <= img.getWidth() ? img.getHeight() : img.getWidth(); final BufferedImage cropedImg = - Thumbnails.of(img).sourceRegion(Positions.CENTER, smallerSide/2, smallerSide/2).size(smallerSide, smallerSide).asBufferedImage(); + Thumbnails.of(img).sourceRegion(Positions.CENTER, smallerSide, smallerSide).size(smallerSide, smallerSide).asBufferedImage(); return cropedImg; } From 3841324043842e71cedb3cb3407165fb34f0bd53 Mon Sep 17 00:00:00 2001 From: Lloyd Watkin Date: Mon, 13 Oct 2014 09:51:40 +0100 Subject: [PATCH 06/13] If user has no affiliation we get an exception --- .../mediaserver/xmpp/pubsub/PubSubClient.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/buddycloud/mediaserver/xmpp/pubsub/PubSubClient.java b/src/main/java/com/buddycloud/mediaserver/xmpp/pubsub/PubSubClient.java index 017c47d..27fa49e 100644 --- a/src/main/java/com/buddycloud/mediaserver/xmpp/pubsub/PubSubClient.java +++ b/src/main/java/com/buddycloud/mediaserver/xmpp/pubsub/PubSubClient.java @@ -172,7 +172,8 @@ private Affiliation getAffiliation(Node node, String userBareJID) while (true) { PubSub reply = (PubSub) node.sendPubsubPacket(Type.GET, request); - + + LOGGER.debug("Affiliations reply " + reply.toXML()); AffiliationsExtension subElem = (AffiliationsExtension) reply .getExtension( PubSubElementType.AFFILIATIONS.getElementName(), @@ -231,16 +232,17 @@ public boolean matchUserCapability(String userJID, String entityId, return false; } + + if (null == affiliation) { + LOGGER.debug("User " + userBareJID + " has no affiliation to node " + node.getId()); + return false; + } LOGGER.debug(userBareJID + " affiliation: " + affiliation.getType().toString()); - if (affiliation != null) { - return capability.isUserAllowed(affiliation.getType() - .toString()); - } + return capability.isUserAllowed(affiliation.getType() + .toString()); } - - return false; } /** From dc7c70731d5c994d543f38e08ff34c5d30b44305 Mon Sep 17 00:00:00 2001 From: Lloyd Watkin Date: Tue, 21 Oct 2014 12:25:34 +0100 Subject: [PATCH 07/13] Add return statement --- .../mediaserver/xmpp/pubsub/PubSubClient.java | 39 ++++++++++--------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/buddycloud/mediaserver/xmpp/pubsub/PubSubClient.java b/src/main/java/com/buddycloud/mediaserver/xmpp/pubsub/PubSubClient.java index aac39ac..b885a8b 100644 --- a/src/main/java/com/buddycloud/mediaserver/xmpp/pubsub/PubSubClient.java +++ b/src/main/java/com/buddycloud/mediaserver/xmpp/pubsub/PubSubClient.java @@ -233,31 +233,32 @@ public boolean matchUserCapability(String userJID, String entityId, } Node node = getNode(entityId); - if (node != null) { - Affiliation affiliation; + if (node == null) { + return false; + } + Affiliation affiliation; - try { - LOGGER.debug("Getting " + userBareJID - + " affiliation for node [" + node.getId() + "]"); - affiliation = getAffiliation(node, userBareJID); - } catch (XMPPException e) { - LOGGER.warn("Could not read node '" + node.getId() - + " affiliation for '" + userBareJID + "'", e); + try { + LOGGER.debug("Getting " + userBareJID + + " affiliation for node [" + node.getId() + "]"); + affiliation = getAffiliation(node, userBareJID); + } catch (XMPPException e) { + LOGGER.warn("Could not read node '" + node.getId() + + " affiliation for '" + userBareJID + "'", e); - return false; - } + return false; + } - if (null == affiliation) { - LOGGER.debug("User " + userBareJID + " has no affiliation to node " + node.getId()); - return false; - } + if (null == affiliation) { + LOGGER.debug("User " + userBareJID + " has no affiliation to node " + node.getId()); + return false; + } + LOGGER.debug(userBareJID + " affiliation: " + affiliation.getType().toString()); - LOGGER.debug(userBareJID + " affiliation: " + affiliation.getType().toString()); + return capability.isUserAllowed(affiliation.getType() + .toString()); - return capability.isUserAllowed(affiliation.getType() - .toString()); - } } /** From f2c88b426dbc5adc957b7112e91e6106f298946e Mon Sep 17 00:00:00 2001 From: Lloyd Watkin Date: Tue, 21 Oct 2014 12:42:19 +0100 Subject: [PATCH 08/13] Build this docker image from master --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 14e39eb..296dccc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,8 +12,8 @@ RUN apt-get upgrade -y RUN apt-get install -y --no-install-recommends maven RUN git clone https://github.com/buddycloud/buddycloud-media-server.git -RUN cd buddycloud-media-server && git checkout develop +RUN cd buddycloud-media-server && git checkout master RUN cd buddycloud-media-server && mvn package ADD contrib/docker/start.sh /data/ RUN chmod +x start.sh -CMD ./start.sh \ No newline at end of file +CMD ./start.sh From afc00a6975c553fef39d02f820b854246ba6e636 Mon Sep 17 00:00:00 2001 From: Thomas Jost Date: Wed, 22 Oct 2014 18:28:46 +0200 Subject: [PATCH 09/13] Fix schema version number in upgrade-2.sql Too much copy/paste from the channels server :) --- postgres/upgrade-2.sql | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/postgres/upgrade-2.sql b/postgres/upgrade-2.sql index abd2151..dd7c3c2 100644 --- a/postgres/upgrade-2.sql +++ b/postgres/upgrade-2.sql @@ -5,9 +5,6 @@ CREATE TABLE "configuration" ("key" TEXT NOT NULL, "updated" TIMESTAMP); INSERT INTO schema_version (version, "when", description) - VALUES (8, 'now', 'Added configuration table'); + VALUES (2, NOW(), 'Added configuration table'); COMMIT; - -INSERT INTO schema_version (version, "when", description) - VALUES (2, NOW(), 'Add configuration table'); \ No newline at end of file From 767631ad770b3991e3ab753927e399e5f609061b Mon Sep 17 00:00:00 2001 From: Abmar Barros Date: Thu, 23 Oct 2014 09:43:18 -0300 Subject: [PATCH 10/13] Update README.md with logging instructions --- README.md | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/README.md b/README.md index 09262ee..fd1ad1c 100644 --- a/README.md +++ b/README.md @@ -323,3 +323,38 @@ property will be used (default is *org.postgresql.Driver*). - **media.storage.root** (Required): root path where the media server will store the media files. - **media.sizelimit** (Optional): the tolerated file content size which the media server will store (default is *104857600* - 100 MB). - **media.todisk.threshold** (Optional): the tolerated file size in bytes (default is *1048576* - 1 MB) which beyond are directly stored on disk. + +### Logging + +The buddycloud media server relies on [logback](http://logback.qos.ch/manual/configuration.html) for writing logs out. In order to configure itself, Logback will: + +* try to find a file called logback.groovy in the classpath. + +* If no such file is found, it tries to find a file called logback-test.xml in the classpath. + +* If no such file is found, it checks for the file logback.xml in the classpath.. + +* If neither file is found, logback configures itself automatically using the BasicConfigurator which will cause logging output to be directed to the console. + +A logback.xml with two appenders (```STDOUT``` writing in the console and ```FILE``` writing on a file) and with the root logger using the ```FILE``` appender looks like this: + +```xml + + + /var/log/buddycloud-media-server/mediaserver.log + + %-5relative %-5level %logger{35} - %msg%n + + + + + + %-5relative %-5level %logger{35} - %msg%n + + + + + + + +``` From 64fff319a4d091ed65684e3045df43ecf5d0cf1d Mon Sep 17 00:00:00 2001 From: Abmar Barros Date: Thu, 23 Oct 2014 09:45:06 -0300 Subject: [PATCH 11/13] Update README.md: numbers instead of bullets --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index fd1ad1c..9f45b9a 100644 --- a/README.md +++ b/README.md @@ -328,13 +328,13 @@ property will be used (default is *org.postgresql.Driver*). The buddycloud media server relies on [logback](http://logback.qos.ch/manual/configuration.html) for writing logs out. In order to configure itself, Logback will: -* try to find a file called logback.groovy in the classpath. +1. try to find a file called logback.groovy in the classpath. -* If no such file is found, it tries to find a file called logback-test.xml in the classpath. +1. If no such file is found, it tries to find a file called logback-test.xml in the classpath. -* If no such file is found, it checks for the file logback.xml in the classpath.. +1. If no such file is found, it checks for the file logback.xml in the classpath.. -* If neither file is found, logback configures itself automatically using the BasicConfigurator which will cause logging output to be directed to the console. +1. If neither file is found, logback configures itself automatically using the BasicConfigurator which will cause logging output to be directed to the console. A logback.xml with two appenders (```STDOUT``` writing in the console and ```FILE``` writing on a file) and with the root logger using the ```FILE``` appender looks like this: From 1f20a83fd0672f3f80097a524a1b9a51356c3bf9 Mon Sep 17 00:00:00 2001 From: Lloyd Watkin Date: Thu, 23 Oct 2014 15:09:52 +0100 Subject: [PATCH 12/13] Add default logback.xml @abmargb said it would work ;) --- contrib/init.d/buddycloud-media-server | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/contrib/init.d/buddycloud-media-server b/contrib/init.d/buddycloud-media-server index 4259c5a..b1b6839 100755 --- a/contrib/init.d/buddycloud-media-server +++ b/contrib/init.d/buddycloud-media-server @@ -7,7 +7,8 @@ RUNFROM=/usr/share/buddycloud-media-server DAEMON=/usr/bin/java JAR_FILE="$(ls $RUNFROM/buddycloud-media-server-jar-with-dependencies.jar)" JAR_FILE="$(basename $JAR_FILE)" -DAEMON_ARGS=" -Xms1024m -Xmx1024m -XX:-OmitStackTraceInFastThrow -Djava.awt.headless=true \ +DAEMON_ARGS=" -Dlogback.configurationFile=logback.xml -Xms1024m -Xmx1024m \ + -XX:-OmitStackTraceInFastThrow -Djava.awt.headless=true \ -cp .:$JAR_FILE com.buddycloud.mediaserver.Main" PIDFILE=/var/run/$NAME.pid SCRIPTNAME=/etc/init.d/buddycloud-media-server From aeb113267351d951b445ca2b6c351285cba25bd0 Mon Sep 17 00:00:00 2001 From: abmargb Date: Tue, 23 Dec 2014 09:48:36 -0300 Subject: [PATCH 13/13] fix startup issues --- .../java/com/buddycloud/mediaserver/Main.java | 79 +++++++++++-------- .../xmpp/MediaServerComponent.java | 10 +++ 2 files changed, 57 insertions(+), 32 deletions(-) diff --git a/src/main/java/com/buddycloud/mediaserver/Main.java b/src/main/java/com/buddycloud/mediaserver/Main.java index e758382..368be89 100644 --- a/src/main/java/com/buddycloud/mediaserver/Main.java +++ b/src/main/java/com/buddycloud/mediaserver/Main.java @@ -15,12 +15,13 @@ */ package com.buddycloud.mediaserver; -import com.buddycloud.mediaserver.commons.MediaServerConfiguration; -import com.buddycloud.mediaserver.web.MediaServerApplication; -import com.buddycloud.mediaserver.xmpp.MediaServerComponent; -import com.buddycloud.mediaserver.xmpp.XMPPToolBox; -import org.jivesoftware.smack.*; +import java.util.Properties; + +import org.jivesoftware.smack.ConnectionConfiguration; import org.jivesoftware.smack.ConnectionConfiguration.SecurityMode; +import org.jivesoftware.smack.PacketListener; +import org.jivesoftware.smack.SmackConfiguration; +import org.jivesoftware.smack.XMPPConnection; import org.jivesoftware.smack.filter.PacketFilter; import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smack.packet.Packet; @@ -33,12 +34,15 @@ import org.slf4j.LoggerFactory; import org.xmpp.component.ComponentException; -import java.util.Properties; +import com.buddycloud.mediaserver.commons.MediaServerConfiguration; +import com.buddycloud.mediaserver.web.MediaServerApplication; +import com.buddycloud.mediaserver.xmpp.MediaServerComponent; +import com.buddycloud.mediaserver.xmpp.XMPPToolBox; public class Main { private static Logger LOGGER = LoggerFactory.getLogger(Main.class); - public static void main(String[] args) { + public static void main(String[] args) throws InterruptedException { Properties configuration = MediaServerConfiguration.getInstance() .getConfiguration(); @@ -49,14 +53,7 @@ public static void main(String[] args) { System.exit(1); } - try { - while (!startXMPPToolBox(configuration)) { - Thread.sleep(5000); - } - } catch (Exception e) { - LOGGER.error("Error while starting XMPP client / component", e); - } - + startXMPPToolBox(configuration); keepAlive(); } @@ -117,26 +114,39 @@ private static void setXMPPReplyTimeout(Properties configuration) { MediaServerConfiguration.XMPP_REPLY_TIMEOUT)); SmackConfiguration.setPacketReplyTimeout(xmppReplyTimeout); } - - private static boolean startXMPPToolBox(Properties configuration) { + + private static void startXMPPToolBox(Properties configuration) + throws InterruptedException { setXMPPReplyTimeout(configuration); - XMPPConnection connection = createAndStartConnection(configuration); - addTraceListeners(connection); - LOGGER.info("Buddycloud Media Server XMPP client connection started!"); - - MediaServerComponent component; - try { - component = createXMPPComponent(configuration); - } catch (ComponentException e) { - return false; - } - + XMPPConnection connection = null; + + while (true) { + try { + connection = createAndStartConnection(configuration); + addTraceListeners(connection); + LOGGER.info("Buddycloud Media Server XMPP client connection started!"); + break; + } catch (Exception e) { + LOGGER.error("Error while starting XMPP client", e); + } + Thread.sleep(30000); + } + + MediaServerComponent component = null; + + while (true) { + try { + component = createXMPPComponent(configuration); + LOGGER.info("Buddycloud Media Server XMPP component started!"); + break; + } catch (Exception e) { + LOGGER.error("Error while starting XMPP component", e); + } + Thread.sleep(30000); + } + XMPPToolBox.getInstance().start(component, connection, configuration); - - LOGGER.info("Buddycloud Media Server XMPP component started!"); - - return true; } private static MediaServerComponent createXMPPComponent( @@ -211,6 +221,11 @@ private static XMPPConnection createAndStartConnection( configuration.getProperty(MediaServerConfiguration.XMPP_CONNECTION_PASSWORD)); } catch (org.jivesoftware.smack.XMPPException e) { LOGGER.error("XMPP connection coudn't be started", e); + try { + connection.disconnect(); + } catch (Exception e2) { + // Do nothing, best effort + } throw new com.buddycloud.mediaserver.commons.exception.XMPPException(e.getMessage(), e); } diff --git a/src/main/java/com/buddycloud/mediaserver/xmpp/MediaServerComponent.java b/src/main/java/com/buddycloud/mediaserver/xmpp/MediaServerComponent.java index d816471..e6d24bb 100644 --- a/src/main/java/com/buddycloud/mediaserver/xmpp/MediaServerComponent.java +++ b/src/main/java/com/buddycloud/mediaserver/xmpp/MediaServerComponent.java @@ -124,4 +124,14 @@ private void addField(Element xEl, String var, String type, fieldEl.addAttribute("type", type); fieldEl.addElement("value").setText(value); } + + @Override + public void postComponentShutdown() { + LOGGER.debug("Buddycloud Media XMPP component was disconnected."); + } + + @Override + public void postComponentStart() { + LOGGER.debug("Buddycloud Media XMPP component is connected and ready to accept packets."); + } }