You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@james.apache.org by rc...@apache.org on 2022/12/07 04:35:54 UTC
[james-project] branch master updated: JAMES-3864 Refactor vhost management
This is an automated email from the ASF dual-hosted git repository.
rcordier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
The following commit(s) were added to refs/heads/master by this push:
new b943ee6e92 JAMES-3864 Refactor vhost management
b943ee6e92 is described below
commit b943ee6e9252b165a189f053e67aa52eebf1dc79
Author: Rene Cordier <rc...@linagora.com>
AuthorDate: Mon Dec 5 16:37:33 2022 +0700
JAMES-3864 Refactor vhost management
vhost parameter should only be used in special cases with bad formatted URIs (like with '_' characters) as a workaround.
For most of the time, adding the vhost in the uri is enough!
---
.../backends/rabbitmq/RabbitMQConfiguration.java | 11 +++++++-
.../rabbitmq/RabbitMQConfigurationTest.java | 30 ++++++++++++++++++++++
.../modules/ROOT/pages/configure/rabbitmq.adoc | 7 ++---
.../sample-configuration/rabbitmq.properties | 5 ++--
.../sample-configuration/rabbitmq.properties | 5 ++--
src/site/xdoc/server/config-rabbitmq.xml | 7 ++---
6 files changed, 54 insertions(+), 11 deletions(-)
diff --git a/backends-common/rabbitmq/src/main/java/org/apache/james/backends/rabbitmq/RabbitMQConfiguration.java b/backends-common/rabbitmq/src/main/java/org/apache/james/backends/rabbitmq/RabbitMQConfiguration.java
index 7e08f3d3ab..9a242ebe51 100644
--- a/backends-common/rabbitmq/src/main/java/org/apache/james/backends/rabbitmq/RabbitMQConfiguration.java
+++ b/backends-common/rabbitmq/src/main/java/org/apache/james/backends/rabbitmq/RabbitMQConfiguration.java
@@ -788,7 +788,16 @@ public class RabbitMQConfiguration {
}
public Optional<String> getVhost() {
- return vhost;
+ return vhost.or(this::getVhostFromPath);
+ }
+
+ private Optional<String> getVhostFromPath() {
+ String vhostPath = uri.getPath();
+ if (vhostPath.startsWith("/")) {
+ return Optional.of(vhostPath.substring(1))
+ .filter(value -> !value.isEmpty());
+ }
+ return Optional.empty();
}
@Override
diff --git a/backends-common/rabbitmq/src/test/java/org/apache/james/backends/rabbitmq/RabbitMQConfigurationTest.java b/backends-common/rabbitmq/src/test/java/org/apache/james/backends/rabbitmq/RabbitMQConfigurationTest.java
index 32f9a2c2cd..9ae0c55c0e 100644
--- a/backends-common/rabbitmq/src/test/java/org/apache/james/backends/rabbitmq/RabbitMQConfigurationTest.java
+++ b/backends-common/rabbitmq/src/test/java/org/apache/james/backends/rabbitmq/RabbitMQConfigurationTest.java
@@ -485,6 +485,36 @@ class RabbitMQConfigurationTest {
.isEqualTo(Optional.of("test"));
}
+ @Test
+ void fromShouldReturnVhostValueWhenDeclaredInURI() {
+ PropertiesConfiguration configuration = new PropertiesConfiguration();
+ String amqpUri = "amqp://james:james@rabbitmqhost:5672/test";
+ configuration.addProperty("uri", amqpUri);
+ String managementUri = "http://james:james@rabbitmqhost:15672/api/";
+ configuration.addProperty("management.uri", managementUri);
+ configuration.addProperty("management.user", DEFAULT_USER);
+ configuration.addProperty("management.password", DEFAULT_PASSWORD_STRING);
+
+ assertThat(RabbitMQConfiguration.from(configuration).getVhost())
+ .isEqualTo(Optional.of("test"));
+ }
+
+ @Test
+ void fromShouldReturnVhostValueWhenGivenAndNotUriOne() {
+ PropertiesConfiguration configuration = new PropertiesConfiguration();
+ String amqpUri = "amqp://james:james@rabbitmqhost:5672/test";
+ configuration.addProperty("uri", amqpUri);
+ String managementUri = "http://james:james@rabbitmqhost:15672/api/";
+ configuration.addProperty("management.uri", managementUri);
+ configuration.addProperty("management.user", DEFAULT_USER);
+ configuration.addProperty("management.password", DEFAULT_PASSWORD_STRING);
+
+ configuration.addProperty("vhost", "vhosttest");
+
+ assertThat(RabbitMQConfiguration.from(configuration).getVhost())
+ .isEqualTo(Optional.of("vhosttest"));
+ }
+
@Nested
class ManagementCredentialsTest {
@Test
diff --git a/server/apps/distributed-app/docs/modules/ROOT/pages/configure/rabbitmq.adoc b/server/apps/distributed-app/docs/modules/ROOT/pages/configure/rabbitmq.adoc
index b3c2665ea7..c12a2e91bc 100644
--- a/server/apps/distributed-app/docs/modules/ROOT/pages/configure/rabbitmq.adoc
+++ b/server/apps/distributed-app/docs/modules/ROOT/pages/configure/rabbitmq.adoc
@@ -13,7 +13,8 @@ to get some examples and hints.
| Property name | explanation
| uri
-| the amqp URI pointing to RabbitMQ server. Details about amqp URI format is in https://www.rabbitmq.com/uri-spec.html[RabbitMQ URI Specification]
+| the amqp URI pointing to RabbitMQ server. If you use a vhost, specify it as well at the end of the URI.
+Details about amqp URI format is in https://www.rabbitmq.com/uri-spec.html[RabbitMQ URI Specification]
| management.uri
| the URI pointing to RabbitMQ Management Service. James need to retrieve some information about listing queues
@@ -101,8 +102,8 @@ A coma separated list of hosts, example: hosts=ip1:5672,ip2:5672
| Whether or not the queue backing notifications should be durable. Optional boolean, defaults to true.
| vhost
-| Optional string. The virtual host used by James to create queues and exchanges on Rabbitmq.
-If omitted, it will use the default Rabbitmq one "/".
+| Optional string. This parameter is only a workaround to support invalid URIs containing character like '_'.
+You still need to specify the vhost in the uri parameter.
|===
diff --git a/server/apps/distributed-app/sample-configuration/rabbitmq.properties b/server/apps/distributed-app/sample-configuration/rabbitmq.properties
index 25fad92687..cb1a92a88c 100644
--- a/server/apps/distributed-app/sample-configuration/rabbitmq.properties
+++ b/server/apps/distributed-app/sample-configuration/rabbitmq.properties
@@ -3,10 +3,11 @@
# Read https://james.apache.org/server/config-rabbitmq.html for further details
# Mandatory
-uri=amqp://rabbitmq:5672
+# If you use a vhost, specify it as well at the end of the URI
+uri=amqp://rabbitmq:5672/vhost
# Vhost to use for creating queues and exchanges
-# Optional, will default to default rabbitmq vhost "/" if not declared
+# Optional, only use this if you have invalid URIs containing characters like '_'
# vhost=vhost1
# Optional, default to the host specified as part of the URI.
diff --git a/server/apps/distributed-pop3-app/sample-configuration/rabbitmq.properties b/server/apps/distributed-pop3-app/sample-configuration/rabbitmq.properties
index 8997445c3f..fd9e9cd40f 100644
--- a/server/apps/distributed-pop3-app/sample-configuration/rabbitmq.properties
+++ b/server/apps/distributed-pop3-app/sample-configuration/rabbitmq.properties
@@ -3,10 +3,11 @@
# Read https://james.apache.org/server/config-rabbitmq.html for further details
# Mandatory
-uri=amqp://rabbitmq:5672
+# If you use a vhost, specify it as well at the end of the URI
+uri=amqp://rabbitmq:5672/vhost
# Vhost to use for creating queues and exchanges
-# Optional, will default to default rabbitmq vhost "/" if not declared
+# Optional, only use this if you have invalid URIs containing characters like '_'
# vhost=vhost1
# Optional, default to the host specified as part of the URI.
diff --git a/src/site/xdoc/server/config-rabbitmq.xml b/src/site/xdoc/server/config-rabbitmq.xml
index 69ef2e6ea7..b684a7abc3 100644
--- a/src/site/xdoc/server/config-rabbitmq.xml
+++ b/src/site/xdoc/server/config-rabbitmq.xml
@@ -43,7 +43,8 @@
<dl>
<dt><strong>uri</strong></dt>
<dd>
- the amqp URI pointing to RabbitMQ server. Details about amqp URI format is in <a href="https://www.rabbitmq.com/uri-spec.html">RabbitMQ URI Specification</a>
+ the amqp URI pointing to RabbitMQ server. If you use a vhost, specify it as well at the end of the URI.
+ Details about amqp URI format is in <a href="https://www.rabbitmq.com/uri-spec.html">RabbitMQ URI Specification</a>
</dd>
<dt><strong>management.uri</strong></dt>
@@ -140,8 +141,8 @@
<dt><strong>vhost</strong></dt>
<dd>Optional string.
- The virtual host used by James to create queues and exchanges on Rabbitmq.
- If omitted, it will use the default Rabbitmq one "/".
+ This parameter is only a workaround to support invalid URIs containing character like '_'.
+ You still need to specify the vhost in the uri parameter.
</dd>
</dl>
</section>
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@james.apache.org
For additional commands, e-mail: notifications-help@james.apache.org