Step 1. Add the JitPack repository to your build file
Add it in your root settings.gradle at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Add it in your settings.gradle.kts at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}
Add to pom.xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Add it in your build.sbt at the end of resolvers:
resolvers += "jitpack" at "https://jitpack.io"
Add it in your project.clj at the end of repositories:
:repositories [["jitpack" "https://jitpack.io"]]
Step 2. Add the dependency
dependencies {
implementation 'com.github.workingintheblackforest:ari4java:v011'
}
dependencies {
implementation("com.github.workingintheblackforest:ari4java:v011")
}
<dependency>
<groupId>com.github.workingintheblackforest</groupId>
<artifactId>ari4java</artifactId>
<version>v011</version>
</dependency>
libraryDependencies += "com.github.workingintheblackforest" % "ari4java" % "v011"
:dependencies [[com.github.workingintheblackforest/ari4java "v011"]]
The Asterisk REST Interface (ARI) bindings for Java.
ARI is an interface available on Asterisk 12/13/14/15 that lets you write applications that run externally and control call flow through REST calls while receiving events on a websocket.
In order to support different versions of the API, what we do is we maintain concrete implementations for each version of the API, but we also have general interfaces that are used to work with objects across different versions.
Getting started?
Tip: join our ari4java Google+ group for news, help and plain bouncing of ideas around.
If you use Gradle (or any tool using Maven dependencies) you can simply declare the lib as:
repositories {
mavenCentral()
jcenter()
}
dependencies {
compile 'ch.loway.oss.ari4java:ari4java:0.4.5'
}
This will download the package and all required dependencies.
The code here is partially hand-written and partially generated out of Swagger definitions.
In order to run codegen (class ch.loway.oss.ari4java.codegen.run), you need the following libraries:
The easiest way to build is simply using the Gradle script supplied.
gradle clean build
This will compile, test and package the current version. It will not run the code generator (for the moment at least). You'll find the resulting jar file under 'build/libs'.
The project requires:
To use the Netty.io HTTP+WS implementation, include netty-all-4.0.12.Final.jar or newer in your classpath.
To initialize:
ARI ari = new ARI();
NettyHttpClient hc = new NettyHttpClient();
hc.initialize("http://my-pbx-ip:8088/", "admin", "admin");
ari.setHttpClient(hc);
ari.setWsClient(hc);
ari.setVersion(AriVersion.ARI_0_0_1);
or make your life easier by using the convenience method supplied in AriFactory.
Sample synchronous call:
ActionApplications ac = ari.getActionImpl(ActionApplications.class);
List<? extends Application> alist = ac.list();
Sample asynchronous call:
ActionAsterisk aa = ari.getActionImpl(ActionAsterisk.class);
aa.getGlobalVar("AMPMGRPASS", new AriCallback<Variable>() {
@Override
public void onSuccess(Variable result) {
// Let's do something with the returned value
}
@Override
public void onFailure(RestException e) {
e.printStackTrace();
}
});
Sample WebSocket connection, waiting for events on hello and goodbye apps:
ActionEvents ae = ari.getActionImpl(ActionEvents.class);
ae.eventWebsocket("hello,goodbye", new AriCallback<Message>() {
@Override
public void onSuccess(Message result) {
// Let's do something with the event
}
@Override
public void onFailure(RestException e) {
e.printStackTrace();
}
});
Thread.sleep(5000); // Wait 5 seconds for events
ari.closeAction(ae); // Now close the websocket
The Message object in the code above will be one of the message subtypes, you will have to introspect to find out which.
The library is released under the GNU LGPL (see LICENSE file). Files under codegen-data come from the Asterisk project and are licensed under the GPLv2 (see LICENSE.asterisk file therein). They are only used to build the classes and are not distribuited in any form with Ari4Java.