<div dir="ltr"><div><div><div>Greeting,<br><br></div>bellow is an example to handle outbound connection and make hung up:<br><br></div>but it never show How to make the connection in first place<br><br></div>is their an example in main of how this function work ?<br>
<div><div><div><div><div><div><br>/*<br> * Copyright 2010 david varnes.<br> *<br> * Licensed under the Apache License, version 2.0 (the "License"); <br> * you may not use this file except in compliance with the License. <br>
 * You may obtain a copy of the License at:<br> *<br> *    <a href="http://www.apache.org/licenses/LICENSE-2.0">http://www.apache.org/licenses/LICENSE-2.0</a><br> *<br> * Unless required by applicable law or agreed to in writing, software<br>
 * distributed under the License is distributed on an "AS IS" BASIS, <br> * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br> * See the License for the specific language governing permissions and<br>
 * limitations under the License.<br> */<br>package org.freeswitch.esl.client.outbound.example;<br><br>import org.freeswitch.esl.client.outbound.AbstractOutboundClientHandler;<br>import org.freeswitch.esl.client.transport.SendMsg;<br>
import org.freeswitch.esl.client.transport.event.EslEvent;<br>import org.freeswitch.esl.client.transport.message.EslMessage;<br>import <a href="http://org.freeswitch.esl.client.transport.message.EslHeaders.Name">org.freeswitch.esl.client.transport.message.EslHeaders.Name</a>;<br>
import org.jboss.netty.channel.Channel;<br>import org.jboss.netty.channel.ChannelHandlerContext;<br><br>/**<br> * Simple example of a handler for outbound connection from FreeSWITCH server.<br> * This class will log some of the FreeSWTICH call channel variables and <br>
 * then hangup the call.  <br> * <br> * @author  david varnes<br> */<br>public class SimpleHangupOutboundHandler extends AbstractOutboundClientHandler<br>{<br>    <br>    @Override<br>    protected void handleConnectResponse( ChannelHandlerContext ctx, EslEvent event )<br>
    {<br>        <a href="http://log.info">log.info</a>( "Received connect response [{}]", event );<br>        if ( event.getEventName().equalsIgnoreCase( "CHANNEL_DATA" ) )<br>        {<br>            // this is the response to the initial connect <br>
            <a href="http://log.info">log.info</a>( "=======================  incoming channel data  =============================" );<br>            <a href="http://log.info">log.info</a>( "Event-Date-Local: [{}]", event.getEventDateLocal() );<br>
            <a href="http://log.info">log.info</a>( "Unique-ID: [{}]", event.getEventHeaders().get( "Unique-ID" ) );<br>            <a href="http://log.info">log.info</a>( "Channel-ANI: [{}]", event.getEventHeaders().get( "Channel-ANI" ) );<br>
            <a href="http://log.info">log.info</a>( "Answer-State: [{}]", event.getEventHeaders().get( "Answer-State" ) );<br>            <a href="http://log.info">log.info</a>( "Caller-Destination-Number: [{}]", event.getEventHeaders().get( "Caller-Destination-Number" ) );<br>
            <a href="http://log.info">log.info</a>( "=======================  = = = = = = = = = = =  =============================" );<br>            <br>            // now hangup the call<br>            hangupCall( ctx.getChannel() );<br>
        }<br>        else<br>        {<br>            throw new IllegalStateException( "Unexpected event after connect: [" + event.getEventName() + ']' );<br>        }<br>    }<br><br>    @Override<br>    protected void handleEslEvent( ChannelHandlerContext ctx, EslEvent event )<br>
    {<br>        <a href="http://log.info">log.info</a>( "Received event [{}]", event );<br>    }<br>    <br>    private void hangupCall( Channel channel )<br>    {<br>        SendMsg hangupMsg = new SendMsg();<br>
        hangupMsg.addCallCommand( "execute" );<br>        hangupMsg.addExecuteAppName( "hangup" );<br>        <br>        EslMessage response = sendSyncMultiLineCommand( channel, hangupMsg.getMsgLines() );<br>
        <br>        if ( response.getHeaderValue( Name.REPLY_TEXT ).startsWith( "+OK" ) )<br>        {<br>            <a href="http://log.info">log.info</a>( "Call hangup successful" );<br>        }<br>
        else<br>        {<br>            log.error( "Call hangup failed: [{}}", response.getHeaderValue( Name.REPLY_TEXT ) );<br>        }<br>    }<br>}<br><br></div></div></div></div></div></div></div>