From 8ba504b32eb66aa08bdd8d51ad9b799ede2ecdfb Mon Sep 17 00:00:00 2001 From: Keith Wall Date: Wed, 8 Aug 2012 22:07:10 +0000 Subject: QPID-4162: Change Java Client/Java Broker to send a session.detached in response to receiving unexpected control on detached transport, as required by AMQP 0-10 spec. The previous behaviour (throwing a ProtocolViolationException) was causing sporadic test failures on a number of CI instances for both Java and Python tests. git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@1370991 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/org/apache/qpid/transport/Connection.java | 26 ++++++++++++---- .../qpid/transport/ProtocolViolationException.java | 35 ---------------------- 2 files changed, 21 insertions(+), 40 deletions(-) delete mode 100644 java/common/src/main/java/org/apache/qpid/transport/ProtocolViolationException.java (limited to 'java/common') diff --git a/java/common/src/main/java/org/apache/qpid/transport/Connection.java b/java/common/src/main/java/org/apache/qpid/transport/Connection.java index 388e3442bf..e87851cf7d 100644 --- a/java/common/src/main/java/org/apache/qpid/transport/Connection.java +++ b/java/common/src/main/java/org/apache/qpid/transport/Connection.java @@ -382,7 +382,7 @@ public class Connection extends ConnectionInvoker { log.debug("SEND: [%s] %s", this, event); } - Sender s = sender; + Sender s = sender; if (s == null) { throw new ConnectionException("connection closed"); @@ -415,15 +415,23 @@ public class Connection extends ConnectionInvoker public void dispatch(Method method) { - Session ssn = getSession(method.getChannel()); + int channel = method.getChannel(); + Session ssn = getSession(channel); if(ssn != null) { ssn.received(method); } else { - throw new ProtocolViolationException( - "Received frames for an already detached session", null); + /* + * A peer receiving any other control on a detached transport MUST discard it and + * send a session.detached with the "not-attached" reason code. + */ + if(log.isDebugEnabled()) + { + log.debug("Control received on unattached channel : %d", channel); + } + invokeSessionDetached(channel, SessionDetachCode.NOT_ATTACHED); } } @@ -663,7 +671,7 @@ public class Connection extends ConnectionInvoker public void setServerProperties(final Map serverProperties) { - _serverProperties = serverProperties == null ? Collections.EMPTY_MAP : serverProperties; + _serverProperties = serverProperties == null ? Collections.emptyMap() : serverProperties; } public Map getServerProperties() @@ -719,4 +727,12 @@ public class Connection extends ConnectionInvoker { return _localAddress; } + + private void invokeSessionDetached(int channel, SessionDetachCode sessionDetachCode) + { + SessionDetached sessionDetached = new SessionDetached(); + sessionDetached.setChannel(channel); + sessionDetached.setCode(sessionDetachCode); + invoke(sessionDetached); + } } diff --git a/java/common/src/main/java/org/apache/qpid/transport/ProtocolViolationException.java b/java/common/src/main/java/org/apache/qpid/transport/ProtocolViolationException.java deleted file mode 100644 index 6787157e8e..0000000000 --- a/java/common/src/main/java/org/apache/qpid/transport/ProtocolViolationException.java +++ /dev/null @@ -1,35 +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.qpid.transport; - - -/** - * ProtocolViolationException - * - */ - -public final class ProtocolViolationException extends ConnectionException -{ - public ProtocolViolationException(String msg,Throwable cause) - { - super(msg, cause); - } -} -- cgit v1.2.1