This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 6cc30eebd6fd CAMEL-27627: camel-asterisk - producer logs in without
events, port option, name set, security label (#31013)
6cc30eebd6fd is described below
commit 6cc30eebd6fde366fa96f186fd6cebe6431e9850
Author: allthingssecurity <[email protected]>
AuthorDate: Sat Nov 28 00:26:54 2026 +0530
CAMEL-27627: camel-asterisk - producer logs in without events, port option,
name set, security label (#31013)
1. The producer logged in with the event mask on, so Asterisk sent it every
event of the PBX, which it read and dropped as it has no listener. It now
logs in with the event mask off. AsteriskConnection gets login(String);
login() keeps the mask on, which the consumer still uses. In
asterisk-java
3.42.2 the mask only goes into the LoginAction (it is kept for the
reconnect); the ConnectEvent of the login is made by asterisk-java.
2. The new port option (default 5038) sets the AMI port. AsteriskConnection
gets a constructor with the port and uses the ManagerConnectionFactory
constructor with the port; the old constructor keeps 5038, which is the
port the factory constructor without one uses.
3. createEndpoint() now sets the name path on the endpoint, so getName()
returns it instead of null.
4. username and password have the label security.
Rebased on the descriptions of CAMEL-23832 (#30959). Their texts are kept,
except the one of hostname, which said that the port is 5038 and cannot be
changed: it now says the port of the port option. The port option has a
description in the same style, and username and password keep theirs.
Regenerated asterisk.json (component and catalog copy), the endpoint
configurer and URI factory, and the endpoint DSL. Upgrade guide entry for
4.24.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
.../apache/camel/catalog/components/asterisk.json | 17 +--
.../asterisk/AsteriskEndpointConfigurer.java | 3 +
.../asterisk/AsteriskEndpointUriFactory.java | 3 +-
.../apache/camel/component/asterisk/asterisk.json | 17 +--
.../component/asterisk/AsteriskComponent.java | 1 +
.../component/asterisk/AsteriskConnection.java | 29 ++++-
.../camel/component/asterisk/AsteriskConsumer.java | 3 +-
.../camel/component/asterisk/AsteriskEndpoint.java | 19 ++-
.../camel/component/asterisk/AsteriskProducer.java | 7 +-
.../component/asterisk/AsteriskConfigTest.java | 1 +
.../asterisk/AsteriskProducerFakeServerTest.java | 55 ++++++++
.../ROOT/pages/camel-4x-upgrade-guide-4_24.adoc | 9 ++
.../dsl/AsteriskEndpointBuilderFactory.java | 140 +++++++++++++++++----
13 files changed, 256 insertions(+), 48 deletions(-)
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/asterisk.json
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/asterisk.json
index 947fcd84de1d..d8d5c4068b53 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/asterisk.json
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/components/asterisk.json
@@ -41,13 +41,14 @@
},
"properties": {
"name": { "index": 0, "kind": "path", "displayName": "Name", "group":
"common", "label": "", "required": true, "type": "string", "javaType":
"java.lang.String", "deprecated": false, "autowired": false, "secret": false,
"description": "A logical name of the endpoint, for example the name of the
Asterisk server. The component does not use it to connect." },
- "hostname": { "index": 1, "kind": "parameter", "displayName": "Hostname",
"group": "common", "label": "", "required": true, "type": "string", "javaType":
"java.lang.String", "deprecated": false, "autowired": false, "secret": false,
"description": "The host name or IP address of the Asterisk server. The
consumer and the producer connect to the Asterisk Manager Interface (AMI) of
this host on port 5038, which cannot be changed." },
- "password": { "index": 2, "kind": "parameter", "displayName": "Password",
"group": "common", "label": "", "required": true, "type": "string", "javaType":
"java.lang.String", "deprecated": false, "autowired": false, "secret": true,
"security": "secret", "description": "The secret of the AMI user, as defined in
the manager.conf file of the Asterisk server." },
- "username": { "index": 3, "kind": "parameter", "displayName": "Username",
"group": "common", "label": "", "required": true, "type": "string", "javaType":
"java.lang.String", "deprecated": false, "autowired": false, "secret": true,
"security": "secret", "description": "The name of the AMI user, as defined in
the manager.conf file of the Asterisk server. The consumer and the producer
each log in with it when they start." },
- "bridgeErrorHandler": { "index": 4, "kind": "parameter", "displayName":
"Bridge Error Handler", "group": "consumer (advanced)", "label":
"consumer,advanced", "required": false, "type": "boolean", "javaType":
"boolean", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": false, "description": "Allows for bridging the consumer to the
Camel routing Error Handler, which mean any exceptions (if possible) occurred
while the Camel consumer is trying to pickup incoming [...]
- "exceptionHandler": { "index": 5, "kind": "parameter", "displayName":
"Exception Handler", "group": "consumer (advanced)", "label":
"consumer,advanced", "required": false, "type": "object", "javaType":
"org.apache.camel.spi.ExceptionHandler", "optionalPrefix": "consumer.",
"deprecated": false, "autowired": false, "secret": false, "description": "To
let the consumer use a custom ExceptionHandler. Notice if the option
bridgeErrorHandler is enabled then this option is not in use. By def [...]
- "exchangePattern": { "index": 6, "kind": "parameter", "displayName":
"Exchange Pattern", "group": "consumer (advanced)", "label":
"consumer,advanced", "required": false, "type": "enum", "javaType":
"org.apache.camel.ExchangePattern", "enum": [ "InOnly", "InOut" ],
"deprecated": false, "autowired": false, "secret": false, "description": "Sets
the exchange pattern when the consumer creates an exchange." },
- "action": { "index": 7, "kind": "parameter", "displayName": "Action",
"group": "producer", "label": "producer", "required": false, "type": "enum",
"javaType": "org.apache.camel.component.asterisk.AsteriskAction", "enum": [
"QUEUE_STATUS", "SIP_PEERS", "EXTENSION_STATE" ], "deprecated": false,
"autowired": false, "secret": false, "description": "The AMI action that the
producer sends for each message: QUEUE_STATUS for the status of the queues and
their members, SIP_PEERS for the list [...]
- "lazyStartProducer": { "index": 8, "kind": "parameter", "displayName":
"Lazy Start Producer", "group": "producer (advanced)", "label":
"producer,advanced", "required": false, "type": "boolean", "javaType":
"boolean", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": false, "description": "Whether the producer should be started
lazy (on the first message). By starting lazy you can use this to allow
CamelContext and routes to startup in situations where a produc [...]
+ "hostname": { "index": 1, "kind": "parameter", "displayName": "Hostname",
"group": "common", "label": "", "required": true, "type": "string", "javaType":
"java.lang.String", "deprecated": false, "autowired": false, "secret": false,
"description": "The host name or IP address of the Asterisk server. The
consumer and the producer connect to the Asterisk Manager Interface (AMI) of
this host on the port of the port option." },
+ "port": { "index": 2, "kind": "parameter", "displayName": "Port", "group":
"common", "label": "", "required": false, "type": "integer", "javaType": "int",
"deprecated": false, "autowired": false, "secret": false, "defaultValue": 5038,
"description": "The port of the Asterisk Manager Interface (AMI) of the
Asterisk server, as set in the manager.conf file of the server." },
+ "bridgeErrorHandler": { "index": 3, "kind": "parameter", "displayName":
"Bridge Error Handler", "group": "consumer (advanced)", "label":
"consumer,advanced", "required": false, "type": "boolean", "javaType":
"boolean", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": false, "description": "Allows for bridging the consumer to the
Camel routing Error Handler, which mean any exceptions (if possible) occurred
while the Camel consumer is trying to pickup incoming [...]
+ "exceptionHandler": { "index": 4, "kind": "parameter", "displayName":
"Exception Handler", "group": "consumer (advanced)", "label":
"consumer,advanced", "required": false, "type": "object", "javaType":
"org.apache.camel.spi.ExceptionHandler", "optionalPrefix": "consumer.",
"deprecated": false, "autowired": false, "secret": false, "description": "To
let the consumer use a custom ExceptionHandler. Notice if the option
bridgeErrorHandler is enabled then this option is not in use. By def [...]
+ "exchangePattern": { "index": 5, "kind": "parameter", "displayName":
"Exchange Pattern", "group": "consumer (advanced)", "label":
"consumer,advanced", "required": false, "type": "enum", "javaType":
"org.apache.camel.ExchangePattern", "enum": [ "InOnly", "InOut" ],
"deprecated": false, "autowired": false, "secret": false, "description": "Sets
the exchange pattern when the consumer creates an exchange." },
+ "action": { "index": 6, "kind": "parameter", "displayName": "Action",
"group": "producer", "label": "producer", "required": false, "type": "enum",
"javaType": "org.apache.camel.component.asterisk.AsteriskAction", "enum": [
"QUEUE_STATUS", "SIP_PEERS", "EXTENSION_STATE" ], "deprecated": false,
"autowired": false, "secret": false, "description": "The AMI action that the
producer sends for each message: QUEUE_STATUS for the status of the queues and
their members, SIP_PEERS for the list [...]
+ "lazyStartProducer": { "index": 7, "kind": "parameter", "displayName":
"Lazy Start Producer", "group": "producer (advanced)", "label":
"producer,advanced", "required": false, "type": "boolean", "javaType":
"boolean", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": false, "description": "Whether the producer should be started
lazy (on the first message). By starting lazy you can use this to allow
CamelContext and routes to startup in situations where a produc [...]
+ "password": { "index": 8, "kind": "parameter", "displayName": "Password",
"group": "security", "label": "security", "required": true, "type": "string",
"javaType": "java.lang.String", "deprecated": false, "autowired": false,
"secret": true, "security": "secret", "description": "The secret of the AMI
user, as defined in the manager.conf file of the Asterisk server." },
+ "username": { "index": 9, "kind": "parameter", "displayName": "Username",
"group": "security", "label": "security", "required": true, "type": "string",
"javaType": "java.lang.String", "deprecated": false, "autowired": false,
"secret": true, "security": "secret", "description": "The name of the AMI user,
as defined in the manager.conf file of the Asterisk server. The consumer and
the producer each log in with it when they start." }
}
}
diff --git
a/components/camel-asterisk/src/generated/java/org/apache/camel/component/asterisk/AsteriskEndpointConfigurer.java
b/components/camel-asterisk/src/generated/java/org/apache/camel/component/asterisk/AsteriskEndpointConfigurer.java
index a492eb60d8df..13d4a15ce4d2 100644
---
a/components/camel-asterisk/src/generated/java/org/apache/camel/component/asterisk/AsteriskEndpointConfigurer.java
+++
b/components/camel-asterisk/src/generated/java/org/apache/camel/component/asterisk/AsteriskEndpointConfigurer.java
@@ -35,6 +35,7 @@ public class AsteriskEndpointConfigurer extends
PropertyConfigurerSupport implem
case "lazystartproducer":
case "lazyStartProducer":
target.setLazyStartProducer(property(camelContext, boolean.class, value));
return true;
case "password": target.setPassword(property(camelContext,
java.lang.String.class, value)); return true;
+ case "port": target.setPort(property(camelContext, int.class, value));
return true;
case "username": target.setUsername(property(camelContext,
java.lang.String.class, value)); return true;
default: return false;
}
@@ -54,6 +55,7 @@ public class AsteriskEndpointConfigurer extends
PropertyConfigurerSupport implem
case "lazystartproducer":
case "lazyStartProducer": return boolean.class;
case "password": return java.lang.String.class;
+ case "port": return int.class;
case "username": return java.lang.String.class;
default: return null;
}
@@ -74,6 +76,7 @@ public class AsteriskEndpointConfigurer extends
PropertyConfigurerSupport implem
case "lazystartproducer":
case "lazyStartProducer": return target.isLazyStartProducer();
case "password": return target.getPassword();
+ case "port": return target.getPort();
case "username": return target.getUsername();
default: return null;
}
diff --git
a/components/camel-asterisk/src/generated/java/org/apache/camel/component/asterisk/AsteriskEndpointUriFactory.java
b/components/camel-asterisk/src/generated/java/org/apache/camel/component/asterisk/AsteriskEndpointUriFactory.java
index 716287f3f930..3e6678286832 100644
---
a/components/camel-asterisk/src/generated/java/org/apache/camel/component/asterisk/AsteriskEndpointUriFactory.java
+++
b/components/camel-asterisk/src/generated/java/org/apache/camel/component/asterisk/AsteriskEndpointUriFactory.java
@@ -24,7 +24,7 @@ public class AsteriskEndpointUriFactory extends
org.apache.camel.support.compone
private static final Set<String> ENDPOINT_IDENTITY_PROPERTY_NAMES;
private static final Map<String, String> MULTI_VALUE_PREFIXES;
static {
- Set<String> props = new HashSet<>(9);
+ Set<String> props = new HashSet<>(10);
props.add("action");
props.add("bridgeErrorHandler");
props.add("exceptionHandler");
@@ -33,6 +33,7 @@ public class AsteriskEndpointUriFactory extends
org.apache.camel.support.compone
props.add("lazyStartProducer");
props.add("name");
props.add("password");
+ props.add("port");
props.add("username");
PROPERTY_NAMES = Collections.unmodifiableSet(props);
Set<String> secretProps = new HashSet<>(2);
diff --git
a/components/camel-asterisk/src/generated/resources/META-INF/org/apache/camel/component/asterisk/asterisk.json
b/components/camel-asterisk/src/generated/resources/META-INF/org/apache/camel/component/asterisk/asterisk.json
index 947fcd84de1d..d8d5c4068b53 100644
---
a/components/camel-asterisk/src/generated/resources/META-INF/org/apache/camel/component/asterisk/asterisk.json
+++
b/components/camel-asterisk/src/generated/resources/META-INF/org/apache/camel/component/asterisk/asterisk.json
@@ -41,13 +41,14 @@
},
"properties": {
"name": { "index": 0, "kind": "path", "displayName": "Name", "group":
"common", "label": "", "required": true, "type": "string", "javaType":
"java.lang.String", "deprecated": false, "autowired": false, "secret": false,
"description": "A logical name of the endpoint, for example the name of the
Asterisk server. The component does not use it to connect." },
- "hostname": { "index": 1, "kind": "parameter", "displayName": "Hostname",
"group": "common", "label": "", "required": true, "type": "string", "javaType":
"java.lang.String", "deprecated": false, "autowired": false, "secret": false,
"description": "The host name or IP address of the Asterisk server. The
consumer and the producer connect to the Asterisk Manager Interface (AMI) of
this host on port 5038, which cannot be changed." },
- "password": { "index": 2, "kind": "parameter", "displayName": "Password",
"group": "common", "label": "", "required": true, "type": "string", "javaType":
"java.lang.String", "deprecated": false, "autowired": false, "secret": true,
"security": "secret", "description": "The secret of the AMI user, as defined in
the manager.conf file of the Asterisk server." },
- "username": { "index": 3, "kind": "parameter", "displayName": "Username",
"group": "common", "label": "", "required": true, "type": "string", "javaType":
"java.lang.String", "deprecated": false, "autowired": false, "secret": true,
"security": "secret", "description": "The name of the AMI user, as defined in
the manager.conf file of the Asterisk server. The consumer and the producer
each log in with it when they start." },
- "bridgeErrorHandler": { "index": 4, "kind": "parameter", "displayName":
"Bridge Error Handler", "group": "consumer (advanced)", "label":
"consumer,advanced", "required": false, "type": "boolean", "javaType":
"boolean", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": false, "description": "Allows for bridging the consumer to the
Camel routing Error Handler, which mean any exceptions (if possible) occurred
while the Camel consumer is trying to pickup incoming [...]
- "exceptionHandler": { "index": 5, "kind": "parameter", "displayName":
"Exception Handler", "group": "consumer (advanced)", "label":
"consumer,advanced", "required": false, "type": "object", "javaType":
"org.apache.camel.spi.ExceptionHandler", "optionalPrefix": "consumer.",
"deprecated": false, "autowired": false, "secret": false, "description": "To
let the consumer use a custom ExceptionHandler. Notice if the option
bridgeErrorHandler is enabled then this option is not in use. By def [...]
- "exchangePattern": { "index": 6, "kind": "parameter", "displayName":
"Exchange Pattern", "group": "consumer (advanced)", "label":
"consumer,advanced", "required": false, "type": "enum", "javaType":
"org.apache.camel.ExchangePattern", "enum": [ "InOnly", "InOut" ],
"deprecated": false, "autowired": false, "secret": false, "description": "Sets
the exchange pattern when the consumer creates an exchange." },
- "action": { "index": 7, "kind": "parameter", "displayName": "Action",
"group": "producer", "label": "producer", "required": false, "type": "enum",
"javaType": "org.apache.camel.component.asterisk.AsteriskAction", "enum": [
"QUEUE_STATUS", "SIP_PEERS", "EXTENSION_STATE" ], "deprecated": false,
"autowired": false, "secret": false, "description": "The AMI action that the
producer sends for each message: QUEUE_STATUS for the status of the queues and
their members, SIP_PEERS for the list [...]
- "lazyStartProducer": { "index": 8, "kind": "parameter", "displayName":
"Lazy Start Producer", "group": "producer (advanced)", "label":
"producer,advanced", "required": false, "type": "boolean", "javaType":
"boolean", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": false, "description": "Whether the producer should be started
lazy (on the first message). By starting lazy you can use this to allow
CamelContext and routes to startup in situations where a produc [...]
+ "hostname": { "index": 1, "kind": "parameter", "displayName": "Hostname",
"group": "common", "label": "", "required": true, "type": "string", "javaType":
"java.lang.String", "deprecated": false, "autowired": false, "secret": false,
"description": "The host name or IP address of the Asterisk server. The
consumer and the producer connect to the Asterisk Manager Interface (AMI) of
this host on the port of the port option." },
+ "port": { "index": 2, "kind": "parameter", "displayName": "Port", "group":
"common", "label": "", "required": false, "type": "integer", "javaType": "int",
"deprecated": false, "autowired": false, "secret": false, "defaultValue": 5038,
"description": "The port of the Asterisk Manager Interface (AMI) of the
Asterisk server, as set in the manager.conf file of the server." },
+ "bridgeErrorHandler": { "index": 3, "kind": "parameter", "displayName":
"Bridge Error Handler", "group": "consumer (advanced)", "label":
"consumer,advanced", "required": false, "type": "boolean", "javaType":
"boolean", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": false, "description": "Allows for bridging the consumer to the
Camel routing Error Handler, which mean any exceptions (if possible) occurred
while the Camel consumer is trying to pickup incoming [...]
+ "exceptionHandler": { "index": 4, "kind": "parameter", "displayName":
"Exception Handler", "group": "consumer (advanced)", "label":
"consumer,advanced", "required": false, "type": "object", "javaType":
"org.apache.camel.spi.ExceptionHandler", "optionalPrefix": "consumer.",
"deprecated": false, "autowired": false, "secret": false, "description": "To
let the consumer use a custom ExceptionHandler. Notice if the option
bridgeErrorHandler is enabled then this option is not in use. By def [...]
+ "exchangePattern": { "index": 5, "kind": "parameter", "displayName":
"Exchange Pattern", "group": "consumer (advanced)", "label":
"consumer,advanced", "required": false, "type": "enum", "javaType":
"org.apache.camel.ExchangePattern", "enum": [ "InOnly", "InOut" ],
"deprecated": false, "autowired": false, "secret": false, "description": "Sets
the exchange pattern when the consumer creates an exchange." },
+ "action": { "index": 6, "kind": "parameter", "displayName": "Action",
"group": "producer", "label": "producer", "required": false, "type": "enum",
"javaType": "org.apache.camel.component.asterisk.AsteriskAction", "enum": [
"QUEUE_STATUS", "SIP_PEERS", "EXTENSION_STATE" ], "deprecated": false,
"autowired": false, "secret": false, "description": "The AMI action that the
producer sends for each message: QUEUE_STATUS for the status of the queues and
their members, SIP_PEERS for the list [...]
+ "lazyStartProducer": { "index": 7, "kind": "parameter", "displayName":
"Lazy Start Producer", "group": "producer (advanced)", "label":
"producer,advanced", "required": false, "type": "boolean", "javaType":
"boolean", "deprecated": false, "autowired": false, "secret": false,
"defaultValue": false, "description": "Whether the producer should be started
lazy (on the first message). By starting lazy you can use this to allow
CamelContext and routes to startup in situations where a produc [...]
+ "password": { "index": 8, "kind": "parameter", "displayName": "Password",
"group": "security", "label": "security", "required": true, "type": "string",
"javaType": "java.lang.String", "deprecated": false, "autowired": false,
"secret": true, "security": "secret", "description": "The secret of the AMI
user, as defined in the manager.conf file of the Asterisk server." },
+ "username": { "index": 9, "kind": "parameter", "displayName": "Username",
"group": "security", "label": "security", "required": true, "type": "string",
"javaType": "java.lang.String", "deprecated": false, "autowired": false,
"secret": true, "security": "secret", "description": "The name of the AMI user,
as defined in the manager.conf file of the Asterisk server. The consumer and
the producer each log in with it when they start." }
}
}
diff --git
a/components/camel-asterisk/src/main/java/org/apache/camel/component/asterisk/AsteriskComponent.java
b/components/camel-asterisk/src/main/java/org/apache/camel/component/asterisk/AsteriskComponent.java
index 239ef1b2e8e6..c708cc025dfc 100644
---
a/components/camel-asterisk/src/main/java/org/apache/camel/component/asterisk/AsteriskComponent.java
+++
b/components/camel-asterisk/src/main/java/org/apache/camel/component/asterisk/AsteriskComponent.java
@@ -39,6 +39,7 @@ public class AsteriskComponent extends DefaultComponent {
@Override
protected Endpoint createEndpoint(String uri, String remaining,
Map<String, Object> parameters) throws Exception {
AsteriskEndpoint endpoint = new AsteriskEndpoint(uri, this);
+ endpoint.setName(remaining);
setProperties(endpoint, parameters);
diff --git
a/components/camel-asterisk/src/main/java/org/apache/camel/component/asterisk/AsteriskConnection.java
b/components/camel-asterisk/src/main/java/org/apache/camel/component/asterisk/AsteriskConnection.java
index b099aec5d061..d9bfdd5cd090 100644
---
a/components/camel-asterisk/src/main/java/org/apache/camel/component/asterisk/AsteriskConnection.java
+++
b/components/camel-asterisk/src/main/java/org/apache/camel/component/asterisk/AsteriskConnection.java
@@ -33,21 +33,33 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public final class AsteriskConnection {
+ /**
+ * The default port of the Asterisk Manager Interface (AMI).
+ */
+ public static final int DEFAULT_PORT = 5038;
+
private static final Logger LOG =
LoggerFactory.getLogger(AsteriskConnection.class);
private final String host;
+ private final int port;
private final String username;
private final String password;
private ManagerConnection managerConnection;
public AsteriskConnection(String host, String username, String password) {
+ this(host, DEFAULT_PORT, username, password);
+ }
+
+ public AsteriskConnection(String host, int port, String username, String
password) {
this.host = host;
+ this.port = port;
this.username = username;
this.password = password;
}
AsteriskConnection(ManagerConnection managerConnection) {
this.host = managerConnection.getHostname();
+ this.port = managerConnection.getPort();
this.username = managerConnection.getUsername();
this.password = managerConnection.getPassword();
this.managerConnection = managerConnection;
@@ -55,23 +67,34 @@ public final class AsteriskConnection {
public void connect() {
if (managerConnection == null) {
- LOG.debug("asterisk connection attempt to {} username: {}", host,
username);
+ LOG.debug("asterisk connection attempt to {}:{} username: {}",
host, port, username);
- ManagerConnectionFactory factory = new
ManagerConnectionFactory(host, username, password);
+ ManagerConnectionFactory factory = new
ManagerConnectionFactory(host, port, username, password);
managerConnection = factory.createManagerConnection();
LOG.debug("asterisk connection established!");
}
}
+ /**
+ * Logs in with the event mask on, so that Asterisk sends all events to
the connection.
+ */
public void login()
throws IllegalStateException, IOException,
AuthenticationFailedException, TimeoutException, CamelAsteriskException {
+ login("on");
+ }
+
+ /**
+ * Logs in with the given event mask, such as on, off, or a list of event
classes like system,call.
+ */
+ public void login(String eventMask)
+ throws IllegalStateException, IOException,
AuthenticationFailedException, TimeoutException, CamelAsteriskException {
// Lazy connect if not done before
connect();
if (managerConnection != null && (managerConnection.getState() ==
ManagerConnectionState.DISCONNECTED
|| managerConnection.getState() ==
ManagerConnectionState.INITIAL)) {
- managerConnection.login("on");
+ managerConnection.login(eventMask);
LOG.debug("asterisk login done!");
} else {
diff --git
a/components/camel-asterisk/src/main/java/org/apache/camel/component/asterisk/AsteriskConsumer.java
b/components/camel-asterisk/src/main/java/org/apache/camel/component/asterisk/AsteriskConsumer.java
index 30803a92c25b..2b5ff2a97d9b 100644
---
a/components/camel-asterisk/src/main/java/org/apache/camel/component/asterisk/AsteriskConsumer.java
+++
b/components/camel-asterisk/src/main/java/org/apache/camel/component/asterisk/AsteriskConsumer.java
@@ -32,7 +32,8 @@ public class AsteriskConsumer extends DefaultConsumer {
public AsteriskConsumer(AsteriskEndpoint endpoint, Processor processor) {
super(endpoint, processor);
- this.connection = new AsteriskConnection(endpoint.getHostname(),
endpoint.getUsername(), endpoint.getPassword());
+ this.connection = new AsteriskConnection(
+ endpoint.getHostname(), endpoint.getPort(),
endpoint.getUsername(), endpoint.getPassword());
this.listener = new EventListener();
}
diff --git
a/components/camel-asterisk/src/main/java/org/apache/camel/component/asterisk/AsteriskEndpoint.java
b/components/camel-asterisk/src/main/java/org/apache/camel/component/asterisk/AsteriskEndpoint.java
index e8da57f2d032..f2be7072ca46 100644
---
a/components/camel-asterisk/src/main/java/org/apache/camel/component/asterisk/AsteriskEndpoint.java
+++
b/components/camel-asterisk/src/main/java/org/apache/camel/component/asterisk/AsteriskEndpoint.java
@@ -69,10 +69,15 @@ public class AsteriskEndpoint extends DefaultEndpoint
implements EndpointService
private String name;
@UriParam(description = "The host name or IP address of the Asterisk
server. The consumer and the producer connect to"
- + " the Asterisk Manager Interface (AMI) of this
host on port 5038, which cannot be changed.")
+ + " the Asterisk Manager Interface (AMI) of this
host on the port of the port option.")
@Metadata(required = true)
private String hostname;
+ @UriParam(defaultValue = "5038",
+ description = "The port of the Asterisk Manager Interface (AMI)
of the Asterisk server, as set in the"
+ + " manager.conf file of the server.")
+ private int port = AsteriskConnection.DEFAULT_PORT;
+
@UriParam(label = "producer",
description = "The AMI action that the producer sends for each
message: QUEUE_STATUS for the status of the queues"
+ " and their members, SIP_PEERS for the list of
SIP peers, or EXTENSION_STATE for the state of the"
@@ -81,13 +86,13 @@ public class AsteriskEndpoint extends DefaultEndpoint
implements EndpointService
+ " producer fails the message.")
private AsteriskAction action;
- @UriParam(security = "secret",
+ @UriParam(label = "security", security = "secret",
description = "The name of the AMI user, as defined in the
manager.conf file of the Asterisk server. The consumer"
+ " and the producer each log in with it when they
start.")
@Metadata(required = true)
private String username;
- @UriParam(security = "secret",
+ @UriParam(label = "security", security = "secret",
description = "The secret of the AMI user, as defined in the
manager.conf file of the Asterisk server.")
@Metadata(required = true)
private String password;
@@ -165,6 +170,14 @@ public class AsteriskEndpoint extends DefaultEndpoint
implements EndpointService
this.hostname = hostname;
}
+ public int getPort() {
+ return port;
+ }
+
+ public void setPort(int port) {
+ this.port = port;
+ }
+
public String getName() {
return name;
}
diff --git
a/components/camel-asterisk/src/main/java/org/apache/camel/component/asterisk/AsteriskProducer.java
b/components/camel-asterisk/src/main/java/org/apache/camel/component/asterisk/AsteriskProducer.java
index db1b1e5c7215..f883a9ae01d5 100644
---
a/components/camel-asterisk/src/main/java/org/apache/camel/component/asterisk/AsteriskProducer.java
+++
b/components/camel-asterisk/src/main/java/org/apache/camel/component/asterisk/AsteriskProducer.java
@@ -37,7 +37,8 @@ public class AsteriskProducer extends DefaultProducer {
private final AsteriskConnection connection;
public AsteriskProducer(AsteriskEndpoint endpoint) {
- this(endpoint, new AsteriskConnection(endpoint.getHostname(),
endpoint.getUsername(), endpoint.getPassword()));
+ this(endpoint, new AsteriskConnection(
+ endpoint.getHostname(), endpoint.getPort(),
endpoint.getUsername(), endpoint.getPassword()));
}
AsteriskProducer(AsteriskEndpoint endpoint, AsteriskConnection connection)
{
@@ -49,7 +50,9 @@ public class AsteriskProducer extends DefaultProducer {
@Override
protected void doStart() throws Exception {
- connection.login();
+ // the producer has no event listener, so Asterisk does not need to
send it the events of the PBX. The events
+ // that answer an action, such as the ones of QUEUE_STATUS, are sent
whatever the event mask is.
+ connection.login("off");
super.doStart();
}
diff --git
a/components/camel-asterisk/src/test/java/org/apache/camel/component/asterisk/AsteriskConfigTest.java
b/components/camel-asterisk/src/test/java/org/apache/camel/component/asterisk/AsteriskConfigTest.java
index f3cf77c45e76..a1a2c9e6284c 100644
---
a/components/camel-asterisk/src/test/java/org/apache/camel/component/asterisk/AsteriskConfigTest.java
+++
b/components/camel-asterisk/src/test/java/org/apache/camel/component/asterisk/AsteriskConfigTest.java
@@ -41,5 +41,6 @@ public class AsteriskConfigTest extends CamelTestSupport {
assertEquals(username, asteriskEndpoint.getUsername());
assertEquals(password, asteriskEndpoint.getPassword());
assertEquals(action, asteriskEndpoint.getAction().name());
+ assertEquals("myVoIP", asteriskEndpoint.getName());
}
}
diff --git
a/components/camel-asterisk/src/test/java/org/apache/camel/component/asterisk/AsteriskProducerFakeServerTest.java
b/components/camel-asterisk/src/test/java/org/apache/camel/component/asterisk/AsteriskProducerFakeServerTest.java
index a73478d8a5ec..83b0c4ac626d 100644
---
a/components/camel-asterisk/src/test/java/org/apache/camel/component/asterisk/AsteriskProducerFakeServerTest.java
+++
b/components/camel-asterisk/src/test/java/org/apache/camel/component/asterisk/AsteriskProducerFakeServerTest.java
@@ -28,8 +28,11 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.concurrent.CopyOnWriteArrayList;
+import org.apache.camel.Consumer;
import org.apache.camel.Exchange;
+import org.apache.camel.Producer;
import org.apache.camel.test.junit6.CamelTestSupport;
import org.asteriskjava.manager.ResponseEvents;
import org.asteriskjava.manager.event.PeerEntryEvent;
@@ -46,6 +49,7 @@ import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertNull;
/**
* Runs the producer against a fake Asterisk Manager Interface (AMI) server on
a random port.
@@ -128,6 +132,52 @@ public class AsteriskProducerFakeServerTest extends
CamelTestSupport {
assertEquals(0, response.getStatus());
}
+ @Test
+ void testProducerLogsInWithoutEvents() {
+ // the producer has no event listener, so it asks Asterisk not to send
it the events of the PBX
+ assertEquals(List.of("off"), server.loginEvents);
+ }
+
+ @Test
+ void testPortOptionAndName() throws Exception {
+ AsteriskEndpoint endpoint =
context.getEndpoint("asterisk:pbx?hostname="
+ +
InetAddress.getLoopbackAddress().getHostAddress() + "&port="
+ + server.getPort()
+ +
"&username=admin&password=secret&action=EXTENSION_STATE",
+ AsteriskEndpoint.class);
+ assertEquals("pbx", endpoint.getName());
+
+ Producer portProducer = endpoint.createProducer();
+ portProducer.start();
+ try {
+ Exchange exchange = endpoint.createExchange();
+ exchange.getMessage().setHeader(AsteriskConstants.EXTENSION,
"1001");
+ exchange.getMessage().setHeader(AsteriskConstants.CONTEXT,
"default");
+ portProducer.process(exchange);
+
+ assertNull(exchange.getException());
+ assertEquals("1001",
assertInstanceOf(ExtensionStateResponse.class,
exchange.getMessage().getBody()).getExten());
+ } finally {
+ portProducer.stop();
+ }
+ }
+
+ @Test
+ void testConsumerLogsInWithEvents() throws Exception {
+ AsteriskEndpoint endpoint =
context.getEndpoint("asterisk:pbx?hostname="
+ +
InetAddress.getLoopbackAddress().getHostAddress() + "&port="
+ + server.getPort() +
"&username=admin&password=secret",
+ AsteriskEndpoint.class);
+ Consumer consumer = endpoint.createConsumer(exchange -> {
+ });
+ consumer.start();
+ try {
+ assertEquals(List.of("off", "on"), server.loginEvents);
+ } finally {
+ consumer.stop();
+ }
+ }
+
private Exchange send(AsteriskAction action) throws Exception {
Exchange exchange = producer.getEndpoint().createExchange();
exchange.getMessage().setHeader(AsteriskConstants.ACTION, action);
@@ -142,6 +192,8 @@ public class AsteriskProducerFakeServerTest extends
CamelTestSupport {
private final ServerSocket serverSocket;
private final List<Socket> sockets = new ArrayList<>();
+ // the Events header of each login, in order
+ private final List<String> loginEvents = new CopyOnWriteArrayList<>();
FakeAmiServer() throws IOException {
serverSocket = new ServerSocket(0, 50,
InetAddress.getLoopbackAddress());
@@ -192,6 +244,9 @@ public class AsteriskProducerFakeServerTest extends
CamelTestSupport {
continue;
}
if (!packet.isEmpty()) {
+ if ("login".equalsIgnoreCase(packet.get("action"))) {
+ loginEvents.add(packet.get("events"));
+ }
write(out, answer(packet.get("action"),
packet.get("actionid")));
packet.clear();
}
diff --git
a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
index be5ab321caf4..cd90815c2d69 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
@@ -4189,6 +4189,15 @@ events, such as `QueueParamsEvent`, `QueueMemberEvent`
and `PeerEntryEvent`. Bef
`ManagerResponse` saying that the list will follow, and the events were lost.
A route that read that response from
the body now finds it in `${body.response}`. `EXTENSION_STATE` still sets the
`ManagerResponse` as the body.
+=== camel-asterisk - the producer logs in without events, and a port option
+
+The `asterisk` producer now logs in to the Asterisk Manager Interface with the
event mask `off`, as it has no event
+listener: Asterisk no longer sends it the events of the PBX. The answers to
its actions, such as the events of the
+`QUEUE_STATUS` list, are not affected. The consumer still logs in with the
event mask `on`.
+
+The new `port` option (default 5038, the port that was used before) sets the
AMI port. The `name` path is now set on
+the endpoint, and `username` and `password` are in the `security` group of the
catalog and the docs.
+
=== camel-jbang - camel export no longer deletes the files of a directory that
no export created
`camel export --dir=<dir>` to a directory other than the current one used to
delete the files of that directory first,
diff --git
a/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/AsteriskEndpointBuilderFactory.java
b/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/AsteriskEndpointBuilderFactory.java
index 2929bf941aaa..ba0c9f293d3c 100644
---
a/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/AsteriskEndpointBuilderFactory.java
+++
b/dsl/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/AsteriskEndpointBuilderFactory.java
@@ -47,7 +47,7 @@ public interface AsteriskEndpointBuilderFactory {
/**
* The host name or IP address of the Asterisk server. The consumer and
* the producer connect to the Asterisk Manager Interface (AMI) of this
- * host on port 5038, which cannot be changed.
+ * host on the port of the port option.
*
* The option is a: <code>java.lang.String</code> type.
*
@@ -61,6 +61,38 @@ public interface AsteriskEndpointBuilderFactory {
doSetProperty("hostname", hostname);
return this;
}
+ /**
+ * The port of the Asterisk Manager Interface (AMI) of the Asterisk
+ * server, as set in the manager.conf file of the server.
+ *
+ * The option is a: <code>int</code> type.
+ *
+ * Default: 5038
+ * Group: common
+ *
+ * @param port the value to set
+ * @return the dsl builder
+ */
+ default AsteriskEndpointConsumerBuilder port(int port) {
+ doSetProperty("port", port);
+ return this;
+ }
+ /**
+ * The port of the Asterisk Manager Interface (AMI) of the Asterisk
+ * server, as set in the manager.conf file of the server.
+ *
+ * The option will be converted to a <code>int</code> type.
+ *
+ * Default: 5038
+ * Group: common
+ *
+ * @param port the value to set
+ * @return the dsl builder
+ */
+ default AsteriskEndpointConsumerBuilder port(String port) {
+ doSetProperty("port", port);
+ return this;
+ }
/**
* The secret of the AMI user, as defined in the manager.conf file of
* the Asterisk server.
@@ -68,7 +100,7 @@ public interface AsteriskEndpointBuilderFactory {
* The option is a: <code>java.lang.String</code> type.
*
* Required: true
- * Group: common
+ * Group: security
*
* @param password the value to set
* @return the dsl builder
@@ -85,7 +117,7 @@ public interface AsteriskEndpointBuilderFactory {
* The option is a: <code>java.lang.String</code> type.
*
* Required: true
- * Group: common
+ * Group: security
*
* @param username the value to set
* @return the dsl builder
@@ -237,7 +269,7 @@ public interface AsteriskEndpointBuilderFactory {
/**
* The host name or IP address of the Asterisk server. The consumer and
* the producer connect to the Asterisk Manager Interface (AMI) of this
- * host on port 5038, which cannot be changed.
+ * host on the port of the port option.
*
* The option is a: <code>java.lang.String</code> type.
*
@@ -252,36 +284,35 @@ public interface AsteriskEndpointBuilderFactory {
return this;
}
/**
- * The secret of the AMI user, as defined in the manager.conf file of
- * the Asterisk server.
+ * The port of the Asterisk Manager Interface (AMI) of the Asterisk
+ * server, as set in the manager.conf file of the server.
*
- * The option is a: <code>java.lang.String</code> type.
+ * The option is a: <code>int</code> type.
*
- * Required: true
+ * Default: 5038
* Group: common
*
- * @param password the value to set
+ * @param port the value to set
* @return the dsl builder
*/
- default AsteriskEndpointProducerBuilder password(String password) {
- doSetProperty("password", password);
+ default AsteriskEndpointProducerBuilder port(int port) {
+ doSetProperty("port", port);
return this;
}
/**
- * The name of the AMI user, as defined in the manager.conf file of the
- * Asterisk server. The consumer and the producer each log in with it
- * when they start.
+ * The port of the Asterisk Manager Interface (AMI) of the Asterisk
+ * server, as set in the manager.conf file of the server.
*
- * The option is a: <code>java.lang.String</code> type.
+ * The option will be converted to a <code>int</code> type.
*
- * Required: true
+ * Default: 5038
* Group: common
*
- * @param username the value to set
+ * @param port the value to set
* @return the dsl builder
*/
- default AsteriskEndpointProducerBuilder username(String username) {
- doSetProperty("username", username);
+ default AsteriskEndpointProducerBuilder port(String port) {
+ doSetProperty("port", port);
return this;
}
/**
@@ -324,6 +355,39 @@ public interface AsteriskEndpointBuilderFactory {
doSetProperty("action", action);
return this;
}
+ /**
+ * The secret of the AMI user, as defined in the manager.conf file of
+ * the Asterisk server.
+ *
+ * The option is a: <code>java.lang.String</code> type.
+ *
+ * Required: true
+ * Group: security
+ *
+ * @param password the value to set
+ * @return the dsl builder
+ */
+ default AsteriskEndpointProducerBuilder password(String password) {
+ doSetProperty("password", password);
+ return this;
+ }
+ /**
+ * The name of the AMI user, as defined in the manager.conf file of the
+ * Asterisk server. The consumer and the producer each log in with it
+ * when they start.
+ *
+ * The option is a: <code>java.lang.String</code> type.
+ *
+ * Required: true
+ * Group: security
+ *
+ * @param username the value to set
+ * @return the dsl builder
+ */
+ default AsteriskEndpointProducerBuilder username(String username) {
+ doSetProperty("username", username);
+ return this;
+ }
}
/**
@@ -396,7 +460,7 @@ public interface AsteriskEndpointBuilderFactory {
/**
* The host name or IP address of the Asterisk server. The consumer and
* the producer connect to the Asterisk Manager Interface (AMI) of this
- * host on port 5038, which cannot be changed.
+ * host on the port of the port option.
*
* The option is a: <code>java.lang.String</code> type.
*
@@ -410,6 +474,38 @@ public interface AsteriskEndpointBuilderFactory {
doSetProperty("hostname", hostname);
return this;
}
+ /**
+ * The port of the Asterisk Manager Interface (AMI) of the Asterisk
+ * server, as set in the manager.conf file of the server.
+ *
+ * The option is a: <code>int</code> type.
+ *
+ * Default: 5038
+ * Group: common
+ *
+ * @param port the value to set
+ * @return the dsl builder
+ */
+ default AsteriskEndpointBuilder port(int port) {
+ doSetProperty("port", port);
+ return this;
+ }
+ /**
+ * The port of the Asterisk Manager Interface (AMI) of the Asterisk
+ * server, as set in the manager.conf file of the server.
+ *
+ * The option will be converted to a <code>int</code> type.
+ *
+ * Default: 5038
+ * Group: common
+ *
+ * @param port the value to set
+ * @return the dsl builder
+ */
+ default AsteriskEndpointBuilder port(String port) {
+ doSetProperty("port", port);
+ return this;
+ }
/**
* The secret of the AMI user, as defined in the manager.conf file of
* the Asterisk server.
@@ -417,7 +513,7 @@ public interface AsteriskEndpointBuilderFactory {
* The option is a: <code>java.lang.String</code> type.
*
* Required: true
- * Group: common
+ * Group: security
*
* @param password the value to set
* @return the dsl builder
@@ -434,7 +530,7 @@ public interface AsteriskEndpointBuilderFactory {
* The option is a: <code>java.lang.String</code> type.
*
* Required: true
- * Group: common
+ * Group: security
*
* @param username the value to set
* @return the dsl builder