public object Create(object parent, object configContext, XmlNode section)
        {
            var result = new RemoraConfig();

            foreach (XmlAttribute attr in section.Attributes)
            {
                switch (attr.Name.ToLowerInvariant())
                {
                    case "maxmessagesize":
                        int maxMessageSizeValue;
                        if (Int32.TryParse(attr.Value, NumberStyles.Integer, CultureInfo.InvariantCulture,
                                           out maxMessageSizeValue))
                            result.MaxMessageSize = maxMessageSizeValue;
                        break;
                    default:
                        result.Properties.Add(attr.Name, attr.Value);
                        break;
                }
            }

            var pipelineNodes = section.SelectNodes("/" + ConfigurationSectionName + "/pipelines/pipeline");

            var pipelineDefs = new List<IPipelineDefinition>();
            foreach (XmlNode pipelineNode in pipelineNodes)
            {
                var pipelineDef = new PipelineDefinition();
                foreach (XmlAttribute attr in pipelineNode.Attributes)
                {
                    switch (attr.Name.ToLowerInvariant())
                    {
                        case "id":
                            pipelineDef.Id = attr.Value;
                            break;
                        case "filter":
                            pipelineDef.UriFilterRegex = attr.Value;
                            break;
                        case "rewrite":
                            pipelineDef.UriRewriteRegex = attr.Value;
                            break;
                        case "clientcertificatefilepath":
                            pipelineDef.ClientCertificateFilePath = attr.Value;
                            break;
                        case "clientcertificatepassword":
                            pipelineDef.ClientCertificatePassword = attr.Value;
                            break;
                        default:
                            pipelineDef.Properties.Add(attr.Name, attr.Value);
                            break;
                    }
                }

                pipelineDef.ComponentDefinitions = ParseComponents(pipelineNode);

                pipelineDefs.Add(pipelineDef);
            }

            result.PipelineDefinitions = pipelineDefs;

            return result;
        }
示例#2
0
        public void It_should_create_an_appropriate_pipeline()
        {
            var container = new WindsorContainer();
            container.Register(Component.For<IPipelineComponent>().ImplementedBy<TestComponentOne>().Named("cmpOne"));
            container.Register(Component.For<IPipelineComponent>().ImplementedBy<TestComponentTwo>().Named("cmpTwo"));

            var pipelineDef1 = PDef("pipe1", "/foo/(.*)", "");
            var pipelineDef2 = PDef("pipe2", "/(.*)", "", "cmpOne", "cmpTwo");
            var config = new RemoraConfig {PipelineDefinitions = new[] {pipelineDef1, pipelineDef2}};

            var factory = new PipelineFactory(container.Kernel, config) {Logger = GetConsoleLogger()};

            var operation1 = new RemoraOperation {IncomingUri = new Uri("http://tempuri.org/foo/something")};
            var result1 = factory.Get(operation1);

            Assert.That(result1.Id, Is.EqualTo(pipelineDef1.Id));
            Assert.That(result1.Components.Count(), Is.EqualTo(0));
            Assert.That(result1.Definition, Is.SameAs(pipelineDef1));
            Assert.That(operation1.ExecutingPipeline, Is.SameAs(result1));
        }
示例#3
0
        public void It_should_rewrite_url_if_present()
        {
            var container = new WindsorContainer();

            var pipelineDef1 = PDef("pipe1", "http(s)?://.*/bar/(.*)", "http://tempuri2.org/$2");
            var pipelineDef2 = PDef("pipe2", "/(.*)", "");
            var config = new RemoraConfig {PipelineDefinitions = new[] {pipelineDef1, pipelineDef2}};

            var factory = new PipelineFactory(container.Kernel, config) {Logger = GetConsoleLogger()};

            var operation1 = new RemoraOperation {IncomingUri = new Uri("http://tempuri.org/bar/foobar?welcome")};
            var result1 = factory.Get(operation1);

            Assert.That(operation1.Request.Uri, Is.EqualTo(new Uri("http://tempuri2.org/foobar?welcome")));

            var operation2 = new RemoraOperation {IncomingUri = new Uri("http://tempuri.org/foo")};
            var result2 = factory.Get(operation2);

            Assert.That(operation2.Request.Uri, Is.Null);
        }
示例#4
0
        public void It_should_throw_UrlRewriteException_when_urlrewriting_fails()
        {
            var container = new WindsorContainer();

            var pipelineDef1 = PDef("pipe", ".*", "foo");
            var config = new RemoraConfig {PipelineDefinitions = new[] {pipelineDef1}};

            var factory = new PipelineFactory(container.Kernel, config) {Logger = GetConsoleLogger()};

            var operation = new RemoraOperation {IncomingUri = new Uri("http://tempuri.org/")};
            Assert.That(() => factory.Get(operation),
                        Throws.Exception.TypeOf<UrlRewriteException>()
                            .With.Message.Contains(".*")
                            .And.Message.Contains("foo")
                );
        }
示例#5
0
        public void It_should_throw_InvalidConfigurationException_when_filter_regex_is_invalid()
        {
            var container = new WindsorContainer();

            var pipelineDef1 = PDef("pipe", "(((", "");
            var config = new RemoraConfig {PipelineDefinitions = new[] {pipelineDef1}};

            var factory = new PipelineFactory(container.Kernel, config) {Logger = GetConsoleLogger()};

            var operation = new RemoraOperation {IncomingUri = new Uri("http://tempuri.org/")};
            Assert.That(() => factory.Get(operation),
                        Throws.Exception.TypeOf<InvalidConfigurationException>()
                            .With.Message.Contains("(((")
                );
        }
示例#6
0
        public void It_should_select_the_first_available_when_ambiguous()
        {
            var container = new WindsorContainer();
            container.Register(Component.For<IPipelineComponent>().ImplementedBy<TestComponentOne>().Named("cmpOne"));
            container.Register(Component.For<IPipelineComponent>().ImplementedBy<TestComponentTwo>().Named("cmpTwo"));

            var pipelineDef1 = PDef("pipe1", "/bar/(.*)", "");
            var pipelineDef2 = PDef("pipe2", "/(.*)", "", "cmpOne", "cmpTwo");
            var pipelineDef3 = PDef("pipe3", "/foo/(.*)", "", "cmpOne", "cmpTwo");
            var config = new RemoraConfig {PipelineDefinitions = new[] {pipelineDef1, pipelineDef2, pipelineDef3}};

            var factory = new PipelineFactory(container.Kernel, config) {Logger = GetConsoleLogger()};

            var operation1 = new RemoraOperation {IncomingUri = new Uri("http://tempuri.org/foo/something")};
            var result1 = factory.Get(operation1);

            Assert.That(result1.Id, Is.EqualTo(pipelineDef2.Id));
            Assert.That(result1.Components.Count(), Is.EqualTo(2));
            Assert.That(result1.Components.First(), Is.TypeOf<TestComponentOne>());
            Assert.That(result1.Components.Skip(1).First(), Is.TypeOf<TestComponentTwo>());
        }