Skip to content

Commit e37cbd5

Browse files
author
Tim Watson
committed
Merge bug25911 into default
2 parents 45ae533 + 3b02ba3 commit e37cbd5

File tree

8 files changed

+116
-71
lines changed

8 files changed

+116
-71
lines changed

projects/client/RabbitMQ.Client/src/client/api/SslHelper.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,15 @@ private bool CertificateValidationCallback(object sender,
9090
public static Stream TcpUpgrade(Stream tcpStream, SslOption sslOption, int timeout)
9191
{
9292
SslHelper helper = new SslHelper(sslOption);
93+
94+
RemoteCertificateValidationCallback remoteCertValidator =
95+
sslOption.CertificateValidationCallback ?? new RemoteCertificateValidationCallback(helper.CertificateValidationCallback);
96+
LocalCertificateSelectionCallback localCertSelector =
97+
sslOption.CertificateSelectionCallback ?? new LocalCertificateSelectionCallback(helper.CertificateSelectionCallback);
98+
9399
SslStream sslStream = new SslStream(tcpStream, false,
94-
new RemoteCertificateValidationCallback(helper.CertificateValidationCallback),
95-
new LocalCertificateSelectionCallback(helper.CertificateSelectionCallback));
100+
remoteCertValidator,
101+
localCertSelector);
96102

97103
sslStream.AuthenticateAsClient(sslOption.ServerName,
98104
sslOption.Certs,

projects/client/RabbitMQ.Client/src/client/api/SslOption.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,18 @@ public SslPolicyErrors AcceptablePolicyErrors
136136
set { m_acceptablePolicyErrors = value; }
137137
}
138138

139+
/// <summary>
140+
/// An optional client specified SSL certificate validation callback. If this is not specified,
141+
/// the default callback will be used in conjunction with the AcceptablePolicyErrors property to
142+
/// determine if the remote server certificate is valid.
143+
/// </summary>
144+
public RemoteCertificateValidationCallback CertificateValidationCallback { get; set; }
145+
146+
/// <summary>
147+
/// An optional client specified SSL certificate selection callback. If this is not specified,
148+
/// the first valid certificate found will be used.
149+
/// </summary>
150+
public LocalCertificateSelectionCallback CertificateSelectionCallback { get; set; }
139151

140152
///<summary>Construct an SslOption specifying both the server cannonical name
141153
///and the client's certificate path.
@@ -145,6 +157,8 @@ public SslOption(string serverName, string certPath, bool enabled)
145157
m_serverName= serverName;
146158
m_certPath = certPath;
147159
m_enabled = enabled;
160+
CertificateValidationCallback = null;
161+
CertificateSelectionCallback = null;
148162
}
149163

150164
///<summary>Construct an SslOption with just the server cannonical name.

projects/client/RabbitMQ.Client/src/client/exceptions/AlreadyClosedException.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,6 @@ public class AlreadyClosedException: OperationInterruptedException
4949
///<summary>Construct an instance containing the given
5050
///shutdown reason.</summary>
5151
public AlreadyClosedException(ShutdownEventArgs reason)
52-
: base(reason) { }
52+
: base(reason, "Already closed") { }
5353
}
5454
}

projects/client/RabbitMQ.Client/src/client/exceptions/OperationInterruptedException.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,16 @@ public OperationInterruptedException(ShutdownEventArgs reason)
8181
m_shutdownReason = reason;
8282
}
8383

84+
///<summary>Construct an OperationInterruptedException with
85+
///the passed-in explanation and prefix, if any.</summary>
86+
public OperationInterruptedException(ShutdownEventArgs reason, String prefix)
87+
: base(reason == null ? (prefix + ": The AMQP operation was interrupted") :
88+
string.Format("{0}: The AMQP operation was interrupted: {1}",
89+
prefix, reason))
90+
{
91+
m_shutdownReason = reason;
92+
}
93+
8494
///<summary>Retrieves the explanation for the shutdown. May
8595
///return null if no explanation is available.</summary>
8696
public ShutdownEventArgs ShutdownReason { get { return m_shutdownReason; } }

projects/client/RabbitMQ.Client/src/client/impl/ConnectionBase.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,9 +1055,7 @@ protected void StartAndTune()
10551055
connectionStartCell.Value;
10561056

