Asterisk ARI接口的一个Java绑定:ari4java

jopen 11年前

ari4java是 Asterisk REST Interface (ARI) 的一个Java绑定。

ARI是 Asterisk 12 提供的一个接口,可以让你编写通过REST调用运行在外部和控制呼叫流程的应用,同时接收WebSocket上的事件的应用程序。

为了使用 Netty.io HTTP+WS 实现,需要包含 netty-all-4.0.12.Final.jar或更新的版本在classpath.中

初始化:

    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);

简单的同步调用:

    ActionApplications ac = ari.getActionImpl(ActionApplications.class);      List<? extends Application> alist = ac.list();

简单的异步调用:

    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();          }      });

WebSocket 连接示例,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


 

项目主页:http://www.open-open.com/lib/view/home/1388623340125