Exemplo n.º 1
0
        public virtual async Task <IActionResult> Index()
        {
            CurrentChannelProvider = ChannelResolver.GetCurrentChannelProvider(ChannelProviders);

            if (CurrentChannelProvider == null)
            {
                Response.StatusCode = 404;
                return(new EmptyResult());
            }

            var currentChannel = await CurrentChannelProvider.GetChannel();

            if (currentChannel == null)
            {
                Response.StatusCode = 404;
                return(new EmptyResult());
            }

            if (ShouldRedirect(currentChannel, HttpContext))
            {
                Response.Redirect(currentChannel.RemoteFeedUrl, false);
            }

            var xml = XmlFormatter.BuildXml(currentChannel);

            return(new XmlResult(xml));
        }
Exemplo n.º 2
0
        protected virtual AbstractEndpoint CreateEndpoint(IMessageHandler handler, MethodInfo method, List <Attribute> annotations)
        {
            AbstractEndpoint endpoint = null;
            var inputChannelName      = MessagingAttributeUtils.ResolveAttribute <string>(annotations, InputChannelProperty);

            if (!string.IsNullOrEmpty(inputChannelName))
            {
                IMessageChannel inputChannel;
                try
                {
                    inputChannel = ChannelResolver.ResolveDestination(inputChannelName);
                    if (inputChannel == null)
                    {
                        inputChannel = new DirectChannel(ApplicationContext, inputChannelName);
                        ApplicationContext.Register(inputChannelName, inputChannel);
                    }
                }
                catch (DestinationResolutionException)
                {
                    inputChannel = new DirectChannel(ApplicationContext, inputChannelName);
                    ApplicationContext.Register(inputChannelName, inputChannel);
                }

                endpoint = DoCreateEndpoint(handler, inputChannel, annotations);
            }

            return(endpoint);
        }
Exemplo n.º 3
0
        private IMessageChannel ResolveErrorChannel(Exception exception)
        {
            var actualThrowable = exception;

            if (exception is MessagingExceptionWrapperException)
            {
                actualThrowable = exception.InnerException;
            }

            var failedMessage = (actualThrowable is MessagingException) ? ((MessagingException)actualThrowable).FailedMessage : null;

            if (DefaultErrorChannel == null && ChannelResolver != null)
            {
                Channel = ChannelResolver.ResolveDestination(IntegrationContextUtils.ERROR_CHANNEL_BEAN_NAME);
            }

            if (failedMessage == null || failedMessage.Headers.ErrorChannel == null)
            {
                return(DefaultErrorChannel);
            }

            var errorChannelHeader = failedMessage.Headers.ErrorChannel;

            if (errorChannelHeader is IMessageChannel)
            {
                return((IMessageChannel)errorChannelHeader);
            }

            if (!(errorChannelHeader is string))
            {
                throw new ArgumentException("Unsupported error channel header type. Expected IMessageChannel or String, but actual type is [" + errorChannelHeader.GetType() + "]");
            }

            if (ChannelResolver != null)
            {
                return(ChannelResolver.ResolveDestination((string)errorChannelHeader)); // NOSONAR not null
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 4
0
        private IMessagingGateway CreateGatewayForMethod(MethodInfo method)
        {
            SimpleMessagingGateway gateway = new SimpleMessagingGateway(new MethodParameterMessageMapper(method), new SimpleMessageMapper());

            if (TaskScheduler != null)
            {
                gateway.TaskScheduler = TaskScheduler;
            }
            GatewayAttribute gatewayAttribute = null;

            object[] attr = method.GetCustomAttributes(typeof(GatewayAttribute), false);
            if (attr.Length == 1)
            {
                gatewayAttribute = attr[0] as GatewayAttribute;
            }

            IMessageChannel requestChannel = _defaultRequestChannel;
            IMessageChannel replyChannel   = _defaultReplyChannel;
            TimeSpan        requestTimeout = _defaultRequestTimeout;
            TimeSpan        replyTimeout   = _defaultReplyTimeout;

            if (gatewayAttribute != null)
            {
                AssertUtils.State(ChannelResolver != null, "ChannelResolver is required");
                string requestChannelName = gatewayAttribute.RequestChannel;
                if (StringUtils.HasText(requestChannelName))
                {
                    if (ChannelResolver == null)
                    {
                        throw new InvalidOperationException("ChannelResolvr must not be null");
                    }

                    requestChannel = ChannelResolver.ResolveChannelName(requestChannelName);

                    if (requestChannel == null)
                    {
                        throw new InvalidAsynchronousStateException("failed to resolve request channel '" + requestChannelName + "'");
                    }
                }

                string replyChannelName = gatewayAttribute.ReplyChannel;
                if (StringUtils.HasText(replyChannelName))
                {
                    if (ChannelResolver == null)
                    {
                        throw new InvalidOperationException("ChannelResolvr must not be null");
                    }

                    replyChannel = ChannelResolver.ResolveChannelName(replyChannelName);

                    if (replyChannel == null)
                    {
                        throw new InvalidAsynchronousStateException("failed to resolve reply channel '" + replyChannelName + "'");
                    }
                }
                requestTimeout = gatewayAttribute.RequestTimeout;
                replyTimeout   = gatewayAttribute.ReplyTimeout;
            }
            gateway.RequestChannel = requestChannel;
            gateway.ReplyChannel   = replyChannel;
            gateway.RequestTimeout = requestTimeout;
            gateway.ReplyTimeout   = replyTimeout;
            if (ObjectFactory != null)
            {
                gateway.ObjectFactory = ObjectFactory;
            }
            return(gateway);
        }