SPRNET-1021 - Avoid antlr exception thrown for internal flow control when selecting handler method in MessageListenerAdapter
This commit is contained in:
@@ -100,7 +100,6 @@ namespace Spring.Messaging.Nms.Listener.Adapter
|
||||
{
|
||||
InitDefaultStrategies();
|
||||
handlerObject = this;
|
||||
processingExpression = Expression.Parse(defaultHandlerMethod + "(#convertedObject)");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -141,6 +140,7 @@ namespace Spring.Messaging.Nms.Listener.Adapter
|
||||
set
|
||||
{
|
||||
defaultHandlerMethod = value;
|
||||
processingExpression = Expression.Parse(defaultHandlerMethod + "(#convertedObject)");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -286,14 +286,14 @@ namespace Spring.Messaging.Nms.Listener.Adapter
|
||||
// Regular case: find a handler method reflectively.
|
||||
object convertedMessage = ExtractMessage(message);
|
||||
|
||||
|
||||
|
||||
IDictionary vars = new Hashtable();
|
||||
vars["convertedObject"] = convertedMessage;
|
||||
|
||||
//Need to parse each time since have overloaded methods and
|
||||
//expression processor caches target of first invocation.
|
||||
//TODO - check JIRA as I believe this has been fixed, otherwise, use regular reflection. -MLP
|
||||
processingExpression = Expression.Parse(defaultHandlerMethod + "(#convertedObject)");
|
||||
//processingExpression = Expression.Parse(defaultHandlerMethod + "(#convertedObject)");
|
||||
|
||||
//Invoke message handler method and get result.
|
||||
object result;
|
||||
@@ -340,6 +340,7 @@ namespace Spring.Messaging.Nms.Listener.Adapter
|
||||
protected virtual void InitDefaultStrategies()
|
||||
{
|
||||
MessageConverter = new SimpleMessageConverter();
|
||||
processingExpression = Expression.Parse(defaultHandlerMethod + "(#convertedObject)");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
|
||||
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
using System.Collections;
|
||||
|
||||
namespace Spring.Messaging.Nms.Listener.Adapter
|
||||
{
|
||||
/// <summary>
|
||||
/// Used in MessageListenerAdapterTests
|
||||
/// </summary>
|
||||
/// <author>Mark Pollack</author>
|
||||
public interface IMessageContentsHandler
|
||||
{
|
||||
void HandleMessage(IDictionary message);
|
||||
|
||||
void HandleMessage(byte[] message);
|
||||
|
||||
void HandleMessage(int message);
|
||||
|
||||
void HandleMessage(object message);
|
||||
|
||||
void HandleMessage(string message);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
using System.Collections;
|
||||
|
||||
namespace Spring.Messaging.Nms.Listener.Adapter
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
///
|
||||
/// </remarks>
|
||||
/// <author>Mark Pollack</author>
|
||||
public class MessageContentsHandler : IMessageContentsHandler
|
||||
{
|
||||
public int HandledStringCount;
|
||||
|
||||
public int HandledByteArrayCount;
|
||||
|
||||
public void HandleMessage(IDictionary message)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public void HandleMessage(byte[] message)
|
||||
{
|
||||
HandledByteArrayCount++;
|
||||
}
|
||||
|
||||
public void HandleMessage(int message)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public void HandleMessage(object message)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
public void HandleMessage(string message)
|
||||
{
|
||||
HandledStringCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
#region License
|
||||
|
||||
/*
|
||||
* Copyright <20> 2002-2007 the original author or authors.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
#region Imports
|
||||
|
||||
using System;
|
||||
using System.Text;
|
||||
using Apache.NMS;
|
||||
using NUnit.Framework;
|
||||
using Rhino.Mocks;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace Spring.Messaging.Nms.Listener.Adapter
|
||||
{
|
||||
/// <summary>
|
||||
/// This class contains tests for MessageListenerAdapter
|
||||
/// </summary>
|
||||
/// <author>Mark Pollack</author>
|
||||
/// <version>$Id:$</version>
|
||||
[TestFixture]
|
||||
public class MessageListenerAdapterTests
|
||||
{
|
||||
private MockRepository mocks;
|
||||
|
||||
private static string TEXT = "I fancy a good cuppa right now";
|
||||
|
||||
private static int NUMBER = 1;
|
||||
|
||||
private static SerializableObject OBJECT = new SerializableObject();
|
||||
|
||||
private static string CORRELATION_ID = "100";
|
||||
|
||||
private static string RESPONSE_TEXT = "... wi' some full fat creamy milk. Top banana.";
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
mocks = new MockRepository();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MessageContentsHandlerForTextMessage()
|
||||
{
|
||||
int numIterations = 10;
|
||||
ITextMessage message = (ITextMessage)mocks.CreateMock(typeof(ITextMessage));
|
||||
Expect.Call(message.Text).Return(TEXT).Repeat.Times(numIterations);
|
||||
MessageContentsHandler handler = new MessageContentsHandler();
|
||||
mocks.ReplayAll();
|
||||
|
||||
MessageListenerAdapter adapter = new MessageListenerAdapter(handler);
|
||||
for (int i = 0; i < numIterations; i++)
|
||||
{
|
||||
adapter.OnMessage(message);
|
||||
}
|
||||
Assert.AreEqual(numIterations, handler.HandledStringCount);
|
||||
|
||||
mocks.VerifyAll();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MessageContentsHandlerForBytesMessage()
|
||||
{
|
||||
int numIterations = 10;
|
||||
IBytesMessage message = (IBytesMessage)mocks.CreateMock(typeof(IBytesMessage));
|
||||
ASCIIEncoding encoding = new ASCIIEncoding();
|
||||
byte[] content = encoding.GetBytes("test");
|
||||
Expect.Call(message.Content).Return(content).Repeat.Times(numIterations);
|
||||
MessageContentsHandler handler = new MessageContentsHandler();
|
||||
mocks.ReplayAll();
|
||||
|
||||
MessageListenerAdapter adapter = new MessageListenerAdapter(handler);
|
||||
for (int i = 0; i < numIterations; i++)
|
||||
{
|
||||
adapter.OnMessage(message);
|
||||
}
|
||||
Assert.AreEqual(numIterations, handler.HandledByteArrayCount);
|
||||
|
||||
mocks.VerifyAll();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MessageContentsHandlerOverloadCalls()
|
||||
{
|
||||
int numIterations = 10;
|
||||
IBytesMessage bytesMessage = (IBytesMessage)mocks.CreateMock(typeof(IBytesMessage));
|
||||
ASCIIEncoding encoding = new ASCIIEncoding();
|
||||
byte[] content = encoding.GetBytes("test");
|
||||
Expect.Call(bytesMessage.Content).Return(content).Repeat.Times(numIterations / 2);
|
||||
|
||||
ITextMessage textMessage = (ITextMessage)mocks.CreateMock(typeof(ITextMessage));
|
||||
Expect.Call(textMessage.Text).Return(TEXT).Repeat.Times(numIterations/2);
|
||||
|
||||
MessageContentsHandler handler = new MessageContentsHandler();
|
||||
mocks.ReplayAll();
|
||||
|
||||
MessageListenerAdapter adapter = new MessageListenerAdapter(handler);
|
||||
for (int i = 0; i < numIterations/2; i++)
|
||||
{
|
||||
adapter.OnMessage(textMessage);
|
||||
adapter.OnMessage(bytesMessage);
|
||||
}
|
||||
Assert.AreEqual(numIterations / 2, handler.HandledByteArrayCount);
|
||||
Assert.AreEqual(numIterations / 2, handler.HandledStringCount);
|
||||
|
||||
mocks.VerifyAll();
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class SerializableObject
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -105,6 +105,9 @@
|
||||
<Compile Include="Messaging\Nms\Integration\SimpleMessageListener.cs" />
|
||||
<Compile Include="Messaging\Nms\Integration\SimpleMessageListenerContainerTests.cs" />
|
||||
<Compile Include="Messaging\Nms\Connections\TestConnectionFactory.cs" />
|
||||
<Compile Include="Messaging\Nms\Listener\Adapter\IMessageContentsHandler.cs" />
|
||||
<Compile Include="Messaging\Nms\Listener\Adapter\MessageContentsHandler.cs" />
|
||||
<Compile Include="Messaging\Nms\Listener\Adapter\MessageListenerAdapterTests.cs" />
|
||||
<Compile Include="Messaging\Nms\StubQueue.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
||||
Reference in New Issue
Block a user