10571057
if (connectionStart == null){
1058-
throw new ProtocolVersionMismatchException(Protocol.MajorVersion,
1059-
Protocol.MinorVersion,
1060-
-1, -1);
1058+
throw new IOException("connection.start was never received, likely due to a network timeout");
10611059
}
10621060

10631061
ServerProperties = connectionStart.m_serverProperties;

projects/client/RabbitMQ.Client/src/client/impl/ModelBase.cs

Lines changed: 7 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -494,16 +494,7 @@ public void Enqueue(IRpcContinuation k)
494494
public void TransmitAndEnqueue(Command cmd, IRpcContinuation k)
495495
{
496496
Enqueue(k);
497-
try
498-
{
499-
m_session.Transmit(cmd);
500-
}
501-
catch (AlreadyClosedException)
502-
{
503-
// Ignored, since the continuation will be told about
504-
// the closure via an OperationInterruptedException because
505-
// of the shutdown event propagation.
506-
}
497+
m_session.Transmit(cmd);
507498
}
508499

509500
public ShutdownEventArgs CloseReason
@@ -903,16 +894,7 @@ private QueueDeclareOk QueueDeclare(string queue, bool passive, bool durable, bo
903894
{
904895
QueueDeclareRpcContinuation k = new QueueDeclareRpcContinuation();
905896
Enqueue(k);
906-
try
907-
{
908-
_Private_QueueDeclare(queue, passive, durable, exclusive, autoDelete, false, arguments);
909-
}
910-
catch (AlreadyClosedException)
911-
{
912-
// Ignored, since the continuation will be told about
913-
// the closure via an OperationInterruptedException because
914-
// of the shutdown event propagation.
915-
}
897+
_Private_QueueDeclare(queue, passive, durable, exclusive, autoDelete, false, arguments);
916898
k.GetReply();
917899
return k.m_result;
918900
}
@@ -997,7 +979,7 @@ public bool WaitForConfirms(TimeSpan timeout, out bool timedOut)
997979
{
998980
while (true)
999981
{
1000-
if (CloseReason != null)
982+
if (!IsOpen)
1001983
throw new AlreadyClosedException(CloseReason);
1002984

1003985
if (m_unconfirmedSet.Count == 0)
@@ -1104,17 +1086,8 @@ public string BasicConsume(string queue,
11041086
Enqueue(k);
11051087
// Non-nowait. We have an unconventional means of getting
11061088
// the RPC response, but a response is still expected.
1107-
try
1108-
{
1109-
_Private_BasicConsume(queue, consumerTag, noLocal, noAck, exclusive,
1089+
_Private_BasicConsume(queue, consumerTag, noLocal, noAck, exclusive,
11101090
/*nowait:*/ false, arguments);
1111-
}
1112-
catch (AlreadyClosedException)
1113-
{
1114-
// Ignored, since the continuation will be told about
1115-
// the closure via an OperationInterruptedException because
1116-
// of the shutdown event propagation.
1117-
}
11181091
k.GetReply();
11191092
string actualConsumerTag = k.m_consumerTag;
11201093

@@ -1150,17 +1123,7 @@ public void BasicCancel(string consumerTag)
11501123

11511124
Enqueue(k);
11521125

1153-
try
1154-
{
1155-
_Private_BasicCancel(consumerTag, false);
1156-
}
1157-
catch (AlreadyClosedException)
1158-
{
1159-
// Ignored, since the continuation will be told about
1160-
// the closure via an OperationInterruptedException because
1161-
// of the shutdown event propagation.
1162-
}
1163-
1126+
_Private_BasicCancel(consumerTag, false);
11641127
k.GetReply();
11651128

11661129
ModelShutdown -= new ModelShutdownEventHandler(k.m_consumer.HandleModelShutdown);
@@ -1206,16 +1169,7 @@ public BasicGetResult BasicGet(string queue,
12061169
{
12071170
BasicGetRpcContinuation k = new BasicGetRpcContinuation();
12081171
Enqueue(k);
1209-
try
1210-
{
1211-
_Private_BasicGet(queue, noAck);
1212-
}
1213-
catch (AlreadyClosedException)
1214-
{
1215-
// Ignored, since the continuation will be told about
1216-
// the closure via an OperationInterruptedException because
1217-
// of the shutdown event propagation.
1218-
}
1172+
_Private_BasicGet(queue, noAck);
12191173
k.GetReply();
12201174
return k.m_result;
12211175
}
@@ -1227,18 +1181,7 @@ public void BasicRecover(bool requeue)
12271181
SimpleBlockingRpcContinuation k = new SimpleBlockingRpcContinuation();
12281182

12291183
Enqueue(k);
1230-
1231-
try
1232-
{
1233-
_Private_BasicRecover(requeue);
1234-
}
1235-
catch (AlreadyClosedException)
1236-
{
1237-
// Ignored, since the continuation will be told about
1238-
// the closure via an OperationInterruptedException because
1239-
// of the shutdown event propagation.
1240-
}
1241-
1184+
_Private_BasicRecover(requeue);
12421185
k.GetReply();
12431186
}
12441187

projects/client/Unit/src/unit/TestConnectionBlocked.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public static bool IsRunningOnMono()
162162
protected void Publish(IConnection conn)
163163
{
164164
IModel ch = conn.CreateModel();
165-
ch.BasicPublish("", "amq.fanout", null, enc.GetBytes("message"));
165+
ch.BasicPublish("amq.fanout", "", null, enc.GetBytes("message"));
166166
}
167167

168168
protected override void ReleaseResources()
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// This source code is dual-licensed under the Apache License, version
2+
// 2.0, and the Mozilla Public License, version 1.1.
3+
//
4+
// The APL v2.0:
5+
//
6+
//---------------------------------------------------------------------------
7+
// Copyright (C) 2007-2013 GoPivotal, Inc.
8+
//
9+
// Licensed under the Apache License, Version 2.0 (the "License");
10+
// you may not use this file except in compliance with the License.
11+
// You may obtain a copy of the License at
12+
//
13+
// http://www.apache.org/licenses/LICENSE-2.0
14+
//
15+
// Unless required by applicable law or agreed to in writing, software
16+
// distributed under the License is distributed on an "AS IS" BASIS,
17+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
// See the License for the specific language governing permissions and
19+
// limitations under the License.
20+
//---------------------------------------------------------------------------
21+
//
22+
// The MPL v1.1:
23+
//
24+
//---------------------------------------------------------------------------
25+
// The contents of this file are subject to the Mozilla Public License
26+
// Version 1.1 (the "License"); you may not use this file except in
27+
// compliance with the License. You may obtain a copy of the License
28+
// at http://www.mozilla.org/MPL/
29+
//
30+
// Software distributed under the License is distributed on an "AS IS"
31+
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
32+
// the License for the specific language governing rights and
33+
// limitations under the License.
34+
//
35+
// The Original Code is RabbitMQ.
36+
//
37+
// The Initial Developer of the Original Code is GoPivotal, Inc.
38+
// Copyright (c) 2007-2014 GoPivotal, Inc. All rights reserved.
39+
//---------------------------------------------------------------------------
40+
41+
using NUnit.Framework;
42+
using System;
43+
using RabbitMQ.Client.Exceptions;
44+
45+
namespace RabbitMQ.Client.Unit
46+
{
47+
[TestFixture]
48+
public class TestExceptionMessages : IntegrationFixture
49+
{
50+
[Test]
51+
public void TestAlreadyClosedExceptionMessage()
52+
{
53+
var uuid = System.Guid.NewGuid().ToString();
54+
try
55+
{
56+
Model.QueueDeclarePassive(uuid);
57+
} catch (Exception e)
58+
{
59+
Assert.That(e, Is.TypeOf(typeof(OperationInterruptedException)));
60+
}
61+
62+
Assert.IsFalse(Model.IsOpen);
63+
64+
try
65+
{
66+
Model.QueueDeclarePassive(uuid);
67+
} catch (AlreadyClosedException e)
68+
{
69+
Assert.That(e, Is.TypeOf(typeof(AlreadyClosedException)));
70+
Assert.IsTrue(e.Message.StartsWith("Already closed"));
71+
}
72+
}
73+
}
74+
}

0 commit comments

Comments
 (0)