/// <exception cref="System.IO.IOException"/>
            public virtual void Handle(Org.Jboss.Netty.Channel.Channel channel, Org.Apache.Hadoop.Security.Token.Token
                                       <DelegationTokenIdentifier> token, string serviceUrl)
            {
                NUnit.Framework.Assert.AreEqual(this._enclosing.testToken, token);
                byte[] bytes = Sharpen.Runtime.GetBytesForString(TestDelegationTokenRemoteFetcher
                                                                 .ExpDate);
                ChannelBuffer cbuffer = ChannelBuffers.Buffer(bytes.Length);

                cbuffer.WriteBytes(bytes);
                HttpResponse response = new DefaultHttpResponse(HttpVersion.Http11, HttpResponseStatus
                                                                .Ok);

                response.SetHeader(HttpHeaders.Names.ContentLength, bytes.Length.ToString());
                response.SetContent(cbuffer);
                channel.Write(response).AddListener(ChannelFutureListener.Close);
            }
            /// <exception cref="System.IO.IOException"/>
            public virtual void Handle(Org.Jboss.Netty.Channel.Channel channel, Org.Apache.Hadoop.Security.Token.Token
                                       <DelegationTokenIdentifier> token, string serviceUrl)
            {
                NUnit.Framework.Assert.AreEqual(this._enclosing.testToken, token);
                Credentials creds = new Credentials();

                creds.AddToken(new Text(serviceUrl), token);
                DataOutputBuffer @out = new DataOutputBuffer();

                creds.Write(@out);
                int           fileLength = @out.GetData().Length;
                ChannelBuffer cbuffer    = ChannelBuffers.Buffer(fileLength);

                cbuffer.WriteBytes(@out.GetData());
                HttpResponse response = new DefaultHttpResponse(HttpVersion.Http11, HttpResponseStatus
                                                                .Ok);

                response.SetHeader(HttpHeaders.Names.ContentLength, fileLength.ToString());
                response.SetContent(cbuffer);
                channel.Write(response).AddListener(ChannelFutureListener.Close);
            }
Пример #3
0
            public int WriteRaw(ChannelBuffer buf, String str)
            {
                if (str == null)
                {
                    str = "null";
                }

                byte[] data = _mEncoding.GetBytes(str);

                int len = data.Length;
                int count = len;
                int offset = 0;

                for (int i = 0; i < len; i++)
                {
                    byte b = data[i];

                    if (b == '\t' || b == '\r' || b == '\n' || b == '\\')
                    {
                        buf.WriteBytes(data, offset, i - offset);
                        buf.WriteByte('\\');

                        if (b == '\t')
                        {
                            buf.WriteByte('t');
                        }
                        else if (b == '\r')
                        {
                            buf.WriteByte('r');
                        }
                        else if (b == '\n')
                        {
                            buf.WriteByte('n');
                        }
                        else
                        {
                            buf.WriteByte(b);
                        }

                        count++;
                        offset = i + 1;
                    }
                }

                if (len > offset)
                {
                    buf.WriteBytes(data, offset, len - offset);
                }

                return count;
            }
Пример #4
0
            public int Write(ChannelBuffer buf, String str)
            {
                if (str == null)
                {
                    str = "null";
                }

                byte[] data = _mEncoding.GetBytes(str);

                buf.WriteBytes(data);
                return data.Length;
            }