From 188748bd3e3fba0e16d3d3d4bc7b1de72e285d09 Mon Sep 17 00:00:00 2001 From: "Rafael H. Schloming" Date: Tue, 29 Jul 2008 02:07:20 +0000 Subject: QPID-1201: fixed up version of aidan's patch, there are still failures when running against an external java broker, however we seem to get past basic connection negotiation now git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@680602 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/org/apache/qpidity/ProtocolException.java | 36 --------------- .../main/java/org/apache/qpidity/ToyClient.java | 4 +- .../apache/qpidity/transport/ClientDelegate.java | 5 +-- .../qpidity/transport/ConnectionDelegate.java | 32 +++---------- .../transport/ProtocolVersionException.java | 52 ++++++++++++++++++++++ .../qpidity/transport/TransportConstants.java | 29 ------------ 6 files changed, 61 insertions(+), 97 deletions(-) delete mode 100644 java/common/src/main/java/org/apache/qpidity/ProtocolException.java create mode 100644 java/common/src/main/java/org/apache/qpidity/transport/ProtocolVersionException.java delete mode 100644 java/common/src/main/java/org/apache/qpidity/transport/TransportConstants.java (limited to 'java/common/src') diff --git a/java/common/src/main/java/org/apache/qpidity/ProtocolException.java b/java/common/src/main/java/org/apache/qpidity/ProtocolException.java deleted file mode 100644 index 596143a1b9..0000000000 --- a/java/common/src/main/java/org/apache/qpidity/ProtocolException.java +++ /dev/null @@ -1,36 +0,0 @@ -/* Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you 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 org.apache.qpidity; - -public class ProtocolException extends QpidException -{ - /** - * Constructor for a Ptotocol Exception. - *

This is the only provided constructor and the parameters have to be set to null when - * they are unknown. - * @param message A description of the reason of this exception. - * @param errorCode A string specifyin the error code of this exception. - * @param cause The linked Execption. - * - */ - public ProtocolException(String message, ErrorCode errorCode, Throwable cause) - { - super(message, errorCode, cause); - } -} diff --git a/java/common/src/main/java/org/apache/qpidity/ToyClient.java b/java/common/src/main/java/org/apache/qpidity/ToyClient.java index f6d2829504..0912f3bdd9 100644 --- a/java/common/src/main/java/org/apache/qpidity/ToyClient.java +++ b/java/common/src/main/java/org/apache/qpidity/ToyClient.java @@ -76,9 +76,7 @@ class ToyClient extends SessionDelegate public void closed() {} }); conn.send(new ProtocolHeader - (1, - TransportConstants.getVersionMajor(), - TransportConstants.getVersionMinor())); + (1, 0, 10)); Channel ch = conn.getChannel(0); Session ssn = new Session("my-session".getBytes()); diff --git a/java/common/src/main/java/org/apache/qpidity/transport/ClientDelegate.java b/java/common/src/main/java/org/apache/qpidity/transport/ClientDelegate.java index 699854fb3b..e770157af4 100644 --- a/java/common/src/main/java/org/apache/qpidity/transport/ClientDelegate.java +++ b/java/common/src/main/java/org/apache/qpidity/transport/ClientDelegate.java @@ -31,10 +31,9 @@ public abstract class ClientDelegate extends ConnectionDelegate public void init(Channel ch, ProtocolHeader hdr) { - if (hdr.getMajor() != TransportConstants.getVersionMajor() && - hdr.getMinor() != TransportConstants.getVersionMinor()) + if (hdr.getMajor() != 0 && hdr.getMinor() != 10) { - throw new RuntimeException("version missmatch: " + hdr); + throw new ProtocolVersionException(hdr.getMajor(), hdr.getMinor()); } } diff --git a/java/common/src/main/java/org/apache/qpidity/transport/ConnectionDelegate.java b/java/common/src/main/java/org/apache/qpidity/transport/ConnectionDelegate.java index 962dd9a5da..14bde3f18d 100644 --- a/java/common/src/main/java/org/apache/qpidity/transport/ConnectionDelegate.java +++ b/java/common/src/main/java/org/apache/qpidity/transport/ConnectionDelegate.java @@ -82,28 +82,12 @@ public abstract class ConnectionDelegate extends MethodDelegate public void init(Channel ch, ProtocolHeader hdr) { - ch.getConnection().send(new ProtocolHeader - (1, - TransportConstants.getVersionMajor(), - TransportConstants.getVersionMinor())); - if (hdr.getMajor() != TransportConstants.getVersionMajor() && - hdr.getMinor() != TransportConstants.getVersionMinor()) - { - // XXX - ch.getConnection().send(new ProtocolHeader - (1, - TransportConstants.getVersionMajor(), - TransportConstants.getVersionMinor())); - ch.getConnection().close(); - } - else - { - List plain = new ArrayList(); - plain.add("PLAIN"); - List utf8 = new ArrayList(); - utf8.add("utf8"); - ch.connectionStart(null, plain, utf8); - } + ch.getConnection().send(new ProtocolHeader (1, hdr.getMajor(), hdr.getMinor())); + List plain = new ArrayList(); + plain.add("PLAIN"); + List utf8 = new ArrayList(); + utf8.add("utf8"); + ch.connectionStart(null, plain, utf8); } // ---------------------------------------------- @@ -294,8 +278,4 @@ public abstract class ConnectionDelegate extends MethodDelegate _virtualHost = host; } - public String getUnsupportedProtocol() - { - return null; - } } diff --git a/java/common/src/main/java/org/apache/qpidity/transport/ProtocolVersionException.java b/java/common/src/main/java/org/apache/qpidity/transport/ProtocolVersionException.java new file mode 100644 index 0000000000..86fe7a3f3f --- /dev/null +++ b/java/common/src/main/java/org/apache/qpidity/transport/ProtocolVersionException.java @@ -0,0 +1,52 @@ +/* + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.apache.qpidity.transport; + + +/** + * ProtocolVersionException + * + */ + +public final class ProtocolVersionException extends TransportException +{ + + private final byte major; + private final byte minor; + + public ProtocolVersionException(byte major, byte minor) + { + super(String.format("version missmatch: %s-%s", major, minor)); + this.major = major; + this.minor = minor; + } + + public byte getMajor() + { + return this.major; + } + + public byte getMinor() + { + return this.minor; + } + +} diff --git a/java/common/src/main/java/org/apache/qpidity/transport/TransportConstants.java b/java/common/src/main/java/org/apache/qpidity/transport/TransportConstants.java deleted file mode 100644 index e9a0705de0..0000000000 --- a/java/common/src/main/java/org/apache/qpidity/transport/TransportConstants.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.apache.qpidity.transport; - -public class TransportConstants -{ - - private static byte _protocol_version_minor = 10; - private static byte _protocol_version_major = 0; - - public static void setVersionMajor(byte value) - { - _protocol_version_major = value; - } - - public static void setVersionMinor(byte value) - { - _protocol_version_minor = value; - } - - public static byte getVersionMajor() - { - return _protocol_version_major; - } - - public static byte getVersionMinor() - { - return _protocol_version_minor; - } - -} -- cgit v1.2.1