diff options
author | Rajith Muditha Attapattu <rajith@apache.org> | 2007-08-13 23:05:11 +0000 |
---|---|---|
committer | Rajith Muditha Attapattu <rajith@apache.org> | 2007-08-13 23:05:11 +0000 |
commit | 6840763b78d2bc42581b5ecd3536f6195e852a2d (patch) | |
tree | d4a6d44d88c2396c117c8e64e9e6c6cc00a3213d | |
parent | b9a3aaab3504ec3cc832f1ee4d0c2266372116f5 (diff) | |
download | qpid-python-6840763b78d2bc42581b5ecd3536f6195e852a2d.tar.gz |
added error code support
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@565561 13f79535-47bb-0310-9956-ffa450edef68
10 files changed, 138 insertions, 31 deletions
diff --git a/java/client/src/main/java/org/apache/qpidity/client/Client.java b/java/client/src/main/java/org/apache/qpidity/client/Client.java index 8465475282..b440561b66 100644 --- a/java/client/src/main/java/org/apache/qpidity/client/Client.java +++ b/java/client/src/main/java/org/apache/qpidity/client/Client.java @@ -10,6 +10,7 @@ import org.apache.qpidity.Channel; import org.apache.qpidity.Connection; import org.apache.qpidity.ConnectionClose; import org.apache.qpidity.ConnectionDelegate; +import org.apache.qpidity.ErrorCode; import org.apache.qpidity.MinaHandler; import org.apache.qpidity.QpidException; import org.apache.qpidity.SessionDelegate; @@ -39,9 +40,13 @@ public class Client implements org.apache.qpidity.client.Connection return new ClientSessionDelegate(); } - @Override public void connectionClose(Channel context, ConnectionClose struct) + @Override public void connectionClose(Channel context, ConnectionClose connectionClose) { - _exceptionListner.onException(new QpidException("Server closed the connection: Reason " + struct.getReplyText(),struct.getReplyCode(),null)); + _exceptionListner.onException( + new QpidException("Server closed the connection: Reason " + + connectionClose.getReplyText(), + ErrorCode.get(connectionClose.getReplyCode()), + null)); } }; diff --git a/java/client/src/main/java/org/apache/qpidity/client/ClientSession.java b/java/client/src/main/java/org/apache/qpidity/client/ClientSession.java index b5d8add9e2..13f3eeb1b6 100644 --- a/java/client/src/main/java/org/apache/qpidity/client/ClientSession.java +++ b/java/client/src/main/java/org/apache/qpidity/client/ClientSession.java @@ -3,6 +3,7 @@ package org.apache.qpidity.client; import java.io.EOFException; import java.io.IOException; import java.util.HashMap; +import java.util.LinkedList; import java.util.List; import java.util.Map; @@ -21,11 +22,9 @@ public class ClientSession extends org.apache.qpidity.Session implements org.apa private ExceptionListener _exceptionListner; private RangeSet _acquiredMessages; private RangeSet _rejectedMessages; - private Map<String,List<RangeSet>> _unackedMessages = new HashMap<String,List<RangeSet>>(); @Override public void sessionClose() { - // release all unacked messages and then issues a close super.sessionClose(); } diff --git a/java/client/src/main/java/org/apache/qpidity/client/ClientSessionDelegate.java b/java/client/src/main/java/org/apache/qpidity/client/ClientSessionDelegate.java index 975dcb6d8b..cd7b66111d 100644 --- a/java/client/src/main/java/org/apache/qpidity/client/ClientSessionDelegate.java +++ b/java/client/src/main/java/org/apache/qpidity/client/ClientSessionDelegate.java @@ -2,6 +2,7 @@ package org.apache.qpidity.client; import java.nio.ByteBuffer; +import org.apache.qpidity.ErrorCode; import org.apache.qpidity.Frame; import org.apache.qpidity.MessageAcquired; import org.apache.qpidity.MessageReject; @@ -10,6 +11,7 @@ import org.apache.qpidity.QpidException; import org.apache.qpidity.Range; import org.apache.qpidity.RangeSet; import org.apache.qpidity.Session; +import org.apache.qpidity.SessionClosed; import org.apache.qpidity.SessionDelegate; import org.apache.qpidity.Struct; @@ -19,6 +21,14 @@ public class ClientSessionDelegate extends SessionDelegate private MessageTransfer _currentTransfer; private MessagePartListener _currentMessageListener; + @Override public void sessionClosed(Session ssn,SessionClosed sessionClosed) + { + ((ClientSession)ssn).notifyException(new QpidException(sessionClosed.getReplyText(),ErrorCode.get(sessionClosed.getReplyCode()),null)); + } + + // -------------------------------------------- + // Message methods + // -------------------------------------------- @Override public void data(Session ssn, Frame frame) { for (ByteBuffer b : frame) @@ -52,10 +62,6 @@ public class ClientSessionDelegate extends SessionDelegate } } - // -------------------------------------------- - // Message methods - // -------------------------------------------- - @Override public void messageReject(Session session, MessageReject struct) { @@ -68,7 +74,7 @@ public class ClientSessionDelegate extends SessionDelegate } } ((ClientSession)session).setRejectedMessages(struct.getTransfers()); - ((ClientSession)session).notifyException(new QpidException("Message Rejected",0,null)); + ((ClientSession)session).notifyException(new QpidException("Message Rejected",ErrorCode.MESSAGE_REJECTED,null)); } @Override public void messageAcquired(Session session, MessageAcquired struct) diff --git a/java/client/src/main/java/org/apache/qpidity/jms/message/MessageImpl.java b/java/client/src/main/java/org/apache/qpidity/jms/message/MessageImpl.java index 1d1ee0582d..0285e60908 100644 --- a/java/client/src/main/java/org/apache/qpidity/jms/message/MessageImpl.java +++ b/java/client/src/main/java/org/apache/qpidity/jms/message/MessageImpl.java @@ -864,7 +864,7 @@ public class MessageImpl extends QpidMessage implements Message { if (_destination == null) { - throw new QpidException("Invalid destination null", null, null); + throw new QpidException("Invalid destination null",null, null); } } diff --git a/java/client/src/main/java/org/apache/qpidity/jms/message/QpidMessage.java b/java/client/src/main/java/org/apache/qpidity/jms/message/QpidMessage.java index 601fd4e0ab..1ddc567e54 100644 --- a/java/client/src/main/java/org/apache/qpidity/jms/message/QpidMessage.java +++ b/java/client/src/main/java/org/apache/qpidity/jms/message/QpidMessage.java @@ -20,15 +20,15 @@ */ package org.apache.qpidity.jms.message; -import org.apache.qpidity.ReplyTo; -import org.apache.qpidity.QpidException; - -import javax.jms.Message; -import java.util.Map; +import java.nio.ByteBuffer; import java.util.Enumeration; -import java.util.Vector; import java.util.HashMap; -import java.nio.ByteBuffer; +import java.util.Map; +import java.util.Vector; + +import org.apache.qpidity.ErrorCode; +import org.apache.qpidity.QpidException; +import org.apache.qpidity.ReplyTo; public class QpidMessage @@ -170,7 +170,7 @@ public class QpidMessage { throw new QpidException( "Problem when setting message delivery mode, " + deliveryMode + " is not a valid mode", - "wrong delivery mode", null); + ErrorCode.UNDEFINED, null); } _qpidityMessage.getDeliveryProperties().setDeliveryMode(deliveryMode); } diff --git a/java/common/src/main/grammar/SelectorParser.jj b/java/common/src/main/grammar/SelectorParser.jj index 3eac164a6d..2dca11748e 100644 --- a/java/common/src/main/grammar/SelectorParser.jj +++ b/java/common/src/main/grammar/SelectorParser.jj @@ -94,7 +94,7 @@ public class SelectorParser { return this.JmsSelector();
}
catch (Throwable e) {
- throw new QpidException(sql,"filter error",e);
+ throw new QpidException(sql,null,e);
}
}
diff --git a/java/common/src/main/java/org/apache/qpidity/ErrorCode.java b/java/common/src/main/java/org/apache/qpidity/ErrorCode.java new file mode 100644 index 0000000000..75f9f00622 --- /dev/null +++ b/java/common/src/main/java/org/apache/qpidity/ErrorCode.java @@ -0,0 +1,101 @@ +package org.apache.qpidity; + +public enum ErrorCode +{ + //Qpid specific - for the time being + UNDEFINED(1,"undefined",true), + MESSAGE_REJECTED(1,"message_rejected",true), + + //This might change in the spec, the error class is not applicable + NO_ERROR(200,"reply-success",true), + + //From the spec + CONTENT_TOO_LARGE(311,"content-too-large",false), + NO_ROUTE(312,"no-route",false), + NO_CONSUMERS(313,"content-consumers",false), + CONNECTION_FORCED(320,"connection-forced",true), + INVALID_PATH(402,"invalid-path",true), + ACCESS_REFUSED(403,"access-refused",false), + NOT_FOUND(404,"not-found",false), + RESOURCE_LOCKED(405,"resource-locked",false), + PRE_CONDITION_FAILED(406,"precondition-failed",false), + + FRAME_ERROR(501,"frame_error",true), + SYNTAX_ERROR(502,"syntax_error",true), + COMMAND_INVALID(503,"command_invalid",true), + SESSION_ERROR(504,"sesion_error",true), + NOT_ALLOWED(530,"not_allowed",true), + NOT_IMPLEMENTED(540,"not_implemented",true), + INTERNAL_ERROR(541,"internal_error",true), + INVALID_ARGUMENT(542,"invalid_argument",true); + + private int _code; + private String _desc; + private boolean _hardError; + + private ErrorCode(int code,String desc,boolean hardError) + { + _code = code; + _desc= desc; + _hardError = hardError; + } + + public int getCode() + { + return _code; + } + + public String getDesc() + { + return _desc; + } + + private boolean isHardError() + { + return _hardError; + } + + public static ErrorCode get(int code) + { + switch(code) + { + case 200 : return NO_ERROR; + case 311 : return CONTENT_TOO_LARGE; + case 312 : return NO_ROUTE; + case 313 : return NO_CONSUMERS; + case 320 : return CONNECTION_FORCED; + case 402 : return INVALID_PATH; + case 403 : return ACCESS_REFUSED; + case 404 : return NOT_FOUND; + case 405 : return RESOURCE_LOCKED; + case 406 : return PRE_CONDITION_FAILED; + case 501 : return FRAME_ERROR; + case 502 : return SYNTAX_ERROR; + case 503 : return COMMAND_INVALID; + case 504 : return SESSION_ERROR; + case 530 : return NOT_ALLOWED; + case 540 : return NOT_IMPLEMENTED; + case 541 : return INTERNAL_ERROR; + case 542 : return INVALID_ARGUMENT; + + default : return UNDEFINED; + } + } + +} + +/* + +<constant name="internal-error" value="541" class="hard-error"> +<doc> + The server could not complete the method because of an internal error. The server may require + intervention by an operator in order to resume normal operations. +</doc> +</constant> + +<constant name="invalid-argument" value="542" class="hard-error"> +<doc> + An invalid or illegal argument was passed to a method, and the operation could not proceed. +</doc> +</constant> +*/
\ No newline at end of file diff --git a/java/common/src/main/java/org/apache/qpidity/QpidException.java b/java/common/src/main/java/org/apache/qpidity/QpidException.java index 5b3671cebd..81e9145282 100644 --- a/java/common/src/main/java/org/apache/qpidity/QpidException.java +++ b/java/common/src/main/java/org/apache/qpidity/QpidException.java @@ -17,17 +17,12 @@ */ package org.apache.qpidity; -/** - * Created by Arnaud Simon - * Date: 20-Jul-2007 - * Time: 10:56:55 - */ public class QpidException extends Exception { /** * AMQP error code */ - private int _errorCode; + private ErrorCode _errorCode; /** * Constructor for a Qpid Exception. @@ -38,24 +33,24 @@ public class QpidException extends Exception * @param cause The linked Execption. * * */ - public QpidException(String message, int errorCode, Throwable cause) + public QpidException(String message, ErrorCode errorCode, Throwable cause) { super(message, cause); _errorCode = errorCode; } - //hack to get rid of a compile error from a generated class + /*hack to get rid of a compile error from a generated class public QpidException(String message, String errorCode, Throwable cause) { - } + }*/ /** * Get this execption error code. * * @return This exception error code. */ - public int getErrorCode() + public ErrorCode getErrorCode() { return _errorCode; } diff --git a/java/common/src/main/java/org/apache/qpidity/SecurityHelper.java b/java/common/src/main/java/org/apache/qpidity/SecurityHelper.java index 474e2f7e8f..d0b3272dec 100644 --- a/java/common/src/main/java/org/apache/qpidity/SecurityHelper.java +++ b/java/common/src/main/java/org/apache/qpidity/SecurityHelper.java @@ -64,7 +64,7 @@ public class SecurityHelper } catch (Exception e) { - throw new QpidException("Unable to create callback handler: " + e,0, e.getCause()); + throw new QpidException("Unable to create callback handler: " + e,ErrorCode.UNDEFINED, e.getCause()); } } diff --git a/java/common/src/main/java/org/apache/qpidity/filter/PropertyExpression.java b/java/common/src/main/java/org/apache/qpidity/filter/PropertyExpression.java index ac3888d5bb..d52dfacfa3 100644 --- a/java/common/src/main/java/org/apache/qpidity/filter/PropertyExpression.java +++ b/java/common/src/main/java/org/apache/qpidity/filter/PropertyExpression.java @@ -18,6 +18,7 @@ package org.apache.qpidity.filter; import org.slf4j.LoggerFactory; +import org.apache.qpidity.ErrorCode; import org.apache.qpidity.QpidException; import javax.jms.Message; @@ -56,7 +57,7 @@ public class PropertyExpression implements Expression } catch (Exception e) { - throw new QpidException("cannot evaluate property ", 0, e); + throw new QpidException("cannot evaluate property ", ErrorCode.UNDEFINED, e); } } return result; |