Asterisk Java Recording Call

Hi,
I’m curently working with asterisk for SIP call. I want to record a part of the call with the API asterisk Java.
I already have a code that call my sip extension “phone1” and make a link with an extension “303” that do some stuff. This part of the code work properly but I decided to add the part that start the recording. Here’s the full code:

import java.io.IOException;
import org.asteriskjava.manager.AuthenticationFailedException;
import org.asteriskjava.manager.ManagerConnection;
import org.asteriskjava.manager.ManagerConnectionFactory;
import org.asteriskjava.manager.TimeoutException;
import org.asteriskjava.manager.action.OriginateAction;
import org.asteriskjava.manager.response.ManagerResponse;
import org.asteriskjava.manager.DefaultManagerConnection;
import org.asteriskjava.manager.action.CommandAction;
import org.asteriskjava.manager.action.MonitorAction;
import org.asteriskjava.manager.action.StopMonitorAction;

public class HelloManager {
    private ManagerConnection managerConnection;

    public HelloManager() throws IOException {
        ManagerConnectionFactory factory = new ManagerConnectionFactory(
                "localhost", "manager", "123");
        this.managerConnection = factory.createManagerConnection();
    }

    public void run() throws IOException, AuthenticationFailedException, TimeoutException, InterruptedException {
        OriginateAction originateAction;
        ManagerResponse originateResponse;

        try {
            originateAction = new OriginateAction();
            originateAction.setChannel("SIP/phone1@192.168.88.36:61255");
            originateAction.setContext("labo");
            originateAction.setExten("303");
            originateAction.setPriority(new Integer(1));
            originateAction.setTimeout(new Integer(30000));

            managerConnection.login();

            try {
                originateResponse = managerConnection.sendAction(originateAction, 30000);
                System.out.println(originateResponse.getResponse());
            } catch (Exception e) {
                e.printStackTrace();
                System.out.println("Error is : " + e.getMessage());
            }

            Thread.sleep(2000);

            try {
                MonitorAction monitorAction = new MonitorAction("SIP/phone1@192.168.88.36:61255", "myFile", "m");
                ManagerResponse monitorResponse = managerConnection.sendAction(monitorAction);
                System.out.println("la réponse : " + monitorResponse.getResponse());

                if (monitorResponse.getResponse().equals("Success")) {
                    System.out.println("Enregistrement de l'appel démarré.");

                    Thread.sleep(2000);

                    StopMonitorAction stopMonitorAction = new StopMonitorAction("SIP/phone1@192.168.88.36:61255");
                    ManagerResponse stopMonitorResponse = managerConnection.sendAction(stopMonitorAction);

                    if (stopMonitorResponse.getResponse().equals("Success")) {
                        System.out.println("Enregistrement de l'appel arrêté.");
                    } else {
                        System.out.println("Impossible d'arrêter l'enregistrement de l'appel.");
                    }
                } else {
                    System.out.println("Impossible de démarrer l'enregistrement de l'appel.");
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("Error " + e.getMessage());
        } finally {
            managerConnection.logoff();
        }
    }

    public static void main(String[] args) throws Exception {
        HelloManager helloManager;
        helloManager = new HelloManager();
        helloManager.run();
    }
}

The problem is that I can’t send the action of recording. Indeed, this line “ManagerResponse stopMonitorResponse = managerConnection.sendAction(stopMonitorAction);” just sending “error” as response. I’m sure the parameters are the right one so I don’t really understand why it does not work.
I have no additionnal output in the CLI console. No error message. The manager :

[general]
enabled=yes
port=5038
bindaddr=0.0.0.0
;debug=on

[manager]
secret=123
permit=0.0.0.0/0.0.0.0
read=all
write=all

And the dialplan:

exten => 303,1,Answer
exten => 303,2,Dial(SIP/3@JVoiceXML)
exten => 303,3,Hangup

Is there additional asterisk parameter to set in order to allow recording ?
Thank for reading.

Fixed this by using an other way : sending CLI command “mixmonitor”

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.