Search in sources :

Example 21 with EslMessage

use of org.freeswitch.esl.client.transport.message.EslMessage in project openhab1-addons by openhab.

the class FreeswitchBinding method executeApiCommand.

/**
     * Execute a api command and return the body as a
     * single comma delimited String
     *
     * @param command
     * @return Each line of the response will be appended to the string,
     *         delimited by a comma
     */
public String executeApiCommand(String command) {
    logger.debug("Trying to execute API command {}", command);
    if (!clientValid() && StringUtils.isBlank(command)) {
        logger.error("Bad command {}", command);
        return null;
    }
    String[] args = command.split(" ", 1);
    /*
         * if we do not have 2 args then this is not valid
         */
    if (args.length == 0) {
        logger.error("Command did not contain a valid command string {}");
        return null;
    }
    EslMessage msg = inboudClient.sendSyncApiCommand(args[0], args.length > 1 ? args[1] : "");
    List<String> bodyLines = msg.getBodyLines();
    StringBuilder builder = new StringBuilder();
    for (String line : bodyLines) {
        if (builder.length() > 0) {
            builder.append(",");
        }
        builder.append(line);
    }
    return builder.toString();
}
Also used : EslMessage(org.freeswitch.esl.client.transport.message.EslMessage)

Aggregations

EslMessage (org.freeswitch.esl.client.transport.message.EslMessage)21 CommandResponse (org.freeswitch.esl.client.transport.CommandResponse)9 Client (org.freeswitch.esl.client.inbound.Client)7 EslEvent (org.freeswitch.esl.client.transport.event.EslEvent)3 InboundConnectionFailure (org.freeswitch.esl.client.inbound.InboundConnectionFailure)2 Test (org.junit.Test)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 IEslEventListener (org.freeswitch.esl.client.IEslEventListener)1 SendMsg (org.freeswitch.esl.client.transport.SendMsg)1 Name (org.freeswitch.esl.client.transport.message.EslHeaders.Name)1 FreeswitchBindingProvider (org.openhab.binding.freeswitch.FreeswitchBindingProvider)1 ConfigurationException (org.osgi.service.cm.ConfigurationException)1