[Asterisk-Users] SIPPeersAction class file not found in the
Asterisk-java.jar file
Stefan Reuter
srt at reucon.net
Thu Aug 4 17:47:52 MST 2005
On Thu, 2005-08-04 at 18:25 +0530, Bharat M. Sarvan wrote:
> I am working on Fastagi and I am making use of
> Asterisk-java. But I don’t find the class file for SIPPeersAction.
The SIPPeersAction is not part of Asterisk-Java 0.1, it is available in
CVS-HEAD only.
Besides that the action classes in net.sf.asterisk.manager.action can
only be used with the Manager API and not with FastAGI.
So if you want to retrieve a list of sip peers you need to do that via
the Manager API. With Asterisk 1.0.x and Asterisk-Java 0.1 you can do
this via the CommandAction. Only if you are already using Asterisk
CVS-HEAD and Asterisk-Java CVS-HEAD you can use the new SipPeerAction.
Example with CommandAction:
import java.util.Iterator;
import net.sf.asterisk.manager.ManagerConnection;
import net.sf.asterisk.manager.ManagerConnectionFactory;
import net.sf.asterisk.manager.action.CommandAction;
import net.sf.asterisk.manager.response.CommandResponse;
public class Manager
{
private ManagerConnection c;
public Manager() throws Exception
{
c = new ManagerConnectionFactory().getManagerConnection("host",
"user", "pass");
}
public void run() throws Exception
{
c.login();
CommandAction action;
CommandResponse response;
Iterator lineIterator;
action = new CommandAction();
action.setCommand("sip show peers");
response = (CommandResponse) c.sendAction(action);
lineIterator = response.getResult().iterator();
while (lineIterator.hasNext())
{
System.out.println(lineIterator.next());
}
c.logoff();
}
public static void main(String[] args) throws Exception
{
new Manager().run();
}
}
This produces something like:
Name/username Host Dyn Nat ACL Mask Port
Status
1313/1313 10.13.0.61 D A 255.255.255.255 5061
Unmonitored
1312/1312 10.13.0.61 D A 255.255.255.255 5061
Unmonitored
1311/1311 10.13.0.61 D A 255.255.255.255 5061
Unmonitored
1310/1310 (Unspecified) D A 255.255.255.255 0
Unmonitored
1303/1303 (Unspecified) D N 255.255.255.255 0
Unmonitored
1302/1302 (Unspecified) D A 255.255.255.255 0
Unmonitored
1301/1301 (Unspecified) D A 255.255.255.255 0
Unmonitored
=Stefan
More information about the asterisk-users
mailing list