[Asterisk-java-cvs] CVS: asterisk-java/src/java/net/sf/asterisk/fastagi AGIHangupException.java,NONE
Brought to you by:
srt
From: Stefan R. <sr...@us...> - 2005-03-11 00:23:38
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22390/src/java/net/sf/asterisk/fastagi Modified Files: AGIReader.java AGIChannelImpl.java AGIConnectionHandler.java AbstractAGIScript.java AGIReaderImpl.java AGIChannel.java AGIScript.java Added Files: AGIHangupException.java AGIException.java Log Message: Added AGIExceptions --- NEW FILE: AGIHangupException.java --- /* * Copyright 2004-2005 Stefan Reuter * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ package net.sf.asterisk.fastagi; /** * The AGIHangupException is thrown if the channel has been hang up while * processing the AGIRequest. * * @author srt * @version $Id: AGIHangupException.java,v 1.1 2005/03/11 00:23:25 srt Exp $ */ public class AGIHangupException extends AGIException { /** * Serial version identifier. */ private static final long serialVersionUID = 3256444698691252274L; public AGIHangupException() { super("Channel was hang up."); } } --- NEW FILE: AGIException.java --- /* * Copyright 2004-2005 Stefan Reuter * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ package net.sf.asterisk.fastagi; /** * Abstract base class for all AGI specific exceptions. * * @author srt * @version $Id: AGIException.java,v 1.1 2005/03/11 00:23:25 srt Exp $ */ public abstract class AGIException extends Exception { /** * */ public AGIException() { super(); } /** * Creates a new AGIExeption with the given message. * * @param message a message decribing the AGIException. */ public AGIException(String message) { super(message); } } Index: AGIReader.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi/AGIReader.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -p -r1.3 -r1.4 --- AGIReader.java 10 Mar 2005 13:45:23 -0000 1.3 +++ AGIReader.java 11 Mar 2005 00:23:25 -0000 1.4 @@ -41,7 +41,8 @@ public interface AGIReader * Reads one reply to an AGICommand from Asterisk. * * @return the reply read. + * @throws AGIHangupException if the channel has been hang up while reading the reply. * @throws IOException if the reply can't be read. */ - AGIReply readReply() throws IOException; + AGIReply readReply() throws AGIHangupException, IOException; } Index: AGIChannelImpl.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi/AGIChannelImpl.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -p -r1.1 -r1.2 --- AGIChannelImpl.java 10 Mar 2005 23:57:06 -0000 1.1 +++ AGIChannelImpl.java 11 Mar 2005 00:23:25 -0000 1.2 @@ -47,7 +47,7 @@ public class AGIChannelImpl implements A this.agiReader = agiReader; } - public synchronized AGIReply sendCommand(AGICommand command) throws IOException + public synchronized AGIReply sendCommand(AGICommand command) throws AGIException, IOException { AGIReply reply; Index: AGIConnectionHandler.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi/AGIConnectionHandler.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -p -r1.4 -r1.5 --- AGIConnectionHandler.java 10 Mar 2005 23:57:06 -0000 1.4 +++ AGIConnectionHandler.java 11 Mar 2005 00:23:25 -0000 1.5 @@ -103,6 +103,10 @@ public class AGIConnectionHandler implem { logger.error("IOException while handling request", e); } + catch (AGIException e) + { + logger.error("AGIException while handling request: " + e.getMessage()); + } finally { try Index: AbstractAGIScript.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi/AbstractAGIScript.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -p -r1.1 -r1.2 --- AbstractAGIScript.java 10 Mar 2005 23:57:06 -0000 1.1 +++ AbstractAGIScript.java 11 Mar 2005 00:23:25 -0000 1.2 @@ -34,9 +34,13 @@ public abstract class AbstractAGIScript * Answers the channel. * * @param channel the channel as received by the service method. - * @throws IOException if the command can't be sent to Asterisk. + * + * @throws AGIException if the command can't be sent to Asterisk because the + * channel was hung up. + * @throws IOException if the command can't be sent to Asterisk due to + * network problems. */ - protected void answer(AGIChannel channel) throws IOException + protected void answer(AGIChannel channel) throws AGIException, IOException { channel.sendCommand(new AnswerCommand()); } @@ -45,9 +49,13 @@ public abstract class AbstractAGIScript * Hangs the channel up. * * @param channel the channel as received by the service method. - * @throws IOException if the command can't be sent to Asterisk. + * + * @throws AGIException if the command can't be sent to Asterisk because the + * channel was already hung up. + * @throws IOException if the command can't be sent to Asterisk due to + * network problems. */ - protected void hangup(AGIChannel channel) throws IOException + protected void hangup(AGIChannel channel) throws AGIException, IOException { channel.sendCommand(new HangupCommand()); } Index: AGIReaderImpl.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi/AGIReaderImpl.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -p -r1.2 -r1.3 --- AGIReaderImpl.java 10 Mar 2005 13:45:23 -0000 1.2 +++ AGIReaderImpl.java 11 Mar 2005 00:23:25 -0000 1.3 @@ -65,7 +65,7 @@ public class AGIReaderImpl implements AG return request; } - public AGIReply readReply() throws IOException + public AGIReply readReply() throws IOException, AGIHangupException { AGIReply reply; List lines; @@ -74,6 +74,12 @@ public class AGIReaderImpl implements AG lines = new ArrayList(); line = socket.readLine(); + + if (line == null) + { + throw new AGIHangupException(); + } + lines.add(line); // read synopsis and usage if statuscode is 520 Index: AGIChannel.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi/AGIChannel.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -p -r1.1 -r1.2 --- AGIChannel.java 10 Mar 2005 23:57:06 -0000 1.1 +++ AGIChannel.java 11 Mar 2005 00:23:25 -0000 1.2 @@ -38,7 +38,9 @@ public interface AGIChannel * @param command the command to send. * @return the reply of the asterisk server containing the return value. * - * @throws IOException if there is a problem sending the command. + * @throws AGIException if the command can't be sent (for example because + * the channel has been hung up) + * @throws IOException if there is a network problem sending the command. */ - AGIReply sendCommand(AGICommand command) throws IOException; + AGIReply sendCommand(AGICommand command) throws AGIException, IOException; } Index: AGIScript.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi/AGIScript.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -p -r1.4 -r1.5 --- AGIScript.java 10 Mar 2005 23:57:06 -0000 1.4 +++ AGIScript.java 11 Mar 2005 00:23:25 -0000 1.5 @@ -36,10 +36,13 @@ public interface AGIScript * AGIScript should handle an incoming AGIRequest. * * @param request the initial data received from Asterisk when requesting - * this script. + * this script. * @param channel a handle to communicate with Asterisk such as sending - * commands to the channel sending the request. - * @throws IOException if there is a problem with the network connection. + * commands to the channel sending the request. + * + * @throws AGIException any exception thrown by your script will be logged. + * @throws IOException any exception thrown by your script will be logged. */ - void service(final AGIRequest request, final AGIChannel channel) throws IOException; + void service(final AGIRequest request, final AGIChannel channel) + throws AGIException, IOException; } |