Skip to content

Commit

Permalink
Merge branch 'master' of github.com:srt/asterisk-java
Browse files Browse the repository at this point in the history
  • Loading branch information
srt committed Aug 7, 2011
2 parents b4c0425 + 2e1541c commit 8ff8321
Show file tree
Hide file tree
Showing 53 changed files with 1,352 additions and 131 deletions.
11 changes: 0 additions & 11 deletions .classpath

This file was deleted.

3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -2,3 +2,6 @@
*.ipr
*.iws
target
.classpath
.project
.settings/*
21 changes: 0 additions & 21 deletions .project

This file was deleted.

68 changes: 68 additions & 0 deletions README.md
@@ -0,0 +1,68 @@
README for Asterisk-Java
========================

INTRODUCTION
------------

The Asterisk-Java package consists of a set of Java classes that allow you to easily build Java applications that interact with an [Asterisk PBX Server](http://asterisk.org). Asterisk-Java supports both interfaces that Asterisk provides for this scenario: The [FastAGI](https://wiki.asterisk.org/wiki/display/AST/Application_AGI) protocol and the [Manager API](https://wiki.asterisk.org/wiki/display/AST/The+Asterisk+Manager+TCP+IP+API).

The FastAGI implementation supports all commands currently available from Asterisk.

The Manager API implementation supports receiving events from the Asterisk server (e.g. call progess, registered peers, channel state) and sending actions to Asterisk (e.g. originate call, agent login/logoff, start/stop voice recording).

A complete list of the available events and actions is available in the javadocs.

See docs/tutorial.html for examples.

GETTING ASTERISK-JAVA
---------------------

Asterisk-Java is available from http://asterisk-java.org

INSTALLATION FROM SOURCE
------------------------

git clone https://github.com/srt/asterisk-java.git
cd asterisk-java
mvn install

After the build is complete, the jar will then be built as target/asterisk-java.jar in the asterisk-java directory.

EXAMPLE
-------

The file 'examples/ExampleCallIn.java' will answer the call and playback the audio file 'tt-monkeys'.

import org.asteriskjava.fastagi.AgiChannel;
import org.asteriskjava.fastagi.AgiException;
import org.asteriskjava.fastagi.AgiRequest;
import org.asteriskjava.fastagi.BaseAgiScript;
/* Example incoming call handler
Answer call, speak message */
public class ExampleCallIn extends BaseAgiScript {
public void service(AgiRequest request, AgiChannel channel) throws AgiException {
answer();
exec("Playback", "tt-monkeys");
hangup();
}
}

The file 'examples/fastagi-mapping.properties' maps your Asterisk diaplan context to the class you would like to invoke above.

callin.agi = ExampleCallIn

To compile and run do:

javac -cp asterisk-java.jar ExampleCallIn.java
java -cp asterisk-java.jar org.asteriskjavafastagi.DefaultAgiServer

SYSTEM REQUIREMENTS
-------------------

