├── docs ├── articles │ ├── intro.md │ └── toc.yml ├── toc.yml ├── api │ ├── .gitignore │ └── index.md ├── images │ └── activemq_logo_icon.png ├── .gitignore ├── index.md ├── template │ └── partials │ │ └── logo.tmpl.partial ├── nms-docs.csproj └── docfx.json ├── keyfile └── NMSKey.snk ├── NOTICE.txt ├── .gitignore ├── README.md ├── RELEASE.md ├── src └── nms-api │ ├── ITextMessage.cs │ ├── IObjectMessage.cs │ ├── IMapMessage.cs │ ├── IStoppable.cs │ ├── IQueue.cs │ ├── ITopic.cs │ ├── IStartable.cs │ ├── IDestination.cs │ ├── MessageExtensions.cs │ ├── ITrace.cs │ ├── ITemporaryQueue.cs │ ├── ITemporaryTopic.cs │ ├── MessageConsumerExtensions.cs │ ├── INetTxConnectionFactory.cs │ ├── NMSConstants.cs │ ├── IConnectionMetaData.cs │ ├── Util │ ├── Atomic.cs │ ├── DateUtils.cs │ ├── NMSExceptionSupport.cs │ ├── CountDownLatch.cs │ ├── MessagePropertyIntercepter.cs │ ├── EndianSupport.cs │ └── XmlUtils.cs │ ├── INetTxConnection.cs │ ├── IPrimitiveMap.cs │ ├── MessageEOFException.cs │ ├── IllegalStateException.cs │ ├── MessageFormatException.cs │ ├── NMSSecurityException.cs │ ├── InvalidClientIDException.cs │ ├── InvalidSelectorException.cs │ ├── NMSConnectionException.cs │ ├── MessageNotReadableException.cs │ ├── ResourceAllocationException.cs │ ├── MessageNotWriteableException.cs │ ├── TransactionInProgressException.cs │ ├── TransactionRolledBackException.cs │ ├── InvalidDestinationException.cs │ ├── MessageProducerExtensions.cs │ ├── IQueueBrowser.cs │ ├── INetTxSession.cs │ ├── NMSException.cs │ ├── nms-api.csproj │ ├── SessionExtensions.cs │ ├── INMSConsumer.cs │ ├── IRedeliveryPolicy.cs │ ├── Tracer.cs │ ├── IMessageConsumer.cs │ ├── IConnectionFactory.cs │ └── IMessage.cs ├── test └── nms-api-test │ ├── Commands │ ├── ObjectMessage.cs │ ├── TextMessage.cs │ ├── Topic.cs │ ├── Queue.cs │ ├── TempTopic.cs │ ├── TempQueue.cs │ ├── TempDestination.cs │ └── MapMessage.cs │ ├── BadConsumeTest.cs │ ├── NmsTracer.cs │ ├── RequestResponseTest.cs │ ├── TextMessage.cs │ ├── nms-api-test.csproj │ ├── NMSPropertyTest.cs │ ├── TempDestinationDeletionTest.cs │ ├── ProducerTest.cs │ ├── EndianTest.cs │ ├── MessageTransformerTest.cs │ └── StreamMessageTest.cs ├── nms.sln └── package.ps1 /docs/articles/intro.md: -------------------------------------------------------------------------------- 1 | # Add your introductions here! 2 | -------------------------------------------------------------------------------- /docs/articles/toc.yml: -------------------------------------------------------------------------------- 1 | - name: Introduction 2 | href: intro.md 3 | -------------------------------------------------------------------------------- /docs/toc.yml: -------------------------------------------------------------------------------- 1 | - name: Api Documentation 2 | href: api/ 3 | homepage: api/index.md 4 | -------------------------------------------------------------------------------- /keyfile/NMSKey.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apache/activemq-nms-api/main/keyfile/NMSKey.snk -------------------------------------------------------------------------------- /docs/api/.gitignore: -------------------------------------------------------------------------------- 1 | ############### 2 | # temp file # 3 | ############### 4 | *.yml 5 | .manifest 6 | -------------------------------------------------------------------------------- /docs/images/activemq_logo_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/apache/activemq-nms-api/main/docs/images/activemq_logo_icon.png -------------------------------------------------------------------------------- /docs/api/index.md: -------------------------------------------------------------------------------- 1 | # PLACEHOLDER 2 | TODO: Add .NET projects to the *src* folder and run `docfx` to generate **REAL** *API Documentation*! 3 | -------------------------------------------------------------------------------- /docs/.gitignore: -------------------------------------------------------------------------------- 1 | ############### 2 | # folder # 3 | ############### 4 | /**/DROP/ 5 | /**/TEMP/ 6 | /**/packages/ 7 | /**/bin/ 8 | /**/obj/ 9 | _site 10 | log.txt -------------------------------------------------------------------------------- /NOTICE.txt: -------------------------------------------------------------------------------- 1 | Apache ActiveMQ NMS API 2 | Copyright 2005-2025 The Apache Software Foundation 3 | 4 | This product includes software developed at 5 | The Apache Software Foundation (http://www.apache.org/). 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | .vs/ 3 | 4 | bin/ 5 | obj/ 6 | build/ 7 | .idea/ 8 | *.csproj.user 9 | nms.sln.startup.json 10 | build/ 11 | package/ 12 | nms.sln.DotSettings.user 13 | tools/ 14 | 15 | .DS_Store 16 | -------------------------------------------------------------------------------- /docs/index.md: -------------------------------------------------------------------------------- 1 | # This is the **HOMEPAGE**. 2 | Refer to [Markdown](http://daringfireball.net/projects/markdown/) for how to write markdown files. 3 | ## Quick Start Notes: 4 | 1. Add images to the *images* folder if the file is referencing an image. 5 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Apache.NMS: The .NET Messaging Service Client API 2 | For more information see http://activemq.apache.org/nms 3 | 4 | ### Building 5 | Visual Studio 2017 or above is required to build Apache.NMS. To build, launch Visual Studio with the nms.sln file and build the solution. 6 | 7 | ### Testing 8 | Tests use the NUnit Framework. 9 | 10 | ### Documentation 11 | NMS documentation is generated automatically using [DocFX](https://dotnet.github.io/docfx/) after build. Documentation files are available under folder: 12 | 13 | `\docs\_site` -------------------------------------------------------------------------------- /RELEASE.md: -------------------------------------------------------------------------------- 1 | 2 | replace \ in the below steps with your rc version, e.g. 1.8.0-rc3 3 | 4 | git clone https://gitbox.apache.org/repos/asf/activemq-nms-api.git 5 | 6 | ensure versions (csproj files, and package.ps1) 7 | 8 | build project 9 | 10 | git tag -m "tag \" \ 11 | git push origin \ 12 | 13 | svn checkout rc dist dev https://dist.apache.org/repos/dist/dev/activemq/activemq-nms-api 14 | 15 | create folder for rc, e.g. mkdir \ 16 | 17 | copy all contents from package dir from project into the rc folder. 18 | 19 | sign the files, you will find a helper script "sign-release.sh", invoke it as 20 | 21 | ./sign-release.sh \ \ 22 | 23 | commit all files into the rc dist dev repo. -------------------------------------------------------------------------------- /src/nms-api/ITextMessage.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | namespace Apache.NMS 19 | { 20 | /// 21 | /// Represents a text based message 22 | /// 23 | public interface ITextMessage : IMessage 24 | { 25 | string Text { get; set; } 26 | } 27 | } -------------------------------------------------------------------------------- /docs/template/partials/logo.tmpl.partial: -------------------------------------------------------------------------------- 1 | {{! Licensed to the Apache Software Foundation (ASF) under one 2 | or more contributor license agreements. See the NOTICE file 3 | distributed with this work for additional information 4 | regarding copyright ownership. The ASF licenses this file 5 | to you under the Apache License, Version 2.0 (the 6 | "License"); you may not use this file except in compliance 7 | with the License. You may obtain a copy of the License at 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | Unless required by applicable law or agreed to in writing, 10 | software distributed under the License is distributed on an 11 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 12 | KIND, either express or implied. See the License for the 13 | specific language governing permissions and limitations 14 | under the License.}} 15 | 16 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /src/nms-api/IObjectMessage.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | namespace Apache.NMS 19 | { 20 | /// 21 | /// Represents an Object message which contains a serializable .Net object. 22 | /// 23 | public interface IObjectMessage : IMessage 24 | { 25 | object Body { get; set; } 26 | } 27 | } -------------------------------------------------------------------------------- /src/nms-api/IMapMessage.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | namespace Apache.NMS 19 | { 20 | /// 21 | /// Represents a Map message which contains key and value pairs which are 22 | /// of primitive types 23 | /// 24 | public interface IMapMessage : IMessage 25 | { 26 | IPrimitiveMap Body { get; } 27 | } 28 | } -------------------------------------------------------------------------------- /src/nms-api/IStoppable.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | using System.Threading.Tasks; 19 | 20 | namespace Apache.NMS 21 | { 22 | /// 23 | /// A lifecycle for NMS objects to indicate they can be stopped 24 | /// 25 | public interface IStoppable 26 | { 27 | void Stop(); 28 | 29 | Task StopAsync(); 30 | } 31 | } -------------------------------------------------------------------------------- /src/nms-api/IQueue.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | namespace Apache.NMS 19 | { 20 | /// 21 | /// Represents a queue in a message broker. A message sent to a queue is delivered 22 | /// to at most one consumer on the queue. 23 | /// 24 | public interface IQueue : IDestination 25 | { 26 | string QueueName { get; } 27 | } 28 | } -------------------------------------------------------------------------------- /src/nms-api/ITopic.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | namespace Apache.NMS 19 | { 20 | /// 21 | /// Represents a topic in a message broker. A message sent to a topic 22 | /// is delivered to all consumers on the topic who are interested in the message. 23 | /// 24 | public interface ITopic : IDestination 25 | { 26 | string TopicName { get; } 27 | } 28 | } -------------------------------------------------------------------------------- /src/nms-api/IStartable.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | using System.Threading.Tasks; 19 | 20 | namespace Apache.NMS 21 | { 22 | /// 23 | /// A lifecycle for NMS objects to indicate they can be started 24 | /// 25 | public interface IStartable 26 | { 27 | void Start(); 28 | 29 | Task StartAsync(); 30 | 31 | bool IsStarted { get; } 32 | } 33 | } -------------------------------------------------------------------------------- /docs/nms-docs.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 19 | 20 | 21 | 22 | 23 | netstandard2.0 24 | nms_docs 25 | 26 | 27 | 28 | 29 | all 30 | runtime; build; native; contentfiles; analyzers; buildtransitive 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /test/nms-api-test/Commands/ObjectMessage.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | using System; 19 | using System.Collections; 20 | using System.IO; 21 | using Apache.NMS; 22 | 23 | namespace Apache.NMS.Commands 24 | { 25 | public class ObjectMessage : Message, IObjectMessage 26 | { 27 | private object body; 28 | 29 | public override string ToString() 30 | { 31 | return GetType().Name + "[" 32 | + " ]"; 33 | } 34 | 35 | // Properties 36 | 37 | public object Body 38 | { 39 | get { return body; } 40 | set { body = value; } 41 | } 42 | } 43 | } -------------------------------------------------------------------------------- /src/nms-api/IDestination.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | namespace Apache.NMS 19 | { 20 | /// 21 | /// Represents the type of the destination such as a queue or topic. 22 | /// 23 | public enum DestinationType 24 | { 25 | Queue, 26 | Topic, 27 | TemporaryQueue, 28 | TemporaryTopic 29 | } 30 | 31 | /// 32 | /// A base interface for destinations such as queues or topics 33 | /// 34 | public interface IDestination : System.IDisposable 35 | { 36 | DestinationType DestinationType { get; } 37 | 38 | bool IsTopic { get; } 39 | bool IsQueue { get; } 40 | bool IsTemporary { get; } 41 | } 42 | } -------------------------------------------------------------------------------- /src/nms-api/MessageExtensions.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | using System; 19 | using System.Text; 20 | using Apache.NMS.Util; 21 | 22 | namespace Apache.NMS 23 | { 24 | #if NET_3_5 || MONO 25 | public static class MessageExtensions 26 | { 27 | /// 28 | /// Deserializes the object from Xml, and returns it. 29 | /// 30 | public static object ToObject(this IMessage message) 31 | { 32 | return ToObject(message); 33 | } 34 | 35 | /// 36 | /// Deserializes the object from Xml, and returns it. 37 | /// 38 | public static T ToObject(this IMessage message) where T : class 39 | { 40 | try 41 | { 42 | if(null != message) 43 | { 44 | return (T) NMSConvert.DeserializeObjFromMessage(message); 45 | } 46 | } 47 | catch(Exception ex) 48 | { 49 | Tracer.ErrorFormat("Error converting message to object: {0}", ex.Message); 50 | } 51 | 52 | return null; 53 | } 54 | } 55 | #endif 56 | } -------------------------------------------------------------------------------- /src/nms-api/ITrace.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | namespace Apache.NMS 19 | { 20 | /// 21 | /// The ITrace interface is used internally by ActiveMQ to log messages. 22 | /// The client aplication may provide an implementation of ITrace if it wishes to 23 | /// route messages to a specific destination. 24 | /// 25 | /// 26 | /// 27 | /// Use the class to register an instance of ITrace as the 28 | /// active trace destination. 29 | /// 30 | /// 31 | public interface ITrace 32 | { 33 | void Debug(string message); 34 | void Info(string message); 35 | void Warn(string message); 36 | void Error(string message); 37 | void Fatal(string message); 38 | 39 | bool IsDebugEnabled { get; } 40 | bool IsInfoEnabled { get; } 41 | bool IsWarnEnabled { get; } 42 | bool IsErrorEnabled { get; } 43 | bool IsFatalEnabled { get; } 44 | } 45 | } -------------------------------------------------------------------------------- /docs/docfx.json: -------------------------------------------------------------------------------- 1 | { 2 | "metadata": [ 3 | { 4 | "src": [ 5 | { 6 | "files": [ 7 | "src/nms-api/nms-api.csproj" 8 | ], 9 | "src": ".." 10 | } 11 | ], 12 | "dest": "api", 13 | "disableGitFeatures": false, 14 | "disableDefaultFilter": false, 15 | "properties": { 16 | "TargetFramework": "netstandard2.0" 17 | } 18 | } 19 | ], 20 | "build": { 21 | "content": [ 22 | { 23 | "files": [ 24 | "api/**.yml", 25 | "api/index.md" 26 | ] 27 | }, 28 | { 29 | "files": [ 30 | "articles/**.md", 31 | "articles/**/toc.yml", 32 | "toc.yml", 33 | "*.md" 34 | ] 35 | } 36 | ], 37 | "resource": [ 38 | { 39 | "files": [ 40 | "images/**" 41 | ] 42 | } 43 | ], 44 | "overwrite": [ 45 | { 46 | "files": [ 47 | "apidoc/**.md" 48 | ], 49 | "exclude": [ 50 | "obj/**", 51 | "_site/**" 52 | ] 53 | } 54 | ], 55 | "globalMetadata": { 56 | "_appTitle": "Apache NMS API Documentation", 57 | "_appLogoPath": "/images/activemq_logo_icon.png", 58 | "_appFooter": "Copyright © 2005-2023 Apache Software Foundation project
Generated by DocFX", 59 | "_enableSearch": "true" 60 | }, 61 | "dest": "_site", 62 | "globalMetadataFiles": [], 63 | "fileMetadataFiles": [], 64 | "template": [ 65 | "default", 66 | "template" 67 | ], 68 | "postProcessors": [], 69 | "markdownEngineName": "markdig", 70 | "noLangKeyword": false, 71 | "keepFileLink": false, 72 | "cleanupCacheHistory": false, 73 | "disableGitFeatures": false 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /test/nms-api-test/BadConsumeTest.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | using System; 19 | using NUnit.Framework; 20 | 21 | namespace Apache.NMS.Test 22 | { 23 | [TestFixture] 24 | public class BadConsumeTest : NMSTestSupport 25 | { 26 | protected IConnection connection; 27 | protected ISession session; 28 | 29 | [SetUp] 30 | public override void SetUp() 31 | { 32 | connection = CreateConnection(GetTestClientId()); 33 | connection.Start(); 34 | session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge); 35 | } 36 | 37 | [TearDown] 38 | public override void TearDown() 39 | { 40 | if (null != session) 41 | { 42 | session.Dispose(); 43 | session = null; 44 | } 45 | 46 | if (null != connection) 47 | { 48 | connection.Dispose(); 49 | connection = null; 50 | } 51 | } 52 | 53 | [Test] 54 | public void TestBadConsumerException() 55 | { 56 | Assert.Throws(() => session.CreateConsumer(null)); 57 | } 58 | } 59 | } -------------------------------------------------------------------------------- /src/nms-api/ITemporaryQueue.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | using System.Threading.Tasks; 19 | 20 | namespace Apache.NMS 21 | { 22 | /// 23 | /// Represents a temporary queue which exists for the duration 24 | /// of the IConnection which created it. 25 | /// 26 | public interface ITemporaryQueue : IQueue 27 | { 28 | /// 29 | /// Deletes this Temporary Destination, If there are existing receivers 30 | /// still using it, a NMSException will be thrown. 31 | /// 32 | /// 33 | /// If NMS Provider fails to Delete the Temp Destination or the client does 34 | /// not support this operation. 35 | /// 36 | void Delete(); 37 | 38 | /// 39 | /// Deletes this Temporary Destination, If there are existing receivers 40 | /// still using it, a NMSException will be thrown. 41 | /// 42 | /// 43 | /// If NMS Provider fails to Delete the Temp Destination or the client does 44 | /// not support this operation. 45 | /// 46 | Task DeleteAsync(); 47 | } 48 | } -------------------------------------------------------------------------------- /src/nms-api/ITemporaryTopic.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | using System.Threading.Tasks; 19 | 20 | namespace Apache.NMS 21 | { 22 | /// 23 | /// Represents a temporary topic which exists for the duration 24 | /// of the IConnection which created it. 25 | /// 26 | public interface ITemporaryTopic : ITopic 27 | { 28 | /// 29 | /// Deletes this Temporary Destination, If there are existing receivers 30 | /// still using it, a NMSException will be thrown. 31 | /// 32 | /// 33 | /// If NMS Provider fails to Delete the Temp Destination or the client does 34 | /// not support this operation. 35 | /// 36 | void Delete(); 37 | 38 | /// 39 | /// Deletes this Temporary Destination, If there are existing receivers 40 | /// still using it, a NMSException will be thrown. 41 | /// 42 | /// 43 | /// If NMS Provider fails to Delete the Temp Destination or the client does 44 | /// not support this operation. 45 | /// 46 | Task DeleteAsync(); 47 | } 48 | } -------------------------------------------------------------------------------- /src/nms-api/MessageConsumerExtensions.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | using System; 19 | using System.Text; 20 | using Apache.NMS.Util; 21 | 22 | namespace Apache.NMS 23 | { 24 | #if NET_3_5 || MONO 25 | public static class MessageConsumerExtensions 26 | { 27 | /// 28 | /// Receives the message from the destination for this consumer. The object must be de-serializable from XML. 29 | /// 30 | public static T Receive(this IMessageConsumer consumer) where T : class 31 | { 32 | return consumer.Receive().ToObject(); 33 | } 34 | 35 | /// 36 | /// Receives the message from the destination for this consumer. The object must be de-serializable from XML. 37 | /// 38 | public static T Receive(this IMessageConsumer consumer, TimeSpan timeout) where T : class 39 | { 40 | return consumer.Receive(timeout).ToObject(); 41 | } 42 | 43 | /// 44 | /// Receives the message from the destination for this consumer. The object must be de-serializable from XML. 45 | /// 46 | public static T ReceiveNoWait(this IMessageConsumer consumer) where T : class 47 | { 48 | return consumer.ReceiveNoWait().ToObject(); 49 | } 50 | } 51 | #endif 52 | } -------------------------------------------------------------------------------- /test/nms-api-test/Commands/TextMessage.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | using System; 19 | using System.IO; 20 | using Apache.NMS; 21 | using Apache.NMS.Util; 22 | 23 | namespace Apache.NMS.Commands 24 | { 25 | public class TextMessage : Message, ITextMessage 26 | { 27 | private String text = null; 28 | 29 | public TextMessage() 30 | { 31 | } 32 | 33 | public TextMessage(String text) 34 | { 35 | this.Text = text; 36 | } 37 | 38 | public override string ToString() 39 | { 40 | string text = this.Text; 41 | 42 | if (text != null && text.Length > 63) 43 | { 44 | text = text.Substring(0, 45) + "..." + text.Substring(text.Length - 12); 45 | } 46 | 47 | return base.ToString() + " Text = " + (text ?? "null"); 48 | } 49 | 50 | public override void ClearBody() 51 | { 52 | base.ClearBody(); 53 | this.text = null; 54 | } 55 | 56 | // Properties 57 | 58 | public string Text 59 | { 60 | get { return this.text; } 61 | set 62 | { 63 | FailIfReadOnlyBody(); 64 | this.text = value; 65 | this.Content = null; 66 | } 67 | } 68 | } 69 | } -------------------------------------------------------------------------------- /nms.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.28917.181 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "nms-api", "src\nms-api\nms-api.csproj", "{6549C694-F8A0-41AE-80A4-2F393BC87C5A}" 7 | EndProject 8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "nms-api-test", "test\nms-api-test\nms-api-test.csproj", "{47B76E87-2F31-414B-9570-C26250BF51CF}" 9 | EndProject 10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "nms-docs", "docs\nms-docs.csproj", "{5BFA4F92-E39C-412F-BA0D-6E5CB9DBBECF}" 11 | EndProject 12 | Global 13 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 14 | Debug|Any CPU = Debug|Any CPU 15 | Release|Any CPU = Release|Any CPU 16 | EndGlobalSection 17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 18 | {6549C694-F8A0-41AE-80A4-2F393BC87C5A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 19 | {6549C694-F8A0-41AE-80A4-2F393BC87C5A}.Debug|Any CPU.Build.0 = Debug|Any CPU 20 | {6549C694-F8A0-41AE-80A4-2F393BC87C5A}.Release|Any CPU.ActiveCfg = Release|Any CPU 21 | {6549C694-F8A0-41AE-80A4-2F393BC87C5A}.Release|Any CPU.Build.0 = Release|Any CPU 22 | {47B76E87-2F31-414B-9570-C26250BF51CF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 23 | {47B76E87-2F31-414B-9570-C26250BF51CF}.Debug|Any CPU.Build.0 = Debug|Any CPU 24 | {47B76E87-2F31-414B-9570-C26250BF51CF}.Release|Any CPU.ActiveCfg = Release|Any CPU 25 | {47B76E87-2F31-414B-9570-C26250BF51CF}.Release|Any CPU.Build.0 = Release|Any CPU 26 | {5BFA4F92-E39C-412F-BA0D-6E5CB9DBBECF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 27 | {5BFA4F92-E39C-412F-BA0D-6E5CB9DBBECF}.Debug|Any CPU.Build.0 = Debug|Any CPU 28 | {5BFA4F92-E39C-412F-BA0D-6E5CB9DBBECF}.Release|Any CPU.ActiveCfg = Release|Any CPU 29 | {5BFA4F92-E39C-412F-BA0D-6E5CB9DBBECF}.Release|Any CPU.Build.0 = Release|Any CPU 30 | EndGlobalSection 31 | GlobalSection(SolutionProperties) = preSolution 32 | HideSolutionNode = FALSE 33 | EndGlobalSection 34 | GlobalSection(ExtensibilityGlobals) = postSolution 35 | SolutionGuid = {56A30ED4-C3B2-42E6-9BFE-383835662642} 36 | EndGlobalSection 37 | EndGlobal 38 | -------------------------------------------------------------------------------- /src/nms-api/INetTxConnectionFactory.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | using System; 19 | 20 | namespace Apache.NMS 21 | { 22 | /// 23 | /// Some application servers provide support for use in a .NET transactions (optional). 24 | /// 25 | /// To include NMS API transactions in a MSDTC transaction, an application server requires a 26 | /// .NET Transaction aware NMS provider that is capable of mapping the MSDTC transaction model 27 | /// into operations that are supported by the application server. An NMS provider exposes its 28 | /// .NET Transaction support using an INetTxConnectionFactory object, which an application 29 | /// server uses to create INetTxConnection objects. 30 | /// 31 | /// The INetTxConnectionFactory interface is optional. NMS providers are not required to support this 32 | /// interface. This interface is for use by NMS providers to support transactional environments. 33 | /// 34 | public interface INetTxConnectionFactory : IConnectionFactory 35 | { 36 | /// 37 | /// Creates a new connection 38 | /// 39 | INetTxConnection CreateNetTxConnection(); 40 | 41 | /// 42 | /// Creates a new connection with the given user name and password 43 | /// 44 | INetTxConnection CreateNetTxConnection(string userName, string password); 45 | } 46 | } -------------------------------------------------------------------------------- /test/nms-api-test/Commands/Topic.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | using System; 19 | 20 | namespace Apache.NMS.Commands 21 | { 22 | /// 23 | /// Summary description for Topic. 24 | /// 25 | public class Topic : Destination, ITopic 26 | { 27 | public Topic() : base() 28 | { 29 | } 30 | 31 | public Topic(String name) : base(name) 32 | { 33 | } 34 | 35 | override public DestinationType DestinationType 36 | { 37 | get { return DestinationType.Topic; } 38 | } 39 | 40 | public String TopicName 41 | { 42 | get { return PhysicalName; } 43 | } 44 | 45 | public override int GetDestinationType() 46 | { 47 | return TOPIC; 48 | } 49 | 50 | public override Destination CreateDestination(String name) 51 | { 52 | return new Topic(name); 53 | } 54 | 55 | public override Object Clone() 56 | { 57 | // Since we are a derived class use the base's Clone() 58 | // to perform the shallow copy. Since it is shallow it 59 | // will include our derived class. Since we are derived, 60 | // this method is an override. 61 | Topic o = (Topic) base.Clone(); 62 | 63 | // Now do the deep work required 64 | // If any new variables are added then this routine will 65 | // likely need updating 66 | 67 | return o; 68 | } 69 | } 70 | } -------------------------------------------------------------------------------- /test/nms-api-test/Commands/Queue.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | using System; 19 | 20 | namespace Apache.NMS.Commands 21 | { 22 | /// 23 | /// Summary description for Queue. 24 | /// 25 | public class Queue : Destination, IQueue 26 | { 27 | public Queue() 28 | : base() 29 | { 30 | } 31 | 32 | public Queue(String name) 33 | : base(name) 34 | { 35 | } 36 | 37 | override public DestinationType DestinationType 38 | { 39 | get { return DestinationType.Queue; } 40 | } 41 | 42 | public String QueueName 43 | { 44 | get { return PhysicalName; } 45 | } 46 | 47 | public override int GetDestinationType() 48 | { 49 | return QUEUE; 50 | } 51 | 52 | public override Destination CreateDestination(String name) 53 | { 54 | return new Queue(name); 55 | } 56 | 57 | public override Object Clone() 58 | { 59 | // Since we are a derived class use the base's Clone() 60 | // to perform the shallow copy. Since it is shallow it 61 | // will include our derived class. Since we are derived, 62 | // this method is an override. 63 | Queue o = (Queue) base.Clone(); 64 | 65 | // Now do the deep work required 66 | // If any new variables are added then this routine will 67 | // likely need updating 68 | 69 | return o; 70 | } 71 | } 72 | } -------------------------------------------------------------------------------- /src/nms-api/NMSConstants.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | using System; 19 | using System.Threading; 20 | 21 | namespace Apache.NMS 22 | { 23 | /// 24 | /// Define an enumerated array of message priorities. 25 | /// 26 | public enum MsgPriority 27 | { 28 | Lowest = 0, 29 | VeryLow = 1, 30 | Low = 2, 31 | AboveLow = 3, 32 | BelowNormal = 4, 33 | Normal = 5, 34 | AboveNormal = 6, 35 | High = 7, 36 | VeryHigh = 8, 37 | Highest = 9 38 | } 39 | 40 | /// 41 | /// Define an enumerated array of message delivery modes. Provider-specific 42 | /// values can be used to extend this enumerated mode. TIBCO is known to 43 | /// provide a third value of ReliableDelivery. At minimum, a provider must 44 | /// support Persistent and NonPersistent. 45 | /// 46 | public enum MsgDeliveryMode 47 | { 48 | Persistent, 49 | NonPersistent 50 | } 51 | 52 | /// 53 | /// Defines a number of constants 54 | /// 55 | public class NMSConstants 56 | { 57 | public const MsgPriority defaultPriority = MsgPriority.Normal; 58 | public const MsgDeliveryMode defaultDeliveryMode = MsgDeliveryMode.Persistent; 59 | public static readonly TimeSpan defaultDeliveryDelay = TimeSpan.Zero; 60 | public static readonly TimeSpan defaultTimeToLive = TimeSpan.Zero; 61 | public static readonly TimeSpan defaultRequestTimeout = TimeSpan.FromMilliseconds(Timeout.Infinite); 62 | } 63 | } -------------------------------------------------------------------------------- /src/nms-api/IConnectionMetaData.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | namespace Apache.NMS 19 | { 20 | /// 21 | /// Provides information describing the NMS IConnection instance. 22 | /// 23 | public interface IConnectionMetaData 24 | { 25 | /// 26 | /// Get the Major version number of the NMS API this Provider supports. 27 | /// 28 | int NMSMajorVersion { get; } 29 | 30 | /// 31 | /// Get the Minor version number of the NMS API this Provider supports. 32 | /// 33 | int NMSMinorVersion { get; } 34 | 35 | /// 36 | /// Get the name of this NMS Provider. 37 | /// 38 | string NMSProviderName { get; } 39 | 40 | /// 41 | /// Gets a formatted string detailing the NMS API version this Provider supports. 42 | /// 43 | string NMSVersion { get; } 44 | 45 | /// 46 | /// Gets a String array of all the NMSX property names this NMS Provider supports. 47 | /// 48 | string[] NMSXPropertyNames { get; } 49 | 50 | /// 51 | /// Gets the Providers Major version number. 52 | /// 53 | int ProviderMajorVersion { get; } 54 | 55 | /// 56 | /// Gets the Providers Minor version number. 57 | /// 58 | int ProviderMinorVersion { get; } 59 | 60 | /// 61 | /// Gets a formatted string detailing the version of this NMS Provider. 62 | /// 63 | string ProviderVersion { get; } 64 | } 65 | } -------------------------------------------------------------------------------- /test/nms-api-test/Commands/TempTopic.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | using System; 19 | 20 | namespace Apache.NMS.Commands 21 | { 22 | /// 23 | /// A Temporary Topic 24 | /// 25 | public class TempTopic : TempDestination, ITemporaryTopic 26 | { 27 | public TempTopic() : base() 28 | { 29 | } 30 | 31 | public TempTopic(String name) : base(name) 32 | { 33 | } 34 | 35 | override public DestinationType DestinationType 36 | { 37 | get { return DestinationType.TemporaryTopic; } 38 | } 39 | 40 | public String TopicName 41 | { 42 | get { return PhysicalName; } 43 | } 44 | 45 | public String GetTopicName() 46 | { 47 | return PhysicalName; 48 | } 49 | 50 | public override int GetDestinationType() 51 | { 52 | return TEMPORARY_TOPIC; 53 | } 54 | 55 | public override Destination CreateDestination(String name) 56 | { 57 | return new TempTopic(name); 58 | } 59 | 60 | public override Object Clone() 61 | { 62 | // Since we are a derived class use the base's Clone() 63 | // to perform the shallow copy. Since it is shallow it 64 | // will include our derived class. Since we are derived, 65 | // this method is an override. 66 | TempTopic o = (TempTopic) base.Clone(); 67 | 68 | // Now do the deep work required 69 | // If any new variables are added then this routine will 70 | // likely need updating 71 | 72 | return o; 73 | } 74 | } 75 | } -------------------------------------------------------------------------------- /test/nms-api-test/Commands/TempQueue.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | using System; 19 | 20 | namespace Apache.NMS.Commands 21 | { 22 | /// 23 | /// A Temporary Queue 24 | /// 25 | public class TempQueue : TempDestination, ITemporaryQueue 26 | { 27 | public TempQueue() 28 | : base() 29 | { 30 | } 31 | 32 | public TempQueue(String name) 33 | : base(name) 34 | { 35 | } 36 | 37 | override public DestinationType DestinationType 38 | { 39 | get { return DestinationType.TemporaryQueue; } 40 | } 41 | 42 | public String QueueName 43 | { 44 | get { return PhysicalName; } 45 | } 46 | 47 | public String GetQueueName() 48 | { 49 | return PhysicalName; 50 | } 51 | 52 | public override int GetDestinationType() 53 | { 54 | return TEMPORARY_QUEUE; 55 | } 56 | 57 | public override Destination CreateDestination(String name) 58 | { 59 | return new TempQueue(name); 60 | } 61 | 62 | public override Object Clone() 63 | { 64 | // Since we are a derived class use the base's Clone() 65 | // to perform the shallow copy. Since it is shallow it 66 | // will include our derived class. Since we are derived, 67 | // this method is an override. 68 | TempQueue o = (TempQueue) base.Clone(); 69 | 70 | // Now do the deep work required 71 | // If any new variables are added then this routine will 72 | // likely need updating 73 | 74 | return o; 75 | } 76 | } 77 | } -------------------------------------------------------------------------------- /test/nms-api-test/Commands/TempDestination.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | using System; 19 | using System.Threading.Tasks; 20 | 21 | namespace Apache.NMS.Commands 22 | { 23 | public abstract class TempDestination : Destination 24 | { 25 | /// 26 | /// Method CreateDestination 27 | /// 28 | /// An Destination 29 | /// A String 30 | public override Destination CreateDestination(String name) 31 | { 32 | return null; 33 | } 34 | 35 | abstract override public DestinationType DestinationType { get; } 36 | 37 | public TempDestination() 38 | : base() 39 | { 40 | } 41 | 42 | public TempDestination(String name) 43 | : base(name) 44 | { 45 | } 46 | 47 | public override Object Clone() 48 | { 49 | // Since we are a derived class use the base's Clone() 50 | // to perform the shallow copy. Since it is shallow it 51 | // will include our derived class. Since we are derived, 52 | // this method is an override. 53 | TempDestination o = (TempDestination) base.Clone(); 54 | 55 | // Now do the deep work required 56 | // If any new variables are added then this routine will 57 | // likely need updating 58 | 59 | return o; 60 | } 61 | 62 | public Task DeleteAsync() 63 | { 64 | return Task.Factory.StartNew(Delete); 65 | } 66 | 67 | public void Delete() 68 | { 69 | throw new NotSupportedException("Stomp Cannot Delete Temporary Destinations"); 70 | } 71 | } 72 | } -------------------------------------------------------------------------------- /src/nms-api/Util/Atomic.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | using System; 19 | 20 | namespace Apache.NMS.Util 21 | { 22 | public class AtomicReference 23 | { 24 | protected T atomicValue; 25 | 26 | public T Value 27 | { 28 | get 29 | { 30 | lock (this) 31 | { 32 | return atomicValue; 33 | } 34 | } 35 | set 36 | { 37 | lock (this) 38 | { 39 | atomicValue = value; 40 | } 41 | } 42 | } 43 | 44 | public AtomicReference() 45 | { 46 | atomicValue = default(T); 47 | } 48 | 49 | public AtomicReference(T defaultValue) 50 | { 51 | atomicValue = defaultValue; 52 | } 53 | 54 | public T GetAndSet(T value) 55 | { 56 | lock (this) 57 | { 58 | T ret = atomicValue; 59 | atomicValue = value; 60 | return ret; 61 | } 62 | } 63 | } 64 | 65 | public class Atomic : AtomicReference where T : IComparable 66 | { 67 | public Atomic() : base() 68 | { 69 | } 70 | 71 | public Atomic(T defaultValue) : base(defaultValue) 72 | { 73 | } 74 | 75 | public bool CompareAndSet(T expected, T newValue) 76 | { 77 | lock (this) 78 | { 79 | if (0 == atomicValue.CompareTo(expected)) 80 | { 81 | atomicValue = newValue; 82 | return true; 83 | } 84 | 85 | return false; 86 | } 87 | } 88 | } 89 | } -------------------------------------------------------------------------------- /src/nms-api/Util/DateUtils.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | using System; 19 | 20 | namespace Apache.NMS.Util 21 | { 22 | public class DateUtils 23 | { 24 | /// 25 | /// The start of the Windows epoch 26 | /// 27 | public static readonly DateTime windowsEpoch = new DateTime(1601, 1, 1, 0, 0, 0, 0); 28 | 29 | /// 30 | /// The start of the Java epoch 31 | /// 32 | public static readonly DateTime javaEpoch = new DateTime(1970, 1, 1, 0, 0, 0, 0); 33 | 34 | /// 35 | /// The difference between the Windows epoch and the Java epoch 36 | /// in milliseconds. 37 | /// 38 | public static readonly long epochDiff; /* = 1164447360000L; */ 39 | 40 | static DateUtils() 41 | { 42 | epochDiff = (javaEpoch.ToFileTimeUtc() - windowsEpoch.ToFileTimeUtc()) 43 | / TimeSpan.TicksPerMillisecond; 44 | } 45 | 46 | public static long ToJavaTime(DateTime dateTime) 47 | { 48 | return (dateTime.ToFileTime() / TimeSpan.TicksPerMillisecond) - epochDiff; 49 | } 50 | 51 | public static DateTime ToDateTime(long javaTime) 52 | { 53 | return DateTime.FromFileTime((javaTime + epochDiff) * TimeSpan.TicksPerMillisecond); 54 | } 55 | 56 | public static long ToJavaTimeUtc(DateTime dateTime) 57 | { 58 | return (dateTime.ToFileTimeUtc() / TimeSpan.TicksPerMillisecond) - epochDiff; 59 | } 60 | 61 | public static DateTime ToDateTimeUtc(long javaTime) 62 | { 63 | return DateTime.FromFileTimeUtc((javaTime + epochDiff) * TimeSpan.TicksPerMillisecond); 64 | } 65 | } 66 | } -------------------------------------------------------------------------------- /src/nms-api/INetTxConnection.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 19 | using System.Threading.Tasks; 20 | #if !NETCF 21 | using System.Transactions; 22 | 23 | #endif 24 | 25 | namespace Apache.NMS 26 | { 27 | /// 28 | /// The INetTxConnection extends the functionality of the IConnection interface by 29 | /// adding the createNetTxSession method (optional). 30 | /// 31 | /// The INetTxConnection interface is optional. NMS providers are not required to support this 32 | /// interface. This interface is for use by NMS providers to support transactional environments. 33 | /// 34 | public interface INetTxConnection : IConnection 35 | { 36 | /// 37 | /// Creates a INetTxSession object. 38 | /// 39 | INetTxSession CreateNetTxSession(); 40 | 41 | /// 42 | /// Creates a INetTxSession object. 43 | /// 44 | Task CreateNetTxSessionAsync(); 45 | 46 | #if !NETCF 47 | /// 48 | /// Creates a INetTxSession object and enlists in the specified Transaction. 49 | /// 50 | INetTxSession CreateNetTxSession(Transaction tx); 51 | 52 | /// 53 | /// Creates a INetTxSession object and enlists in the specified Transaction. 54 | /// 55 | Task CreateNetTxSessionAsync(Transaction tx); 56 | 57 | INetTxSession CreateNetTxSession(bool enlistsNativeMsDtcResource); 58 | 59 | Task CreateNetTxSessionAsync(bool enlistsNativeMsDtcResource); 60 | 61 | INetTxSession CreateNetTxSession(Transaction tx, bool enlistsNativeMsDtcResource); 62 | 63 | Task CreateNetTxSessionAsync(Transaction tx, bool enlistsNativeMsDtcResource); 64 | #endif 65 | } 66 | } -------------------------------------------------------------------------------- /src/nms-api/IPrimitiveMap.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | using System.Collections; 19 | 20 | namespace Apache.NMS 21 | { 22 | /// 23 | /// Represents a Map of primitive types where the keys are all string instances 24 | /// and the values are strings or numbers. 25 | /// 26 | public interface IPrimitiveMap 27 | { 28 | void Clear(); 29 | 30 | bool Contains(object key); 31 | 32 | void Remove(object key); 33 | 34 | int Count { get; } 35 | 36 | ICollection Keys { get; } 37 | 38 | ICollection Values { get; } 39 | 40 | object this[string key] { get; set; } 41 | 42 | string GetString(string key); 43 | void SetString(string key, string value); 44 | 45 | bool GetBool(string key); 46 | void SetBool(string key, bool value); 47 | 48 | byte GetByte(string key); 49 | void SetByte(string key, byte value); 50 | 51 | char GetChar(string key); 52 | void SetChar(string key, char value); 53 | 54 | short GetShort(string key); 55 | void SetShort(string key, short value); 56 | 57 | int GetInt(string key); 58 | void SetInt(string key, int value); 59 | 60 | long GetLong(string key); 61 | void SetLong(string key, long value); 62 | 63 | float GetFloat(string key); 64 | void SetFloat(string key, float value); 65 | 66 | double GetDouble(string key); 67 | void SetDouble(string key, double value); 68 | 69 | IList GetList(string key); 70 | void SetList(string key, IList list); 71 | 72 | void SetBytes(string key, byte[] value); 73 | void SetBytes(string key, byte[] value, int offset, int length); 74 | byte[] GetBytes(string key); 75 | 76 | IDictionary GetDictionary(string key); 77 | void SetDictionary(string key, IDictionary dictionary); 78 | } 79 | } -------------------------------------------------------------------------------- /test/nms-api-test/NmsTracer.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #define TRACE // Force tracing to be enabled for this class 19 | 20 | namespace Apache.NMS.Test 21 | { 22 | public class NmsTracer : Apache.NMS.ITrace 23 | { 24 | #region ITrace Members 25 | 26 | public void Debug(string message) 27 | { 28 | #if !NETCF 29 | System.Diagnostics.Trace.WriteLine(string.Format("DEBUG: {0}", message)); 30 | #endif 31 | } 32 | 33 | public void Error(string message) 34 | { 35 | #if !NETCF 36 | System.Diagnostics.Trace.WriteLine(string.Format("ERROR: {0}", message)); 37 | #endif 38 | } 39 | 40 | public void Fatal(string message) 41 | { 42 | #if !NETCF 43 | System.Diagnostics.Trace.WriteLine(string.Format("FATAL: {0}", message)); 44 | #endif 45 | } 46 | 47 | public void Info(string message) 48 | { 49 | #if !NETCF 50 | System.Diagnostics.Trace.WriteLine(string.Format("INFO: {0}", message)); 51 | #endif 52 | } 53 | 54 | public void Warn(string message) 55 | { 56 | #if !NETCF 57 | System.Diagnostics.Trace.WriteLine(string.Format("WARN: {0}", message)); 58 | #endif 59 | } 60 | 61 | public bool IsDebugEnabled 62 | { 63 | get { return true; } 64 | } 65 | 66 | public bool IsErrorEnabled 67 | { 68 | get { return true; } 69 | } 70 | 71 | public bool IsFatalEnabled 72 | { 73 | get { return true; } 74 | } 75 | 76 | public bool IsInfoEnabled 77 | { 78 | get { return true; } 79 | } 80 | 81 | public bool IsWarnEnabled 82 | { 83 | get { return true; } 84 | } 85 | 86 | #endregion 87 | } 88 | } -------------------------------------------------------------------------------- /src/nms-api/MessageEOFException.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | using System; 21 | 22 | namespace Apache.NMS 23 | { 24 | [Serializable] 25 | public class MessageEOFException : NMSException 26 | { 27 | public MessageEOFException() 28 | : base() 29 | { 30 | } 31 | 32 | public MessageEOFException(string message) 33 | : base(message) 34 | { 35 | } 36 | 37 | public MessageEOFException(string message, string errorCode) 38 | : base(message, errorCode) 39 | { 40 | } 41 | 42 | public MessageEOFException(string message, Exception innerException) 43 | : base(message, innerException) 44 | { 45 | } 46 | 47 | public MessageEOFException(string message, string errorCode, Exception innerException) 48 | : base(message, errorCode, innerException) 49 | { 50 | } 51 | 52 | #region ISerializable interface implementation 53 | 54 | #if !NETCF 55 | 56 | /// 57 | /// Initializes a new instance of the MessageEOFException class with serialized data. 58 | /// Throws System.ArgumentNullException if the info parameter is null. 59 | /// Throws System.Runtime.Serialization.SerializationException if the class name is null or System.Exception.HResult is zero (0). 60 | /// 61 | /// The SerializationInfo that holds the serialized object data about the exception being thrown. 62 | /// The StreamingContext that contains contextual information about the source or destination. 63 | protected MessageEOFException(System.Runtime.Serialization.SerializationInfo info, 64 | System.Runtime.Serialization.StreamingContext context) 65 | : base(info, context) 66 | { 67 | } 68 | 69 | #endif 70 | 71 | #endregion 72 | } 73 | } -------------------------------------------------------------------------------- /src/nms-api/IllegalStateException.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | using System; 21 | 22 | namespace Apache.NMS 23 | { 24 | [Serializable] 25 | public class IllegalStateException : NMSException 26 | { 27 | public IllegalStateException() 28 | : base() 29 | { 30 | } 31 | 32 | public IllegalStateException(string message) 33 | : base(message) 34 | { 35 | } 36 | 37 | public IllegalStateException(string message, string errorCode) 38 | : base(message, errorCode) 39 | { 40 | } 41 | 42 | public IllegalStateException(string message, Exception innerException) 43 | : base(message, innerException) 44 | { 45 | } 46 | 47 | public IllegalStateException(string message, string errorCode, Exception innerException) 48 | : base(message, errorCode, innerException) 49 | { 50 | } 51 | 52 | #region ISerializable interface implementation 53 | 54 | #if !NETCF 55 | 56 | /// 57 | /// Initializes a new instance of the IllegalStateException class with serialized data. 58 | /// Throws System.ArgumentNullException if the info parameter is null. 59 | /// Throws System.Runtime.Serialization.SerializationException if the class name is null or System.Exception.HResult is zero (0). 60 | /// 61 | /// The SerializationInfo that holds the serialized object data about the exception being thrown. 62 | /// The StreamingContext that contains contextual information about the source or destination. 63 | protected IllegalStateException(System.Runtime.Serialization.SerializationInfo info, 64 | System.Runtime.Serialization.StreamingContext context) 65 | : base(info, context) 66 | { 67 | } 68 | 69 | #endif 70 | 71 | #endregion 72 | } 73 | } -------------------------------------------------------------------------------- /src/nms-api/MessageFormatException.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | using System; 21 | 22 | namespace Apache.NMS 23 | { 24 | [Serializable] 25 | public class MessageFormatException : NMSException 26 | { 27 | public MessageFormatException() 28 | : base() 29 | { 30 | } 31 | 32 | public MessageFormatException(string message) 33 | : base(message) 34 | { 35 | } 36 | 37 | public MessageFormatException(string message, string errorCode) 38 | : base(message, errorCode) 39 | { 40 | } 41 | 42 | public MessageFormatException(string message, Exception innerException) 43 | : base(message, innerException) 44 | { 45 | } 46 | 47 | public MessageFormatException(string message, string errorCode, Exception innerException) 48 | : base(message, errorCode, innerException) 49 | { 50 | } 51 | 52 | #region ISerializable interface implementation 53 | 54 | #if !NETCF 55 | 56 | /// 57 | /// Initializes a new instance of the MessageFormatException class with serialized data. 58 | /// Throws System.ArgumentNullException if the info parameter is null. 59 | /// Throws System.Runtime.Serialization.SerializationException if the class name is null or System.Exception.HResult is zero (0). 60 | /// 61 | /// The SerializationInfo that holds the serialized object data about the exception being thrown. 62 | /// The StreamingContext that contains contextual information about the source or destination. 63 | protected MessageFormatException(System.Runtime.Serialization.SerializationInfo info, 64 | System.Runtime.Serialization.StreamingContext context) 65 | : base(info, context) 66 | { 67 | } 68 | 69 | #endif 70 | 71 | #endregion 72 | } 73 | } -------------------------------------------------------------------------------- /src/nms-api/NMSSecurityException.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | using System; 19 | 20 | namespace Apache.NMS 21 | { 22 | /// 23 | /// Represents a security failure. 24 | /// 25 | [Serializable] 26 | public class NMSSecurityException : NMSException 27 | { 28 | public NMSSecurityException() 29 | : base() 30 | { 31 | } 32 | 33 | public NMSSecurityException(string message) 34 | : base(message) 35 | { 36 | } 37 | 38 | public NMSSecurityException(string message, string errorCode) 39 | : base(message, errorCode) 40 | { 41 | } 42 | 43 | public NMSSecurityException(string message, Exception innerException) 44 | : base(message, innerException) 45 | { 46 | } 47 | 48 | public NMSSecurityException(string message, string errorCode, Exception innerException) 49 | : base(message, errorCode, innerException) 50 | { 51 | } 52 | 53 | #region ISerializable interface implementation 54 | 55 | #if !NETCF 56 | 57 | /// 58 | /// Initializes a new instance of the NMSSecurityException class with serialized data. 59 | /// Throws System.ArgumentNullException if the info parameter is null. 60 | /// Throws System.Runtime.Serialization.SerializationException if the class name is null or System.Exception.HResult is zero (0). 61 | /// 62 | /// The SerializationInfo that holds the serialized object data about the exception being thrown. 63 | /// The StreamingContext that contains contextual information about the source or destination. 64 | protected NMSSecurityException(System.Runtime.Serialization.SerializationInfo info, 65 | System.Runtime.Serialization.StreamingContext context) 66 | : base(info, context) 67 | { 68 | } 69 | 70 | #endif 71 | 72 | #endregion 73 | } 74 | } -------------------------------------------------------------------------------- /src/nms-api/InvalidClientIDException.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | using System; 21 | 22 | namespace Apache.NMS 23 | { 24 | [Serializable] 25 | public class InvalidClientIDException : NMSException 26 | { 27 | public InvalidClientIDException() 28 | : base() 29 | { 30 | } 31 | 32 | public InvalidClientIDException(string message) 33 | : base(message) 34 | { 35 | } 36 | 37 | public InvalidClientIDException(string message, string errorCode) 38 | : base(message, errorCode) 39 | { 40 | } 41 | 42 | public InvalidClientIDException(string message, Exception innerException) 43 | : base(message, innerException) 44 | { 45 | } 46 | 47 | public InvalidClientIDException(string message, string errorCode, Exception innerException) 48 | : base(message, errorCode, innerException) 49 | { 50 | } 51 | 52 | #region ISerializable interface implementation 53 | 54 | #if !NETCF 55 | 56 | /// 57 | /// Initializes a new instance of the InvalidClientIDException class with serialized data. 58 | /// Throws System.ArgumentNullException if the info parameter is null. 59 | /// Throws System.Runtime.Serialization.SerializationException if the class name is null or System.Exception.HResult is zero (0). 60 | /// 61 | /// The SerializationInfo that holds the serialized object data about the exception being thrown. 62 | /// The StreamingContext that contains contextual information about the source or destination. 63 | protected InvalidClientIDException(System.Runtime.Serialization.SerializationInfo info, 64 | System.Runtime.Serialization.StreamingContext context) 65 | : base(info, context) 66 | { 67 | } 68 | 69 | #endif 70 | 71 | #endregion 72 | } 73 | } -------------------------------------------------------------------------------- /src/nms-api/InvalidSelectorException.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | using System; 21 | 22 | namespace Apache.NMS 23 | { 24 | [Serializable] 25 | public class InvalidSelectorException : NMSException 26 | { 27 | public InvalidSelectorException() 28 | : base() 29 | { 30 | } 31 | 32 | public InvalidSelectorException(string message) 33 | : base(message) 34 | { 35 | } 36 | 37 | public InvalidSelectorException(string message, string errorCode) 38 | : base(message, errorCode) 39 | { 40 | } 41 | 42 | public InvalidSelectorException(string message, Exception innerException) 43 | : base(message, innerException) 44 | { 45 | } 46 | 47 | public InvalidSelectorException(string message, string errorCode, Exception innerException) 48 | : base(message, errorCode, innerException) 49 | { 50 | } 51 | 52 | #region ISerializable interface implementation 53 | 54 | #if !NETCF 55 | 56 | /// 57 | /// Initializes a new instance of the InvalidSelectorException class with serialized data. 58 | /// Throws System.ArgumentNullException if the info parameter is null. 59 | /// Throws System.Runtime.Serialization.SerializationException if the class name is null or System.Exception.HResult is zero (0). 60 | /// 61 | /// The SerializationInfo that holds the serialized object data about the exception being thrown. 62 | /// The StreamingContext that contains contextual information about the source or destination. 63 | protected InvalidSelectorException(System.Runtime.Serialization.SerializationInfo info, 64 | System.Runtime.Serialization.StreamingContext context) 65 | : base(info, context) 66 | { 67 | } 68 | 69 | #endif 70 | 71 | #endregion 72 | } 73 | } -------------------------------------------------------------------------------- /src/nms-api/NMSConnectionException.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | using System; 19 | 20 | namespace Apache.NMS 21 | { 22 | /// 23 | /// Represents a connection failure. 24 | /// 25 | [Serializable] 26 | public class NMSConnectionException : NMSException 27 | { 28 | public NMSConnectionException() 29 | : base() 30 | { 31 | } 32 | 33 | public NMSConnectionException(string message) 34 | : base(message) 35 | { 36 | } 37 | 38 | public NMSConnectionException(string message, string errorCode) 39 | : base(message, errorCode) 40 | { 41 | } 42 | 43 | public NMSConnectionException(string message, Exception innerException) 44 | : base(message, innerException) 45 | { 46 | } 47 | 48 | public NMSConnectionException(string message, string errorCode, Exception innerException) 49 | : base(message, errorCode, innerException) 50 | { 51 | } 52 | 53 | #region ISerializable interface implementation 54 | 55 | #if !NETCF 56 | 57 | /// 58 | /// Initializes a new instance of the NMSConnectionException class with serialized data. 59 | /// Throws System.ArgumentNullException if the info parameter is null. 60 | /// Throws System.Runtime.Serialization.SerializationException if the class name is null or System.Exception.HResult is zero (0). 61 | /// 62 | /// The SerializationInfo that holds the serialized object data about the exception being thrown. 63 | /// The StreamingContext that contains contextual information about the source or destination. 64 | protected NMSConnectionException(System.Runtime.Serialization.SerializationInfo info, 65 | System.Runtime.Serialization.StreamingContext context) 66 | : base(info, context) 67 | { 68 | } 69 | 70 | #endif 71 | 72 | #endregion 73 | } 74 | } -------------------------------------------------------------------------------- /src/nms-api/MessageNotReadableException.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | using System; 21 | 22 | namespace Apache.NMS 23 | { 24 | [Serializable] 25 | public class MessageNotReadableException : NMSException 26 | { 27 | public MessageNotReadableException() 28 | : base() 29 | { 30 | } 31 | 32 | public MessageNotReadableException(string message) 33 | : base(message) 34 | { 35 | } 36 | 37 | public MessageNotReadableException(string message, string errorCode) 38 | : base(message, errorCode) 39 | { 40 | } 41 | 42 | public MessageNotReadableException(string message, Exception innerException) 43 | : base(message, innerException) 44 | { 45 | } 46 | 47 | public MessageNotReadableException(string message, string errorCode, Exception innerException) 48 | : base(message, errorCode, innerException) 49 | { 50 | } 51 | 52 | #region ISerializable interface implementation 53 | 54 | #if !NETCF 55 | 56 | /// 57 | /// Initializes a new instance of the MessageNotReadableException class with serialized data. 58 | /// Throws System.ArgumentNullException if the info parameter is null. 59 | /// Throws System.Runtime.Serialization.SerializationException if the class name is null or System.Exception.HResult is zero (0). 60 | /// 61 | /// The SerializationInfo that holds the serialized object data about the exception being thrown. 62 | /// The StreamingContext that contains contextual information about the source or destination. 63 | protected MessageNotReadableException(System.Runtime.Serialization.SerializationInfo info, 64 | System.Runtime.Serialization.StreamingContext context) 65 | : base(info, context) 66 | { 67 | } 68 | 69 | #endif 70 | 71 | #endregion 72 | } 73 | } -------------------------------------------------------------------------------- /src/nms-api/ResourceAllocationException.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | using System; 21 | 22 | namespace Apache.NMS 23 | { 24 | [Serializable] 25 | public class ResourceAllocationException : NMSException 26 | { 27 | public ResourceAllocationException() 28 | : base() 29 | { 30 | } 31 | 32 | public ResourceAllocationException(string message) 33 | : base(message) 34 | { 35 | } 36 | 37 | public ResourceAllocationException(string message, string errorCode) 38 | : base(message, errorCode) 39 | { 40 | } 41 | 42 | public ResourceAllocationException(string message, Exception innerException) 43 | : base(message, innerException) 44 | { 45 | } 46 | 47 | public ResourceAllocationException(string message, string errorCode, Exception innerException) 48 | : base(message, errorCode, innerException) 49 | { 50 | } 51 | 52 | #region ISerializable interface implementation 53 | 54 | #if !NETCF 55 | 56 | /// 57 | /// Initializes a new instance of the ResourceAllocationException class with serialized data. 58 | /// Throws System.ArgumentNullException if the info parameter is null. 59 | /// Throws System.Runtime.Serialization.SerializationException if the class name is null or System.Exception.HResult is zero (0). 60 | /// 61 | /// The SerializationInfo that holds the serialized object data about the exception being thrown. 62 | /// The StreamingContext that contains contextual information about the source or destination. 63 | protected ResourceAllocationException(System.Runtime.Serialization.SerializationInfo info, 64 | System.Runtime.Serialization.StreamingContext context) 65 | : base(info, context) 66 | { 67 | } 68 | 69 | #endif 70 | 71 | #endregion 72 | } 73 | } -------------------------------------------------------------------------------- /test/nms-api-test/Commands/MapMessage.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | using System; 19 | using System.IO; 20 | using Apache.NMS; 21 | using Apache.NMS.Util; 22 | 23 | namespace Apache.NMS.Commands 24 | { 25 | public class MapMessage : Message, IMapMessage 26 | { 27 | private PrimitiveMap body; 28 | private PrimitiveMapInterceptor typeConverter; 29 | 30 | public MapMessage() : base() 31 | { 32 | } 33 | 34 | public MapMessage(PrimitiveMap body) : base() 35 | { 36 | this.body = body; 37 | this.typeConverter = new PrimitiveMapInterceptor(this, this.body); 38 | } 39 | 40 | public override void ClearBody() 41 | { 42 | this.body = null; 43 | this.typeConverter = null; 44 | base.ClearBody(); 45 | } 46 | 47 | public override bool ReadOnlyBody 48 | { 49 | get { return base.ReadOnlyBody; } 50 | 51 | set 52 | { 53 | if (this.typeConverter != null) 54 | { 55 | this.typeConverter.ReadOnly = true; 56 | } 57 | 58 | base.ReadOnlyBody = value; 59 | } 60 | } 61 | 62 | 63 | public IPrimitiveMap Body 64 | { 65 | get 66 | { 67 | if (this.body == null) 68 | { 69 | this.body = new PrimitiveMap(); 70 | this.typeConverter = new PrimitiveMapInterceptor(this, this.body); 71 | } 72 | 73 | return this.typeConverter; 74 | } 75 | 76 | set 77 | { 78 | this.body = value as PrimitiveMap; 79 | if (value != null) 80 | { 81 | this.typeConverter = new PrimitiveMapInterceptor(this, value); 82 | } 83 | else 84 | { 85 | this.typeConverter = null; 86 | } 87 | } 88 | } 89 | } 90 | } -------------------------------------------------------------------------------- /src/nms-api/MessageNotWriteableException.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | using System; 21 | 22 | namespace Apache.NMS 23 | { 24 | [Serializable] 25 | public class MessageNotWriteableException : NMSException 26 | { 27 | public MessageNotWriteableException() 28 | : base() 29 | { 30 | } 31 | 32 | public MessageNotWriteableException(string message) 33 | : base(message) 34 | { 35 | } 36 | 37 | public MessageNotWriteableException(string message, string errorCode) 38 | : base(message, errorCode) 39 | { 40 | } 41 | 42 | public MessageNotWriteableException(string message, Exception innerException) 43 | : base(message, innerException) 44 | { 45 | } 46 | 47 | public MessageNotWriteableException(string message, string errorCode, Exception innerException) 48 | : base(message, errorCode, innerException) 49 | { 50 | } 51 | 52 | #region ISerializable interface implementation 53 | 54 | #if !NETCF 55 | 56 | /// 57 | /// Initializes a new instance of the MessageNotWriteableException class with serialized data. 58 | /// Throws System.ArgumentNullException if the info parameter is null. 59 | /// Throws System.Runtime.Serialization.SerializationException if the class name is null or System.Exception.HResult is zero (0). 60 | /// 61 | /// The SerializationInfo that holds the serialized object data about the exception being thrown. 62 | /// The StreamingContext that contains contextual information about the source or destination. 63 | protected MessageNotWriteableException(System.Runtime.Serialization.SerializationInfo info, 64 | System.Runtime.Serialization.StreamingContext context) 65 | : base(info, context) 66 | { 67 | } 68 | 69 | #endif 70 | 71 | #endregion 72 | } 73 | } -------------------------------------------------------------------------------- /src/nms-api/TransactionInProgressException.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | using System; 21 | 22 | namespace Apache.NMS 23 | { 24 | [Serializable] 25 | public class TransactionInProgressException : NMSException 26 | { 27 | public TransactionInProgressException() 28 | : base() 29 | { 30 | } 31 | 32 | public TransactionInProgressException(string message) 33 | : base(message) 34 | { 35 | } 36 | 37 | public TransactionInProgressException(string message, string errorCode) 38 | : base(message, errorCode) 39 | { 40 | } 41 | 42 | public TransactionInProgressException(string message, Exception innerException) 43 | : base(message, innerException) 44 | { 45 | } 46 | 47 | public TransactionInProgressException(string message, string errorCode, Exception innerException) 48 | : base(message, errorCode, innerException) 49 | { 50 | } 51 | 52 | #region ISerializable interface implementation 53 | 54 | #if !NETCF 55 | 56 | /// 57 | /// Initializes a new instance of the TransactionInProgressException class with serialized data. 58 | /// Throws System.ArgumentNullException if the info parameter is null. 59 | /// Throws System.Runtime.Serialization.SerializationException if the class name is null or System.Exception.HResult is zero (0). 60 | /// 61 | /// The SerializationInfo that holds the serialized object data about the exception being thrown. 62 | /// The StreamingContext that contains contextual information about the source or destination. 63 | protected TransactionInProgressException(System.Runtime.Serialization.SerializationInfo info, 64 | System.Runtime.Serialization.StreamingContext context) 65 | : base(info, context) 66 | { 67 | } 68 | 69 | #endif 70 | 71 | #endregion 72 | } 73 | } -------------------------------------------------------------------------------- /src/nms-api/TransactionRolledBackException.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | using System; 21 | 22 | namespace Apache.NMS 23 | { 24 | [Serializable] 25 | public class TransactionRolledBackException : NMSException 26 | { 27 | public TransactionRolledBackException() 28 | : base() 29 | { 30 | } 31 | 32 | public TransactionRolledBackException(string message) 33 | : base(message) 34 | { 35 | } 36 | 37 | public TransactionRolledBackException(string message, string errorCode) 38 | : base(message, errorCode) 39 | { 40 | } 41 | 42 | public TransactionRolledBackException(string message, Exception innerException) 43 | : base(message, innerException) 44 | { 45 | } 46 | 47 | public TransactionRolledBackException(string message, string errorCode, Exception innerException) 48 | : base(message, errorCode, innerException) 49 | { 50 | } 51 | 52 | #region ISerializable interface implementation 53 | 54 | #if !NETCF 55 | 56 | /// 57 | /// Initializes a new instance of the TransactionRolledBackException class with serialized data. 58 | /// Throws System.ArgumentNullException if the info parameter is null. 59 | /// Throws System.Runtime.Serialization.SerializationException if the class name is null or System.Exception.HResult is zero (0). 60 | /// 61 | /// The SerializationInfo that holds the serialized object data about the exception being thrown. 62 | /// The StreamingContext that contains contextual information about the source or destination. 63 | protected TransactionRolledBackException(System.Runtime.Serialization.SerializationInfo info, 64 | System.Runtime.Serialization.StreamingContext context) 65 | : base(info, context) 66 | { 67 | } 68 | 69 | #endif 70 | 71 | #endregion 72 | } 73 | } -------------------------------------------------------------------------------- /src/nms-api/Util/NMSExceptionSupport.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | using System; 19 | 20 | namespace Apache.NMS.Util 21 | { 22 | public sealed class NMSExceptionSupport 23 | { 24 | private NMSExceptionSupport() 25 | { 26 | } 27 | 28 | public static NMSException Create(string message, string errorCode, Exception cause) 29 | { 30 | NMSException exception = new NMSException(message, errorCode, cause); 31 | return exception; 32 | } 33 | 34 | public static NMSException Create(string message, Exception cause) 35 | { 36 | NMSException exception = new NMSException(message, cause); 37 | return exception; 38 | } 39 | 40 | public static NMSException Create(Exception cause) 41 | { 42 | if (cause is NMSException) 43 | { 44 | return (NMSException) cause; 45 | } 46 | 47 | string msg = cause.Message; 48 | if (msg == null || msg.Length == 0) 49 | { 50 | msg = cause.ToString(); 51 | } 52 | 53 | NMSException exception = new NMSException(msg, cause); 54 | return exception; 55 | } 56 | 57 | public static MessageEOFException CreateMessageEOFException(Exception cause) 58 | { 59 | string msg = cause.Message; 60 | if (msg == null || msg.Length == 0) 61 | { 62 | msg = cause.ToString(); 63 | } 64 | 65 | MessageEOFException exception = new MessageEOFException(msg, cause); 66 | return exception; 67 | } 68 | 69 | public static MessageFormatException CreateMessageFormatException(Exception cause) 70 | { 71 | string msg = cause.Message; 72 | if (msg == null || msg.Length == 0) 73 | { 74 | msg = cause.ToString(); 75 | } 76 | 77 | MessageFormatException exception = new MessageFormatException(msg, cause); 78 | return exception; 79 | } 80 | } 81 | } -------------------------------------------------------------------------------- /src/nms-api/InvalidDestinationException.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | using System; 19 | 20 | namespace Apache.NMS 21 | { 22 | /// 23 | /// An attempt is made to access an invalid destination 24 | /// 25 | [Serializable] 26 | public class InvalidDestinationException : NMSException 27 | { 28 | public InvalidDestinationException() 29 | : base() 30 | { 31 | } 32 | 33 | public InvalidDestinationException(string message) 34 | : base(message) 35 | { 36 | } 37 | 38 | public InvalidDestinationException(string message, string errorCode) 39 | : base(message, errorCode) 40 | { 41 | } 42 | 43 | public InvalidDestinationException(string message, Exception innerException) 44 | : base(message, innerException) 45 | { 46 | } 47 | 48 | public InvalidDestinationException(string message, string errorCode, Exception innerException) 49 | : base(message, errorCode, innerException) 50 | { 51 | } 52 | 53 | #region ISerializable interface implementation 54 | 55 | #if !NETCF 56 | 57 | /// 58 | /// Initializes a new instance of the InvalidDestinationException class with serialized data. 59 | /// Throws System.ArgumentNullException if the info parameter is null. 60 | /// Throws System.Runtime.Serialization.SerializationException if the class name is null or System.Exception.HResult is zero (0). 61 | /// 62 | /// The SerializationInfo that holds the serialized object data about the exception being thrown. 63 | /// The StreamingContext that contains contextual information about the source or destination. 64 | protected InvalidDestinationException(System.Runtime.Serialization.SerializationInfo info, 65 | System.Runtime.Serialization.StreamingContext context) 66 | : base(info, context) 67 | { 68 | } 69 | 70 | #endif 71 | 72 | #endregion 73 | } 74 | } -------------------------------------------------------------------------------- /src/nms-api/MessageProducerExtensions.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | using System; 19 | using System.Text; 20 | using Apache.NMS.Util; 21 | 22 | namespace Apache.NMS 23 | { 24 | #if NET_3_5 || MONO 25 | public static class MessageProducerExtensions 26 | { 27 | /// 28 | /// Extension function to create a text message from an object. The object must be serializable to XML. 29 | /// 30 | public static ITextMessage CreateXmlMessage(this IMessageProducer producer, object obj) 31 | { 32 | return NMSConvert.SerializeObjToMessage(producer.CreateTextMessage(), obj); 33 | } 34 | 35 | /// 36 | /// Sends the message to the default destination for this producer. The object must be serializable to XML. 37 | /// 38 | public static void Send(this IMessageProducer producer, object objMessage) 39 | { 40 | producer.Send(producer.CreateXmlMessage(objMessage)); 41 | } 42 | 43 | /// 44 | /// Sends the message to the default destination with the explicit QoS configuration. The object must be serializable to XML. 45 | /// 46 | public static void Send(this IMessageProducer producer, object objMessage, MsgDeliveryMode deliveryMode, MsgPriority priority, TimeSpan timeToLive) 47 | { 48 | producer.Send(producer.CreateXmlMessage(objMessage), deliveryMode, priority, timeToLive); 49 | } 50 | 51 | /// 52 | /// Sends the message to the given destination 53 | /// 54 | public static void Send(this IMessageProducer producer, IDestination destination, object objMessage) 55 | { 56 | producer.Send(destination, producer.CreateXmlMessage(objMessage)); 57 | } 58 | 59 | /// 60 | /// Sends the message to the given destination with the explicit QoS configuration. The object must be serializable to XML. 61 | /// 62 | public static void Send(this IMessageProducer producer, IDestination destination, object objMessage, MsgDeliveryMode deliveryMode, MsgPriority priority, TimeSpan timeToLive) 63 | { 64 | producer.Send(destination, producer.CreateXmlMessage(objMessage), deliveryMode, priority, timeToLive); 65 | } 66 | } 67 | #endif 68 | } -------------------------------------------------------------------------------- /src/nms-api/Util/CountDownLatch.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | using System; 19 | using System.Threading; 20 | 21 | namespace Apache.NMS.Util 22 | { 23 | public class CountDownLatch 24 | { 25 | private readonly ManualResetEvent mutex = new ManualResetEvent(false); 26 | private int remaining; 27 | 28 | public CountDownLatch(int i) 29 | { 30 | remaining = i; 31 | } 32 | 33 | /// 34 | /// Decrement the count, releasing any waiting Threads when the count reaches Zero. 35 | /// 36 | public void countDown() 37 | { 38 | lock (mutex) 39 | { 40 | if (remaining > 0) 41 | { 42 | remaining--; 43 | if (0 == remaining) 44 | { 45 | mutex.Set(); 46 | } 47 | } 48 | } 49 | } 50 | 51 | /// 52 | /// Gets the current count for this Latch. 53 | /// 54 | public int Remaining 55 | { 56 | get 57 | { 58 | lock (mutex) 59 | { 60 | return remaining; 61 | } 62 | } 63 | } 64 | 65 | /// 66 | /// Causes the current Thread to wait for the count to reach zero, unless 67 | /// the Thread is interrupted. 68 | /// 69 | public void await() 70 | { 71 | this.await(TimeSpan.FromMilliseconds(Timeout.Infinite)); 72 | } 73 | 74 | /// 75 | /// Causes the current thread to wait until the latch has counted down to zero, unless 76 | /// the thread is interrupted, or the specified waiting time elapses. 77 | /// 78 | public bool await(TimeSpan timeout) 79 | { 80 | return mutex.WaitOne((int) timeout.TotalMilliseconds, false); 81 | } 82 | 83 | public WaitHandle AsyncWaitHandle 84 | { 85 | get { return mutex; } 86 | } 87 | } 88 | } -------------------------------------------------------------------------------- /test/nms-api-test/RequestResponseTest.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | using System; 19 | using Apache.NMS.Util; 20 | using NUnit.Framework; 21 | 22 | namespace Apache.NMS.Test 23 | { 24 | [TestFixture] 25 | public class RequestResponseTest : NMSTestSupport 26 | { 27 | [Test] 28 | [Category("RequestResponse")] 29 | public void TestRequestResponseMessaging() 30 | { 31 | using (IConnection connection = CreateConnection()) 32 | { 33 | connection.Start(); 34 | using (ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge)) 35 | { 36 | IDestination destination = CreateDestination(session, DestinationType.Queue); 37 | ITemporaryQueue replyTo = session.CreateTemporaryQueue(); 38 | 39 | using (IMessageConsumer consumer = session.CreateConsumer(destination)) 40 | using (IMessageProducer producer = session.CreateProducer(destination)) 41 | { 42 | IMessage request = session.CreateMessage(); 43 | 44 | request.NMSReplyTo = replyTo; 45 | 46 | producer.Send(request); 47 | 48 | request = consumer.Receive(TimeSpan.FromMilliseconds(3000)); 49 | Assert.IsNotNull(request); 50 | Assert.IsNotNull(request.NMSReplyTo); 51 | 52 | using (IMessageProducer responder = session.CreateProducer(request.NMSReplyTo)) 53 | { 54 | IMessage response = session.CreateTextMessage("RESPONSE"); 55 | responder.Send(response); 56 | } 57 | } 58 | 59 | using (IMessageConsumer consumer = session.CreateConsumer(replyTo)) 60 | { 61 | ITextMessage response = consumer.Receive(TimeSpan.FromMilliseconds(3000)) as ITextMessage; 62 | Assert.IsNotNull(response); 63 | Assert.AreEqual("RESPONSE", response.Text); 64 | } 65 | } 66 | } 67 | } 68 | } 69 | } -------------------------------------------------------------------------------- /src/nms-api/IQueueBrowser.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | using System.Threading.Tasks; 19 | 20 | namespace Apache.NMS 21 | { 22 | /// 23 | /// A client uses a QueueBrowser object to look at messages on a queue without removing them. 24 | /// 25 | /// The Enumeration method returns a java.util.Enumeration that is used to scan the queue's 26 | /// messages. It may be an enumeration of the entire content of a queue, or it may contain 27 | /// only the messages matching a message selector. 28 | /// 29 | /// Messages may be arriving and expiring while the scan is done. The NMS API does not 30 | /// require the content of an enumeration to be a static snapshot of queue content. Whether 31 | /// these changes are visible or not depends on the NMS provider. 32 | /// 33 | public interface IQueueBrowser : System.Collections.IEnumerable, System.IDisposable 34 | { 35 | /// 36 | /// Closes the QueueBrowser. 37 | /// 38 | /// 39 | /// If NMS Provider fails to close the Browser for some reason. 40 | /// 41 | void Close(); 42 | 43 | /// 44 | /// Closes the QueueBrowser. 45 | /// 46 | /// 47 | /// If NMS Provider fails to close the Browser for some reason. 48 | /// 49 | Task CloseAsync(); 50 | 51 | /// 52 | /// Gets this queue browser's message selector expression. If no Message 53 | /// selector was specified than this method returns null. 54 | /// 55 | /// 56 | /// If NMS Provider fails to get the Message Selector for some reason. 57 | /// 58 | string MessageSelector { get; } 59 | 60 | /// 61 | /// Gets the queue associated with this queue browser. 62 | /// 63 | /// 64 | /// If NMS Provider fails to retrieve the IQueue associated with the Browser 65 | /// doe to some internal error. 66 | /// 67 | IQueue Queue { get; } 68 | } 69 | } -------------------------------------------------------------------------------- /src/nms-api/INetTxSession.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #if !NETCF 19 | using System.Threading.Tasks; 20 | using System.Transactions; 21 | 22 | #endif 23 | 24 | namespace Apache.NMS 25 | { 26 | /// 27 | /// The INetTxSession interface extends the capability of Session by adding access to a NMS 28 | /// provider's support for the Distributed Transactions (optional). The transaction support 29 | /// leverages the .NET Frameworks System.Transactions API. 30 | /// 31 | /// The NMS Provider implements this interface by participating in the current ambient transaction 32 | /// as defined by the System.Transactions.Transaction.Current static member. Whenever a new 33 | /// Transaction is entered the NMS provider should enlist in that transaction. When there is no 34 | /// ambient transaction then the NMS Provider should allow the INetTxSession instance to behave 35 | /// as a session that is in Auto Acknowledge mode. 36 | /// 37 | /// Calling the Commit or Rollback methods on a INetTxSession instance should throw an exception 38 | /// as those operations are controlled by the Transaction Manager. 39 | /// 40 | /// The INetTxSession interface is optional. NMS providers are not required to support this 41 | /// interface. This interface is for use by NMS providers to support transactional environments. 42 | /// 43 | public interface INetTxSession : ISession 44 | { 45 | #if !NETCF 46 | /// 47 | /// Enlist the Session in the specified Transaction. 48 | /// 49 | /// If the Session is already enlisted in a Transaction or there is an Ambient 50 | /// Transaction and the given TX is not that Transaction then an exception should 51 | /// be thrown. 52 | /// 53 | void Enlist(Transaction tx); 54 | 55 | /// 56 | /// Enlist the Session in the specified Transaction. 57 | /// 58 | /// If the Session is already enlisted in a Transaction or there is an Ambient 59 | /// Transaction and the given TX is not that Transaction then an exception should 60 | /// be thrown. 61 | /// 62 | Task EnlistAsync(Transaction tx); 63 | 64 | bool EnlistsMsDtcNativeResource { get; set; } 65 | #endif 66 | } 67 | } -------------------------------------------------------------------------------- /test/nms-api-test/TextMessage.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | using Apache.NMS.Util; 19 | using NUnit.Framework; 20 | 21 | namespace Apache.NMS.Test 22 | { 23 | [TestFixture] 24 | public class TextMessageTest : NMSTestSupport 25 | { 26 | [Test] 27 | public void SendReceiveTextMessage( 28 | [Values(MsgDeliveryMode.Persistent, MsgDeliveryMode.NonPersistent)] 29 | MsgDeliveryMode deliveryMode) 30 | { 31 | using (IConnection connection = CreateConnection(GetTestClientId())) 32 | { 33 | connection.Start(); 34 | using (ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge)) 35 | { 36 | IDestination destination = CreateDestination(session, DestinationType.Queue); 37 | using (IMessageConsumer consumer = session.CreateConsumer(destination)) 38 | using (IMessageProducer producer = session.CreateProducer(destination)) 39 | { 40 | producer.DeliveryMode = deliveryMode; 41 | IMessage request = session.CreateTextMessage("Hello World!"); 42 | producer.Send(request); 43 | 44 | IMessage message = consumer.Receive(receiveTimeout); 45 | AssertTextMessageEqual(request, message); 46 | Assert.AreEqual(deliveryMode, message.NMSDeliveryMode, "NMSDeliveryMode does not match"); 47 | } 48 | } 49 | } 50 | } 51 | 52 | /// 53 | /// Assert that two messages are ITextMessages and their text bodies are equal. 54 | /// 55 | /// 56 | /// 57 | protected void AssertTextMessageEqual(IMessage expected, IMessage actual) 58 | { 59 | ITextMessage expectedTextMsg = expected as ITextMessage; 60 | Assert.IsNotNull(expectedTextMsg, "'expected' message not a text message"); 61 | ITextMessage actualTextMsg = actual as ITextMessage; 62 | Assert.IsNotNull(actualTextMsg, "'actual' message not a text message"); 63 | Assert.AreEqual(expectedTextMsg.Text, actualTextMsg.Text, "Text message does not match."); 64 | } 65 | } 66 | } -------------------------------------------------------------------------------- /package.ps1: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | $pkgname = "Apache.NMS" 17 | $pkgver = "2.2.0" 18 | $frameworks = "net40", "netstandard2.0" 19 | 20 | write-progress "Creating package directory." "Initializing..." 21 | if (!(test-path package)) { 22 | mkdir package 23 | } 24 | else { 25 | # Clean package content if exists 26 | Remove-Item package\* -Recurse 27 | } 28 | 29 | if (test-path build) { 30 | Push-Location build 31 | 32 | $pkgdir = "..\package" 33 | 34 | write-progress "Packaging Application files." "Scanning..." 35 | $zipfile = "$pkgdir\$pkgname-$pkgver-bin.zip" 36 | 37 | Compress-Archive -Path ..\LICENSE.txt, ..\NOTICE.txt -Update -DestinationPath $zipfile 38 | 39 | # clean up temp 40 | Remove-Item temp -Recurse -ErrorAction Ignore 41 | 42 | foreach ($framework in $frameworks) { 43 | Copy-Item $framework -Destination temp\$framework -Recurse 44 | 45 | # clean up third party binaries 46 | Get-ChildItem temp -File -Exclude "*Apache.NMS*" -Recurse | Remove-Item -Recurse 47 | 48 | Compress-Archive -Path "temp\$framework" -Update -DestinationPath $zipfile 49 | } 50 | 51 | $nupkg = "$pkgname.$pkgver.nupkg" 52 | $nupkgdestination = "$pkgdir\$nupkg" 53 | Copy-Item -Path $nupkg -Destination $nupkgdestination 54 | 55 | $snupkg = "$pkgname.$pkgver.snupkg" 56 | $snupkgdestination = "$pkgdir\$snupkg" 57 | Copy-Item -Path $snupkg -Destination $snupkgdestination 58 | 59 | # clean up temp 60 | Remove-Item temp -Recurse -ErrorAction Inquire 61 | 62 | Pop-Location 63 | } 64 | 65 | write-progress "Packaging Source code files." "Scanning..." 66 | $pkgdir = "package" 67 | $zipfile = "$pkgdir\$pkgname-$pkgver-src.zip" 68 | 69 | # clean temp dir if exists 70 | Remove-Item temp -Recurse -ErrorAction Ignore 71 | 72 | # copy files to temp dir 73 | Copy-Item src -Destination temp\src -Recurse 74 | Copy-Item test -Destination temp\test -Recurse 75 | 76 | # clean up debug artifacts if there are any 77 | Get-ChildItem temp -Include bin, obj -Recurse | Remove-Item -Recurse 78 | 79 | Compress-Archive -Path temp\*, LICENSE.txt, NOTICE.txt, keyfile, nms.sln, package.ps1 -Update -DestinationPath $zipfile 80 | 81 | write-progress "Removing temp files" 82 | Remove-Item temp -Recurse 83 | 84 | write-progress "Packaging Docs" "Scanning..." 85 | $pkgdir = "package" 86 | $zipfile = "$pkgdir\$pkgname-$pkgver-docs.zip" 87 | 88 | Compress-Archive -Path "docs\_site\*", "LICENSE.txt", "NOTICE.txt" -Update -DestinationPath $zipfile 89 | 90 | write-progress -Completed "Packaging" "Complete." 91 | -------------------------------------------------------------------------------- /test/nms-api-test/nms-api-test.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 19 | 20 | 21 | AnyCPU 22 | Library 23 | net40;netstandard2.0 24 | Apache.NMS.Test 25 | Apache.NMS.Test 26 | 27 | 28 | 29 | ..\..\build\ 30 | true 31 | 32 | 33 | 34 | true 35 | Apache.NMS.Test 36 | 2.0.0 37 | Apache ActiveMQ 38 | Apache Software Foundation 39 | Apache NMS API 40 | Apache NMS (.Net Standard Messaging Library) Test Suite 41 | Copyright (C) 2005-2023 Apache Software Foundation 42 | https://activemq.apache.org/components/nms/ 43 | https://github.com/apache/activemq-nms-api/blob/master/LICENSE.txt 44 | https://activemq.apache.org/assets/img/activemq_logo_icon.png 45 | https://github.com/apache/activemq-nms-api 46 | git 47 | apache;activemq;nms;api;net;test;messaging 48 | LICENSE.txt 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | true 58 | ..\..\keyfile\NMSKey.snk 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /test/nms-api-test/NMSPropertyTest.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | using System; 19 | using Apache.NMS.Util; 20 | using NUnit.Framework; 21 | 22 | namespace Apache.NMS.Test 23 | { 24 | [TestFixture] 25 | public class NMSPropertyTest : NMSTestSupport 26 | { 27 | // standard NMS properties 28 | protected string expectedText = "Hey this works!"; 29 | protected string correlationID = "FooBar"; 30 | protected MsgPriority priority = MsgPriority.Normal; 31 | protected String type = "FooType"; 32 | protected String groupID = "BarGroup"; 33 | protected int groupSeq = 1; 34 | 35 | [Test] 36 | public void SendReceiveNMSProperties( 37 | [Values(MsgDeliveryMode.Persistent, MsgDeliveryMode.NonPersistent)] 38 | MsgDeliveryMode deliveryMode) 39 | { 40 | using (IConnection connection = CreateConnection(GetTestClientId())) 41 | { 42 | connection.Start(); 43 | using (ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge)) 44 | { 45 | IDestination destination = CreateDestination(session, DestinationType.Queue); 46 | using (IMessageConsumer consumer = session.CreateConsumer(destination)) 47 | using (IMessageProducer producer = session.CreateProducer(destination)) 48 | { 49 | producer.Priority = priority; 50 | producer.DeliveryMode = deliveryMode; 51 | ITextMessage request = session.CreateTextMessage(expectedText); 52 | 53 | // Set the headers 54 | request.NMSCorrelationID = correlationID; 55 | request.NMSType = type; 56 | request.Properties["NMSXGroupID"] = groupID; 57 | request.Properties["NMSXGroupSeq"] = groupSeq; 58 | 59 | producer.Send(request); 60 | 61 | ITextMessage message = consumer.Receive(receiveTimeout) as ITextMessage; 62 | 63 | Assert.IsNotNull(message, "Did not receive an ITextMessage!"); 64 | Assert.AreEqual(expectedText, message.Text, "Message text does not match."); 65 | 66 | // compare standard NMS headers 67 | Assert.AreEqual(correlationID, message.NMSCorrelationID, "NMSCorrelationID does not match"); 68 | Assert.AreEqual(deliveryMode, message.NMSDeliveryMode, "NMSDeliveryMode does not match"); 69 | Assert.AreEqual(priority, message.NMSPriority, "NMSPriority does not match"); 70 | Assert.AreEqual(type, message.NMSType, "NMSType does not match"); 71 | Assert.AreEqual(groupID, message.Properties["NMSXGroupID"], "NMSXGroupID does not match"); 72 | Assert.AreEqual(groupSeq, message.Properties["NMSXGroupSeq"], "NMSXGroupSeq does not match"); 73 | } 74 | } 75 | } 76 | } 77 | } 78 | } -------------------------------------------------------------------------------- /test/nms-api-test/TempDestinationDeletionTest.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | using System; 19 | using Apache.NMS.Util; 20 | using NUnit.Framework; 21 | 22 | namespace Apache.NMS.Test 23 | { 24 | [TestFixture] 25 | public class TempDestinationTests : NMSTestSupport 26 | { 27 | protected const string QUEUE_DESTINATION_NAME = "queue://TEST.AutoDeleteQueue"; 28 | protected const string TOPIC_DESTINATION_NAME = "topic://TEST.AutoDeleteTopic"; 29 | protected const string TEMP_QUEUE_DESTINATION_NAME = "temp-queue://TEST.AutoDeleteTempQueue"; 30 | protected const string TEMP_TOPIC_DESTINATION_NAME = "temp-topic://TEST.AutoDeleteTempTopic"; 31 | 32 | [Test] 33 | public void TempDestinationDeletionTest( 34 | [Values(MsgDeliveryMode.Persistent, MsgDeliveryMode.NonPersistent)] 35 | MsgDeliveryMode deliveryMode, 36 | [Values(QUEUE_DESTINATION_NAME, TOPIC_DESTINATION_NAME, TEMP_QUEUE_DESTINATION_NAME, 37 | TEMP_TOPIC_DESTINATION_NAME)] 38 | string destinationName) 39 | { 40 | using (IConnection connection1 = CreateConnection(GetTestClientId())) 41 | { 42 | connection1.Start(); 43 | using (ISession session = connection1.CreateSession(AcknowledgementMode.AutoAcknowledge)) 44 | { 45 | const int MaxNumDestinations = 100; 46 | 47 | for (int index = 1; index <= MaxNumDestinations; index++) 48 | { 49 | IDestination destination = CreateDestination(session, destinationName); 50 | 51 | using (IMessageProducer producer = session.CreateProducer(destination)) 52 | using (IMessageConsumer consumer = session.CreateConsumer(destination)) 53 | { 54 | producer.DeliveryMode = deliveryMode; 55 | 56 | IMessage request = session.CreateTextMessage("Hello World, Just Passing Through!"); 57 | 58 | request.NMSType = "TEMP_MSG"; 59 | producer.Send(request); 60 | IMessage receivedMsg = consumer.Receive(TimeSpan.FromMilliseconds(5000)); 61 | Assert.IsNotNull(receivedMsg); 62 | Assert.AreEqual(receivedMsg.NMSType, "TEMP_MSG"); 63 | 64 | // Ensures that Consumer closes out its subscription 65 | consumer.Close(); 66 | } 67 | 68 | try 69 | { 70 | session.DeleteDestination(destination); 71 | } 72 | catch (NotSupportedException) 73 | { 74 | // Might as well not try this again. 75 | break; 76 | } 77 | } 78 | } 79 | } 80 | } 81 | } 82 | } -------------------------------------------------------------------------------- /src/nms-api/NMSException.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | using System; 19 | 20 | namespace Apache.NMS 21 | { 22 | /// 23 | /// Represents an NMS exception 24 | /// 25 | [Serializable] 26 | public class NMSException : Exception 27 | { 28 | protected string exceptionErrorCode; 29 | 30 | public NMSException() 31 | : base() 32 | { 33 | } 34 | 35 | public NMSException(string message) 36 | : base(message) 37 | { 38 | } 39 | 40 | public NMSException(string message, string errorCode) 41 | : this(message) 42 | { 43 | exceptionErrorCode = errorCode; 44 | } 45 | 46 | public NMSException(string message, Exception innerException) 47 | : base(message, innerException) 48 | { 49 | } 50 | 51 | public NMSException(string message, string errorCode, Exception innerException) 52 | : base(message, innerException) 53 | { 54 | exceptionErrorCode = errorCode; 55 | } 56 | 57 | #region ISerializable interface implementation 58 | 59 | #if !NETCF 60 | 61 | /// 62 | /// Initializes a new instance of the NMSException class with serialized data. 63 | /// Throws System.ArgumentNullException if the info parameter is null. 64 | /// Throws System.Runtime.Serialization.SerializationException if the class name is null or System.Exception.HResult is zero (0). 65 | /// 66 | /// The SerializationInfo that holds the serialized object data about the exception being thrown. 67 | /// The StreamingContext that contains contextual information about the source or destination. 68 | protected NMSException(System.Runtime.Serialization.SerializationInfo info, 69 | System.Runtime.Serialization.StreamingContext context) 70 | : base(info, context) 71 | { 72 | exceptionErrorCode = info.GetString("NMSException.exceptionErrorCode"); 73 | } 74 | 75 | /// 76 | /// When overridden in a derived class, sets the SerializationInfo with information about the exception. 77 | /// 78 | /// The SerializationInfo that holds the serialized object data about the exception being thrown. 79 | /// The StreamingContext that contains contextual information about the source or destination. 80 | public override void GetObjectData(System.Runtime.Serialization.SerializationInfo info, 81 | System.Runtime.Serialization.StreamingContext context) 82 | { 83 | base.GetObjectData(info, context); 84 | info.AddValue("NMSException.exceptionErrorCode", exceptionErrorCode); 85 | } 86 | 87 | #endif 88 | 89 | #endregion 90 | 91 | /// 92 | /// Returns the error code for the exception, if one has been provided. 93 | /// 94 | public string ErrorCode 95 | { 96 | get { return exceptionErrorCode; } 97 | } 98 | } 99 | } -------------------------------------------------------------------------------- /src/nms-api/nms-api.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 19 | 20 | 21 | AnyCPU 22 | Library 23 | net40;netstandard2.0 24 | Apache.NMS 25 | Apache.NMS 26 | 27 | 28 | 29 | ..\..\build\ 30 | true 31 | 32 | 33 | 34 | true 35 | Apache.NMS 36 | 2.2.0 37 | Apache ActiveMQ 38 | Apache Software Foundation 39 | Apache NMS API 40 | Apache NMS (.Net Standard Messaging Library): An abstract interface to Message Oriented Middleware (MOM) providers 41 | Copyright (C) 2005-2025 Apache Software Foundation 42 | https://activemq.apache.org/components/nms/ 43 | https://github.com/apache/activemq-nms-api/blob/master/LICENSE.txt 44 | https://activemq.apache.org/assets/img/activemq_logo_icon.png 45 | https://github.com/apache/activemq-nms-api 46 | git 47 | apache;activemq;nms;api;net;messaging 48 | LICENSE.txt 49 | 50 | 51 | 52 | 53 | 54 | true 55 | 56 | true 57 | snupkg 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | true 77 | ..\..\keyfile\NMSKey.snk 78 | 79 | 80 | -------------------------------------------------------------------------------- /src/nms-api/SessionExtensions.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | using System.Text; 19 | using Apache.NMS.Util; 20 | 21 | namespace Apache.NMS 22 | { 23 | #if NET_3_5 || MONO 24 | public static class SessionExtensions 25 | { 26 | /// 27 | /// Extension function to create a text message from an object. The object must be serializable to XML. 28 | /// 29 | public static ITextMessage CreateXmlMessage(this ISession session, object obj) 30 | { 31 | return NMSConvert.SerializeObjToMessage(session.CreateTextMessage(), obj); 32 | } 33 | 34 | /// 35 | /// Extension function to get the destination by parsing the embedded type prefix. Default is Queue if no prefix is 36 | /// embedded in the destinationName. 37 | /// 38 | public static IDestination GetDestination(this ISession session, string destinationName) 39 | { 40 | return SessionUtil.GetDestination(session, destinationName); 41 | } 42 | 43 | /// 44 | /// Extension function to get the destination by parsing the embedded type prefix. 45 | /// 46 | public static IDestination GetDestination(this ISession session, string destinationName, DestinationType defaultType) 47 | { 48 | return SessionUtil.GetDestination(session, destinationName, defaultType); 49 | } 50 | 51 | /// 52 | /// Extension function to get the destination by parsing the embedded type prefix. 53 | /// 54 | public static IQueue GetQueue(this ISession session, string queueName) 55 | { 56 | return SessionUtil.GetQueue(session, queueName); 57 | } 58 | 59 | /// 60 | /// Extension function to get the destination by parsing the embedded type prefix. 61 | /// 62 | public static ITopic GetTopic(this ISession session, string topicName) 63 | { 64 | return SessionUtil.GetTopic(session, topicName); 65 | } 66 | 67 | /// 68 | /// Extension function to delete the named destination by parsing the embedded type prefix. Default is Queue if no prefix is 69 | /// embedded in the destinationName. 70 | /// 71 | public static void DeleteDestination(this ISession session, string destinationName) 72 | { 73 | SessionUtil.DeleteDestination(session, destinationName); 74 | } 75 | 76 | /// 77 | /// Extension function to delete the named destination by parsing the embedded type prefix. 78 | /// 79 | public static void DeleteDestination(this ISession session, string destinationName, DestinationType defaultType) 80 | { 81 | SessionUtil.DeleteDestination(session, destinationName, defaultType); 82 | } 83 | 84 | /// 85 | /// Extension function to delete the named destination by parsing the embedded type prefix. 86 | /// 87 | public static void DeleteQueue(this ISession session, string queueName) 88 | { 89 | SessionUtil.DeleteDestination(session, queueName); 90 | } 91 | 92 | /// 93 | /// Extension function to delete the named destination by parsing the embedded type prefix. 94 | /// 95 | public static void DeleteTopic(this ISession session, string topicName) 96 | { 97 | SessionUtil.DeleteDestination(session, topicName); 98 | } 99 | } 100 | #endif 101 | } -------------------------------------------------------------------------------- /src/nms-api/INMSConsumer.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | using System; 19 | using System.Threading.Tasks; 20 | 21 | namespace Apache.NMS 22 | { 23 | /// 24 | /// An object capable of sending messages to some destination 25 | /// https://www.oracle.com/technical-resources/articles/java/jms20.html 26 | /// 27 | public interface INMSConsumer : System.IDisposable 28 | { 29 | /// 30 | /// Waits until a message is available and returns it 31 | /// 32 | IMessage Receive(); 33 | 34 | /// 35 | /// Waits until a message is available and returns it 36 | /// 37 | Task ReceiveAsync(); 38 | 39 | /// 40 | /// If a message is available within the timeout duration it is returned otherwise this method returns null 41 | /// 42 | IMessage Receive(TimeSpan timeout); 43 | 44 | /// 45 | /// If a message is available within the timeout duration it is returned otherwise this method returns null 46 | /// 47 | Task ReceiveAsync(TimeSpan timeout); 48 | 49 | /// 50 | /// Receives the next message if one is immediately available for delivery on the client side 51 | /// otherwise this method returns null. It is never an error for this method to return null, the 52 | /// time of Message availability varies so your client cannot rely on this method to receive a 53 | /// message immediately after one has been sent. 54 | /// 55 | IMessage ReceiveNoWait(); 56 | 57 | 58 | T ReceiveBody(); 59 | 60 | Task ReceiveBodyAsync(); 61 | 62 | T ReceiveBody(TimeSpan timeout); 63 | 64 | Task ReceiveBodyAsync(TimeSpan timeout); 65 | 66 | T ReceiveBodyNoWait(); 67 | 68 | string MessageSelector { get; } 69 | 70 | /// 71 | /// A listener which can be used to consume messages 72 | /// 73 | event MessageListener Listener; 74 | 75 | /// 76 | /// An asynchronous listener which can be used to consume messages asynchronously 77 | /// 78 | event AsyncMessageListener AsyncListener; 79 | 80 | /// 81 | /// Closes the message consumer. 82 | /// 83 | /// 84 | /// Clients should close message consumers when they are not needed. 85 | /// This call blocks until a receive or message listener in progress has completed. 86 | /// A blocked message consumer receive call returns null when this message consumer is closed. 87 | /// 88 | void Close(); 89 | 90 | /// 91 | /// Closes the message consumer. 92 | /// 93 | /// 94 | /// Clients should close message consumers when they are not needed. 95 | /// 96 | Task CloseAsync(); 97 | 98 | /// 99 | /// A Delegate that is called each time a Message is dispatched to allow the client to do 100 | /// any necessary transformations on the received message before it is delivered. 101 | /// 102 | ConsumerTransformerDelegate ConsumerTransformer { get; set; } 103 | } 104 | } -------------------------------------------------------------------------------- /src/nms-api/Util/MessagePropertyIntercepter.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | using System; 19 | using System.Reflection; 20 | 21 | namespace Apache.NMS.Util 22 | { 23 | /// 24 | /// Utility class used to set NMS properties via introspection for IMessage derived 25 | /// instances. This class allows IMessage classes to define Message specific properties 26 | /// that can be accessed using the standard property get / set semantics. 27 | /// 28 | /// This is especially useful for NMSX type properties which can vary by provider and 29 | /// are obtianed via a call to IConnectionMetaData.NMSXPropertyNames. The client can 30 | /// set the properties on an IMessage instance without a direct cast to the providers 31 | /// specific Message types. 32 | /// 33 | /// Properties accessed in this way are treated as NMS Message headers which are never 34 | /// read-only therefore there is no exception thrown if the message itself is in the 35 | /// read-only property mode. 36 | /// 37 | public class MessagePropertyIntercepter : PrimitiveMapInterceptor 38 | { 39 | private const BindingFlags publicBinding = BindingFlags.Public | BindingFlags.Instance; 40 | private readonly Type messageType; 41 | 42 | public MessagePropertyIntercepter(IMessage message, IPrimitiveMap properties) 43 | : base(message, properties) 44 | { 45 | this.messageType = message.GetType(); 46 | } 47 | 48 | public MessagePropertyIntercepter(IMessage message, IPrimitiveMap properties, bool readOnly) 49 | : base(message, properties, readOnly) 50 | { 51 | this.messageType = message.GetType(); 52 | } 53 | 54 | protected override object GetObjectProperty(string name) 55 | { 56 | PropertyInfo propertyInfo = this.messageType.GetProperty(name, publicBinding); 57 | 58 | if (name.StartsWith("NMS")) 59 | { 60 | if (null != propertyInfo && propertyInfo.CanRead) 61 | { 62 | return propertyInfo.GetValue(this.message, null); 63 | } 64 | else 65 | { 66 | FieldInfo fieldInfo = this.messageType.GetField(name, publicBinding); 67 | 68 | if (null != fieldInfo) 69 | { 70 | return fieldInfo.GetValue(this.message); 71 | } 72 | } 73 | } 74 | 75 | return base.GetObjectProperty(name); 76 | } 77 | 78 | protected override void SetObjectProperty(string name, object value) 79 | { 80 | PropertyInfo propertyInfo = this.messageType.GetProperty(name, publicBinding); 81 | 82 | if (!name.StartsWith("NMS")) 83 | { 84 | base.SetObjectProperty(name, value); 85 | } 86 | else if (null != propertyInfo && propertyInfo.CanWrite) 87 | { 88 | propertyInfo.SetValue(this.message, value, null); 89 | } 90 | else 91 | { 92 | FieldInfo fieldInfo = this.messageType.GetField(name, publicBinding); 93 | 94 | if (null != fieldInfo && !fieldInfo.IsLiteral && !fieldInfo.IsInitOnly) 95 | { 96 | fieldInfo.SetValue(this.message, value); 97 | } 98 | else 99 | { 100 | base.SetObjectProperty(name, value); 101 | } 102 | } 103 | } 104 | } 105 | } -------------------------------------------------------------------------------- /src/nms-api/IRedeliveryPolicy.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | using System; 19 | 20 | namespace Apache.NMS 21 | { 22 | public interface IRedeliveryPolicy : ICloneable 23 | { 24 | /// 25 | /// Gets or sets the collision avoidance percent. This causes the redelivery delay 26 | /// to be adjusted in order to avoid possible collision when messages are redelivered 27 | /// to concurrent consumers. 28 | /// 29 | /// The collision avoidance factor. 30 | int CollisionAvoidancePercent { get; set; } 31 | 32 | /// 33 | /// Gets or sets a value indicating whether to [use collision avoidance]. 34 | /// 35 | /// 36 | /// true if [use collision avoidance]; otherwise, false. 37 | /// 38 | bool UseCollisionAvoidance { get; set; } 39 | 40 | /// 41 | /// The time in milliseconds to initially delay a redelivery 42 | /// 43 | /// The initial redelivery delay. 44 | int InitialRedeliveryDelay { get; set; } 45 | 46 | /// 47 | /// Gets or sets the maximum redeliveries. A value less than zero indicates 48 | /// that there is no maximum and the NMS provider should retry forever. 49 | /// 50 | /// The maximum redeliveries. 51 | int MaximumRedeliveries { get; set; } 52 | 53 | /// 54 | /// The time in milliseconds to delay a redelivery 55 | /// 56 | /// The redelivered counter. 57 | /// 58 | int RedeliveryDelay(int redeliveredCounter); 59 | 60 | /// 61 | /// Gets or sets a value indicating whether [use exponential back off]. 62 | /// 63 | /// 64 | /// true if [use exponential back off]; otherwise, false. 65 | /// 66 | bool UseExponentialBackOff { get; set; } 67 | 68 | /// 69 | /// Gets or sets the back off multiplier. 70 | /// 71 | /// The back off multiplier. 72 | int BackOffMultiplier { get; set; } 73 | 74 | /// 75 | /// Returns the provider-specific outcome to use when a message is rejected by the client 76 | /// after reaching the maximum redelivery threshold for the specified destination. 77 | /// 78 | /// The returned integer should map to an outcome defined by the specific provider implementation: 79 | /// 80 | /// For AMQP: 81 | /// 0 - ACCEPTED 82 | /// 1 - REJECTED 83 | /// 2 - RELEASED 84 | /// 3 - MODIFIED_FAILED 85 | /// 4 - MODIFIED_UNDELIVERABLE_HERE 86 | /// 87 | /// For OpenWire: 88 | /// 0 - DeliveredAck 89 | /// 1 - PoisonAck 90 | /// 2 - ConsumedAck 91 | /// 3 - RedeliveredAck 92 | /// 4 - IndividualAck 93 | /// 5 - UnmatchedAck 94 | /// 6 - ExpiredAck 95 | /// 96 | /// It is the responsibility of the provider to interpret the returned value appropriately. 97 | /// 98 | /// The destination the message was received from. 99 | /// An integer representing the provider-specific outcome code. 100 | int GetOutcome(IDestination destination); 101 | } 102 | } -------------------------------------------------------------------------------- /test/nms-api-test/ProducerTest.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | using System; 19 | using NUnit.Framework; 20 | 21 | namespace Apache.NMS.Test 22 | { 23 | [TestFixture] 24 | public class ProducerTest : NMSTestSupport 25 | { 26 | [Test] 27 | public void TestProducerSendToNullDestinationWithoutDefault() 28 | { 29 | using (IConnection connection = CreateConnection(GetTestClientId())) 30 | { 31 | connection.Start(); 32 | using (ISession session = connection.CreateSession()) 33 | { 34 | IMessageProducer producer = session.CreateProducer(null); 35 | 36 | try 37 | { 38 | producer.Send(null, session.CreateTextMessage("Message")); 39 | Assert.Fail("Producer should have thrown an NotSupportedException"); 40 | } 41 | catch (NotSupportedException) 42 | { 43 | } 44 | catch (Exception ex) 45 | { 46 | Assert.Fail("Wrong Exception Type Thrown: " + ex.GetType().Name); 47 | } 48 | } 49 | } 50 | } 51 | 52 | [Test] 53 | public void TestProducerSendToNullDestinationWithDefault() 54 | { 55 | using (IConnection connection = CreateConnection(GetTestClientId())) 56 | { 57 | connection.Start(); 58 | using (ISession session = connection.CreateSession()) 59 | { 60 | IDestination unusedDest = session.CreateTemporaryQueue(); 61 | 62 | IMessageProducer producer = session.CreateProducer(unusedDest); 63 | 64 | try 65 | { 66 | producer.Send(null, session.CreateTextMessage("Message")); 67 | Assert.Fail("Producer should have thrown an InvalidDestinationException"); 68 | } 69 | catch (InvalidDestinationException) 70 | { 71 | } 72 | catch (Exception ex) 73 | { 74 | Assert.Fail("Wrong Exception Type Thrown: " + ex.GetType().Name); 75 | } 76 | } 77 | } 78 | } 79 | 80 | [Test] 81 | public void TestProducerSendToNonDefaultDestination() 82 | { 83 | using (IConnection connection = CreateConnection(GetTestClientId())) 84 | { 85 | connection.Start(); 86 | using (ISession session = connection.CreateSession()) 87 | { 88 | IDestination unusedDest = session.CreateTemporaryQueue(); 89 | IDestination usedDest = session.CreateTemporaryQueue(); 90 | 91 | IMessageProducer producer = session.CreateProducer(unusedDest); 92 | 93 | try 94 | { 95 | producer.Send(usedDest, session.CreateTextMessage("Message")); 96 | Assert.Fail("Producer should have thrown an NotSupportedException"); 97 | } 98 | catch (NotSupportedException) 99 | { 100 | } 101 | catch (Exception ex) 102 | { 103 | Assert.Fail("Wrong Exception Type Thrown: " + ex.GetType().Name); 104 | } 105 | } 106 | } 107 | } 108 | } 109 | } -------------------------------------------------------------------------------- /src/nms-api/Tracer.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | namespace Apache.NMS 19 | { 20 | public sealed class Tracer 21 | { 22 | private static ITrace s_trace = null; 23 | 24 | // prevent instantiation of this class. All methods are static. 25 | private Tracer() 26 | { 27 | } 28 | 29 | public static ITrace Trace 30 | { 31 | get { return s_trace; } 32 | set { s_trace = value; } 33 | } 34 | 35 | public static bool IsDebugEnabled 36 | { 37 | get { return s_trace != null && s_trace.IsDebugEnabled; } 38 | } 39 | 40 | public static bool IsInfoEnabled 41 | { 42 | get { return s_trace != null && s_trace.IsInfoEnabled; } 43 | } 44 | 45 | public static bool IsWarnEnabled 46 | { 47 | get { return s_trace != null && s_trace.IsWarnEnabled; } 48 | } 49 | 50 | public static bool IsErrorEnabled 51 | { 52 | get { return s_trace != null && s_trace.IsErrorEnabled; } 53 | } 54 | 55 | public static bool IsFatalEnabled 56 | { 57 | get { return s_trace != null && s_trace.IsFatalEnabled; } 58 | } 59 | 60 | public static void Debug(object message) 61 | { 62 | if (IsDebugEnabled) 63 | { 64 | s_trace.Debug(message.ToString()); 65 | } 66 | } 67 | 68 | public static void DebugFormat(string format, params object[] args) 69 | { 70 | if (IsDebugEnabled) 71 | { 72 | s_trace.Debug(string.Format(format, args)); 73 | } 74 | } 75 | 76 | public static void Info(object message) 77 | { 78 | if (IsInfoEnabled) 79 | { 80 | s_trace.Info(message.ToString()); 81 | } 82 | } 83 | 84 | public static void InfoFormat(string format, params object[] args) 85 | { 86 | if (IsInfoEnabled) 87 | { 88 | s_trace.Info(string.Format(format, args)); 89 | } 90 | } 91 | 92 | public static void Warn(object message) 93 | { 94 | if (IsWarnEnabled) 95 | { 96 | s_trace.Warn(message.ToString()); 97 | } 98 | } 99 | 100 | public static void WarnFormat(string format, params object[] args) 101 | { 102 | if (IsWarnEnabled) 103 | { 104 | s_trace.Warn(string.Format(format, args)); 105 | } 106 | } 107 | 108 | public static void Error(object message) 109 | { 110 | if (IsErrorEnabled) 111 | { 112 | s_trace.Error(message.ToString()); 113 | } 114 | } 115 | 116 | public static void ErrorFormat(string format, params object[] args) 117 | { 118 | if (IsErrorEnabled) 119 | { 120 | s_trace.Error(string.Format(format, args)); 121 | } 122 | } 123 | 124 | public static void Fatal(object message) 125 | { 126 | if (IsFatalEnabled) 127 | { 128 | s_trace.Fatal(message.ToString()); 129 | } 130 | } 131 | 132 | public static void FatalFormat(string format, params object[] args) 133 | { 134 | if (IsFatalEnabled) 135 | { 136 | s_trace.Fatal(string.Format(format, args)); 137 | } 138 | } 139 | } 140 | } -------------------------------------------------------------------------------- /src/nms-api/Util/EndianSupport.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | using System; 19 | using System.IO; 20 | 21 | namespace Apache.NMS.Util 22 | { 23 | /// 24 | /// Support class that switches from one endian to the other. 25 | /// 26 | [CLSCompliant(false)] 27 | public class EndianSupport 28 | { 29 | public static char SwitchEndian(char x) 30 | { 31 | return (char) ( 32 | (((char) ((byte) (x))) << 8) | 33 | (((char) ((byte) (x >> 8)))) 34 | ); 35 | } 36 | 37 | public static short SwitchEndian(short x) 38 | { 39 | return (short) ( 40 | (((ushort) ((byte) (x))) << 8) | 41 | (((ushort) ((byte) (x >> 8)))) 42 | ); 43 | } 44 | 45 | public static int SwitchEndian(int x) 46 | { 47 | return 48 | (((int) ((byte) (x))) << 24) | 49 | (((int) ((byte) (x >> 8))) << 16) | 50 | (((int) ((byte) (x >> 16))) << 8) | 51 | (((int) ((byte) (x >> 24)))); 52 | } 53 | 54 | public static long SwitchEndian(long x) 55 | { 56 | return 57 | (((long) ((byte) (x))) << 56) | 58 | (((long) ((byte) (x >> 8))) << 48) | 59 | (((long) ((byte) (x >> 16))) << 40) | 60 | (((long) ((byte) (x >> 24))) << 32) | 61 | (((long) ((byte) (x >> 32))) << 24) | 62 | (((long) ((byte) (x >> 40))) << 16) | 63 | (((long) ((byte) (x >> 48))) << 8) | 64 | (((long) ((byte) (x >> 56)))); 65 | } 66 | 67 | public static ushort SwitchEndian(ushort x) 68 | { 69 | return (ushort) ( 70 | (((ushort) ((byte) (x))) << 8) | 71 | (((ushort) ((byte) (x >> 8)))) 72 | ); 73 | } 74 | 75 | public static uint SwitchEndian(uint x) 76 | { 77 | return 78 | (((uint) ((byte) (x))) << 24) | 79 | (((uint) ((byte) (x >> 8))) << 16) | 80 | (((uint) ((byte) (x >> 16))) << 8) | 81 | (((uint) ((byte) (x >> 24)))); 82 | } 83 | 84 | public static ulong SwitchEndian(ulong x) 85 | { 86 | return 87 | (((ulong) ((byte) (x))) << 56) | 88 | (((ulong) ((byte) (x >> 8))) << 48) | 89 | (((ulong) ((byte) (x >> 16))) << 40) | 90 | (((ulong) ((byte) (x >> 24))) << 32) | 91 | (((ulong) ((byte) (x >> 32))) << 24) | 92 | (((ulong) ((byte) (x >> 40))) << 16) | 93 | (((ulong) ((byte) (x >> 48))) << 8) | 94 | (((ulong) ((byte) (x >> 56)))); 95 | } 96 | 97 | public static double SwitchEndian(double x) 98 | { 99 | MemoryStream ms = new MemoryStream(); 100 | BinaryWriter bw = new BinaryWriter(ms); 101 | bw.Write(x); 102 | bw.Flush(); 103 | ms = new MemoryStream(SwitchEndian(ms.ToArray())); 104 | BinaryReader br = new BinaryReader(ms); 105 | return br.ReadDouble(); 106 | } 107 | 108 | 109 | public static float SwitchEndian(float x) 110 | { 111 | MemoryStream ms = new MemoryStream(); 112 | BinaryWriter bw = new BinaryWriter(ms); 113 | bw.Write(x); 114 | bw.Flush(); 115 | ms = new MemoryStream(SwitchEndian(ms.ToArray())); 116 | BinaryReader br = new BinaryReader(ms); 117 | return br.ReadSingle(); 118 | } 119 | 120 | 121 | public static byte[] SwitchEndian(byte[] x) 122 | { 123 | byte[] rc = new byte[x.Length]; 124 | int j = x.Length - 1; 125 | for (int i = 0; i < x.Length; i++) 126 | { 127 | rc[i] = x[j]; 128 | j--; 129 | } 130 | 131 | return rc; 132 | } 133 | } 134 | } -------------------------------------------------------------------------------- /test/nms-api-test/EndianTest.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | using System.IO; 19 | using Apache.NMS.Util; 20 | using NUnit.Framework; 21 | 22 | namespace Apache.NMS.Test 23 | { 24 | [TestFixture] 25 | public class EndianTest 26 | { 27 | [Test] 28 | public void TestLongEndian() 29 | { 30 | long value = 0x0102030405060708L; 31 | long newValue = EndianSupport.SwitchEndian(value); 32 | Assert.AreEqual(0x0807060504030201L, newValue); 33 | long actual = EndianSupport.SwitchEndian(newValue); 34 | Assert.AreEqual(value, actual); 35 | } 36 | 37 | [Test] 38 | public void TestIntEndian() 39 | { 40 | int value = 0x12345678; 41 | int newValue = EndianSupport.SwitchEndian(value); 42 | Assert.AreEqual(0x78563412, newValue); 43 | int actual = EndianSupport.SwitchEndian(newValue); 44 | Assert.AreEqual(value, actual); 45 | } 46 | 47 | [Test] 48 | public void TestCharEndian() 49 | { 50 | char value = 'J'; 51 | char newValue = EndianSupport.SwitchEndian(value); 52 | char actual = EndianSupport.SwitchEndian(newValue); 53 | Assert.AreEqual(value, actual); 54 | } 55 | 56 | [Test] 57 | public void TestShortEndian() 58 | { 59 | short value = 0x1234; 60 | short newValue = EndianSupport.SwitchEndian(value); 61 | Assert.AreEqual(0x3412, newValue); 62 | short actual = EndianSupport.SwitchEndian(newValue); 63 | Assert.AreEqual(value, actual); 64 | } 65 | 66 | [Test] 67 | public void TestNegativeLongEndian() 68 | { 69 | long value = -0x0102030405060708L; 70 | long newValue = EndianSupport.SwitchEndian(value); 71 | long actual = EndianSupport.SwitchEndian(newValue); 72 | Assert.AreEqual(value, actual); 73 | } 74 | 75 | [Test] 76 | public void TestNegativeIntEndian() 77 | { 78 | int value = -0x12345678; 79 | int newValue = EndianSupport.SwitchEndian(value); 80 | int actual = EndianSupport.SwitchEndian(newValue); 81 | Assert.AreEqual(value, actual); 82 | } 83 | 84 | [Test] 85 | public void TestNegativeShortEndian() 86 | { 87 | short value = -0x1234; 88 | short newValue = EndianSupport.SwitchEndian(value); 89 | short actual = EndianSupport.SwitchEndian(newValue); 90 | Assert.AreEqual(value, actual); 91 | } 92 | 93 | [Test] 94 | public void TestFloatDontNeedEndianSwitch() 95 | { 96 | float value = -1.223F; 97 | 98 | // Convert to int so we can compare to Java version. 99 | MemoryStream ms = new MemoryStream(4); 100 | BinaryWriter bw = new BinaryWriter(ms); 101 | bw.Write(value); 102 | bw.Close(); 103 | ms = new MemoryStream(ms.ToArray()); 104 | BinaryReader br = new BinaryReader(ms); 105 | 106 | // System.out.println(Integer.toString(Float.floatToIntBits(-1.223F), 16)); 107 | Assert.AreEqual(-0x406374bc, br.ReadInt32()); 108 | } 109 | 110 | [Test] 111 | public void TestDoublDontNeedEndianSwitch() 112 | { 113 | double value = -1.223D; 114 | 115 | // Convert to int so we can compare to Java version. 116 | MemoryStream ms = new MemoryStream(4); 117 | BinaryWriter bw = new BinaryWriter(ms); 118 | bw.Write(value); 119 | bw.Close(); 120 | ms = new MemoryStream(ms.ToArray()); 121 | BinaryReader br = new BinaryReader(ms); 122 | long longVersion = br.ReadInt64(); 123 | 124 | // System.out.println(Long.toString(Double.doubleToLongBits(-1.223D), 16)); 125 | Assert.AreEqual(-0x400c6e978d4fdf3b, longVersion); 126 | } 127 | } 128 | } -------------------------------------------------------------------------------- /src/nms-api/IMessageConsumer.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | using System.Threading; 19 | using System.Threading.Tasks; 20 | 21 | namespace Apache.NMS 22 | { 23 | /// 24 | /// A delegate that can receive messages. 25 | /// 26 | public delegate void MessageListener(IMessage message); 27 | 28 | /// 29 | /// A delegate that can receive messages asynchronously. 30 | /// 31 | public delegate Task AsyncMessageListener(IMessage message, CancellationToken cancellationToken); 32 | 33 | /// 34 | /// A delegate that a client can register that will be called each time a consumer dispatches a message 35 | /// to the client code to allow the client to Transform a received message from one type to another, 36 | /// StreamMessage to TextMessage, ObjectMessage to TextMessage containing XML, etc. This allows a 37 | /// client to create a consumer that will automatically transform a message to a type that the client is 38 | /// capable of processing or adding additional information to a received message. For messages that do 39 | /// not need to be processed the client should return null from this method, in this case the original 40 | /// message will be dispatched to the client. 41 | /// 42 | public delegate IMessage ConsumerTransformerDelegate(ISession session, IMessageConsumer consumer, IMessage message); 43 | 44 | /// 45 | /// A consumer of messages 46 | /// 47 | public interface IMessageConsumer : System.IDisposable 48 | { 49 | /// 50 | /// Waits until a message is available and returns it 51 | /// 52 | IMessage Receive(); 53 | 54 | /// 55 | /// Waits until a message is available and returns it 56 | /// 57 | Task ReceiveAsync(); 58 | 59 | /// 60 | /// If a message is available within the timeout duration it is returned otherwise this method returns null 61 | /// 62 | IMessage Receive(System.TimeSpan timeout); 63 | 64 | /// 65 | /// If a message is available within the timeout duration it is returned otherwise this method returns null 66 | /// 67 | Task ReceiveAsync(System.TimeSpan timeout); 68 | 69 | /// 70 | /// Receives the next message if one is immediately available for delivery on the client side 71 | /// otherwise this method returns null. It is never an error for this method to return null, the 72 | /// time of Message availability varies so your client cannot rely on this method to receive a 73 | /// message immediately after one has been sent. 74 | /// 75 | IMessage ReceiveNoWait(); 76 | 77 | /// 78 | /// An listener which can be used to consume messages 79 | /// 80 | event MessageListener Listener; 81 | 82 | /// 83 | /// An asynchronous listener which can be used to consume messages asynchronously 84 | /// 85 | event AsyncMessageListener AsyncListener; 86 | 87 | /// 88 | /// Closes the message consumer. 89 | /// 90 | /// 91 | /// Clients should close message consumers them when they are not needed. 92 | /// This call blocks until a receive or message listener in progress has completed. 93 | /// A blocked message consumer receive call returns null when this message consumer is closed. 94 | /// 95 | void Close(); 96 | 97 | /// 98 | /// Closes the message consumer. 99 | /// 100 | /// 101 | /// Clients should close message consumers when they are not needed. 102 | /// 103 | Task CloseAsync(); 104 | 105 | /// 106 | /// A Delegate that is called each time a Message is dispatched to allow the client to do 107 | /// any necessary transformations on the received message before it is delivered. 108 | /// 109 | ConsumerTransformerDelegate ConsumerTransformer { get; set; } 110 | 111 | string MessageSelector { get; } 112 | } 113 | } -------------------------------------------------------------------------------- /src/nms-api/IConnectionFactory.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | using System; 19 | using System.Threading.Tasks; 20 | 21 | namespace Apache.NMS 22 | { 23 | /// 24 | /// A Factory of IConnection objects 25 | /// 26 | public interface IConnectionFactory 27 | { 28 | /// 29 | /// Creates a new connection 30 | /// 31 | IConnection CreateConnection(); 32 | 33 | /// 34 | /// Creates a new connection with the given user name and password 35 | /// 36 | IConnection CreateConnection(string userName, string password); 37 | 38 | /// 39 | /// Creates a new connection 40 | /// 41 | Task CreateConnectionAsync(); 42 | 43 | /// 44 | /// Creates a new connection with the given user name and password 45 | /// 46 | Task CreateConnectionAsync(string userName, string password); 47 | 48 | /// 49 | /// Creates a new context 50 | /// 51 | INMSContext CreateContext(); 52 | 53 | /// 54 | /// Creates a new context with the given acknowledgement mode. 55 | /// 56 | INMSContext CreateContext(AcknowledgementMode acknowledgementMode); 57 | 58 | /// 59 | /// Creates a new context with the given user name and password 60 | /// 61 | INMSContext CreateContext(string userName, string password); 62 | 63 | /// 64 | /// Creates a new context with the given user name, password and acknowledgement mode 65 | /// 66 | INMSContext CreateContext(string userName, string password, AcknowledgementMode acknowledgementMode); 67 | 68 | /// 69 | /// Creates a new context 70 | /// 71 | Task CreateContextAsync(); 72 | 73 | /// 74 | /// Creates a new context with the given acknowledgement mode. 75 | /// 76 | Task CreateContextAsync(AcknowledgementMode acknowledgementMode); 77 | 78 | /// 79 | /// Creates a new context with the given user name and password 80 | /// 81 | Task CreateContextAsync(string userName, string password); 82 | 83 | /// 84 | /// Creates a new context with the given user name, password and acknowledgement mode 85 | /// 86 | Task CreateContextAsync(string userName, string password, AcknowledgementMode acknowledgementMode); 87 | 88 | /// 89 | /// Get/or set the broker Uri. 90 | /// 91 | Uri BrokerUri { get; set; } 92 | 93 | /// 94 | /// Get/or set the redelivery policy that new IConnection objects are 95 | /// assigned upon creation. 96 | /// 97 | IRedeliveryPolicy RedeliveryPolicy { get; set; } 98 | 99 | /// 100 | /// A Delegate that is called each time a Message is dispatched to allow the client to do 101 | /// any necessary transformations on the received message before it is delivered. The 102 | /// ConnectionFactory sets the provided delegate instance on each Connection instance that 103 | /// is created from this factory, each connection in turn passes the delegate along to each 104 | /// Session it creates which then passes that along to the Consumers it creates. 105 | /// 106 | ConsumerTransformerDelegate ConsumerTransformer { get; set; } 107 | 108 | /// 109 | /// A delegate that is called each time a Message is sent from this Producer which allows 110 | /// the application to perform any needed transformations on the Message before it is sent. 111 | /// The ConnectionFactory sets the provided delegate instance on each Connection instance that 112 | /// is created from this factory, each connection in turn passes the delegate along to each 113 | /// Session it creates which then passes that along to the Producers it creates. 114 | /// 115 | ProducerTransformerDelegate ProducerTransformer { get; set; } 116 | } 117 | } -------------------------------------------------------------------------------- /test/nms-api-test/MessageTransformerTest.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | using System; 19 | using Apache.NMS.Util; 20 | using NUnit.Framework; 21 | 22 | namespace Apache.NMS.Test 23 | { 24 | [TestFixture] 25 | public class MessageTransformerTest : NMSTestSupport 26 | { 27 | private string propertyName = "ADDITIONAL-PROPERTY"; 28 | private string propertyValue = "ADDITIONAL-PROPERTY-VALUE"; 29 | 30 | [Test] 31 | public void TestProducerTransformer( 32 | [Values(MsgDeliveryMode.Persistent, MsgDeliveryMode.NonPersistent)] 33 | MsgDeliveryMode deliveryMode) 34 | { 35 | using (IConnection connection = CreateConnection()) 36 | { 37 | connection.Start(); 38 | using (ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge)) 39 | { 40 | IDestination destination = session.CreateTemporaryTopic(); 41 | using (IMessageConsumer consumer = session.CreateConsumer(destination)) 42 | using (IMessageProducer producer = session.CreateProducer(destination)) 43 | { 44 | producer.DeliveryMode = deliveryMode; 45 | producer.ProducerTransformer = DoProducerTransform; 46 | 47 | IMessage message = session.CreateMessage(); 48 | 49 | message.Properties["Test"] = "Value"; 50 | 51 | producer.Send(message); 52 | 53 | message = consumer.Receive(TimeSpan.FromMilliseconds(5000)); 54 | 55 | Assert.IsNotNull(message); 56 | Assert.IsTrue(message.Properties.Count == 2); 57 | 58 | Assert.AreEqual("Value", message.Properties["Test"]); 59 | Assert.AreEqual(propertyValue, message.Properties[propertyName]); 60 | } 61 | } 62 | } 63 | } 64 | 65 | [Test] 66 | public void TestConsumerTransformer( 67 | [Values(MsgDeliveryMode.Persistent, MsgDeliveryMode.NonPersistent)] 68 | MsgDeliveryMode deliveryMode) 69 | { 70 | using (IConnection connection = CreateConnection()) 71 | { 72 | connection.Start(); 73 | using (ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge)) 74 | { 75 | IDestination destination = session.CreateTemporaryTopic(); 76 | using (IMessageConsumer consumer = session.CreateConsumer(destination)) 77 | using (IMessageProducer producer = session.CreateProducer(destination)) 78 | { 79 | producer.DeliveryMode = deliveryMode; 80 | 81 | consumer.ConsumerTransformer = DoConsumerTransform; 82 | 83 | IMessage message = session.CreateMessage(); 84 | 85 | message.Properties["Test"] = "Value"; 86 | 87 | producer.Send(message); 88 | 89 | message = consumer.Receive(TimeSpan.FromMilliseconds(5000)); 90 | 91 | Assert.IsNotNull(message); 92 | Assert.IsTrue(message.Properties.Count == 2, "Property Count should be 2"); 93 | 94 | Assert.AreEqual("Value", message.Properties["Test"], "Propert 'Value' was incorrect"); 95 | Assert.AreEqual(propertyValue, message.Properties[propertyName], "Property not inserted"); 96 | } 97 | } 98 | } 99 | } 100 | 101 | private IMessage DoProducerTransform(ISession session, IMessageProducer producer, IMessage message) 102 | { 103 | message.Properties[propertyName] = propertyValue; 104 | 105 | return message; 106 | } 107 | 108 | private IMessage DoConsumerTransform(ISession session, IMessageConsumer consumer, IMessage message) 109 | { 110 | IMessage newMessage = session.CreateMessage(); 111 | 112 | MessageTransformation.CopyNMSMessageProperties(message, newMessage); 113 | 114 | newMessage.Properties[propertyName] = propertyValue; 115 | 116 | return newMessage; 117 | } 118 | } 119 | } -------------------------------------------------------------------------------- /src/nms-api/IMessage.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | using System; 19 | using System.Threading.Tasks; 20 | 21 | namespace Apache.NMS 22 | { 23 | /// 24 | /// Represents a message either to be sent to a message broker or received from a message broker. 25 | /// 26 | public interface IMessage 27 | { 28 | /// 29 | /// If using client acknowledgement mode on the session, then this method will acknowledge that the 30 | /// message has been processed correctly. 31 | /// 32 | void Acknowledge(); 33 | 34 | /// 35 | /// If using client acknowledgement mode on the session, then this method will acknowledge that the 36 | /// message has been processed correctly. 37 | /// 38 | Task AcknowledgeAsync(); 39 | 40 | /// 41 | /// Clears out the message body. Clearing a message's body does not clear its header 42 | /// values or property entries. 43 | /// 44 | /// If this message body was read-only, calling this method leaves the message body in 45 | /// the same state as an empty body in a newly created message. 46 | /// 47 | void ClearBody(); 48 | 49 | /// 50 | /// Clears a message's properties. 51 | /// 52 | /// The message's header fields and body are not cleared. 53 | /// 54 | void ClearProperties(); 55 | 56 | /// 57 | /// Provides access to the message properties (headers). 58 | /// 59 | IPrimitiveMap Properties { get; } 60 | 61 | /// 62 | /// The correlation ID used to correlate messages from conversations or long running business processes. 63 | /// 64 | string NMSCorrelationID { get; set; } 65 | 66 | /// 67 | /// The destination of the message. This property is set by the IMessageProducer. 68 | /// 69 | IDestination NMSDestination { get; set; } 70 | 71 | /// 72 | /// The amount of time for which this message is valid. Zero if this message does not expire. 73 | /// 74 | TimeSpan NMSTimeToLive { get; set; } 75 | 76 | /// 77 | /// The message ID which is set by the provider. 78 | /// 79 | string NMSMessageId { get; set; } 80 | 81 | /// 82 | /// Whether or not this message is persistent. 83 | /// 84 | MsgDeliveryMode NMSDeliveryMode { get; set; } 85 | 86 | /// 87 | /// The Priority of this message. 88 | /// 89 | MsgPriority NMSPriority { get; set; } 90 | 91 | /// 92 | /// Returns true if this message has been redelivered to this or another consumer before being acknowledged successfully. 93 | /// 94 | bool NMSRedelivered { get; set; } 95 | 96 | /// 97 | /// The destination that the consumer of this message should send replies to 98 | /// 99 | IDestination NMSReplyTo { get; set; } 100 | 101 | /// 102 | /// The timestamp of when the message was pubished in UTC time. If the publisher disables setting 103 | /// the timestamp on the message, the time will be set to the start of the UNIX epoc (1970-01-01 00:00:00). 104 | /// 105 | DateTime NMSTimestamp { get; set; } 106 | 107 | /// 108 | /// The type name of this message. 109 | /// 110 | string NMSType { get; set; } 111 | 112 | /// 113 | /// When a message is sent, the NMSDeliveryTime header field is 114 | /// left unassigned. After completion of the send or 115 | /// publish method, it holds the delivery time of the message. 116 | /// This is the the difference, measured in milliseconds, 117 | /// between the delivery time and midnight, January 1, 1970 UTC. 118 | /// 119 | /// A message's delivery time is the earliest time when a JMS provider may 120 | /// deliver the message to a consumer. The provider must not deliver messages 121 | /// before the delivery time has been reached. 122 | /// 123 | DateTime NMSDeliveryTime { get; set; } 124 | 125 | T Body(); 126 | 127 | bool IsBodyAssignableTo(Type type); 128 | } 129 | } -------------------------------------------------------------------------------- /test/nms-api-test/StreamMessageTest.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | using Apache.NMS.Util; 19 | using NUnit.Framework; 20 | 21 | namespace Apache.NMS.Test 22 | { 23 | [TestFixture] 24 | public class StreamMessageTest : NMSTestSupport 25 | { 26 | protected bool a = true; 27 | protected byte b = 123; 28 | protected char c = 'c'; 29 | protected short d = 0x1234; 30 | protected int e = 0x12345678; 31 | protected long f = 0x1234567812345678; 32 | protected string g = "Hello World!"; 33 | protected bool h = false; 34 | protected byte i = 0xFF; 35 | protected short j = -0x1234; 36 | protected int k = -0x12345678; 37 | protected long l = -0x1234567812345678; 38 | protected float m = 2.1F; 39 | protected double n = 2.3; 40 | 41 | [Test] 42 | public void SendReceiveStreamMessage( 43 | [Values(MsgDeliveryMode.Persistent, MsgDeliveryMode.NonPersistent)] 44 | MsgDeliveryMode deliveryMode) 45 | { 46 | using (IConnection connection = CreateConnection(GetTestClientId())) 47 | { 48 | connection.Start(); 49 | using (ISession session = connection.CreateSession(AcknowledgementMode.AutoAcknowledge)) 50 | { 51 | IDestination destination = CreateDestination(session, DestinationType.Queue); 52 | using (IMessageConsumer consumer = session.CreateConsumer(destination)) 53 | using (IMessageProducer producer = session.CreateProducer(destination)) 54 | { 55 | producer.DeliveryMode = deliveryMode; 56 | IStreamMessage request; 57 | 58 | try 59 | { 60 | request = session.CreateStreamMessage(); 61 | } 62 | catch (System.NotSupportedException) 63 | { 64 | return; 65 | } 66 | 67 | request.WriteBoolean(a); 68 | request.WriteByte(b); 69 | request.WriteChar(c); 70 | request.WriteInt16(d); 71 | request.WriteInt32(e); 72 | request.WriteInt64(f); 73 | request.WriteString(g); 74 | request.WriteBoolean(h); 75 | request.WriteByte(i); 76 | request.WriteInt16(j); 77 | request.WriteInt32(k); 78 | request.WriteInt64(l); 79 | request.WriteSingle(m); 80 | request.WriteDouble(n); 81 | producer.Send(request); 82 | 83 | IStreamMessage message = consumer.Receive(receiveTimeout) as IStreamMessage; 84 | Assert.IsNotNull(message, "No message returned!"); 85 | Assert.AreEqual(deliveryMode, message.NMSDeliveryMode, "NMSDeliveryMode does not match"); 86 | 87 | // use generic API to access entries 88 | Assert.AreEqual(a, message.ReadBoolean(), "Stream Boolean Value: a"); 89 | Assert.AreEqual(b, message.ReadByte(), "Stream Byte Value: b"); 90 | Assert.AreEqual(c, message.ReadChar(), "Stream Char Value: c"); 91 | Assert.AreEqual(d, message.ReadInt16(), "Stream Int16 Value: d"); 92 | Assert.AreEqual(e, message.ReadInt32(), "Stream Int32 Value: e"); 93 | Assert.AreEqual(f, message.ReadInt64(), "Stream Int64 Value: f"); 94 | Assert.AreEqual(g, message.ReadString(), "Stream String Value: g"); 95 | Assert.AreEqual(h, message.ReadBoolean(), "Stream Boolean Value: h"); 96 | Assert.AreEqual(i, message.ReadByte(), "Stream Byte Value: i"); 97 | Assert.AreEqual(j, message.ReadInt16(), "Stream Int16 Value: j"); 98 | Assert.AreEqual(k, message.ReadInt32(), "Stream Int32 Value: k"); 99 | Assert.AreEqual(l, message.ReadInt64(), "Stream Int64 Value: l"); 100 | Assert.AreEqual(m, message.ReadSingle(), "Stream Single Value: m"); 101 | Assert.AreEqual(n, message.ReadDouble(), "Stream Double Value: n"); 102 | } 103 | } 104 | } 105 | } 106 | } 107 | } -------------------------------------------------------------------------------- /src/nms-api/Util/XmlUtils.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | using System; 19 | using System.IO; 20 | using System.Text; 21 | using System.Text.RegularExpressions; 22 | using System.Xml; 23 | using System.Xml.Serialization; 24 | 25 | namespace Apache.NMS.Util 26 | { 27 | /// 28 | /// Class to provide support for working with Xml objects. 29 | /// 30 | public class XmlUtil 31 | { 32 | private static readonly XmlWriterSettings xmlWriterSettings; 33 | 34 | /// 35 | /// Static class constructor. 36 | /// 37 | static XmlUtil() 38 | { 39 | xmlWriterSettings = new XmlWriterSettings(); 40 | xmlWriterSettings.Encoding = new UTF8Encoding(false, false); 41 | } 42 | 43 | /// 44 | /// Serialize the object to XML format. The XML encoding will be UTF-8. A Byte Order Mark (BOM) 45 | /// will NOT be placed at the beginning of the string. 46 | /// 47 | /// 48 | /// 49 | public static string Serialize(object obj) 50 | { 51 | try 52 | { 53 | byte[] encodedBytes; 54 | 55 | using (MemoryStream outputStream = new MemoryStream()) 56 | using (XmlWriter xmlWriter = XmlWriter.Create(outputStream, xmlWriterSettings)) 57 | { 58 | XmlSerializer serializer = new XmlSerializer(obj.GetType()); 59 | 60 | // Set the error handlers. 61 | serializer.UnknownNode += serializer_UnknownNode; 62 | serializer.UnknownElement += serializer_UnknownElement; 63 | serializer.UnknownAttribute += serializer_UnknownAttribute; 64 | serializer.Serialize(xmlWriter, obj); 65 | encodedBytes = outputStream.ToArray(); 66 | } 67 | 68 | return xmlWriterSettings.Encoding.GetString(encodedBytes, 0, encodedBytes.Length); 69 | } 70 | catch (Exception ex) 71 | { 72 | Tracer.ErrorFormat("Error serializing object: {0}", ex.Message); 73 | return null; 74 | } 75 | } 76 | 77 | public static object Deserialize(Type objType, string text) 78 | { 79 | if (null == text) 80 | { 81 | return null; 82 | } 83 | 84 | try 85 | { 86 | XmlSerializer serializer = new XmlSerializer(objType); 87 | 88 | // Set the error handlers. 89 | serializer.UnknownNode += serializer_UnknownNode; 90 | serializer.UnknownElement += serializer_UnknownElement; 91 | serializer.UnknownAttribute += serializer_UnknownAttribute; 92 | return serializer.Deserialize(new StringReader(text)); 93 | } 94 | catch (Exception ex) 95 | { 96 | Tracer.ErrorFormat("Error deserializing object: {0}", ex.Message); 97 | return null; 98 | } 99 | } 100 | 101 | /// 102 | /// From xml spec valid chars: 103 | /// #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF] 104 | /// any Unicode character, excluding the surrogate blocks, FFFE, and FFFF. 105 | /// 106 | private const string invalidXMLMatch = @"[^\x09\x0A\x0D\x20-\xD7FF\xE000-\xFFFD\x10000-x10FFFF]"; 107 | 108 | private static readonly Regex regexInvalidXMLChars = new Regex(invalidXMLMatch); 109 | 110 | /// 111 | /// This removes characters that are invalid for xml encoding 112 | /// 113 | /// Text to be encoded. 114 | /// Text with invalid xml characters removed. 115 | public static string CleanInvalidXmlChars(string text) 116 | { 117 | return regexInvalidXMLChars.Replace(text, ""); 118 | } 119 | 120 | private static void serializer_UnknownNode(object sender, XmlNodeEventArgs e) 121 | { 122 | Tracer.ErrorFormat("Unknown Node: {0}\t{1}", e.Name, e.Text); 123 | } 124 | 125 | private static void serializer_UnknownElement(object sender, XmlElementEventArgs e) 126 | { 127 | Tracer.ErrorFormat("Unknown Element: {0}\t{1}", e.Element.Name, e.Element.Value); 128 | } 129 | 130 | private static void serializer_UnknownAttribute(object sender, XmlAttributeEventArgs e) 131 | { 132 | Tracer.ErrorFormat("Unknown attribute: {0}='{1}'", e.Attr.Name, e.Attr.Value); 133 | } 134 | } 135 | } --------------------------------------------------------------------------------