You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2016/09/21 12:29:00 UTC
[08/10] camel git commit: CAMEL-10321,
Asterisk Component: documentation adoc
CAMEL-10321, Asterisk Component: documentation adoc
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/4cab9466
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/4cab9466
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/4cab9466
Branch: refs/heads/master
Commit: 4cab94661ac8d000dc5823e1412cf64f518f7990
Parents: 7feb7e7
Author: Fabryprog <fa...@gmail.com>
Authored: Sat Sep 17 00:15:14 2016 +0200
Committer: Andrea Cosentino <an...@gmail.com>
Committed: Wed Sep 21 13:44:14 2016 +0200
----------------------------------------------------------------------
.../src/main/docs/asterisk-component.adoc | 59 ++++++++++++++++++
.../component/asterisk/AsteriskActionEnum.java | 21 +++++++
.../component/asterisk/AsteriskConstants.java | 4 ++
.../component/asterisk/AsteriskEndpoint.java | 4 --
.../component/asterisk/AsteriskProducer.java | 2 +-
.../asterisk/CamelAsteriskException.java | 2 +-
.../org/apache/camel/component/asterisk | 1 -
.../component/asterisk/AsteriskConfigTest.java | 41 +++++++++++++
.../asterisk/AsteriskConsumerTest.java | 64 ++++++++++++++++++++
.../asterisk/AsteriskProducerTest.java | 54 +++++++++++++++++
10 files changed, 245 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/4cab9466/components/camel-asterisk/src/main/docs/asterisk-component.adoc
----------------------------------------------------------------------
diff --git a/components/camel-asterisk/src/main/docs/asterisk-component.adoc b/components/camel-asterisk/src/main/docs/asterisk-component.adoc
new file mode 100644
index 0000000..10e3368
--- /dev/null
+++ b/components/camel-asterisk/src/main/docs/asterisk-component.adoc
@@ -0,0 +1,59 @@
+[[AsteriskComponent-AsteriskComponent]]
+Asterisk Component
+~~~~~~~~~~~~~~~~~~~
+
+*Available as of Camel 2.18*
+
+The *asterisk:* component allows you to work easily with an Asterisk PBX Server http://www.asterisk.org/ using https://asterisk-java.org/[asterisk-java]
+
+This component help to interface with http://www.voip-info.org/wiki-Asterisk+manager+API[Asterisk Manager Interface]
+
+Maven users will need to add the following dependency to their `pom.xml`
+for this component:
+
+[source,xml]
+------------------------------------------------------------
+<dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-asterisk</artifactId>
+ <version>x.x.x</version>
+ <!-- use the same version as your Camel core version -->
+</dependency>
+------------------------------------------------------------
+
+[[AsteriskComponent-URIformat]]
+URI format
+^^^^^^^^^^
+
+[source,java]
+-------------------------------------------------------------------------------------------------------------------------
+asterisk:name[?options]
+-------------------------------------------------------------------------------------------------------------------------
+
+[[AsteriskComponent-Options]]
+Options
+^^^^^^^
+
+// component options: START
+The Asterisk component supports 4 endpoint options which are listed below:
+
+{% raw %}
+[width="100%",cols="1,1m,1m,5",options="header"]
+|=======================================================================
+| Name | Group | Java Type | Description
+| hostname | common | String | *Required* This is hostname / ip of Asterisk Server.
+| username | common | String | username
+| password | common | String | password
+| action | producer | AsteriskActionEnum | *Required* Operation to send via AMI
+|=======================================================================
+{% endraw %}
+// endpoint options: END
+
+[[Asterisk-Actions]]
+Action
+^^^^^^
+Supported actions are:
+
+* QUEUE_STATUS, Queue Status
+* SIP_PEERS, List SIP Peers
+* EXTENSION_STATE, Check Extension Status
http://git-wip-us.apache.org/repos/asf/camel/blob/4cab9466/components/camel-asterisk/src/main/java/org/apache/camel/component/asterisk/AsteriskActionEnum.java
----------------------------------------------------------------------
diff --git a/components/camel-asterisk/src/main/java/org/apache/camel/component/asterisk/AsteriskActionEnum.java b/components/camel-asterisk/src/main/java/org/apache/camel/component/asterisk/AsteriskActionEnum.java
new file mode 100644
index 0000000..da1c0fd
--- /dev/null
+++ b/components/camel-asterisk/src/main/java/org/apache/camel/component/asterisk/AsteriskActionEnum.java
@@ -0,0 +1,21 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.asterisk;
+
+public enum AsteriskActionEnum {
+ QUEUE_STATUS, SIP_PEERS, EXTENSION_STATE;
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/4cab9466/components/camel-asterisk/src/main/java/org/apache/camel/component/asterisk/AsteriskConstants.java
----------------------------------------------------------------------
diff --git a/components/camel-asterisk/src/main/java/org/apache/camel/component/asterisk/AsteriskConstants.java b/components/camel-asterisk/src/main/java/org/apache/camel/component/asterisk/AsteriskConstants.java
index 249dc2e..9666753 100644
--- a/components/camel-asterisk/src/main/java/org/apache/camel/component/asterisk/AsteriskConstants.java
+++ b/components/camel-asterisk/src/main/java/org/apache/camel/component/asterisk/AsteriskConstants.java
@@ -20,4 +20,8 @@ public final class AsteriskConstants {
public static final String EVENT_NAME = "AsteriskEventName";
public static final String EXTEN = "AsteriskExtension";
public static final String CONTEXT = "AsteriskContext";
+
+ private AsteriskConstants() {
+ }
+
}
http://git-wip-us.apache.org/repos/asf/camel/blob/4cab9466/components/camel-asterisk/src/main/java/org/apache/camel/component/asterisk/AsteriskEndpoint.java
----------------------------------------------------------------------
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 c261b32..0ca8304 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
@@ -44,10 +44,6 @@ public class AsteriskEndpoint extends DefaultEndpoint {
@SuppressWarnings("unused")
private static final Logger LOG = LoggerFactory.getLogger(AsteriskProducer.class);
- protected enum ActionsEnum {
- QUEUE_STATUS, SIP_PEERS, EXTENSION_STATE;
- }
-
@UriPath(description = "Name of component") @Metadata(required = "true")
private String name;
http://git-wip-us.apache.org/repos/asf/camel/blob/4cab9466/components/camel-asterisk/src/main/java/org/apache/camel/component/asterisk/AsteriskProducer.java
----------------------------------------------------------------------
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 50a6cd8..bea860c 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
@@ -55,7 +55,7 @@ public class AsteriskProducer extends DefaultProducer {
public void process(Exchange exchange) throws Exception {
ManagerAction action;
- switch (AsteriskEndpoint.ActionsEnum.valueOf(endpoint.getAction())) {
+ switch (AsteriskActionEnum.valueOf(endpoint.getAction())) {
case QUEUE_STATUS:
action = new QueueStatusAction();
break;
http://git-wip-us.apache.org/repos/asf/camel/blob/4cab9466/components/camel-asterisk/src/main/java/org/apache/camel/component/asterisk/CamelAsteriskException.java
----------------------------------------------------------------------
diff --git a/components/camel-asterisk/src/main/java/org/apache/camel/component/asterisk/CamelAsteriskException.java b/components/camel-asterisk/src/main/java/org/apache/camel/component/asterisk/CamelAsteriskException.java
index cc773d4..77e33d0 100644
--- a/components/camel-asterisk/src/main/java/org/apache/camel/component/asterisk/CamelAsteriskException.java
+++ b/components/camel-asterisk/src/main/java/org/apache/camel/component/asterisk/CamelAsteriskException.java
@@ -19,6 +19,7 @@ package org.apache.camel.component.asterisk;
import org.apache.camel.CamelException;
public class CamelAsteriskException extends CamelException {
+ private static final long serialVersionUID = -8873987361491963823L;
public CamelAsteriskException() {
super();
@@ -28,6 +29,5 @@ public class CamelAsteriskException extends CamelException {
super(message);
}
- private static final long serialVersionUID = -8873987361491963823L;
}
http://git-wip-us.apache.org/repos/asf/camel/blob/4cab9466/components/camel-asterisk/src/main/resources/META-INF/services/org/apache/camel/component/asterisk
----------------------------------------------------------------------
diff --git a/components/camel-asterisk/src/main/resources/META-INF/services/org/apache/camel/component/asterisk b/components/camel-asterisk/src/main/resources/META-INF/services/org/apache/camel/component/asterisk
index e45f21d..4923c0b 100644
--- a/components/camel-asterisk/src/main/resources/META-INF/services/org/apache/camel/component/asterisk
+++ b/components/camel-asterisk/src/main/resources/META-INF/services/org/apache/camel/component/asterisk
@@ -14,5 +14,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
-
class=org.apache.camel.component.asterisk.AsteriskComponent
http://git-wip-us.apache.org/repos/asf/camel/blob/4cab9466/components/camel-asterisk/src/test/java/org/apache/camel/component/asterisk/AsteriskConfigTest.java
----------------------------------------------------------------------
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
new file mode 100644
index 0000000..738f87a
--- /dev/null
+++ b/components/camel-asterisk/src/test/java/org/apache/camel/component/asterisk/AsteriskConfigTest.java
@@ -0,0 +1,41 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.asterisk;
+
+import org.apache.camel.Endpoint;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Test;
+
+public class AsteriskConfigTest extends CamelTestSupport {
+
+ private String hostname = "192.168.0.254";
+ private String username = "username";
+ private String password = "password";
+ private String action = "action";
+
+ @Test
+ public void asteriskEndpointData() throws Exception {
+ Endpoint endpoint = context.getEndpoint("asterisk://myVoIP?hostname=" + hostname + "&username=" + username + "&password=" + password + "&action=" + action);
+ assertTrue("Endpoint not an AsteriskEndpoint: " + endpoint, endpoint instanceof AsteriskEndpoint);
+ AsteriskEndpoint asteriskEndpoint = (AsteriskEndpoint)endpoint;
+
+ assertEquals(hostname, asteriskEndpoint.getHostname());
+ assertEquals(username, asteriskEndpoint.getUsername());
+ assertEquals(password, asteriskEndpoint.getPassword());
+ assertEquals(action, asteriskEndpoint.getAction());
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/4cab9466/components/camel-asterisk/src/test/java/org/apache/camel/component/asterisk/AsteriskConsumerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-asterisk/src/test/java/org/apache/camel/component/asterisk/AsteriskConsumerTest.java b/components/camel-asterisk/src/test/java/org/apache/camel/component/asterisk/AsteriskConsumerTest.java
new file mode 100644
index 0000000..3924662
--- /dev/null
+++ b/components/camel-asterisk/src/test/java/org/apache/camel/component/asterisk/AsteriskConsumerTest.java
@@ -0,0 +1,64 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.asterisk;
+
+import java.util.List;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Ignore("CAMEL-10321: Set host, port and oids to test asterisk consumer.")
+public class AsteriskConsumerTest extends CamelTestSupport {
+ private static final Logger LOG = LoggerFactory.getLogger(AsteriskConsumerTest.class);
+
+ private String hostname = "192.168.0.254";
+ private String username = "username";
+ private String password = "password";
+
+ @Ignore
+ @Test
+ public void testReceiveTraps() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedMinimumMessageCount(1);
+ mock.assertIsSatisfied();
+ List<Exchange> events = mock.getExchanges();
+ if (LOG.isInfoEnabled()) {
+ for (Exchange e : events) {
+ LOG.info("ASTERISK EVENTS: " + e.getIn().getBody(String.class));
+ }
+ }
+ }
+
+ @Test
+ public void testStartRoute() throws Exception {
+ // do nothing here , just make sure the camel route can started.
+ }
+
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ public void configure() {
+ from("asterisk:myVoIP?hostname=" + hostname + "&username=" + username + "&password=" + password).id("route1").transform(body().convertToString()).to("mock:result");
+ }
+ };
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/4cab9466/components/camel-asterisk/src/test/java/org/apache/camel/component/asterisk/AsteriskProducerTest.java
----------------------------------------------------------------------
diff --git a/components/camel-asterisk/src/test/java/org/apache/camel/component/asterisk/AsteriskProducerTest.java b/components/camel-asterisk/src/test/java/org/apache/camel/component/asterisk/AsteriskProducerTest.java
new file mode 100644
index 0000000..63f5471
--- /dev/null
+++ b/components/camel-asterisk/src/test/java/org/apache/camel/component/asterisk/AsteriskProducerTest.java
@@ -0,0 +1,54 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.asterisk;
+
+import java.util.concurrent.TimeUnit;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.junit.Ignore;
+import org.junit.Test;
+
+@Ignore("CAMEL-10321: Set host, port and oids to test asterisk producer.")
+public class AsteriskProducerTest extends CamelTestSupport {
+
+ private String hostname = "192.168.0.254";
+ private String username = "username";
+ private String password = "password";
+ private String action = AsteriskActionEnum.EXTENSION_STATE.name();
+
+ @Test
+ public void testSnmpProducer() throws Exception {
+ template.sendBody("direct:in", "");
+
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedMinimumMessageCount(1);
+
+ assertMockEndpointsSatisfied(5, TimeUnit.SECONDS);
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ public void configure() {
+ from("direct:in").to("asterisk://myVoIP?hostname=" + hostname + "&username=" + username + "&password=" + password + "&action=" + action).log("${body}")
+ .to("mock:result");
+ }
+ };
+ }
+}