Asterisk-Java needs a Java Virtual Machine of at least version 1.6 ([Java SE 6.0](http://www.oracle.com/technetwork/java/javase/downloads/index.html)). If you want to build the jar from source, you will
also need [Maven](http://maven.apache.org/).

LEGAL
-----

Asterisk-Java is subject to the terms detailed in the license agreement accompanying it.
36 changes: 0 additions & 36 deletions README.txt

This file was deleted.

21 changes: 21 additions & 0 deletions examples/ExampleCallin.java
@@ -0,0 +1,21 @@
/* Cloudvox - answer and control a phone call with Java
Place and receive phone calls via open API: http://cloudvox.com/
Learn about call scripting, Asterisk/AGI, voice apps: http://help.cloudvox.com/
Added to the project and modified by Tropo: http://tropo.com */

import org.asteriskjava.fastagi.AgiChannel;
import org.asteriskjava.fastagi.AgiException;
import org.asteriskjava.fastagi.AgiRequest;
import org.asteriskjava.fastagi.BaseAgiScript;

/* Example incoming call handler
Answer call, speak message */
public class ExampleCallIn extends BaseAgiScript {
public void service(AgiRequest request, AgiChannel channel) throws AgiException {
answer();

exec("Playback", "tt-monkeys");

hangup();
}
}
1 change: 1 addition & 0 deletions examples/fastagi-mapping.properties
@@ -0,0 +1 @@
callin.agi = ExampleCallIn
4 changes: 2 additions & 2 deletions src/main/java/org/asteriskjava/config/ConfigFileReader.java
Expand Up @@ -21,11 +21,11 @@ public class ConfigFileReader
private static final int MAX_LINE_LENGTH = 8192;
private static char COMMENT_META = ';';
private static char COMMENT_TAG = '-';
private static final Set<Class> WARNING_CLASSES;
private static final Set<Class<?>> WARNING_CLASSES;

static
{
WARNING_CLASSES = new HashSet<Class>();
WARNING_CLASSES = new HashSet<Class<?>>();
WARNING_CLASSES.add(MissingEqualSignException.class);
WARNING_CLASSES.add(UnknownDirectiveException.class);
WARNING_CLASSES.add(MissingDirectiveParameterException.class);
Expand Down
Expand Up @@ -113,7 +113,7 @@ protected synchronized ClassLoader getClassLoader()
@SuppressWarnings("unchecked")
protected AgiScript createAgiScriptInstance(String className)
{
Class tmpClass;
Class<?> tmpClass;
Class<AgiScript> agiScriptClass;
Constructor<AgiScript> constructor;
AgiScript agiScript;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/asteriskjava/fastagi/AgiRequest.java
Expand Up @@ -34,7 +34,7 @@ public interface AgiRequest
*
* @return Map contain raw request name/value pairs.
*/
Map getRequest();
Map<String, String> getRequest();

/**
* Returns the name of the script to execute including its full path.<p>
Expand Down
Expand Up @@ -133,7 +133,7 @@ public synchronized void setShareInstances(boolean shareInstances)
private synchronized void loadResourceBundle()
{
ResourceBundle resourceBundle;
Enumeration keys;
Enumeration<?> keys;

mappings = new HashMap<String, String>();
if (shareInstances)
Expand Down
Expand Up @@ -2,7 +2,6 @@

import org.asteriskjava.fastagi.AgiChannel;
import org.asteriskjava.fastagi.AgiRequest;
import org.asteriskjava.util.SocketConnectionFacade;

/**
* An AgiChannelFactory creates instances of AgiChannels,
Expand Down
Expand Up @@ -19,7 +19,6 @@
import org.asteriskjava.fastagi.*;
import org.asteriskjava.fastagi.command.*;
import org.asteriskjava.fastagi.reply.AgiReply;
import org.asteriskjava.util.SocketConnectionFacade;

/**
* Default implementation of the AgiChannel interface.
Expand Down
Expand Up @@ -16,7 +16,6 @@
*/
package org.asteriskjava.fastagi.internal;

import java.io.*;
import java.util.*;
import java.util.regex.*;

Expand Down
Expand Up @@ -469,7 +469,7 @@ public synchronized String getVersion() throws ManagerCommunicationException
response = sendAction(new CommandAction(command));
if (response instanceof CommandResponse)
{
final List result;
final List<?> result;

result = ((CommandResponse) response).getResult();
if (result.size() > 0)
Expand Down Expand Up @@ -1128,12 +1128,6 @@ private void handleOriginateEvent(OriginateResponseEvent originateEvent)
return;
}

if (channel.wasInState(ChannelState.UP))
{
cb.onSuccess(channel);
return;
}

if (channel.wasBusy())
{
cb.onBusy(channel);
Expand Down Expand Up @@ -1169,9 +1163,15 @@ private void handleOriginateEvent(OriginateResponseEvent originateEvent)
return;
}
}

if (channel.wasInState(ChannelState.DOWN))
{
cb.onNoAnswer(channel);
return;
}

// if nothing else matched we asume no answer
cb.onNoAnswer(channel);
// if nothing else matched we asume success
cb.onSuccess(channel);
}
catch (Throwable t)
{
Expand Down
@@ -0,0 +1,73 @@
package org.asteriskjava.manager.action;

/**
* The ConfbridgeKickAction kicks a channel out of a conference.
*
* @author jmb
* @version $Id$
*/
public class ConfbridgeKickAction extends AbstractManagerAction {

/**
* Serializable version identifier
*/
private static final long serialVersionUID = 3827556611709875112L;

private String conference;
private String channel;

/**
* Creates a new empty ConfbridgeKickAction.
*/
public ConfbridgeKickAction() {
super();
}

/**
* Creates a new ConfbridgeKickAction.
*
* @param conference the conference number.
* @param channel number of the channel in the conference.
*/
public ConfbridgeKickAction(String conference, String channel) {
this.setConference(conference);
this.setChannel(channel);
}

/**
* Returns the name of this action, i.e. "ConfbridgeKick".
*/
@Override
public String getAction() {
return "ConfbridgeKick";
}

/**
* Sets the id of the conference to kick a channel from.
*/
public void setConference(String conference) {
this.conference = conference;
}

/**
* Returns the id of the conference to kick a channel from.
*/
public String getConference() {
return conference;
}

/**
* Sets the number of the channel to kick.
*/
public void setChannel(String channel) {
this.channel = channel;
}

/**
* Returns the number of the channel to kick.
*/
public String getChannel() {
return channel;
}

}
@@ -0,0 +1,31 @@
package org.asteriskjava.manager.action;

public class ConfbridgeListAction extends AbstractManagerAction {

/**
*
*/
private static final long serialVersionUID = 1L;
private String conference;

public ConfbridgeListAction() {
}

public ConfbridgeListAction(String conference) {
this.conference = conference;
}

public void setConference(String conference) {
this.conference = conference;
}

public String getConference() {
return conference;
}

@Override
public String getAction() {
return "ConfbridgeList";
}

}

0 comments on commit 8ff8321

Please sign in to comment.