[Asterisk-java-cvs] CVS: asterisk-java/src/java/net/sf/asterisk/fastagi AGINetworkException.java,NON
Brought to you by:
srt
From: Stefan R. <sr...@us...> - 2005-03-11 09:37:51
|
Update of /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23195/src/java/net/sf/asterisk/fastagi Modified Files: AGIReader.java AGIChannelImpl.java AGIWriter.java AGIConnectionHandler.java AbstractAGIScript.java AGIReaderImpl.java AGIWriterImpl.java AGIException.java AGIChannel.java AGIScript.java Added Files: AGINetworkException.java Log Message: Added AGINetworkException Wrapped IOExceptions in new AGINetworkException --- NEW FILE: AGINetworkException.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 AGINetworkException usally wraps an IOException denoting a network * problem when talking to the Asterisk server. * * @author srt * @version $Id: AGINetworkException.java,v 1.1 2005/03/11 09:37:39 srt Exp $ */ public class AGINetworkException extends AGIException { /** * Serial version identifier. */ private static final long serialVersionUID = 3256445789629723703L; public AGINetworkException(String message, Throwable cause) { super(message, cause); } } Index: AGIReader.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi/AGIReader.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -p -r1.4 -r1.5 --- AGIReader.java 11 Mar 2005 00:23:25 -0000 1.4 +++ AGIReader.java 11 Mar 2005 09:37:37 -0000 1.5 @@ -16,8 +16,6 @@ */ package net.sf.asterisk.fastagi; -import java.io.IOException; - import net.sf.asterisk.fastagi.reply.AGIReply; /** @@ -33,16 +31,15 @@ public interface AGIReader * Reads the initial request data from Asterisk. * * @return the request read. - * @throws IOException if the request can't be read. + * @throws AGIException if the request can't be read. */ - AGIRequest readRequest() throws IOException; + AGIRequest readRequest() throws AGIException; /** * 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. + * @throws AGIException if the reply can't be read. */ - AGIReply readReply() throws AGIHangupException, IOException; + AGIReply readReply() throws AGIException; } Index: AGIChannelImpl.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi/AGIChannelImpl.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -p -r1.2 -r1.3 --- AGIChannelImpl.java 11 Mar 2005 00:23:25 -0000 1.2 +++ AGIChannelImpl.java 11 Mar 2005 09:37:39 -0000 1.3 @@ -16,8 +16,6 @@ */ package net.sf.asterisk.fastagi; -import java.io.IOException; - import net.sf.asterisk.fastagi.command.AGICommand; import net.sf.asterisk.fastagi.reply.AGIReply; import net.sf.asterisk.io.SocketConnectionFacade; @@ -47,7 +45,7 @@ public class AGIChannelImpl implements A this.agiReader = agiReader; } - public synchronized AGIReply sendCommand(AGICommand command) throws AGIException, IOException + public synchronized AGIReply sendCommand(AGICommand command) throws AGIException { AGIReply reply; Index: AGIWriter.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi/AGIWriter.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -p -r1.1 -r1.2 --- AGIWriter.java 9 Mar 2005 23:52:48 -0000 1.1 +++ AGIWriter.java 11 Mar 2005 09:37:39 -0000 1.2 @@ -16,8 +16,6 @@ */ package net.sf.asterisk.fastagi; -import java.io.IOException; - import net.sf.asterisk.fastagi.command.AGICommand; /** @@ -32,7 +30,7 @@ public interface AGIWriter * Sends the given command to the Asterisk server. * * @param command the command to send. - * @throws IOException if the command can't be sent. + * @throws AGIException if the command can't be sent. */ - void sendCommand(AGICommand command) throws IOException; + void sendCommand(AGICommand command) throws AGIException; } Index: AGIConnectionHandler.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi/AGIConnectionHandler.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -p -r1.5 -r1.6 --- AGIConnectionHandler.java 11 Mar 2005 00:23:25 -0000 1.5 +++ AGIConnectionHandler.java 11 Mar 2005 09:37:39 -0000 1.6 @@ -99,14 +99,14 @@ public class AGIConnectionHandler implem + request.getRequestURL()); } } - catch (IOException e) - { - logger.error("IOException while handling request", e); - } catch (AGIException e) { logger.error("AGIException while handling request: " + e.getMessage()); } + catch (Exception e) + { + logger.error("Unexpected Exception while handling request", e); + } finally { try Index: AbstractAGIScript.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi/AbstractAGIScript.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -p -r1.2 -r1.3 --- AbstractAGIScript.java 11 Mar 2005 00:23:25 -0000 1.2 +++ AbstractAGIScript.java 11 Mar 2005 09:37:39 -0000 1.3 @@ -16,8 +16,6 @@ */ package net.sf.asterisk.fastagi; -import java.io.IOException; - import net.sf.asterisk.fastagi.command.AnswerCommand; import net.sf.asterisk.fastagi.command.HangupCommand; @@ -35,12 +33,9 @@ public abstract class AbstractAGIScript * * @param channel the channel as received by the service method. * - * @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. + * @throws AGIException if the command can't be sent to Asterisk. */ - protected void answer(AGIChannel channel) throws AGIException, IOException + protected void answer(AGIChannel channel) throws AGIException { channel.sendCommand(new AnswerCommand()); } @@ -50,12 +45,9 @@ public abstract class AbstractAGIScript * * @param channel the channel as received by the service method. * - * @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. + * @throws AGIException if the command can't be sent to Asterisk. */ - protected void hangup(AGIChannel channel) throws AGIException, IOException + protected void hangup(AGIChannel channel) throws AGIException { 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.3 retrieving revision 1.4 diff -u -d -p -r1.3 -r1.4 --- AGIReaderImpl.java 11 Mar 2005 00:23:25 -0000 1.3 +++ AGIReaderImpl.java 11 Mar 2005 09:37:39 -0000 1.4 @@ -42,30 +42,39 @@ public class AGIReaderImpl implements AG this.requestBuilder = new RequestBuilderImpl(); } - public AGIRequest readRequest() throws IOException + public AGIRequest readRequest() throws AGIException { AGIRequest request; String line; List lines; - + lines = new ArrayList(); - - while ((line = socket.readLine()) != null) + + try { - if (line.length() == 0) + while ((line = socket.readLine()) != null) { - break; + if (line.length() == 0) + { + break; + } + + lines.add(line); } - - lines.add(line); } - + catch (IOException e) + { + throw new AGINetworkException( + "Unable to read request from Asterisk: " + e.getMessage(), + e); + } + request = requestBuilder.buildRequest(lines); - + return request; } - - public AGIReply readReply() throws IOException, AGIHangupException + + public AGIReply readReply() throws AGIException { AGIReply reply; List lines; @@ -73,28 +82,45 @@ public class AGIReaderImpl implements AG lines = new ArrayList(); - line = socket.readLine(); - + try + { + line = socket.readLine(); + } + catch (IOException e) + { + throw new AGINetworkException( + "Unable to read reply from Asterisk: " + e.getMessage(), e); + } + if (line == null) { throw new AGIHangupException(); } - + lines.add(line); // read synopsis and usage if statuscode is 520 if (line.startsWith(Integer .toString(AGIReply.SC_INVALID_COMMAND_SYNTAX))) { - while ((line = socket.readLine()) != null) + try { - lines.add(line); - if (line.startsWith(Integer - .toString(AGIReply.SC_INVALID_COMMAND_SYNTAX))) + while ((line = socket.readLine()) != null) { - break; + 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 = replyBuilder.buildReply(lines); Index: AGIWriterImpl.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi/AGIWriterImpl.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -p -r1.1 -r1.2 --- AGIWriterImpl.java 9 Mar 2005 23:52:48 -0000 1.1 +++ AGIWriterImpl.java 11 Mar 2005 09:37:39 -0000 1.2 @@ -36,9 +36,17 @@ public class AGIWriterImpl implements AG this.socket = socket; } - public void sendCommand(AGICommand command) throws IOException + public void sendCommand(AGICommand command) throws AGIException { - socket.write(command.buildCommand() + "\n"); - socket.flush(); + try + { + socket.write(command.buildCommand() + "\n"); + socket.flush(); + } + catch (IOException e) + { + throw new AGINetworkException( + "Unable to send command to Asterisk: " + e.getMessage(), e); + } } } Index: AGIException.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi/AGIException.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -p -r1.1 -r1.2 --- AGIException.java 11 Mar 2005 00:23:25 -0000 1.1 +++ AGIException.java 11 Mar 2005 09:37:39 -0000 1.2 @@ -42,4 +42,15 @@ public abstract class AGIException exten super(message); } + + /** + * Creates a new AGIExeption with the given message and cause. + * + * @param message a message decribing the AGIException. + * @param cause the throwable that caused this exception to be thrown. + */ + public AGIException(String message, Throwable cause) + { + super(message, cause); + } } Index: AGIChannel.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi/AGIChannel.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -p -r1.2 -r1.3 --- AGIChannel.java 11 Mar 2005 00:23:25 -0000 1.2 +++ AGIChannel.java 11 Mar 2005 09:37:39 -0000 1.3 @@ -16,8 +16,6 @@ */ package net.sf.asterisk.fastagi; -import java.io.IOException; - import net.sf.asterisk.fastagi.command.AGICommand; import net.sf.asterisk.fastagi.reply.AGIReply; @@ -38,9 +36,8 @@ public interface AGIChannel * @param command the command to send. * @return the reply of the asterisk server containing the return value. * - * @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. + * @throws AGIException if the command can't be sent to Asterisk (for + * example because the channel has been hung up) */ - AGIReply sendCommand(AGICommand command) throws AGIException, IOException; + AGIReply sendCommand(AGICommand command) throws AGIException; } Index: AGIScript.java =================================================================== RCS file: /cvsroot/asterisk-java/asterisk-java/src/java/net/sf/asterisk/fastagi/AGIScript.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -p -r1.5 -r1.6 --- AGIScript.java 11 Mar 2005 00:23:25 -0000 1.5 +++ AGIScript.java 11 Mar 2005 09:37:39 -0000 1.6 @@ -16,8 +16,6 @@ */ package net.sf.asterisk.fastagi; -import java.io.IOException; - /** * AGIScripts are used by the AsteriskServer to handle AGIRequests received from * the Asterisk server.<br> @@ -36,13 +34,12 @@ 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. + * 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 AGIException, IOException; + throws AGIException; } |