return request;
}
public AgiReply readReply() throws AgiException
{
AgiReply reply;
List<String> lines;
String line;
lines = new ArrayList<String>();
try
{
line = socket.readLine();
}
catch (IOException e)
{
// readline throws IOException if the connection has been closed
throw new AgiHangupException();
}
if (line == null)
{
throw new AgiHangupException();
}
// TODO Asterisk 1.6 sends "HANGUP" when the channel is hung up.
//System.out.println(line);
if (line.startsWith("HANGUP"))
{
if (line.length() > 6)
{
line = line.substring(6);
}
else
{
return readReply();
}
}
lines.add(line);
// read synopsis and usage if statuscode is 520
if (line.startsWith(Integer.toString(AgiReply.SC_INVALID_COMMAND_SYNTAX)))
{
try
{
while ((line = socket.readLine()) != null)
{
lines.add(line);
if (line.startsWith(Integer.toString(AgiReply.SC_INVALID_COMMAND_SYNTAX)))
{
break;
}
}
}
catch (IOException e)
{
throw new AgiNetworkException("Unable to read reply from Asterisk: " + e.getMessage(), e);
}
}
reply = new AgiReplyImpl(lines);
// Special handling for gosub, see AJ-257
if (reply.getStatus() == AgiReply.SC_TRYING)
{
return readReply();
}
else
{